Search in sources :

Example 6 with BodySerDe

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

the class ConjureBodySerDeTest method testEmptyResponse_list_raw.

@Test
@SuppressWarnings("rawtypes")
public void testEmptyResponse_list_raw() {
    BodySerDe serde = DefaultConjureRuntime.builder().build().bodySerDe();
    List result = serde.deserializer(new TypeMarker<List>() {
    }).deserialize(new TestResponse().code(204));
    assertThat(result).isEmpty();
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) TypeMarker(com.palantir.dialogue.TypeMarker) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 7 with BodySerDe

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

the class ConjureBodySerDeTest method testRepeatableBinaryRequestBodyProducesRepeatableRequest.

@Test
public void testRepeatableBinaryRequestBodyProducesRepeatableRequest() {
    BodySerDe serde = DefaultConjureRuntime.builder().build().bodySerDe();
    RequestBody requestBody = serde.serialize(new BinaryRequestBody() {

        @Override
        public void write(OutputStream _requestBody) {
        }

        @Override
        public boolean repeatable() {
            return true;
        }
    });
    assertThat(requestBody.repeatable()).isTrue();
}
Also used : OutputStream(java.io.OutputStream) BodySerDe(com.palantir.dialogue.BodySerDe) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) RequestBody(com.palantir.dialogue.RequestBody) Test(org.junit.jupiter.api.Test)

Example 8 with BodySerDe

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

the class ConjureBodySerDeTest method testNonRepeatableBinaryRequestBodyProducesNonRepeatableRequest.

@Test
public void testNonRepeatableBinaryRequestBodyProducesNonRepeatableRequest() {
    BodySerDe serde = DefaultConjureRuntime.builder().build().bodySerDe();
    RequestBody requestBody = serde.serialize(new BinaryRequestBody() {

        @Override
        public void write(OutputStream _requestBody) {
        }

        @Override
        public boolean repeatable() {
            return false;
        }
    });
    assertThat(requestBody.repeatable()).isFalse();
}
Also used : OutputStream(java.io.OutputStream) BodySerDe(com.palantir.dialogue.BodySerDe) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) RequestBody(com.palantir.dialogue.RequestBody) Test(org.junit.jupiter.api.Test)

Example 9 with BodySerDe

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

the class ConjureBodySerDeTest method testDefaultContentType.

@Test
public void testDefaultContentType() throws IOException {
    BodySerDe serializers = conjureBodySerDe("text/plain", "application/json");
    // first encoding is default
    RequestBody body = serializers.serializer(TYPE).serialize("test");
    assertThat(body.contentType()).isEqualTo("text/plain");
    assertThat(serializers.deserializer(TYPE).accepts()).hasValue("text/plain, application/json");
}
Also used : BodySerDe(com.palantir.dialogue.BodySerDe) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) RequestBody(com.palantir.dialogue.RequestBody) Test(org.junit.jupiter.api.Test)

Example 10 with BodySerDe

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

the class ConjureBodySerDeTest method testRequestUnknownContentType.

@Test
public void testRequestUnknownContentType() throws IOException {
    BodySerDe serializers = conjureBodySerDe("application/json", "text/plain");
    RequestBody body = serializers.serializer(TYPE).serialize("test");
    assertThat(body.contentType()).isEqualTo("application/json");
}
Also used : BodySerDe(com.palantir.dialogue.BodySerDe) BinaryRequestBody(com.palantir.dialogue.BinaryRequestBody) RequestBody(com.palantir.dialogue.RequestBody) 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