Search in sources :

Example 1 with WebSocketClientRegistry

use of org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry in project mockserver by mock-server.

the class MockServerMatcherBasicResponsesTest method prepareTestFixture.

@Before
public void prepareTestFixture() {
    Scheduler scheduler = mock(Scheduler.class);
    WebSocketClientRegistry webSocketClientRegistry = mock(WebSocketClientRegistry.class);
    requestMatchers = new RequestMatchers(configuration(), new MockServerLogger(), scheduler, webSocketClientRegistry);
}
Also used : MockServerLogger(org.mockserver.logging.MockServerLogger) Scheduler(org.mockserver.scheduler.Scheduler) WebSocketClientRegistry(org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry) Before(org.junit.Before)

Example 2 with WebSocketClientRegistry

use of org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry in project mockserver by mock-server.

the class MockServerMatcherClearAndResetTest method prepareTestFixture.

@Before
public void prepareTestFixture() {
    configuration = configuration();
    mockServerLogger = new MockServerLogger();
    WebSocketClientRegistry webSocketClientRegistry = mock(WebSocketClientRegistry.class);
    requestMatchers = new RequestMatchers(configuration(), mockServerLogger, new Scheduler(configuration(), mockServerLogger, true), webSocketClientRegistry);
}
Also used : MockServerLogger(org.mockserver.logging.MockServerLogger) Scheduler(org.mockserver.scheduler.Scheduler) WebSocketClientRegistry(org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry) Before(org.junit.Before)

Example 3 with WebSocketClientRegistry

use of org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry in project mockserver by mock-server.

the class MockServerMatcherSequentialResponsesTest method prepareTestFixture.

@Before
public void prepareTestFixture() {
    MockServerLogger mockLogFormatter = mock(MockServerLogger.class);
    Scheduler scheduler = mock(Scheduler.class);
    WebSocketClientRegistry webSocketClientRegistry = mock(WebSocketClientRegistry.class);
    requestMatchers = new RequestMatchers(configuration(), mockLogFormatter, scheduler, webSocketClientRegistry);
}
Also used : MockServerLogger(org.mockserver.logging.MockServerLogger) Scheduler(org.mockserver.scheduler.Scheduler) WebSocketClientRegistry(org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry) Before(org.junit.Before)

Example 4 with WebSocketClientRegistry

use of org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry 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 5 with WebSocketClientRegistry

use of org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry 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)

Aggregations

WebSocketClientRegistry (org.mockserver.closurecallback.websocketregistry.WebSocketClientRegistry)13 MockServerLogger (org.mockserver.logging.MockServerLogger)12 Before (org.junit.Before)9 Scheduler (org.mockserver.scheduler.Scheduler)7 Test (org.junit.Test)4 HttpState (org.mockserver.mock.HttpState)4 HttpObjectCallback (org.mockserver.model.HttpObjectCallback)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 RequestMatchers (org.mockserver.mock.RequestMatchers)2 HttpResponse (org.mockserver.model.HttpResponse)1