Search in sources :

Example 1 with HttpObjectCallback

use of org.mockserver.model.HttpObjectCallback in project mockserver by mock-server.

the class HttpObjectCallbackDTOTest method shouldBuildObject.

@Test
public void shouldBuildObject() {
    // given
    String clientId = UUIDService.getUUID();
    HttpObjectCallback httpObjectCallback = new HttpObjectCallback().withClientId(clientId);
    // when
    HttpObjectCallback builtHttpObjectCallback = new HttpObjectCallbackDTO(httpObjectCallback).buildObject();
    // then
    assertThat(builtHttpObjectCallback.getClientId(), is(clientId));
}
Also used : HttpObjectCallback(org.mockserver.model.HttpObjectCallback) Test(org.junit.Test)

Example 2 with HttpObjectCallback

use of org.mockserver.model.HttpObjectCallback in project mockserver by mock-server.

the class HttpForwardObjectCallbackActionHandlerTest method shouldReturnNotFound.

@Test
public void shouldReturnNotFound() throws ExecutionException, InterruptedException {
    // given
    HttpActionHandler mockActionHandler = mock(HttpActionHandler.class);
    HttpState mockHttpStateHandler = mock(HttpState.class);
    WebSocketClientRegistry mockWebSocketClientRegistry = mock(WebSocketClientRegistry.class);
    HttpObjectCallback httpObjectCallback = new HttpObjectCallback().withClientId("some_clientId");
    HttpRequest request = request().withBody("some_body");
    ResponseWriter mockResponseWriter = mock(ResponseWriter.class);
    when(mockHttpStateHandler.getWebSocketClientRegistry()).thenReturn(mockWebSocketClientRegistry);
    when(mockHttpStateHandler.getMockServerLogger()).thenReturn(new MockServerLogger());
    when(mockWebSocketClientRegistry.sendClientMessage(eq("some_clientId"), any(HttpRequest.class), isNull())).thenReturn(false);
    // when
    new HttpForwardObjectCallbackActionHandler(mockHttpStateHandler, null).handle(mockActionHandler, httpObjectCallback, request, mockResponseWriter, true, null);
    // then
    verify(mockWebSocketClientRegistry).registerForwardCallbackHandler(any(String.class), any(WebSocketRequestCallback.class));
    verify(mockWebSocketClientRegistry).sendClientMessage(eq("some_clientId"), any(HttpRequest.class), isNull());
    ArgumentCaptor<HttpForwardActionResult> httpForwardActionResultArgumentCaptor = ArgumentCaptor.forClass(HttpForwardActionResult.class);
    verify(mockActionHandler).writeForwardActionResponse(httpForwardActionResultArgumentCaptor.capture(), same(mockResponseWriter), same(request), same(httpObjectCallback), eq(true));
    assertThat(httpForwardActionResultArgumentCaptor.getValue().getHttpResponse().get(), is(notFoundResponse()));
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) HttpObjectCallback(org.mockserver.model.HttpObjectCallback) ResponseWriter(org.mockserver.responsewriter.ResponseWriter) MockServerLogger(org.mockserver.logging.MockServerLogger) WebSocketRequestCallback(org.mockserver.closurecallback.websocketregistry.WebSocketRequestCallback) WebSocketClientRegistry(org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry) HttpState(org.mockserver.mock.HttpState) Test(org.junit.Test)

Example 3 with HttpObjectCallback

use of org.mockserver.model.HttpObjectCallback in project mockserver by mock-server.

the class HttpResponseObjectCallbackActionHandlerTest method shouldReturnNotFound.

@Test
public void shouldReturnNotFound() {
    // given
    HttpActionHandler mockActionHandler = mock(HttpActionHandler.class);
    HttpState mockHttpStateHandler = mock(HttpState.class);
    WebSocketClientRegistry mockWebSocketClientRegistry = mock(WebSocketClientRegistry.class);
    HttpObjectCallback httpObjectCallback = new HttpObjectCallback().withClientId("some_clientId");
    HttpRequest request = request().withBody("some_body");
    ResponseWriter mockResponseWriter = mock(ResponseWriter.class);
    when(mockHttpStateHandler.getWebSocketClientRegistry()).thenReturn(mockWebSocketClientRegistry);
    when(mockHttpStateHandler.getMockServerLogger()).thenReturn(new MockServerLogger());
    when(mockWebSocketClientRegistry.sendClientMessage(eq("some_clientId"), any(HttpRequest.class), isNull())).thenReturn(false);
    // when
    new HttpResponseObjectCallbackActionHandler(mockHttpStateHandler).handle(mockActionHandler, httpObjectCallback, request, mockResponseWriter, true, null);
    // then
    verify(mockWebSocketClientRegistry).registerResponseCallbackHandler(any(String.class), any(WebSocketResponseCallback.class));
    verify(mockWebSocketClientRegistry).sendClientMessage(eq("some_clientId"), any(HttpRequest.class), isNull());
    verify(mockActionHandler).writeResponseActionResponse(notFoundResponse().removeHeader(WEB_SOCKET_CORRELATION_ID_HEADER_NAME), mockResponseWriter, request, httpObjectCallback, true);
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) HttpObjectCallback(org.mockserver.model.HttpObjectCallback) ResponseWriter(org.mockserver.responsewriter.ResponseWriter) MockServerLogger(org.mockserver.logging.MockServerLogger) WebSocketClientRegistry(org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry) HttpState(org.mockserver.mock.HttpState) WebSocketResponseCallback(org.mockserver.closurecallback.websocketregistry.WebSocketResponseCallback) Test(org.junit.Test)

Example 4 with HttpObjectCallback

use of org.mockserver.model.HttpObjectCallback in project mockserver by mock-server.

the class HttpObjectCallbackDTOTest method shouldReturnValuesSetInSetter.

@Test
public void shouldReturnValuesSetInSetter() {
    // given
    String clientId = UUIDService.getUUID();
    HttpObjectCallback httpObjectCallback = new HttpObjectCallback();
    // when
    HttpObjectCallbackDTO httpObjectCallbackDTO = new HttpObjectCallbackDTO(httpObjectCallback);
    httpObjectCallbackDTO.setClientId(clientId);
    // then
    assertThat(httpObjectCallbackDTO.getClientId(), is(clientId));
}
Also used : HttpObjectCallback(org.mockserver.model.HttpObjectCallback) Test(org.junit.Test)

Example 5 with HttpObjectCallback

use of org.mockserver.model.HttpObjectCallback in project mockserver by mock-server.

the class HttpObjectCallbackDTOTest method shouldHandleNullFieldInput.

@Test
public void shouldHandleNullFieldInput() {
    // when
    HttpObjectCallbackDTO httpObjectCallbackDTO = new HttpObjectCallbackDTO(new HttpObjectCallback());
    // then
    assertThat(httpObjectCallbackDTO.getClientId(), is(nullValue()));
}
Also used : HttpObjectCallback(org.mockserver.model.HttpObjectCallback) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 HttpObjectCallback (org.mockserver.model.HttpObjectCallback)8 WebSocketClientRegistry (org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry)4 MockServerLogger (org.mockserver.logging.MockServerLogger)4 HttpState (org.mockserver.mock.HttpState)4 HttpRequest (org.mockserver.model.HttpRequest)4 ResponseWriter (org.mockserver.responsewriter.ResponseWriter)4 WebSocketRequestCallback (org.mockserver.closurecallback.websocketregistry.WebSocketRequestCallback)2 WebSocketResponseCallback (org.mockserver.closurecallback.websocketregistry.WebSocketResponseCallback)2