Search in sources :

Example 1 with BodySerDe

use of com.palantir.dialogue.BodySerDe 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 BodySerDe

use of com.palantir.dialogue.BodySerDe 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 BodySerDe

use of com.palantir.dialogue.BodySerDe 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 BodySerDe

use of com.palantir.dialogue.BodySerDe 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 BodySerDe

use of com.palantir.dialogue.BodySerDe 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

BodySerDe (com.palantir.dialogue.BodySerDe)20 Test (org.junit.jupiter.api.Test)20 TestResponse (com.palantir.dialogue.TestResponse)13 BinaryRequestBody (com.palantir.dialogue.BinaryRequestBody)7 RequestBody (com.palantir.dialogue.RequestBody)7 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 CloseRecordingInputStream (com.palantir.dialogue.CloseRecordingInputStream)2 TypeMarker (com.palantir.dialogue.TypeMarker)2 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ImmutableList (com.google.common.collect.ImmutableList)1 SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)1 List (java.util.List)1