Search in sources :

Example 1 with Response

use of net.morimekta.test.providence.service.Response in project providence by morimekta.

the class ProvidenceServletTest method testSimpleRequest.

@Test
public void testSimpleRequest() throws IOException, Failure {
    AtomicBoolean called = new AtomicBoolean();
    when(impl.test(any(Request.class))).thenAnswer(i -> {
        called.set(true);
        return new Response("response");
    });
    TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory(), provider));
    Response response = client.test(new Request("request"));
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    assertNotNull(response);
    assertEquals("{text:\"response\"}", response.asString());
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(instrumentation);
}
Also used : HttpResponse(com.google.api.client.http.HttpResponse) Response(net.morimekta.test.providence.service.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestService(net.morimekta.test.providence.service.TestService) PServiceCall(net.morimekta.providence.PServiceCall) HttpRequest(com.google.api.client.http.HttpRequest) Request(net.morimekta.test.providence.service.Request) HttpClientHandler(net.morimekta.providence.client.HttpClientHandler) Test(org.junit.Test)

Example 2 with Response

use of net.morimekta.test.providence.service.Response in project providence by morimekta.

the class ProvidenceServlet_ThriftClientTest method testThriftClient.

@Test
public void testThriftClient() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client = new net.morimekta.test.thrift.service.TestService.Client(protocol);
    doAnswer(i -> new Response("reply")).when(impl).test(any(Request.class));
    net.morimekta.test.thrift.service.Response response = client.test(new net.morimekta.test.thrift.service.Request("call"));
    assertThat(response.getText(), is("reply"));
    verify(impl).test(any(Request.class));
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
Also used : TestService(net.morimekta.test.providence.service.TestService) Request(net.morimekta.test.providence.service.Request) THttpClient(org.apache.thrift.transport.THttpClient) Response(net.morimekta.test.providence.service.Response) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) PServiceCall(net.morimekta.providence.PServiceCall) ApacheHttpTransport(com.google.api.client.http.apache.ApacheHttpTransport) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Aggregations

PServiceCall (net.morimekta.providence.PServiceCall)2 Request (net.morimekta.test.providence.service.Request)2 Response (net.morimekta.test.providence.service.Response)2 TestService (net.morimekta.test.providence.service.TestService)2 Test (org.junit.Test)2 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpResponse (com.google.api.client.http.HttpResponse)1 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpClientHandler (net.morimekta.providence.client.HttpClientHandler)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1