Search in sources :

Example 1 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-boot by spring-projects.

the class DispatcherFilterTests method handledByDispatcher.

@Test
public void handledByDispatcher() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest("GET", "/hello");
    HttpServletResponse response = new MockHttpServletResponse();
    willReturn(true).given(this.dispatcher).handle(any(ServerHttpRequest.class), any(ServerHttpResponse.class));
    this.filter.doFilter(request, response, this.chain);
    verifyZeroInteractions(this.chain);
    verify(this.dispatcher).handle(this.serverRequestCaptor.capture(), this.serverResponseCaptor.capture());
    ServerHttpRequest dispatcherRequest = this.serverRequestCaptor.getValue();
    ServletServerHttpRequest actualRequest = (ServletServerHttpRequest) dispatcherRequest;
    ServerHttpResponse dispatcherResponse = this.serverResponseCaptor.getValue();
    ServletServerHttpResponse actualResponse = (ServletServerHttpResponse) dispatcherResponse;
    assertThat(actualRequest.getServletRequest()).isEqualTo(request);
    assertThat(actualResponse.getServletResponse()).isEqualTo(response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) Test(org.junit.Test)

Example 2 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-boot by spring-projects.

the class HttpRestartServerHandlerTests method handleDelegatesToServer.

@Test
public void handleDelegatesToServer() throws Exception {
    HttpRestartServer server = mock(HttpRestartServer.class);
    HttpRestartServerHandler handler = new HttpRestartServerHandler(server);
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    ServerHttpResponse response = mock(ServerHttpResponse.class);
    handler.handle(request, response);
    verify(server).handle(request, response);
}
Also used : ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) Test(org.junit.Test)

Example 3 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-boot by spring-projects.

the class UrlHandlerMapperTests method handlesMatchedUrl.

@Test
public void handlesMatchedUrl() throws Exception {
    UrlHandlerMapper mapper = new UrlHandlerMapper("/tunnel", this.handler);
    HttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/tunnel");
    ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    assertThat(mapper.getHandler(request)).isEqualTo(this.handler);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) Test(org.junit.Test)

Example 4 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-boot by spring-projects.

the class HttpTunnelServerHandlerTests method handleDelegatesToServer.

@Test
public void handleDelegatesToServer() throws Exception {
    HttpTunnelServer server = mock(HttpTunnelServer.class);
    HttpTunnelServerHandler handler = new HttpTunnelServerHandler(server);
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    ServerHttpResponse response = mock(ServerHttpResponse.class);
    handler.handle(request, response);
    verify(server).handle(request, response);
}
Also used : ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) Test(org.junit.Test)

Example 5 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest 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)

Aggregations

ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)19 Test (org.junit.Test)13 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)10 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)6 MockMultipartFile (org.springframework.mock.web.test.MockMultipartFile)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)4 HttpHeaders (org.springframework.http.HttpHeaders)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockMultipartHttpServletRequest (org.springframework.mock.web.test.MockMultipartHttpServletRequest)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 HttpConnection (org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection)2 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)2 URI (java.net.URI)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MediaType (org.springframework.http.MediaType)1 ServerHttpAsyncRequestControl (org.springframework.http.server.ServerHttpAsyncRequestControl)1