Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@@ -18,7 +18,7 @@ package sample;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.boot.configurationprocessor.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
|
||||
@@ -34,11 +34,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ConfigurationProcessorIntegrationTests {
|
||||
class ConfigurationProcessorIntegrationTests {
|
||||
|
||||
private static ConfigurationMetadataRepository repository;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void readMetadata() throws IOException {
|
||||
Resource resource = new ClassPathResource("META-INF/spring-configuration-metadata.json");
|
||||
assertThat(resource.exists()).isTrue();
|
||||
@@ -49,7 +49,7 @@ public class ConfigurationProcessorIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractTypeFromAnnotatedGetter() {
|
||||
void extractTypeFromAnnotatedGetter() {
|
||||
ConfigurationMetadataProperty property = repository.getAllProperties().get("annotated.name");
|
||||
assertThat(property).isNotNull();
|
||||
assertThat(property.getType()).isEqualTo("java.lang.String");
|
||||
|
||||
@@ -28,15 +28,11 @@ import net.bytebuddy.description.annotation.AnnotationDescription;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.dynamic.DynamicType.Builder;
|
||||
import net.bytebuddy.implementation.FixedValue;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
@@ -52,41 +48,34 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class DevToolsIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder temp = new TemporaryFolder();
|
||||
@TempDir
|
||||
static File temp;
|
||||
|
||||
private static final BuildOutput buildOutput = new BuildOutput(DevToolsIntegrationTests.class);
|
||||
|
||||
private LaunchedApplication launchedApplication;
|
||||
|
||||
private final File serverPortFile;
|
||||
private final File serverPortFile = new File(buildOutput.getRootLocation(), "server.port");
|
||||
|
||||
private final ApplicationLauncher applicationLauncher;
|
||||
@RegisterExtension
|
||||
final JvmLauncher javaLauncher = new JvmLauncher();
|
||||
|
||||
@Rule
|
||||
public JvmLauncher javaLauncher = new JvmLauncher();
|
||||
|
||||
public DevToolsIntegrationTests(ApplicationLauncher applicationLauncher) {
|
||||
this.applicationLauncher = applicationLauncher;
|
||||
this.serverPortFile = new File(DevToolsIntegrationTests.buildOutput.getRootLocation(), "server.port");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void launchApplication() throws Exception {
|
||||
private void launchApplication(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
this.serverPortFile.delete();
|
||||
this.launchedApplication = this.applicationLauncher.launchApplication(this.javaLauncher, this.serverPortFile);
|
||||
this.launchedApplication = applicationLauncher.launchApplication(this.javaLauncher, this.serverPortFile);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopApplication() throws InterruptedException {
|
||||
this.launchedApplication.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addARequestMappingToAnExistingController() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void addARequestMappingToAnExistingController(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -98,8 +87,11 @@ public class DevToolsIntegrationTests {
|
||||
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeARequestMappingFromAnExistingController() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void removeARequestMappingFromAnExistingController(ApplicationLauncher applicationLauncher)
|
||||
throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -109,8 +101,10 @@ public class DevToolsIntegrationTests {
|
||||
.isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAController() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void createAController(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -123,8 +117,10 @@ public class DevToolsIntegrationTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAControllerAndThenAddARequestMapping() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void createAControllerAndThenAddARequestMapping(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -139,8 +135,11 @@ public class DevToolsIntegrationTests {
|
||||
assertThat(template.getForObject(urlBase + "/three", String.class)).isEqualTo("three");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAControllerAndThenAddARequestMappingToAnExistingController() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void createAControllerAndThenAddARequestMappingToAnExistingController(
|
||||
ApplicationLauncher applicationLauncher) throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -157,8 +156,10 @@ public class DevToolsIntegrationTests {
|
||||
assertThat(template.getForObject(urlBase + "/three", String.class)).isEqualTo("three");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteAController() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void deleteAController(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -170,8 +171,10 @@ public class DevToolsIntegrationTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAControllerAndThenDeleteIt() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void createAControllerAndThenDeleteIt(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -215,8 +218,7 @@ public class DevToolsIntegrationTests {
|
||||
return new ControllerBuilder(name, this.launchedApplication.getClassesDirectory());
|
||||
}
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() throws IOException {
|
||||
static Object[] parameters() throws IOException {
|
||||
Directories directories = new Directories(buildOutput, temp);
|
||||
return new Object[] { new Object[] { new LocalApplicationLauncher(directories) },
|
||||
new Object[] { new ExplodedRemoteApplicationLauncher(directories) },
|
||||
|
||||
@@ -28,14 +28,11 @@ import net.bytebuddy.description.annotation.AnnotationDescription;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.implementation.FixedValue;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
@@ -51,42 +48,36 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class DevToolsWithLazyInitializationIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder temp = new TemporaryFolder();
|
||||
@TempDir
|
||||
static File temp;
|
||||
|
||||
private static final BuildOutput buildOutput = new BuildOutput(DevToolsIntegrationTests.class);
|
||||
|
||||
private LaunchedApplication launchedApplication;
|
||||
|
||||
private final File serverPortFile;
|
||||
private final File serverPortFile = new File(buildOutput.getRootLocation(), "server.port");
|
||||
|
||||
private final ApplicationLauncher applicationLauncher;
|
||||
@RegisterExtension
|
||||
final JvmLauncher javaLauncher = new JvmLauncher();
|
||||
|
||||
@Rule
|
||||
public JvmLauncher javaLauncher = new JvmLauncher();
|
||||
|
||||
public DevToolsWithLazyInitializationIntegrationTests(ApplicationLauncher applicationLauncher) {
|
||||
this.applicationLauncher = applicationLauncher;
|
||||
this.serverPortFile = new File(buildOutput.getRootLocation(), "server.port");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void launchApplication() throws Exception {
|
||||
private void launchApplication(ApplicationLauncher applicationLauncher) throws Exception {
|
||||
this.serverPortFile.delete();
|
||||
this.launchedApplication = this.applicationLauncher.launchApplication(this.javaLauncher, this.serverPortFile,
|
||||
this.launchedApplication = applicationLauncher.launchApplication(this.javaLauncher, this.serverPortFile,
|
||||
"--spring.main.lazy-initialization=true");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stopApplication() throws InterruptedException {
|
||||
this.launchedApplication.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addARequestMappingToAnExistingControllerWhenLazyInit() throws Exception {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("parameters")
|
||||
public void addARequestMappingToAnExistingControllerWhenLazyInit(ApplicationLauncher applicationLauncher)
|
||||
throws Exception {
|
||||
launchApplication(applicationLauncher);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
String urlBase = "http://localhost:" + awaitServerPort();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
@@ -125,8 +116,7 @@ public class DevToolsWithLazyInitializationIntegrationTests {
|
||||
return new ControllerBuilder(name, this.launchedApplication.getClassesDirectory());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Object[] parameters() throws IOException {
|
||||
static Object[] parameters() throws IOException {
|
||||
Directories directories = new Directories(buildOutput, temp);
|
||||
return new Object[] { new Object[] { new LocalApplicationLauncher(directories) },
|
||||
new Object[] { new ExplodedRemoteApplicationLauncher(directories) },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,6 @@ package org.springframework.boot.devtools.tests;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
|
||||
/**
|
||||
@@ -31,9 +29,9 @@ class Directories {
|
||||
|
||||
private final BuildOutput buildOutput;
|
||||
|
||||
private final TemporaryFolder temp;
|
||||
private final File temp;
|
||||
|
||||
Directories(BuildOutput buildOutput, TemporaryFolder temp) {
|
||||
Directories(BuildOutput buildOutput, File temp) {
|
||||
this.buildOutput = buildOutput;
|
||||
this.temp = temp;
|
||||
}
|
||||
@@ -43,7 +41,7 @@ class Directories {
|
||||
}
|
||||
|
||||
File getRemoteAppDirectory() {
|
||||
return new File(this.temp.getRoot(), "remote");
|
||||
return new File(this.temp, "remote");
|
||||
}
|
||||
|
||||
File getDependenciesDirectory() {
|
||||
@@ -51,7 +49,7 @@ class Directories {
|
||||
}
|
||||
|
||||
File getAppDirectory() {
|
||||
return new File(this.temp.getRoot(), "app");
|
||||
return new File(this.temp, "app");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
|
||||
import org.junit.jupiter.api.extension.Extension;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* JUnit {@link TestRule} that launched a JVM and redirects its output to a test
|
||||
* {@link Extension} that launches a JVM and redirects its output to a test
|
||||
* method-specific location.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class JvmLauncher implements TestRule {
|
||||
class JvmLauncher implements BeforeTestExecutionCallback {
|
||||
|
||||
private static final Pattern NON_ALPHABET_PATTERN = Pattern.compile("[^A-Za-z]+");
|
||||
|
||||
@@ -45,11 +45,10 @@ class JvmLauncher implements TestRule {
|
||||
private File outputDirectory;
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
public void beforeTestExecution(ExtensionContext context) throws Exception {
|
||||
this.outputDirectory = new File(this.buildOutput.getRootLocation(),
|
||||
"output/" + NON_ALPHABET_PATTERN.matcher(description.getMethodName()).replaceAll(""));
|
||||
"output/" + NON_ALPHABET_PATTERN.matcher(context.getRequiredTestMethod().getName()).replaceAll(""));
|
||||
this.outputDirectory.mkdirs();
|
||||
return base;
|
||||
}
|
||||
|
||||
LaunchedJvm launch(String name, String classpath, String... args) throws IOException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package org.springframework.boot.tests.hibernate52;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class Hibernate52ApplicationTests {
|
||||
|
||||
|
||||
@@ -46,18 +46,14 @@ import com.github.dockerjava.core.util.CompressArchiveUtil;
|
||||
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec;
|
||||
import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.boot.ansi.AnsiColor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
|
||||
/**
|
||||
* Integration tests for Spring Boot's launch script on OSs that use SysVinit.
|
||||
@@ -65,19 +61,213 @@ import static org.junit.Assume.assumeThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Ali Shahbour
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class SysVinitLaunchScriptIT {
|
||||
|
||||
private final SpringBootDockerCmdExecFactory commandExecFactory = new SpringBootDockerCmdExecFactory();
|
||||
|
||||
private static final char ESC = 27;
|
||||
|
||||
private final String os;
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void statusWhenStopped(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "status-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 3");
|
||||
assertThat(output).has(coloredString(AnsiColor.RED, "Not running"));
|
||||
}
|
||||
|
||||
private final String version;
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void statusWhenStarted(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "status-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Parameters(name = "{0} {1}")
|
||||
public static List<Object[]> parameters() {
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void statusWhenKilled(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "status-when-killed.sh");
|
||||
assertThat(output).contains("Status: 1");
|
||||
assertThat(output)
|
||||
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void stopWhenStopped(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "stop-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void forceStopWhenStopped(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "force-stop-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void startWhenStarted(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "start-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Already running [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void restartWhenStopped(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "restart-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void restartWhenStarted(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "restart-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID2", output) + "]"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void startWhenStopped(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "start-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void basicLaunch(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "basic-launch.sh");
|
||||
assertThat(output).doesNotContain("PID_FOLDER");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithMissingLogFolderGeneratesAWarning(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "launch-with-missing-log-folder.sh");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.YELLOW, "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithMissingPidFolderGeneratesAWarning(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "launch-with-missing-pid-folder.sh");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.YELLOW, "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithSingleCommandLineArgument(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-single-command-line-argument.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithMultipleCommandLineArguments(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-multiple-command-line-arguments.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithSingleRunArg(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-single-run-arg.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithMultipleRunArgs(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-multiple-run-args.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithSingleJavaOpt(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-single-java-opt.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithDoubleLinkSingleJavaOpt(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-double-link-single-java-opt.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithMultipleJavaOpts(String os, String version) throws Exception {
|
||||
doLaunch(os, version, "launch-with-multiple-java-opts.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithUseOfStartStopDaemonDisabled(String os, String version) throws Exception {
|
||||
// CentOS doesn't have start-stop-daemon
|
||||
Assumptions.assumeFalse(os.equals("CentOS"));
|
||||
doLaunch(os, version, "launch-with-use-of-start-stop-daemon-disabled.sh");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithRelativePidFolder(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "launch-with-relative-pid-folder.sh");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void pidFolderOwnership(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "pid-folder-ownership.sh");
|
||||
assertThat(output).contains("phil root");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void pidFileOwnership(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "pid-file-ownership.sh");
|
||||
assertThat(output).contains("phil root");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void logFileOwnership(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "log-file-ownership.sh");
|
||||
assertThat(output).contains("phil root");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void logFileOwnershipIsChangedWhenCreated(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "log-file-ownership-is-changed-when-created.sh");
|
||||
assertThat(output).contains("andy root");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void logFileOwnershipIsUnchangedWhenExists(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "log-file-ownership-is-unchanged-when-exists.sh");
|
||||
assertThat(output).contains("root root");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("parameters")
|
||||
public void launchWithRelativeLogFolder(String os, String version) throws Exception {
|
||||
String output = doTest(os, version, "launch-with-relative-log-folder.sh");
|
||||
assertThat(output).contains("Log written");
|
||||
}
|
||||
|
||||
static List<Object[]> parameters() {
|
||||
List<Object[]> parameters = new ArrayList<>();
|
||||
for (File os : new File("src/test/resources/conf").listFiles()) {
|
||||
for (File version : os.listFiles()) {
|
||||
@@ -87,191 +277,13 @@ public class SysVinitLaunchScriptIT {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public SysVinitLaunchScriptIT(String os, String version) {
|
||||
this.os = os;
|
||||
this.version = version;
|
||||
private void doLaunch(String os, String version, String script) throws Exception {
|
||||
assertThat(doTest(os, version, script)).contains("Launched");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusWhenStopped() throws Exception {
|
||||
String output = doTest("status-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 3");
|
||||
assertThat(output).has(coloredString(AnsiColor.RED, "Not running"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusWhenStarted() throws Exception {
|
||||
String output = doTest("status-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusWhenKilled() throws Exception {
|
||||
String output = doTest("status-when-killed.sh");
|
||||
assertThat(output).contains("Status: 1");
|
||||
assertThat(output)
|
||||
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopWhenStopped() throws Exception {
|
||||
String output = doTest("stop-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forceStopWhenStopped() throws Exception {
|
||||
String output = doTest("force-stop-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWhenStarted() throws Exception {
|
||||
String output = doTest("start-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Already running [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restartWhenStopped() throws Exception {
|
||||
String output = doTest("restart-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restartWhenStarted() throws Exception {
|
||||
String output = doTest("restart-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID2", output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWhenStopped() throws Exception {
|
||||
String output = doTest("start-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicLaunch() throws Exception {
|
||||
String output = doTest("basic-launch.sh");
|
||||
assertThat(output).doesNotContain("PID_FOLDER");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithMissingLogFolderGeneratesAWarning() throws Exception {
|
||||
String output = doTest("launch-with-missing-log-folder.sh");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.YELLOW, "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithMissingPidFolderGeneratesAWarning() throws Exception {
|
||||
String output = doTest("launch-with-missing-pid-folder.sh");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.YELLOW, "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithSingleCommandLineArgument() throws Exception {
|
||||
doLaunch("launch-with-single-command-line-argument.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithMultipleCommandLineArguments() throws Exception {
|
||||
doLaunch("launch-with-multiple-command-line-arguments.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithSingleRunArg() throws Exception {
|
||||
doLaunch("launch-with-single-run-arg.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithMultipleRunArgs() throws Exception {
|
||||
doLaunch("launch-with-multiple-run-args.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithSingleJavaOpt() throws Exception {
|
||||
doLaunch("launch-with-single-java-opt.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithDoubleLinkSingleJavaOpt() throws Exception {
|
||||
doLaunch("launch-with-double-link-single-java-opt.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithMultipleJavaOpts() throws Exception {
|
||||
doLaunch("launch-with-multiple-java-opts.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithUseOfStartStopDaemonDisabled() throws Exception {
|
||||
// CentOS doesn't have start-stop-daemon
|
||||
assumeThat(this.os, is(not("CentOS")));
|
||||
doLaunch("launch-with-use-of-start-stop-daemon-disabled.sh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithRelativePidFolder() throws Exception {
|
||||
String output = doTest("launch-with-relative-pid-folder.sh");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pidFolderOwnership() throws Exception {
|
||||
String output = doTest("pid-folder-ownership.sh");
|
||||
assertThat(output).contains("phil root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pidFileOwnership() throws Exception {
|
||||
String output = doTest("pid-file-ownership.sh");
|
||||
assertThat(output).contains("phil root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logFileOwnership() throws Exception {
|
||||
String output = doTest("log-file-ownership.sh");
|
||||
assertThat(output).contains("phil root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logFileOwnershipIsChangedWhenCreated() throws Exception {
|
||||
String output = doTest("log-file-ownership-is-changed-when-created.sh");
|
||||
assertThat(output).contains("andy root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logFileOwnershipIsUnchangedWhenExists() throws Exception {
|
||||
String output = doTest("log-file-ownership-is-unchanged-when-exists.sh");
|
||||
assertThat(output).contains("root root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithRelativeLogFolder() throws Exception {
|
||||
String output = doTest("launch-with-relative-log-folder.sh");
|
||||
assertThat(output).contains("Log written");
|
||||
}
|
||||
|
||||
private void doLaunch(String script) throws Exception {
|
||||
assertThat(doTest(script)).contains("Launched");
|
||||
}
|
||||
|
||||
private String doTest(String script) throws Exception {
|
||||
private String doTest(String os, String version, String script) throws Exception {
|
||||
DockerClient docker = createClient();
|
||||
String imageId = buildImage(docker);
|
||||
String imageId = buildImage(os, version, docker);
|
||||
String container = createContainer(docker, imageId, script);
|
||||
try {
|
||||
copyFilesToContainer(docker, container, script);
|
||||
@@ -309,9 +321,9 @@ public class SysVinitLaunchScriptIT {
|
||||
return DockerClientBuilder.getInstance(config).withDockerCmdExecFactory(this.commandExecFactory).build();
|
||||
}
|
||||
|
||||
private String buildImage(DockerClient docker) {
|
||||
String dockerfile = "src/test/resources/conf/" + this.os + "/" + this.version + "/Dockerfile";
|
||||
String tag = "spring-boot-it/" + this.os.toLowerCase(Locale.ENGLISH) + ":" + this.version;
|
||||
private String buildImage(String os, String version, DockerClient docker) {
|
||||
String dockerfile = "src/test/resources/conf/" + os + "/" + version + "/Dockerfile";
|
||||
String tag = "spring-boot-it/" + os.toLowerCase(Locale.ENGLISH) + ":" + version;
|
||||
BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
|
||||
|
||||
private List<BuildResponseItem> items = new ArrayList<>();
|
||||
|
||||
@@ -24,7 +24,9 @@ import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.rules.ExternalResource;
|
||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -32,12 +34,11 @@ import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Base {@link ExternalResource} for launching a Spring Boot application as part of a
|
||||
* JUnit test.
|
||||
* Base class for launching a Spring Boot application as part of a JUnit test.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
abstract class AbstractApplicationLauncher extends ExternalResource {
|
||||
abstract class AbstractApplicationLauncher implements BeforeEachCallback, AfterEachCallback {
|
||||
|
||||
private final ApplicationBuilder applicationBuilder;
|
||||
|
||||
@@ -53,13 +54,13 @@ abstract class AbstractApplicationLauncher extends ExternalResource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void before() throws Throwable {
|
||||
this.process = startApplication();
|
||||
public void afterEach(ExtensionContext context) throws Exception {
|
||||
this.process.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void after() {
|
||||
this.process.destroy();
|
||||
public void beforeEach(ExtensionContext context) throws Exception {
|
||||
this.process = startApplication();
|
||||
}
|
||||
|
||||
public final int getHttpPort() {
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
/**
|
||||
* Base class for embedded servlet container integration tests.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class AbstractEmbeddedServletContainerIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder temporaryFolder = new TemporaryFolder() {
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final BuildOutput buildOutput = new BuildOutput(
|
||||
AbstractEmbeddedServletContainerIntegrationTests.class);
|
||||
|
||||
@Rule
|
||||
public final AbstractApplicationLauncher launcher;
|
||||
|
||||
protected final RestTemplate rest = new RestTemplate();
|
||||
|
||||
public static Object[] parameters(String packaging,
|
||||
List<Class<? extends AbstractApplicationLauncher>> applicationLaunchers) {
|
||||
List<Object> parameters = new ArrayList<>();
|
||||
parameters.addAll(createParameters(packaging, "jetty", applicationLaunchers));
|
||||
parameters.addAll(createParameters(packaging, "tomcat", applicationLaunchers));
|
||||
parameters.addAll(createParameters(packaging, "undertow", applicationLaunchers));
|
||||
return parameters.toArray(new Object[0]);
|
||||
}
|
||||
|
||||
private static List<Object> createParameters(String packaging, String container,
|
||||
List<Class<? extends AbstractApplicationLauncher>> applicationLaunchers) {
|
||||
List<Object> parameters = new ArrayList<>();
|
||||
ApplicationBuilder applicationBuilder = new ApplicationBuilder(temporaryFolder, packaging, container);
|
||||
for (Class<? extends AbstractApplicationLauncher> launcherClass : applicationLaunchers) {
|
||||
try {
|
||||
AbstractApplicationLauncher launcher = launcherClass
|
||||
.getDeclaredConstructor(ApplicationBuilder.class, BuildOutput.class)
|
||||
.newInstance(applicationBuilder, buildOutput);
|
||||
String name = StringUtils.capitalize(container) + ": " + launcher.getDescription(packaging);
|
||||
parameters.add(new Object[] { name, launcher });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
protected AbstractEmbeddedServletContainerIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
this.launcher = launcher;
|
||||
this.rest.setErrorHandler(new ResponseErrorHandler() {
|
||||
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse response) throws IOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
this.rest.setUriTemplateHandler(new UriTemplateHandler() {
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Object... uriVariables) {
|
||||
return URI.create("http://localhost:" + launcher.getHttpPort() + uriTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Map<String, ?> uriVariables) {
|
||||
return URI.create("http://localhost:" + launcher.getHttpPort() + uriTemplate);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -33,7 +34,6 @@ import org.apache.maven.shared.invoker.DefaultInvoker;
|
||||
import org.apache.maven.shared.invoker.InvocationRequest;
|
||||
import org.apache.maven.shared.invoker.InvocationResult;
|
||||
import org.apache.maven.shared.invoker.MavenInvocationException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -48,26 +48,34 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class ApplicationBuilder {
|
||||
|
||||
private final TemporaryFolder temp;
|
||||
private final Path temp;
|
||||
|
||||
private final String packaging;
|
||||
|
||||
private final String container;
|
||||
|
||||
ApplicationBuilder(TemporaryFolder temp, String packaging, String container) {
|
||||
ApplicationBuilder(Path temp, String packaging, String container) {
|
||||
this.temp = temp;
|
||||
this.packaging = packaging;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
File buildApplication() throws Exception {
|
||||
File containerFolder = new File(this.temp.getRoot(), this.container);
|
||||
File containerFolder = new File(this.temp.toFile(), this.container);
|
||||
if (containerFolder.exists()) {
|
||||
return new File(containerFolder, "app/target/app-0.0.1." + this.packaging);
|
||||
}
|
||||
return doBuildApplication(containerFolder);
|
||||
}
|
||||
|
||||
String getPackaging() {
|
||||
return this.packaging;
|
||||
}
|
||||
|
||||
String getContainer() {
|
||||
return this.container;
|
||||
}
|
||||
|
||||
private File doBuildApplication(File containerFolder) throws IOException, MavenInvocationException {
|
||||
File resourcesJar = createResourcesJar();
|
||||
File appFolder = new File(containerFolder, "app");
|
||||
@@ -80,7 +88,7 @@ class ApplicationBuilder {
|
||||
}
|
||||
|
||||
private File createResourcesJar() throws IOException {
|
||||
File resourcesJar = new File(this.temp.getRoot(), "resources.jar");
|
||||
File resourcesJar = new File(this.temp.toFile(), "resources.jar");
|
||||
if (resourcesJar.exists()) {
|
||||
return resourcesJar;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
||||
import org.junit.jupiter.api.extension.Extension;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ParameterContext;
|
||||
import org.junit.jupiter.api.extension.ParameterResolutionException;
|
||||
import org.junit.jupiter.api.extension.ParameterResolver;
|
||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
||||
import org.junit.platform.commons.util.ReflectionUtils;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
/**
|
||||
* {@link TestTemplateInvocationContextProvider} for templated
|
||||
* {@link EmbeddedServletContainerTest embedded servlet container tests}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class EmbeddedServerContainerInvocationContextProvider
|
||||
implements TestTemplateInvocationContextProvider, AfterAllCallback {
|
||||
|
||||
private static final Set<String> CONTAINERS = new HashSet<>(Arrays.asList("jetty", "tomcat", "undertow"));
|
||||
|
||||
private static final BuildOutput buildOutput = new BuildOutput(
|
||||
EmbeddedServerContainerInvocationContextProvider.class);
|
||||
|
||||
private final Path tempDir;
|
||||
|
||||
public EmbeddedServerContainerInvocationContextProvider() throws IOException {
|
||||
this.tempDir = Files.createTempDirectory("embedded-servlet-container-tests");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTestTemplate(ExtensionContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
|
||||
EmbeddedServletContainerTest annotation = context.getRequiredTestClass()
|
||||
.getAnnotation(EmbeddedServletContainerTest.class);
|
||||
return CONTAINERS.stream()
|
||||
.map((container) -> new ApplicationBuilder(this.tempDir, annotation.packaging(), container))
|
||||
.flatMap((builder) -> {
|
||||
return Stream.of(annotation.launchers())
|
||||
.map((launcherClass) -> ReflectionUtils.newInstance(launcherClass, builder, buildOutput))
|
||||
.map((launcher) -> new EmbeddedServletContainerInvocationContext(
|
||||
StringUtils.capitalize(builder.getContainer()) + ": "
|
||||
+ launcher.getDescription(builder.getPackaging()),
|
||||
launcher));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterAll(ExtensionContext context) throws Exception {
|
||||
FileSystemUtils.deleteRecursively(this.tempDir);
|
||||
}
|
||||
|
||||
static class EmbeddedServletContainerInvocationContext implements TestTemplateInvocationContext, ParameterResolver {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final AbstractApplicationLauncher launcher;
|
||||
|
||||
public EmbeddedServletContainerInvocationContext(String name, AbstractApplicationLauncher launcher) {
|
||||
this.name = name;
|
||||
this.launcher = launcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Extension> getAdditionalExtensions() {
|
||||
return Arrays.asList(this.launcher, new RestTemplateParameterResolver(this.launcher));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(int invocationIndex) {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
if (parameterContext.getParameter().getType().equals(AbstractApplicationLauncher.class)) {
|
||||
return true;
|
||||
}
|
||||
if (parameterContext.getParameter().getType().equals(RestTemplate.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
if (parameterContext.getParameter().getType().equals(AbstractApplicationLauncher.class)) {
|
||||
return this.launcher;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class RestTemplateParameterResolver implements ParameterResolver {
|
||||
|
||||
private final AbstractApplicationLauncher launcher;
|
||||
|
||||
private RestTemplateParameterResolver(AbstractApplicationLauncher launcher) {
|
||||
this.launcher = launcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
return parameterContext.getParameter().getType().equals(RestTemplate.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
RestTemplate rest = new RestTemplate();
|
||||
rest.setErrorHandler(new ResponseErrorHandler() {
|
||||
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse response) throws IOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
rest.setUriTemplateHandler(new UriTemplateHandler() {
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Object... uriVariables) {
|
||||
return URI.create("http://localhost:" + RestTemplateParameterResolver.this.launcher.getHttpPort()
|
||||
+ uriTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Map<String, ?> uriVariables) {
|
||||
return URI.create("http://localhost:" + RestTemplateParameterResolver.this.launcher.getHttpPort()
|
||||
+ uriTemplate);
|
||||
}
|
||||
|
||||
});
|
||||
return rest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,29 +30,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class EmbeddedServletContainerJarDevelopmentIntegrationTests
|
||||
extends AbstractEmbeddedServletContainerIntegrationTests {
|
||||
@EmbeddedServletContainerTest(packaging = "jar",
|
||||
launchers = { BootRunApplicationLauncher.class, IdeApplicationLauncher.class })
|
||||
public class EmbeddedServletContainerJarDevelopmentIntegrationTests {
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("jar",
|
||||
Arrays.asList(BootRunApplicationLauncher.class, IdeApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerJarDevelopmentIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
@TestTemplate
|
||||
public void metaInfResourceFromDependencyIsAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
@TestTemplate
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,49 +30,39 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class EmbeddedServletContainerJarPackagingIntegrationTests
|
||||
extends AbstractEmbeddedServletContainerIntegrationTests {
|
||||
@EmbeddedServletContainerTest(packaging = "jar",
|
||||
launchers = { PackagedApplicationLauncher.class, ExplodedApplicationLauncher.class })
|
||||
public class EmbeddedServletContainerJarPackagingIntegrationTests {
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("jar",
|
||||
Arrays.asList(PackagedApplicationLauncher.class, ExplodedApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerJarPackagingIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
@TestTemplate
|
||||
public void nestedMetaInfResourceIsAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
@TestTemplate
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedJarIsNotAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/BOOT-INF/lib/resources-1.0.jar", String.class);
|
||||
@TestTemplate
|
||||
public void nestedJarIsNotAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/BOOT-INF/lib/resources-1.0.jar", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationClassesAreNotAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
@TestTemplate
|
||||
public void applicationClassesAreNotAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest
|
||||
.getForEntity("/BOOT-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launcherIsNotAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/org/springframework/boot/loader/Launcher.class",
|
||||
@TestTemplate
|
||||
public void launcherIsNotAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/org/springframework/boot/loader/Launcher.class",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author awilkinson
|
||||
*/
|
||||
@Retention(RUNTIME)
|
||||
@Target(TYPE)
|
||||
@ExtendWith(EmbeddedServerContainerInvocationContextProvider.class)
|
||||
public @interface EmbeddedServletContainerTest {
|
||||
|
||||
String packaging();
|
||||
|
||||
Class<? extends AbstractApplicationLauncher>[] launchers();
|
||||
|
||||
}
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,36 +30,26 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class EmbeddedServletContainerWarDevelopmentIntegrationTests
|
||||
extends AbstractEmbeddedServletContainerIntegrationTests {
|
||||
@EmbeddedServletContainerTest(packaging = "war",
|
||||
launchers = { BootRunApplicationLauncher.class, IdeApplicationLauncher.class })
|
||||
public class EmbeddedServletContainerWarDevelopmentIntegrationTests {
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("war",
|
||||
Arrays.asList(BootRunApplicationLauncher.class, IdeApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerWarDevelopmentIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
@TestTemplate
|
||||
public void metaInfResourceFromDependencyIsAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
@TestTemplate
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webappResourcesAreAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/webapp-resource.txt", String.class);
|
||||
@TestTemplate
|
||||
public void webappResourcesAreAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/webapp-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
package org.springframework.boot.context.embedded;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,59 +30,48 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class EmbeddedServletContainerWarPackagingIntegrationTests
|
||||
extends AbstractEmbeddedServletContainerIntegrationTests {
|
||||
@EmbeddedServletContainerTest(packaging = "war",
|
||||
launchers = { PackagedApplicationLauncher.class, ExplodedApplicationLauncher.class })
|
||||
public class EmbeddedServletContainerWarPackagingIntegrationTests {
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("war",
|
||||
Arrays.asList(PackagedApplicationLauncher.class, ExplodedApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerWarPackagingIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
@TestTemplate
|
||||
public void nestedMetaInfResourceIsAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
@TestTemplate
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedJarIsNotAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/WEB-INF/lib/resources-1.0.jar", String.class);
|
||||
@TestTemplate
|
||||
public void nestedJarIsNotAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/WEB-INF/lib/resources-1.0.jar", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationClassesAreNotAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
@TestTemplate
|
||||
public void applicationClassesAreNotAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest
|
||||
.getForEntity("/WEB-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webappResourcesAreAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/webapp-resource.txt", String.class);
|
||||
@TestTemplate
|
||||
public void webappResourcesAreAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/webapp-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loaderClassesAreNotAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/org/springframework/boot/loader/Launcher.class",
|
||||
@TestTemplate
|
||||
public void loaderClassesAreNotAvailableViaHttp(RestTemplate rest) {
|
||||
ResponseEntity<String> entity = rest.getForEntity("/org/springframework/boot/loader/Launcher.class",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
entity = this.rest.getForEntity("/org/springframework/../springframework/boot/loader/Launcher.class",
|
||||
String.class);
|
||||
entity = rest.getForEntity("/org/springframework/../springframework/boot/loader/Launcher.class", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user