Move port in use exception test as it does not apply to Tomcat
See gh-8737
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
response.setStatusCode(HttpStatus.OK);
|
||||
return response.writeWith(request.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user