Search in sources :

Example 16 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class IltConsumerSyncMethodTest method callMethodWithExtendedErrorEnum.

@Test
public void callMethodWithExtendedErrorEnum() {
    LOG.info(name.getMethodName() + "");
    // 1st test
    try {
        String wantedExceptionArg = "ProviderRuntimeException";
        testInterfaceProxy.methodWithExtendedErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - 1st - unexpected return without exception");
        return;
    } catch (ProviderRuntimeException e) {
        if (e.getMessage() == null || !e.getMessage().endsWith("Exception from methodWithExtendedErrorEnum")) {
            fail(name.getMethodName() + " - FAILED - 1st - invalid exception message");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    // 2nd test
    try {
        String wantedExceptionArg = "ApplicationException_1";
        testInterfaceProxy.methodWithExtendedErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - 2nd - unexpected return without exception");
        return;
    } catch (ApplicationException e) {
        if (e.getError() != MethodWithExtendedErrorEnumErrorEnum.ERROR_3_3_NTC) {
            fail(name.getMethodName() + " - FAILED - 2nd - unexpected exception error enum value");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    // 3rd test
    try {
        String wantedExceptionArg = "ApplicationException_2";
        testInterfaceProxy.methodWithExtendedErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - 3rd - unexpected return without exception");
        return;
    } catch (ApplicationException e) {
        if (e.getError() != MethodWithExtendedErrorEnumErrorEnum.ERROR_2_1_TC2) {
            fail(name.getMethodName() + " - FAILED - 3rd - unexpected exception error enum value");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 17 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class IltConsumerSyncMethodTest method callMethodWithAnonymousErrorEnum.

@Test
public void callMethodWithAnonymousErrorEnum() {
    LOG.info(name.getMethodName() + "");
    try {
        String wantedExceptionArg = "ProviderRuntimeException";
        testInterfaceProxy.methodWithAnonymousErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - got no result");
        return;
    } catch (ProviderRuntimeException e) {
        if (e.getMessage() == null || !e.getMessage().endsWith("Exception from methodWithAnonymousErrorEnum")) {
            fail(name.getMethodName() + " - FAILED - got invalid ProviderRuntimeException");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    // 2nd test
    try {
        String wantedExceptionArg = "ApplicationException";
        testInterfaceProxy.methodWithAnonymousErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - unexpected return of method");
        return;
    } catch (ApplicationException e) {
        if (e.getError() != MethodWithAnonymousErrorEnumErrorEnum.ERROR_3_1_NTC) {
            fail(name.getMethodName() + " - FAILED - got invalid exception error enum value");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 18 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class IltProviderBean method methodWithAnonymousErrorEnum.

/*
     * methodWithAnonymousErrorEnum
     */
@Override
public void methodWithAnonymousErrorEnum(String wantedExceptionArg) throws ApplicationException {
    logger.warn("*************************************************");
    logger.warn("* IltProvider.methodWithAnonymousErrorEnum called");
    logger.warn("*************************************************");
    if (wantedExceptionArg.equals("ProviderRuntimeException")) {
        throw new ProviderRuntimeException("Exception from methodWithAnonymousErrorEnum");
    } else if (wantedExceptionArg.equals("ApplicationException")) {
        throw new ApplicationException(MethodWithAnonymousErrorEnumErrorEnum.ERROR_3_1_NTC);
    }
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 19 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class IltProviderBean method methodWithExtendedErrorEnum.

/*
     * methodWithExtendedErrorEnum
     */
@Override
public void methodWithExtendedErrorEnum(String wantedExceptionArg) throws ApplicationException {
    logger.warn("************************************************");
    logger.warn("* IltProvider.methodWithExtendedErrorEnum called");
    logger.warn("************************************************");
    if (wantedExceptionArg.equals("ProviderRuntimeException")) {
        throw new ProviderRuntimeException("Exception from methodWithExtendedErrorEnum");
    } else if (wantedExceptionArg.equals("ApplicationException_1")) {
        throw new ApplicationException(MethodWithExtendedErrorEnumErrorEnum.ERROR_3_3_NTC);
    } else if (wantedExceptionArg.equals("ApplicationException_2")) {
        throw new ApplicationException(MethodWithExtendedErrorEnumErrorEnum.ERROR_2_1_TC2);
    }
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 20 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class ProviderWrapperTest method testInvokeMethodThrowingApplicationException.

@Test
public void testInvokeMethodThrowingApplicationException() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testThrowsApplicationException");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertNotNull(result);
    assertTrue(result instanceof Promise);
    assertTrue(((Promise<?>) result).isRejected());
    ((Promise<?>) result).then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            fail("Should never get here");
        }

        @Override
        public void onRejection(JoynrException error) {
            assertTrue(error instanceof ApplicationException);
        }
    });
}
Also used : Promise(io.joynr.provider.Promise) ApplicationException(joynr.exceptions.ApplicationException) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Aggregations

ApplicationException (joynr.exceptions.ApplicationException)31 Test (org.junit.Test)21 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)13 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)13 joynr.tests.testProxy (joynr.tests.testProxy)7 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)6 Reply (joynr.Reply)5 DeferredVoid (io.joynr.provider.DeferredVoid)4 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 JoynrException (io.joynr.exceptions.JoynrException)3 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)3 CheckForNull (javax.annotation.CheckForNull)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 SynchronizedReplyCaller (io.joynr.dispatching.rpc.SynchronizedReplyCaller)2 MessagingQos (io.joynr.messaging.MessagingQos)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)2 Ignore (org.junit.Ignore)2