Search in sources :

Example 1 with RemoteException

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

the class ConjureExceptionHandlerTest method handles401RemoteException.

@Test
public void handles401RemoteException() throws IOException {
    SerializableError remoteError = SerializableError.forException(new ServiceException(ErrorType.create(Code.UNAUTHORIZED, "Test:ErrorName"), SafeArg.of("foo", "bar")));
    exception = new RemoteException(remoteError, ErrorType.UNAUTHORIZED.httpErrorCode());
    Response response = execute();
    // Propagates errorInstanceId and does not change error code and name
    // Does not propagate args
    SerializableError expectedPropagatedError = SerializableError.builder().errorCode(ErrorType.UNAUTHORIZED.code().toString()).errorName("Test:ErrorName").errorInstanceId(remoteError.errorInstanceId()).build();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Encodings.json().serializer(new TypeMarker<SerializableError>() {
    }).serialize(expectedPropagatedError, stream);
    assertThat(response.body().string()).isEqualTo(stream.toString(StandardCharsets.UTF_8));
    assertThat(response.code()).isEqualTo(ErrorType.UNAUTHORIZED.httpErrorCode());
}
Also used : Response(okhttp3.Response) ServiceException(com.palantir.conjure.java.api.errors.ServiceException) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) TypeMarker(com.palantir.conjure.java.undertow.lib.TypeMarker) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.jupiter.api.Test)

Example 2 with RemoteException

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

the class SingleParamServicesTest method runTestCase.

@Test
public void runTestCase() throws Exception {
    Assume.assumeFalse(Cases.shouldIgnore(endpointName, jsonString));
    System.out.println(String.format("Invoking %s %s(%s)", serviceName, endpointName, jsonString));
    Object service = servicesMaps.get(serviceName).asList().get(serviceIndex);
    for (Method method : servicesMaps.get(serviceName).getClass().getMethods()) {
        String name = method.getName();
        if (method.getParameterCount() == 1) {
            // conjure-java generates `default` methods for optional query params, we don't want to call these
            continue;
        }
        if (endpointName.get().equals(name)) {
            try {
                // HACKHACK, index parameter order is different for different services.
                if ("singleHeaderService".equals(serviceName)) {
                    Type type = method.getGenericParameterTypes()[0];
                    Class<?> cls = ClassUtils.getClass(type.getTypeName());
                    method.invoke(service, objectMapper.readValue(jsonString, cls), index);
                } else {
                    Type type = method.getGenericParameterTypes()[1];
                    Class<?> cls = ClassUtils.getClass(type.getTypeName());
                    method.invoke(service, index, objectMapper.readValue(jsonString, cls));
                }
                log.info("Successfully post param to endpoint {} and index {}", endpointName, index);
            } catch (RemoteException e) {
                log.error("Caught exception with params: {}", e.getError().parameters(), e);
                throw e;
            }
        }
    }
}
Also used : Type(java.lang.reflect.Type) Method(java.lang.reflect.Method) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.Test)

Example 3 with RemoteException

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

the class EteErrors method testIsError.

@Test
void testIsError() {
    RemoteException remoteException = serializeServiceException(ConjureErrors.invalidServiceDefinition("my-service", "service-def"));
    assertThat(ConjureErrors.isInvalidServiceDefinition(remoteException)).isTrue();
    assertThat(ConjureErrors.isInvalidTypeDefinition(remoteException)).isFalse();
}
Also used : RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.jupiter.api.Test)

Example 4 with RemoteException

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

the class EteErrors method testIsError_differentNamespaces.

@Test
void testIsError_differentNamespaces() {
    RemoteException remoteException = serializeServiceException(ConjureJavaErrors.javaCompilationFailed());
    assertThat(ConjureJavaErrors.isJavaCompilationFailed(remoteException)).isTrue();
    assertThat(ConjureJavaOtherErrors.isJavaCompilationFailed(remoteException)).isFalse();
}
Also used : RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.jupiter.api.Test)

Example 5 with RemoteException

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

the class RemoteExceptionAssertTest method testSanity.

@Test
public void testSanity() throws Exception {
    ErrorType actualType = ErrorType.FAILED_PRECONDITION;
    SerializableError error = SerializableError.forException(new ServiceException(actualType));
    Assertions.assertThat(new RemoteException(error, actualType.httpErrorCode())).isGeneratedFromErrorType(actualType);
    assertThatThrownBy(() -> Assertions.assertThat(new RemoteException(error, actualType.httpErrorCode() + 1)).isGeneratedFromErrorType(actualType)).isInstanceOf(AssertionError.class).hasMessage("Expected error status to be %s, but found %s", actualType.httpErrorCode(), actualType.httpErrorCode() + 1);
}
Also used : ErrorType(com.palantir.conjure.java.api.errors.ErrorType) ServiceException(com.palantir.conjure.java.api.errors.ServiceException) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) 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