Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -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