Polishing

This commit is contained in:
Sam Brannen 2019-09-05 13:45:30 +02:00
parent d9e3b8b9a5
commit ef50777535
1 changed files with 10 additions and 22 deletions

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.reactive.result.method.annotation;
package org.springframework.web.reactive.result.method.annotation;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -38,18 +38,12 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ContextPathIntegrationTests { class ContextPathIntegrationTests {
@Test @Test
public void multipleWebFluxApps() throws Exception { void multipleWebFluxApps() throws Exception {
AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext(WebAppConfig.class);
context1.register(WebAppConfig.class); AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext(WebAppConfig.class);
context1.refresh();
AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext();
context2.register(WebAppConfig.class);
context2.refresh();
HttpHandler webApp1Handler = WebHttpHandlerBuilder.applicationContext(context1).build(); HttpHandler webApp1Handler = WebHttpHandlerBuilder.applicationContext(context1).build();
HttpHandler webApp2Handler = WebHttpHandlerBuilder.applicationContext(context2).build(); HttpHandler webApp2Handler = WebHttpHandlerBuilder.applicationContext(context2).build();
@ -78,10 +72,8 @@ public class ContextPathIntegrationTests {
} }
@Test @Test
public void servletPathMapping() throws Exception { void servletPathMapping() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebAppConfig.class);
context.register(WebAppConfig.class);
context.refresh();
TomcatHttpServer server = new TomcatHttpServer(); TomcatHttpServer server = new TomcatHttpServer();
server.setContextPath("/app"); server.setContextPath("/app");
@ -94,11 +86,8 @@ public class ContextPathIntegrationTests {
server.start(); server.start();
try { try {
RestTemplate restTemplate = new RestTemplate();
String actual;
String url = "http://localhost:" + server.getPort() + "/app/api/test"; String url = "http://localhost:" + server.getPort() + "/app/api/test";
actual = restTemplate.getForObject(url, String.class); String actual = new RestTemplate().getForObject(url, String.class);
assertThat(actual).isEqualTo("Tested in /app/api"); assertThat(actual).isEqualTo("Tested in /app/api");
} }
finally { finally {
@ -107,13 +96,12 @@ public class ContextPathIntegrationTests {
} }
@EnableWebFlux @EnableWebFlux
@Configuration @Configuration
static class WebAppConfig { static class WebAppConfig {
@Bean @Bean
public TestController testController() { TestController testController() {
return new TestController(); return new TestController();
} }
} }
@ -123,7 +111,7 @@ public class ContextPathIntegrationTests {
static class TestController { static class TestController {
@GetMapping("/test") @GetMapping("/test")
public String handle(ServerHttpRequest request) { String handle(ServerHttpRequest request) {
return "Tested in " + request.getPath().contextPath().value(); return "Tested in " + request.getPath().contextPath().value();
} }
} }