use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class ContentEncodingChannelTest method testChannelCreationWithTag.
@Test
void testChannelCreationWithTag() {
EndpointChannel delegate = _req -> Futures.immediateCancelledFuture();
EndpointChannel result = ContentEncodingChannel.of(delegate, new Endpoint() {
@Override
public HttpMethod httpMethod() {
return HttpMethod.POST;
}
@Override
public String serviceName() {
return "service";
}
@Override
public String endpointName() {
return "endpoint";
}
@Override
public String version() {
return "1.2.3";
}
@Override
public Set<String> tags() {
return ImmutableSet.of("compress-request");
}
});
assertThat(result).isNotSameAs(delegate);
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class DialogueChannelTest method test_can_use_sticky_attachments_impl.
private void test_can_use_sticky_attachments_impl(NodeSelectionStrategy nodeSelectionStrategy, ImmutableList<String> uris) throws ExecutionException {
String uriHeader = "uri";
DialogueChannelFactory factory = args -> {
mockChannel = Mockito.mock(Channel.class);
lenient().when(mockChannel.execute(eq(endpoint), any())).thenAnswer((Answer<ListenableFuture<Response>>) _invocation -> Futures.immediateFuture(TestResponse.withBody(null).withHeader(uriHeader, args.uri())));
return mockChannel;
};
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(ClientConfiguration.builder().uris(uris).from(stubConfig).nodeSelectionStrategy(nodeSelectionStrategy).build()).factory(factory).random(new Random(1L)).build();
request = createRequestWithAddExecutedOnAttachment();
response = Futures.getDone(channel.execute(endpoint, request));
String expectedUri = response.getFirstHeader(uriHeader).get();
Consumer<Request> stickyTarget = StickyAttachments.copyStickyTarget(response);
request = Request.builder().build();
stickyTarget.accept(request);
response = Futures.getDone(channel.execute(endpoint, request));
assertThat(response.getFirstHeader(uriHeader)).hasValue(expectedUri);
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class QueuedChannelTest method testQueuedResponseClosedOnCancel.
@Test
public void testQueuedResponseClosedOnCancel() {
Request queuedRequest = Request.builder().pathParams(ImmutableMap.of("foo", "bar")).build();
when(delegate.maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS)).thenReturn(Optional.empty());
ListenableFuture<Response> result = queuedChannel.maybeExecute(endpoint, queuedRequest).get();
verify(delegate, times(2)).maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS);
when(delegate.maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS)).thenReturn(Optional.of(Futures.immediateFuture(Mockito.mock(Response.class))));
when(delegate.maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS)).thenAnswer((Answer<Optional<ListenableFuture<Response>>>) _invocation -> {
assertThat(result.cancel(true)).isTrue();
return Optional.of(Futures.immediateFuture(mockResponse));
});
// Force scheduling
queuedChannel.maybeExecute(endpoint, request);
assertThat(result).isCancelled();
verify(delegate, times(1)).maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS);
verify(mockResponse, times(1)).close();
}
use of com.palantir.dialogue.Endpoint in project conjure-java-runtime by palantir.
the class JaxRsClientDialogueEndpointTest method testPostWithBody_defaultContentType.
@Test
public void testPostWithBody_defaultContentType() {
Channel channel = stubNoContentResponseChannel();
StubServiceWithoutContentType service = JaxRsClient.create(StubServiceWithoutContentType.class, channel, runtime);
service.post("Hello, World!");
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("StubServiceWithoutContentType");
assertThat(endpoint.endpointName()).isEqualTo("post");
assertThat(endpoint.httpMethod()).isEqualTo(HttpMethod.POST);
Request request = requestCaptor.getValue();
assertThat(request.body()).isPresent();
assertThat(request.body().get().contentType()).isEqualTo("application/json");
assertThat(request.headerParams().asMap()).containsExactly(new AbstractMap.SimpleImmutableEntry<>("Content-Length", ImmutableList.of("15")));
}
use of com.palantir.dialogue.Endpoint in project conjure-java-runtime by palantir.
the class JaxRsClientDialogueEndpointTest method testTrailingWildcardParameter_emptyString.
@Test
public void testTrailingWildcardParameter_emptyString() {
Channel channel = stubNoContentResponseChannel();
StubService service = JaxRsClient.create(StubService.class, channel, runtime);
service.complexPath("dynamic0", "");
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");
// Empty string must be included
verify(urlBuilder).pathSegment("");
}
Aggregations