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();
}
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");
}
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");
}
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");
}
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();
}
Aggregations