Search in sources :

Example 11 with ApplicationException

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

the class AbstractProviderProxyEnd2EndTest method syncMethodCallReturnsImplicitErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncMethodCallReturnsImplicitErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.methodWithImplicitErrorEnum();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        ApplicationException expected = new ApplicationException(MethodWithImplicitErrorEnumErrorEnum.IMPLICIT_ERROR);
        assertEquals(expected, e);
    }
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 12 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 13 with ApplicationException

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

the class IltConsumerAsyncMethodTest method callMethodWithMultipleStructParametersAsync.

@Test
public void callMethodWithMultipleStructParametersAsync() {
    LOG.info(name.getMethodName() + "");
    try {
        // setup input parameters
        ExtendedStructOfPrimitives extendedStructOfPrimitivesArg = IltUtil.createExtendedStructOfPrimitives();
        BaseStruct baseStructArg = IltUtil.createBaseStruct();
        MethodWithMultipleStructParametersCallback callback = new MethodWithMultipleStructParametersCallback() {

            @Override
            public void onSuccess(BaseStructWithoutElements baseStructWithoutElementsOut, ExtendedExtendedBaseStruct extendedExtendedBaseStructOut) {
                // check results
                if (!IltUtil.checkBaseStructWithoutElements(baseStructWithoutElementsOut)) {
                    methodWithMultipleStructParametersAsyncCallbackResult = false;
                    methodWithMultipleStructParametersAsyncCallbackDone = true;
                    LOG.info(name.getMethodName() + " - callback - invalid baseStructWithoutElementsOut");
                    LOG.info(name.getMethodName() + " - FAILED");
                    return;
                }
                if (!IltUtil.checkExtendedExtendedBaseStruct(extendedExtendedBaseStructOut)) {
                    methodWithMultipleStructParametersAsyncCallbackResult = false;
                    methodWithMultipleStructParametersAsyncCallbackDone = true;
                    LOG.info(name.getMethodName() + " - callback - invalid extendedExtendedBaseStructOut");
                    LOG.info(name.getMethodName() + " - FAILED");
                    return;
                }
                methodWithMultipleStructParametersAsyncCallbackResult = true;
                methodWithMultipleStructParametersAsyncCallbackDone = true;
            }

            @Override
            public void onFailure(JoynrRuntimeException error) {
                methodWithMultipleStructParametersAsyncCallbackResult = false;
                methodWithMultipleStructParametersAsyncCallbackDone = true;
                if (error instanceof JoynrRuntimeException) {
                    LOG.info(name.getMethodName() + " - callback - caught exception " + ((JoynrRuntimeException) error).getMessage());
                } else {
                    LOG.info(name.getMethodName() + " - callback - caught exception");
                }
                LOG.info(name.getMethodName() + " - FAILED");
            }
        };
        MethodWithMultipleStructParametersFuture future = testInterfaceProxy.methodWithMultipleStructParameters(callback, extendedStructOfPrimitivesArg, baseStructArg);
        try {
            long timeoutInMilliseconds = 8000;
            LOG.info(name.getMethodName() + " - about to call future.get");
            MethodWithMultipleStructParametersReturned result = future.get(timeoutInMilliseconds);
            if (result == null) {
                fail(name.getMethodName() + " - FAILED - got no result");
                return;
            }
            LOG.info(name.getMethodName() + " - returned from future.get");
            // check results from future
            if (!IltUtil.checkBaseStructWithoutElements(result.baseStructWithoutElementsOut)) {
                fail(name.getMethodName() + " - FAILED - got invalid result - baseStructWithoutElementsOut");
                return;
            }
            if (!IltUtil.checkExtendedExtendedBaseStruct(result.extendedExtendedBaseStructOut)) {
                fail(name.getMethodName() + " - FAILED - got invalid result - extendedExtendedBaseStructOut");
                return;
            }
            LOG.info(name.getMethodName() + " - future result checks OK");
            // should have been called ahead anyway
            if (methodWithMultipleStructParametersAsyncCallbackDone == false) {
                LOG.info(name.getMethodName() + " - about to wait for a second for callback");
                Thread.sleep(1000);
                LOG.info(name.getMethodName() + " - wait for callback is over");
            } else {
                LOG.info(name.getMethodName() + " - callback already done");
            }
            if (methodWithMultipleStructParametersAsyncCallbackDone == false) {
                fail(name.getMethodName() + " - FAILED - callback NOT done");
                return;
            }
            if (methodWithMultipleStructParametersAsyncCallbackResult == false) {
                fail(name.getMethodName() + " - FAILED - callback reported error");
                return;
            }
            LOG.info(name.getMethodName() + " - callback has set OK flags");
        } catch (InterruptedException | JoynrRuntimeException | ApplicationException e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : MethodWithMultipleStructParametersFuture(joynr.interlanguagetest.TestInterfaceAsync.MethodWithMultipleStructParametersFuture) MethodWithMultipleStructParametersReturned(joynr.interlanguagetest.TestInterfaceSync.MethodWithMultipleStructParametersReturned) ExtendedExtendedBaseStruct(joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct) MethodWithMultipleStructParametersCallback(joynr.interlanguagetest.TestInterfaceAsync.MethodWithMultipleStructParametersCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ExtendedExtendedBaseStruct(joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct) BaseStruct(joynr.interlanguagetest.namedTypeCollection2.BaseStruct) ExtendedStructOfPrimitives(joynr.interlanguagetest.namedTypeCollection2.ExtendedStructOfPrimitives) ApplicationException(joynr.exceptions.ApplicationException) BaseStructWithoutElements(joynr.interlanguagetest.namedTypeCollection2.BaseStructWithoutElements) Test(org.junit.Test)

Example 14 with ApplicationException

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

the class IltConsumerSyncMethodTest method callMethodWithExistingErrorEnum.

@Test
public void callMethodWithExistingErrorEnum() {
    LOG.info(name.getMethodName() + "");
    // 1st test
    try {
        String wantedExceptionArg = "ProviderRuntimeException";
        testInterfaceProxy.methodWithExistingErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - 1st - unexpected return without exception");
        return;
    } catch (ProviderRuntimeException e) {
        if (e.getMessage() == null || !e.getMessage().endsWith("Exception from methodWithExistingErrorEnum")) {
            fail(name.getMethodName() + " - FAILED - 1st - got invalid exception content");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - 1st - caught unexpected exception type: " + e.getMessage());
        return;
    }
    // 2nd test
    try {
        String wantedExceptionArg = "ApplicationException_1";
        testInterfaceProxy.methodWithExistingErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - 2nd - unexpected return without exception");
        return;
    } catch (ApplicationException e) {
        if (e.getError() != ExtendedErrorEnumTc.ERROR_2_3_TC2) {
            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.methodWithExistingErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - 3rd - unexpected return without exception");
        return;
    } catch (ApplicationException e) {
        if (e.getError() != ExtendedErrorEnumTc.ERROR_1_2_TC_2) {
            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 15 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)

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