Move port in use exception test as it does not apply to Tomcat

See gh-8737
pull/9829/merge
Andy Wilkinson 7 years ago
parent 9b6b663cc7
commit 0013493402

@ -16,8 +16,13 @@
package org.springframework.boot.web.embedded.netty; 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.AbstractReactiveWebServerFactory;
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; 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}. * Tests for {@link NettyReactiveWebServerFactory}.
@ -32,4 +37,17 @@ public class NettyReactiveWebServerFactoryTests
return new NettyReactiveWebServerFactory(0); 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();
}
} }

@ -25,7 +25,6 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; import reactor.test.StepVerifier;
import org.springframework.boot.testsupport.rule.OutputCapture; import org.springframework.boot.testsupport.rule.OutputCapture;
import org.springframework.boot.web.server.PortInUseException;
import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServer;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; 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 org.springframework.web.reactive.function.client.WebClient;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
/** /**
* Base for testing classes that extends {@link AbstractReactiveWebServerFactory}. * Base for testing classes that extends {@link AbstractReactiveWebServerFactory}.
@ -104,29 +102,22 @@ public abstract class AbstractReactiveWebServerFactoryTests {
assertThat(this.webServer.getPort()).isEqualTo(specificPort); 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() { protected WebClient getWebClient() {
return WebClient.create("http://localhost:" + this.webServer.getPort()); return WebClient.create("http://localhost:" + this.webServer.getPort());
} }
protected static class EchoHandler implements HttpHandler { protected static class EchoHandler implements HttpHandler {
public EchoHandler() {
}
@Override @Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
response.setStatusCode(HttpStatus.OK); response.setStatusCode(HttpStatus.OK);
return response.writeWith(request.getBody()); return response.writeWith(request.getBody());
} }
} }
} }

Loading…
Cancel
Save