From 0013493402ef68c3852c49e1d16c07b7b26b3d0a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 21 Jul 2017 22:22:39 +0100 Subject: [PATCH] Move port in use exception test as it does not apply to Tomcat See gh-8737 --- .../NettyReactiveWebServerFactoryTests.java | 18 ++++++++++++++++ ...AbstractReactiveWebServerFactoryTests.java | 21 ++++++------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java index 7040c3c661..077d78253a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java @@ -16,8 +16,13 @@ package org.springframework.boot.web.embedded.netty; +import org.junit.Test; + import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; +import org.springframework.boot.web.server.PortInUseException; + +import static org.hamcrest.Matchers.equalTo; /** * Tests for {@link NettyReactiveWebServerFactory}. @@ -32,4 +37,17 @@ public class NettyReactiveWebServerFactoryTests return new NettyReactiveWebServerFactory(0); } + @Test + public void portInUseExceptionIsThrownWhenPortIsAlreadyInUse() throws Exception { + AbstractReactiveWebServerFactory factory = getFactory(); + factory.setPort(0); + this.webServer = factory.getWebServer(new EchoHandler()); + this.webServer.start(); + factory.setPort(this.webServer.getPort()); + this.thrown.expect(PortInUseException.class); + this.thrown.expectMessage( + equalTo("Port " + this.webServer.getPort() + " is already in use")); + factory.getWebServer(new EchoHandler()).start(); + } + } diff --git a/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java index fc39695dd6..712b02778d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java @@ -25,7 +25,6 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.boot.testsupport.rule.OutputCapture; -import org.springframework.boot.web.server.PortInUseException; import org.springframework.boot.web.server.WebServer; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -38,7 +37,6 @@ import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.equalTo; /** * Base for testing classes that extends {@link AbstractReactiveWebServerFactory}. @@ -104,29 +102,22 @@ public abstract class AbstractReactiveWebServerFactoryTests { assertThat(this.webServer.getPort()).isEqualTo(specificPort); } - @Test - public void portInUseExceptionIsThrownWhenPortIsAlreadyInUse() throws Exception { - AbstractReactiveWebServerFactory factory = getFactory(); - factory.setPort(0); - this.webServer = factory.getWebServer(new EchoHandler()); - this.webServer.start(); - factory.setPort(this.webServer.getPort()); - this.thrown.expect(PortInUseException.class); - this.thrown.expectMessage( - equalTo("Port " + this.webServer.getPort() + " is already in use")); - factory.getWebServer(new EchoHandler()).start(); - } - protected WebClient getWebClient() { return WebClient.create("http://localhost:" + this.webServer.getPort()); } protected static class EchoHandler implements HttpHandler { + + public EchoHandler() { + + } + @Override public Mono handle(ServerHttpRequest request, ServerHttpResponse response) { response.setStatusCode(HttpStatus.OK); return response.writeWith(request.getBody()); } + } }