Search in sources :

Example 26 with Request

use of com.palantir.dialogue.Request in project dialogue by palantir.

the class ContentEncodingChannelTest method testNoBody.

@Test
void testNoBody() {
    Request request = Request.builder().build();
    Request wrapped = ContentEncodingChannel.wrap(request);
    assertThat(wrapped).isSameAs(request);
}
Also used : Request(com.palantir.dialogue.Request) Test(org.junit.jupiter.api.Test)

Example 27 with Request

use of com.palantir.dialogue.Request in project dialogue by palantir.

the class ContentEncodingChannelTest method testContentLengthExistsOutsideBody.

@Test
void testContentLengthExistsOutsideBody() {
    // This case shouldn't be supported in any way, however
    // it's best to handle unexpected cases gracefully.
    Request request = Request.builder().putHeaderParams("Content-Length", "123").body(StubBody.INSTANCE).build();
    Request wrapped = ContentEncodingChannel.wrap(request);
    assertThat(wrapped).isSameAs(request);
}
Also used : Request(com.palantir.dialogue.Request) Test(org.junit.jupiter.api.Test)

Example 28 with Request

use of com.palantir.dialogue.Request in project dialogue by palantir.

the class ContentEncodingChannelTest method testContentEncodingExists.

@Test
void testContentEncodingExists() {
    Request request = Request.builder().putHeaderParams("Content-Encoding", "identity").body(StubBody.INSTANCE).build();
    Request wrapped = ContentEncodingChannel.wrap(request);
    assertThat(wrapped).isSameAs(request);
}
Also used : Request(com.palantir.dialogue.Request) Test(org.junit.jupiter.api.Test)

Example 29 with Request

use of com.palantir.dialogue.Request in project dialogue by palantir.

the class DialogueChannelTest method createRequestWithAddExecutedOnAttachment.

private Request createRequestWithAddExecutedOnAttachment() {
    Request newRequest = Request.builder().build();
    StickyAttachments.requestStickyToken(newRequest);
    return newRequest;
}
Also used : Request(com.palantir.dialogue.Request)

Example 30 with Request

use of com.palantir.dialogue.Request in project dialogue by palantir.

the class DialogueChannelTest method bad_channel_throwing_an_exception_still_returns_a_future.

@Test
public void bad_channel_throwing_an_exception_still_returns_a_future() {
    Channel badUserImplementation = new Channel() {

        @Override
        public ListenableFuture<Response> execute(Endpoint _endpoint, Request _request) {
            throw new IllegalStateException("Always throw");
        }
    };
    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(IllegalStateException.class);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) TestEndpoint(com.palantir.dialogue.TestEndpoint) Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) Request(com.palantir.dialogue.Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Request (com.palantir.dialogue.Request)40 Test (org.junit.jupiter.api.Test)21 Channel (com.palantir.dialogue.Channel)14 Endpoint (com.palantir.dialogue.Endpoint)14 Response (com.palantir.dialogue.Response)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 TestResponse (com.palantir.dialogue.TestResponse)8 Test (org.junit.Test)8 TestEndpoint (com.palantir.dialogue.TestEndpoint)6 Optional (java.util.Optional)6 Futures (com.google.common.util.concurrent.Futures)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 RequestBody (com.palantir.dialogue.RequestBody)5 UrlBuilder (com.palantir.dialogue.UrlBuilder)5 OutputStream (java.io.OutputStream)5 Duration (java.time.Duration)5 ExecutionException (java.util.concurrent.ExecutionException)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 ImmutableList (com.google.common.collect.ImmutableList)4