Search in sources :

Example 1 with Channel

use of com.palantir.dialogue.Channel in project conjure-java-runtime by palantir.

the class JaxRsClientDialogueEndpointTest method stubNoContentResponseChannel.

static Channel stubNoContentResponseChannel() {
    Channel channel = mock(Channel.class);
    Response response = mock(Response.class);
    when(response.body()).thenReturn(new ByteArrayInputStream(new byte[0]));
    when(response.code()).thenReturn(204);
    when(response.headers()).thenReturn(ImmutableListMultimap.of());
    when(channel.execute(any(Endpoint.class), any(Request.class))).thenReturn(Futures.immediateFuture(response));
    return channel;
}
Also used : Response(com.palantir.dialogue.Response) Endpoint(com.palantir.dialogue.Endpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Channel(com.palantir.dialogue.Channel) Request(com.palantir.dialogue.Request)

Example 2 with Channel

use of com.palantir.dialogue.Channel in project conjure-java-runtime by palantir.

the class JaxRsClientDialogueEndpointTest method testSlashPathParameter.

@Test
public void testSlashPathParameter() {
    Channel channel = stubNoContentResponseChannel();
    StubService service = JaxRsClient.create(StubService.class, channel, runtime);
    service.innerPath("/");
    ArgumentCaptor<Endpoint> endpointCaptor = ArgumentCaptor.forClass(Endpoint.class);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    verify(channel).execute(endpointCaptor.capture(), requestCaptor.capture());
    UrlBuilder urlBuilder = mock(UrlBuilder.class);
    endpointCaptor.getValue().renderPath(ImmutableMap.of(), urlBuilder);
    // context path
    verify(urlBuilder).pathSegment("foo");
    // encoded into %2F by DefaultUrlBuilder
    verify(urlBuilder).pathSegment("/");
}
Also used : Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) Request(com.palantir.dialogue.Request) UrlBuilder(com.palantir.dialogue.UrlBuilder) Test(org.junit.Test)

Example 3 with Channel

use of com.palantir.dialogue.Channel in project conjure-java-runtime by palantir.

the class JaxRsClientDialogueEndpointTest method testEndpoint.

@Test
public void testEndpoint() {
    Channel channel = stubNoContentResponseChannel();
    StubService service = JaxRsClient.create(StubService.class, channel, runtime);
    service.ping();
    ArgumentCaptor<Endpoint> endpointCaptor = ArgumentCaptor.forClass(Endpoint.class);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    verify(channel).execute(endpointCaptor.capture(), requestCaptor.capture());
    Endpoint endpoint = endpointCaptor.getValue();
    assertThat(endpoint.serviceName()).isEqualTo("StubService");
    assertThat(endpoint.endpointName()).isEqualTo("ping");
    assertThat(endpoint.httpMethod()).isEqualTo(HttpMethod.GET);
    Request request = requestCaptor.getValue();
    assertThat(request.body()).isEmpty();
    assertThat(request.headerParams().asMap()).containsExactly(new AbstractMap.SimpleImmutableEntry<>("Accept", ImmutableList.of("application/json")));
}
Also used : AbstractMap(java.util.AbstractMap) Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) Request(com.palantir.dialogue.Request) Test(org.junit.Test)

Example 4 with Channel

use of com.palantir.dialogue.Channel in project conjure-java-runtime by palantir.

the class JaxRsClientDialogueEndpointTest method testTrailingWildcardParameter_slashes.

@Test
public void testTrailingWildcardParameter_slashes() {
    Channel channel = stubNoContentResponseChannel();
    StubService service = JaxRsClient.create(StubService.class, channel, runtime);
    service.complexPath("dynamic0", "dynamic1/dynamic2");
    ArgumentCaptor<Endpoint> endpointCaptor = ArgumentCaptor.forClass(Endpoint.class);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    verify(channel).execute(endpointCaptor.capture(), requestCaptor.capture());
    UrlBuilder urlBuilder = mock(UrlBuilder.class);
    endpointCaptor.getValue().renderPath(ImmutableMap.of(), urlBuilder);
    // context path
    verify(urlBuilder).pathSegment("foo");
    verify(urlBuilder).pathSegment("static0");
    verify(urlBuilder).pathSegment("dynamic0");
    verify(urlBuilder).pathSegment("static1");
    // Value should not be split into multiple segments
    verify(urlBuilder).pathSegment("dynamic1/dynamic2");
}
Also used : Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) Request(com.palantir.dialogue.Request) UrlBuilder(com.palantir.dialogue.UrlBuilder) Test(org.junit.Test)

Example 5 with Channel

use of com.palantir.dialogue.Channel in project conjure-java-runtime by palantir.

the class JaxRsClientDialogueEndpointTest method testQueryParameterCollection.

@Test
public void testQueryParameterCollection() {
    Channel channel = stubNoContentResponseChannel();
    StubService service = JaxRsClient.create(StubService.class, channel, runtime);
    service.collectionOfQueryParams(ImmutableList.of("a", "/", "", "a b", "a+b"));
    ArgumentCaptor<Endpoint> endpointCaptor = ArgumentCaptor.forClass(Endpoint.class);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    verify(channel).execute(endpointCaptor.capture(), requestCaptor.capture());
    UrlBuilder urlBuilder = mock(UrlBuilder.class);
    endpointCaptor.getValue().renderPath(ImmutableMap.of(), urlBuilder);
    verify(urlBuilder).queryParam("query", "a");
    verify(urlBuilder).queryParam("query", "/");
    verify(urlBuilder).queryParam("query", "");
    verify(urlBuilder).queryParam("query", "a b");
    verify(urlBuilder).queryParam("query", "a+b");
}
Also used : Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) Request(com.palantir.dialogue.Request) UrlBuilder(com.palantir.dialogue.UrlBuilder) Test(org.junit.Test)

Aggregations

Channel (com.palantir.dialogue.Channel)60 Test (org.junit.jupiter.api.Test)35 Response (com.palantir.dialogue.Response)26 EndpointChannel (com.palantir.dialogue.EndpointChannel)19 Request (com.palantir.dialogue.Request)19 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)18 Endpoint (com.palantir.dialogue.Endpoint)18 TestEndpoint (com.palantir.dialogue.TestEndpoint)12 TestResponse (com.palantir.dialogue.TestResponse)12 Test (org.junit.Test)11 Duration (java.time.Duration)9 IOException (java.io.IOException)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Meter (com.codahale.metrics.Meter)6 UrlBuilder (com.palantir.dialogue.UrlBuilder)6 Undertow (io.undertow.Undertow)6 Optional (java.util.Optional)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Futures (com.google.common.util.concurrent.Futures)5