use of com.palantir.dialogue.Request in project dialogue by palantir.
the class DialogueChannelTest method bad_channel_throwing_an_error_still_returns_a_future.
@Test
public void bad_channel_throwing_an_error_still_returns_a_future() {
Channel badUserImplementation = new Channel() {
@Override
public ListenableFuture<Response> execute(Endpoint _endpoint, Request _request) {
throw new NoClassDefFoundError("something is broken");
}
};
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(stubConfig).factory(_args -> badUserImplementation).build();
// this should never throw
ListenableFuture<Response> future = channel.execute(endpoint, request);
// only when we access things do we allow exceptions
assertThatThrownBy(() -> Futures.getUnchecked(future)).hasCauseInstanceOf(NoClassDefFoundError.class);
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class StickyAttachmentsTest method validate_is_passthrough_if_no_request_sticky_token_attachment.
@Test
public void validate_is_passthrough_if_no_request_sticky_token_attachment() {
Request request = Request.builder().build();
when(delegate.maybeExecute(TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED)).thenReturn(Optional.of(responseSettableFuture));
assertThat(StickyAttachments.maybeExecuteAndValidateRequestStickyToken(stickyTokenHandler, TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED)).hasValue(responseSettableFuture);
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class StickyAttachmentsTest method validate_throws_and_closes_response_if_attachments_are_not_present.
@Test
public void validate_throws_and_closes_response_if_attachments_are_not_present() {
Request request = Request.builder().build();
StickyAttachments.requestStickyToken(request);
when(delegate.maybeExecute(TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED)).thenReturn(Optional.of(responseSettableFuture));
ListenableFuture<Response> responseListenableFuture = StickyAttachments.maybeExecuteAndValidateRequestStickyToken(delegate, TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED).get();
TestResponse response = TestResponse.withBody(null);
responseSettableFuture.set(response);
assertThatThrownBy(() -> Futures.getDone(responseListenableFuture)).isInstanceOf(ExecutionException.class).hasRootCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("Requested sticky token on request but token not present on response");
assertThat(response.isClosed()).isTrue();
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class UrlBuilderTest method testQueryParamOrder_requestRendering.
@Test
public void testQueryParamOrder_requestRendering() throws Exception {
String key1 = UUID.randomUUID().toString();
String value1 = UUID.randomUUID().toString();
String key2 = UUID.randomUUID().toString();
String value2 = UUID.randomUUID().toString();
String key3 = UUID.randomUUID().toString();
String value3 = UUID.randomUUID().toString();
String key4 = UUID.randomUUID().toString();
String value4 = UUID.randomUUID().toString();
String key5 = UUID.randomUUID().toString();
String value5 = UUID.randomUUID().toString();
Request request = Request.builder().putQueryParams(key1, value1).putQueryParams(key2, value2).putQueryParams(key3, value3).putQueryParams(key4, value4).putQueryParams(key5, value5).build();
BaseUrl baseUrl = BaseUrl.of(new URL("http://foo:42/bar"));
String target = baseUrl.render(TestEndpoint.GET, request).toString();
assertThat(target).isEqualTo(String.format("http://foo:42/bar?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", key1, value1, key2, value2, key3, value3, key4, value4, key5, value5));
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class DefaultClientsTest method testAddsAcceptHeader.
@ParameterizedTest
@EnumSource(CallType.class)
public void testAddsAcceptHeader(CallType callType) {
String expectedAccept = "application/json";
Request request = Request.builder().build();
when(stringDeserializer.deserialize(eq(response))).thenReturn("value");
when(stringDeserializer.accepts()).thenReturn(Optional.of(expectedAccept));
when(channel.execute(eq(endpoint), any())).thenReturn(Futures.immediateFuture(response));
ListenableFuture<String> result = call(callType, request);
assertStringResult(callType, result);
verify(channel).execute(eq(endpoint), requestCaptor.capture());
assertThat(requestCaptor.getValue().headerParams().get(HttpHeaders.ACCEPT)).containsExactly(expectedAccept);
}
Aggregations