Search in sources :

Example 1 with HttpConnection

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);
}
Also used : HttpConnection(org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection) Test(org.junit.Test)

Example 2 with HttpConnection

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpConnection(org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest)

Example 3 with HttpConnection

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");
}
Also used : HttpConnection(org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection) HttpTunnelPayload(org.springframework.boot.devtools.tunnel.payload.HttpTunnelPayload) Test(org.junit.Test)

Example 4 with HttpConnection

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();
}
Also used : HttpConnection(org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection) Test(org.junit.Test)

Example 5 with HttpConnection

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();
}
Also used : HttpConnection(org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServerHttpAsyncRequestControl(org.springframework.http.server.ServerHttpAsyncRequestControl) Test(org.junit.Test)

Aggregations

HttpConnection (org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection)5 Test (org.junit.Test)4 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)2 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HttpTunnelPayload (org.springframework.boot.devtools.tunnel.payload.HttpTunnelPayload)1 ServerHttpAsyncRequestControl (org.springframework.http.server.ServerHttpAsyncRequestControl)1