|
|
|
@ -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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|