use of com.palantir.dialogue.BodySerDe in project dialogue by palantir.
the class BinaryEncodingTest method testBinary.
@Test
public void testBinary() throws IOException {
TestResponse response = new TestResponse().code(200).contentType("application/octet-stream");
BodySerDe serializers = new ConjureBodySerDe(ImmutableList.of(WeightedEncoding.of(new ConjureBodySerDeTest.StubEncoding("application/json"))), ErrorDecoder.INSTANCE, Encodings.emptyContainerDeserializer(), DefaultConjureRuntime.DEFAULT_SERDE_CACHE_SPEC);
InputStream deserialized = serializers.inputStreamDeserializer().deserialize(response);
assertThat(deserialized.available()).isEqualTo(0);
CloseRecordingInputStream rawInputStream = response.body();
rawInputStream.assertNotClosed();
assertThat(response.isClosed()).describedAs("response is unclosed initially").isFalse();
deserialized.close();
assertThat(response.isClosed()).describedAs("Response#close was never called, but no big deal because the body is the only resource worth" + " closing").isFalse();
}
use of com.palantir.dialogue.BodySerDe in project dialogue by palantir.
the class BinaryEncodingTest method testBinary_optional_present.
@Test
public void testBinary_optional_present() throws IOException {
TestResponse response = new TestResponse().code(200).contentType("application/octet-stream");
BodySerDe serializers = new ConjureBodySerDe(ImmutableList.of(WeightedEncoding.of(new ConjureBodySerDeTest.StubEncoding("application/json"))), ErrorDecoder.INSTANCE, Encodings.emptyContainerDeserializer(), DefaultConjureRuntime.DEFAULT_SERDE_CACHE_SPEC);
Optional<InputStream> maybe = serializers.optionalInputStreamDeserializer().deserialize(response);
assertThat(maybe).isPresent();
InputStream deserialized = maybe.get();
assertThat(deserialized.available()).isEqualTo(0);
CloseRecordingInputStream rawInputStream = response.body();
rawInputStream.assertNotClosed();
assertThat(response.isClosed()).describedAs("response is unclosed initially").isFalse();
deserialized.close();
assertThat(response.isClosed()).describedAs("Response#close was never called, but no big deal because the body is the only resource worth" + " closing").isFalse();
}
use of com.palantir.dialogue.BodySerDe in project dialogue by palantir.
the class ConjureBodySerDeTest method testEmptyResponse_failure.
@Test
public void testEmptyResponse_failure() {
TestResponse response = new TestResponse().code(400);
ServiceException serviceException = new ServiceException(ErrorType.INVALID_ARGUMENT);
SerializableError serialized = SerializableError.forException(serviceException);
errorDecoder = mock(ErrorDecoder.class);
when(errorDecoder.isError(response)).thenReturn(true);
when(errorDecoder.decode(response)).thenReturn(new RemoteException(serialized, 400));
BodySerDe serializers = conjureBodySerDe("application/json");
assertThatExceptionOfType(RemoteException.class).isThrownBy(() -> serializers.emptyBodyDeserializer().deserialize(response));
}
use of com.palantir.dialogue.BodySerDe in project dialogue by palantir.
the class ConjureBodySerDeTest method testDefaultBinaryRequestBodyProducesNonRepeatableRequestBody.
@Test
public void testDefaultBinaryRequestBodyProducesNonRepeatableRequestBody() {
BodySerDe serde = DefaultConjureRuntime.builder().build().bodySerDe();
RequestBody requestBody = serde.serialize(_requestBody -> {
});
assertThat(requestBody.repeatable()).isFalse();
}
use of com.palantir.dialogue.BodySerDe in project dialogue by palantir.
the class ConjureBodySerDeTest method testRequestOptionalEmpty.
@Test
public void testRequestOptionalEmpty() {
TestResponse response = new TestResponse().code(204);
BodySerDe serializers = conjureBodySerDe("application/json");
Optional<String> value = serializers.deserializer(OPTIONAL_TYPE).deserialize(response);
assertThat(value).isEmpty();
}
Aggregations