use of org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection in project spring-boot by spring-projects.
the class HttpTunnelServerTests method httpConnectionRespondWithStatus.
@Test
public void httpConnectionRespondWithStatus() throws Exception {
HttpConnection connection = new HttpConnection(this.request, this.response);
connection.waitForResponse();
connection.respond(HttpStatus.I_AM_A_TEAPOT);
assertThat(this.servletResponse.getStatus()).isEqualTo(418);
assertThat(this.servletResponse.getContentLength()).isEqualTo(0);
}
use of org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection in project spring-boot by spring-projects.
the class HttpTunnelServerTests method testHttpConnectionNonAsync.
private void testHttpConnectionNonAsync(long sleepBeforeResponse) throws IOException, InterruptedException {
ServerHttpRequest request = mock(ServerHttpRequest.class);
given(request.getAsyncRequestControl(this.response)).willThrow(new IllegalArgumentException());
final HttpConnection connection = new HttpConnection(request, this.response);
final AtomicBoolean responded = new AtomicBoolean();
Thread connectionThread = new Thread() {
@Override
public void run() {
connection.waitForResponse();
responded.set(true);
}
};
connectionThread.start();
assertThat(responded.get()).isFalse();
Thread.sleep(sleepBeforeResponse);
connection.respond(HttpStatus.NO_CONTENT);
connectionThread.join();
assertThat(responded.get()).isTrue();
}
use of org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection in project spring-boot by spring-projects.
the class HttpTunnelServerTests method httpConnectionRespondWithPayload.
@Test
public void httpConnectionRespondWithPayload() throws Exception {
HttpConnection connection = new HttpConnection(this.request, this.response);
connection.waitForResponse();
connection.respond(new HttpTunnelPayload(1, ByteBuffer.wrap("hello".getBytes())));
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
assertThat(this.servletResponse.getContentAsString()).isEqualTo("hello");
assertThat(this.servletResponse.getHeader(SEQ_HEADER)).isEqualTo("1");
}
use of org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection in project spring-boot by spring-projects.
the class HttpTunnelServerTests method httpConnectionRunning.
@Test
public void httpConnectionRunning() throws Exception {
HttpConnection connection = new HttpConnection(this.request, this.response);
assertThat(connection.isOlderThan(100)).isFalse();
Thread.sleep(200);
assertThat(connection.isOlderThan(100)).isTrue();
}
use of org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection in project spring-boot by spring-projects.
the class HttpTunnelServerTests method httpConnectionAsync.
@Test
public void httpConnectionAsync() throws Exception {
ServerHttpAsyncRequestControl async = mock(ServerHttpAsyncRequestControl.class);
ServerHttpRequest request = mock(ServerHttpRequest.class);
given(request.getAsyncRequestControl(this.response)).willReturn(async);
HttpConnection connection = new HttpConnection(request, this.response);
connection.waitForResponse();
verify(async).start();
connection.respond(HttpStatus.NO_CONTENT);
verify(async).complete();
}
Aggregations