Search in sources :

Example 1 with TestResponse

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

the class ConjureBodySerDeTest method testBinary_optional_empty.

@Test
public void testBinary_optional_empty() {
    TestResponse response = new TestResponse().code(204);
    BodySerDe serializers = conjureBodySerDe("application/json");
    assertThat(serializers.optionalInputStreamDeserializer().deserialize(response)).isEmpty();
    assertThat(response.body().isClosed()).describedAs("inputstream should be closed").isTrue();
    assertThat(response.isClosed()).describedAs("response should be closed").isTrue();
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 2 with TestResponse

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

the class ConjureBodySerDeTest method testRequestContentType.

@Test
public void testRequestContentType() throws IOException {
    TestResponse response = new TestResponse().contentType("text/plain");
    BodySerDe serializers = conjureBodySerDe("application/json", "text/plain");
    String value = serializers.deserializer(TYPE).deserialize(response);
    assertThat(value).isEqualTo("text/plain");
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 3 with TestResponse

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

the class ConjureBodySerDeTest method testUnsupportedRequestContentType.

@Test
public void testUnsupportedRequestContentType() {
    TestResponse response = new TestResponse().contentType("application/unknown");
    BodySerDe serializers = conjureBodySerDe("application/json");
    assertThatThrownBy(() -> serializers.deserializer(TYPE).deserialize(response)).isInstanceOf(SafeRuntimeException.class).hasMessageContaining("Unsupported Content-Type");
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) TestResponse(com.palantir.dialogue.TestResponse) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 4 with TestResponse

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

the class ConjureBodySerDeTest method testRequestNoContentType.

@Test
public void testRequestNoContentType() {
    TestResponse response = new TestResponse();
    BodySerDe serializers = conjureBodySerDe("application/json");
    assertThatThrownBy(() -> serializers.deserializer(TYPE).deserialize(response)).isInstanceOf(SafeIllegalArgumentException.class).hasMessageContaining("Response is missing Content-Type header");
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 5 with TestResponse

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

the class ConjureBodySerDeTest method if_deserialize_throws_response_is_still_closed.

@Test
public void if_deserialize_throws_response_is_still_closed() {
    TestResponse response = new TestResponse().code(200).contentType("application/json");
    BodySerDe serializers = new ConjureBodySerDe(ImmutableList.of(WeightedEncoding.of(BrokenEncoding.INSTANCE)), ErrorDecoder.INSTANCE, Encodings.emptyContainerDeserializer(), DefaultConjureRuntime.DEFAULT_SERDE_CACHE_SPEC);
    assertThatThrownBy(() -> serializers.deserializer(TYPE).deserialize(response)).isInstanceOf(SafeRuntimeException.class).hasMessage("brokenEncoding is broken");
    assertThat(response.body().isClosed()).describedAs("inputstream should be closed").isTrue();
    assertThat(response.isClosed()).describedAs("response should be closed").isTrue();
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) TestResponse(com.palantir.dialogue.TestResponse) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Aggregations

TestResponse (com.palantir.dialogue.TestResponse)31 Test (org.junit.jupiter.api.Test)26 BodySerDe (com.palantir.dialogue.BodySerDe)13 Response (com.palantir.dialogue.Response)13 EndpointChannel (com.palantir.dialogue.EndpointChannel)7 CloseRecordingInputStream (com.palantir.dialogue.CloseRecordingInputStream)4 InputStream (java.io.InputStream)4 Request (com.palantir.dialogue.Request)3 TypeMarker (com.palantir.dialogue.TypeMarker)3 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)3 IOException (java.io.IOException)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 RemoteException (com.palantir.conjure.java.api.errors.RemoteException)2 SerializableError (com.palantir.conjure.java.api.errors.SerializableError)2 ServiceException (com.palantir.conjure.java.api.errors.ServiceException)2 Channel (com.palantir.dialogue.Channel)2 Endpoint (com.palantir.dialogue.Endpoint)2 Random (java.util.Random)2 Meter (com.codahale.metrics.Meter)1