Search in sources :

Example 36 with ProviderRuntimeException

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

the class IltProvider method methodWithoutOutputParameter.

/*
     * methodWithoutOutputParameter
     *
     * can only resolve or reject since there is no output parameter
     */
@Override
public Promise<DeferredVoid> methodWithoutOutputParameter(Boolean booleanArg) {
    logger.warn("*************************************************");
    logger.warn("* IltProvider.methodWithoutOutputParameter called");
    logger.warn("*************************************************");
    DeferredVoid deferred = new DeferredVoid();
    if (booleanArg != false) {
        logger.warn("methodWithoutOutputParameter: invalid argument booleanArg");
        deferred.reject(new ProviderRuntimeException("methodWithoutOutputParameter: received wrong argument"));
        return new Promise<DeferredVoid>(deferred);
    }
    deferred.resolve();
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 37 with ProviderRuntimeException

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

the class IltProvider method methodWithSinglePrimitiveParameters.

/*
     * methodWithSinglePrimitiveParameters
     *
     * returns the integer parameter as string
     */
@Override
public Promise<MethodWithSinglePrimitiveParametersDeferred> methodWithSinglePrimitiveParameters(Short uInt16Arg) {
    logger.warn("********************************************************");
    logger.warn("* IltProvider.methodWithSinglePrimitiveParameters called");
    logger.warn("********************************************************");
    MethodWithSinglePrimitiveParametersDeferred deferred = new MethodWithSinglePrimitiveParametersDeferred();
    // if (Short.toUnsignedInt(uInt16Arg) != 65535) {
    if (uInt16Arg != 32767) {
        logger.warn("methodWithSinglePrimitiveParameters: invalid argument uInt16Arg");
        deferred.reject(new ProviderRuntimeException("methodWithSinglePrimitiveParameters: received wrong argument"));
        return new Promise<MethodWithSinglePrimitiveParametersDeferred>(deferred);
    }
    // send back the input converted to a string
    deferred.resolve(new Integer(Short.toUnsignedInt(uInt16Arg)).toString());
    return new Promise<MethodWithSinglePrimitiveParametersDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 38 with ProviderRuntimeException

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

the class IltConsumerAttributeSubscriptionTest method callSubscribeAttributeWithExceptionFromGetter.

@Test
public void callSubscribeAttributeWithExceptionFromGetter() {
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    int minIntervalMs = 0;
    int maxIntervalMs = 10000;
    long validityMs = 60000;
    int alertAfterIntervalMs = 20000;
    int publicationTtlMs = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
    boolean result;
    LOG.info(name.getMethodName() + "");
    try {
        subscriptionIdFuture = testInterfaceProxy.subscribeToAttributeWithExceptionFromGetter(new AttributeSubscriptionAdapter<Boolean>() {

            @Override
            public void onReceive(Boolean value) {
                LOG.info(name.getMethodName() + " - callback - got unexpected publication");
                subscribeAttributeWithExceptionFromGetterCallbackResult = false;
                subscribeAttributeWithExceptionFromGetterCallbackDone = true;
            }

            @Override
            public void onError(JoynrRuntimeException error) {
                if (error instanceof ProviderRuntimeException) {
                    if (((ProviderRuntimeException) error).getMessage().equals("Exception from getAttributeWithExceptionFromGetter")) {
                        LOG.info(name.getMethodName() + " - callback - got expected exception " + ((JoynrRuntimeException) error).getMessage());
                        subscribeAttributeWithExceptionFromGetterCallbackResult = true;
                        subscribeAttributeWithExceptionFromGetterCallbackDone = true;
                        return;
                    }
                    LOG.info(name.getMethodName() + " - callback - caught invalid exception " + ((JoynrRuntimeException) error).getMessage());
                } else if (error instanceof JoynrRuntimeException) {
                    LOG.info(name.getMethodName() + " - callback - caught invalid exception " + ((JoynrRuntimeException) error).getMessage());
                } else {
                    LOG.info(name.getMethodName() + " - callback - caught invalid exception ");
                }
                subscribeAttributeWithExceptionFromGetterCallbackResult = false;
                subscribeAttributeWithExceptionFromGetterCallbackDone = true;
            }
        }, subscriptionQos);
        subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        // should have been called ahead anyway
        if (subscribeAttributeWithExceptionFromGetterCallbackDone == 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 (!subscribeAttributeWithExceptionFromGetterCallbackDone) {
            fail(name.getMethodName() + " - FAILED - callback did not get called in time");
            result = false;
        } else if (subscribeAttributeWithExceptionFromGetterCallbackResult) {
            LOG.info(name.getMethodName() + " - callback got called and received expected exception");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called but received unexpected result");
            result = false;
        }
        // try to unsubscribe in any case
        try {
            testInterfaceProxy.unsubscribeFromAttributeWithExceptionFromGetter(subscriptionId);
            LOG.info(name.getMethodName() + " - unsubscribe successful");
        } catch (Exception e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
            result = false;
        }
        if (!result) {
            LOG.info(name.getMethodName() + " - FAILED");
        } else {
            LOG.info(name.getMethodName() + " - OK");
        }
        return;
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        LOG.info(name.getMethodName() + " - caught unexpected exception");
        LOG.info(name.getMethodName() + " - FAILED");
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 39 with ProviderRuntimeException

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

the class IltConsumerSyncMethodTest method callMethodWithoutErrorEnum.

/*
     * SYNCHRONOUS METHOD CALLS WITH EXCEPTION HANDLING
     */
@Test
public void callMethodWithoutErrorEnum() {
    LOG.info(name.getMethodName() + "");
    try {
        String wantedExceptionArg = "ProviderRuntimeException";
        testInterfaceProxy.methodWithoutErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - unexpected return");
        return;
    } catch (ProviderRuntimeException e) {
        if (e.getMessage() == null || !e.getMessage().endsWith("Exception from methodWithoutErrorEnum")) {
            fail(name.getMethodName() + " - FAILED - invalid exception message");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 40 with ProviderRuntimeException

use of joynr.exceptions.ProviderRuntimeException 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)

Aggregations

ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)67 Promise (io.joynr.provider.Promise)27 ApplicationException (joynr.exceptions.ApplicationException)23 Test (org.junit.Test)21 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)19 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)13 DiscoveryException (io.joynr.exceptions.DiscoveryException)10 DeferredVoid (io.joynr.provider.DeferredVoid)10 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)8 JoynrTimeoutException (io.joynr.exceptions.JoynrTimeoutException)8 JoynrWaitExpiredException (io.joynr.exceptions.JoynrWaitExpiredException)8 joynr.tests.testProxy (joynr.tests.testProxy)8 ExtendedExtendedBaseStruct (joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 JoynrException (io.joynr.exceptions.JoynrException)4 ExtendedBaseStruct (joynr.interlanguagetest.namedTypeCollection2.ExtendedBaseStruct)4 JoynrVersion (io.joynr.JoynrVersion)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)3 Deferred (io.joynr.provider.Deferred)3 PromiseListener (io.joynr.provider.PromiseListener)3