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);
}
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);
}
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;
}
}
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");
}
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");
}
Aggregations