Search in sources :

Example 21 with RemoteException

use of com.palantir.conjure.java.api.errors.RemoteException 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));
}
Also used : ServiceException(com.palantir.conjure.java.api.errors.ServiceException) TestResponse(com.palantir.dialogue.TestResponse) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Example 22 with RemoteException

use of com.palantir.conjure.java.api.errors.RemoteException in project dialogue by palantir.

the class ConjureBodySerDeTest method testErrorsDecoded.

@Test
public void testErrorsDecoded() {
    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("text/plain");
    assertThatExceptionOfType(RemoteException.class).isThrownBy(() -> serializers.deserializer(TYPE).deserialize(response));
    assertThat(response.isClosed()).describedAs("response should be closed").isTrue();
    assertThat(response.body().isClosed()).describedAs("inputstream should be closed").isTrue();
}
Also used : ServiceException(com.palantir.conjure.java.api.errors.ServiceException) TestResponse(com.palantir.dialogue.TestResponse) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) BodySerDe(com.palantir.dialogue.BodySerDe) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteException (com.palantir.conjure.java.api.errors.RemoteException)22 Test (org.junit.jupiter.api.Test)11 SerializableError (com.palantir.conjure.java.api.errors.SerializableError)7 ServiceException (com.palantir.conjure.java.api.errors.ServiceException)7 Test (org.junit.Test)6 UnknownRemoteException (com.palantir.conjure.java.api.errors.UnknownRemoteException)5 Response (okhttp3.Response)5 TypeMarker (com.palantir.conjure.java.undertow.lib.TypeMarker)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 BodySerDe (com.palantir.dialogue.BodySerDe)2 TestResponse (com.palantir.dialogue.TestResponse)2 SafeIoException (com.palantir.logsafe.exceptions.SafeIoException)2 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 Call (okhttp3.Call)2 Callback (okhttp3.Callback)2 MockResponse (okhttp3.mockwebserver.MockResponse)2