Search in sources :

Example 26 with ApplicationException

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

the class AbstractSubscriptionEnd2EndTest method testSubscribeToNonExistentDomain.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_ON_SOME_PATH_EXCEPTION", justification = "NPE in test would fail test")
@SuppressWarnings("unchecked")
@Ignore
@Test
public void testSubscribeToNonExistentDomain() throws InterruptedException {
    AttributeSubscriptionListener<Integer> integerListener = mock(AttributeSubscriptionListener.class);
    testProxy proxyToNonexistentDomain = null;
    try {
        ProxyBuilder<testProxy> proxyBuilder;
        String nonExistentDomain = UUID.randomUUID().toString() + "-domaindoesnotexist-end2end";
        MessagingQos messagingQos = new MessagingQos(20000);
        DiscoveryQos discoveryQos = new DiscoveryQos(50000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
        proxyBuilder = consumerRuntime.getProxyBuilder(nonExistentDomain, testProxy.class);
        proxyToNonexistentDomain = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    } catch (DiscoveryException e) {
        logger.error(e.getMessage(), e);
    } catch (JoynrIllegalStateException e) {
        logger.error(e.getMessage(), e);
    }
    // This should not cause an exception
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(30000);
    subscriptionQos.setAlertAfterIntervalMs(0);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxyToNonexistentDomain.subscribeToTestAttribute(integerListener, subscriptionQos);
    Thread.sleep(4000);
    try {
        proxyToNonexistentDomain.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
    } catch (JoynrRuntimeException | ApplicationException e) {
        assertTrue(e.getMessage(), e != null);
    }
    getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) ApplicationException(joynr.exceptions.ApplicationException) DiscoveryException(io.joynr.exceptions.DiscoveryException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with ApplicationException

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

the class ProxyTest method createProxyAndCallSyncMethodFailWithApplicationError.

@Test
public void createProxyAndCallSyncMethodFailWithApplicationError() throws Exception {
    String requestReplyId = "createProxyAndCallSyncMethod_requestReplyId";
    Mockito.when(requestReplyManager.sendSyncRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<SynchronizedReplyCaller>any(), Mockito.<MessagingQos>any())).thenReturn(new Reply(requestReplyId, new ApplicationException(ApplicationErrors.ERROR_VALUE_2, "syncMethodCallApplicationException")));
    ProxyBuilder<TestInterface> proxyBuilder = getProxyBuilder(TestInterface.class);
    TestInterface proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    ApplicationException exception = null;
    try {
        proxy.methodWithApplicationError();
        Assert.fail("Should throw ApplicationException");
    } catch (ApplicationException e) {
        exception = e;
    }
    Assert.assertEquals(new ApplicationException(ApplicationErrors.ERROR_VALUE_2, "syncMethodCallApplicationException"), exception);
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) Reply(joynr.Reply) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 28 with ApplicationException

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

the class ProxyTest method createProxyAndCallAsyncMethodFailWithApplicationError.

@SuppressWarnings({ "unchecked" })
@Test
public void createProxyAndCallAsyncMethodFailWithApplicationError() throws Exception {
    final ApplicationException expected = new ApplicationException(ApplicationErrors.ERROR_VALUE_3, "TEST: createProxyAndCallAsyncMethodFailWithApplicationError");
    TestInterface proxy = getTestInterfaceProxy();
    // when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
    // messageCallback on it.
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
            // capture the replyCaller passed into the dispatcher for calling later
            ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
            verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), any(ExpiryDate.class));
            String requestReplyId = "createProxyAndCallAsyncMethodSuccess_requestReplyId";
            // pass the response to the replyCaller
            replyCallerCaptor.getValue().messageCallBack(new Reply(requestReplyId, expected));
            return null;
        }
    }).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
    CallbackWithModeledError<String, Enum<?>> callbackWithApplicationException = Mockito.mock(CallbackWithModeledError.class);
    final Future<String> future = proxy.asyncMethodWithApplicationError(callbackWithApplicationException);
    // the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
    try {
        future.get(1000);
        Assert.fail("Should throw ApplicationException");
    } catch (ApplicationException e) {
        Assert.assertEquals(expected, e);
    }
    verify(callbackWithApplicationException).onFailure(expected.getError());
    Assert.assertEquals(RequestStatusCode.ERROR, future.getStatus().getCode());
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ReplyCaller(io.joynr.dispatching.rpc.ReplyCaller) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) ApplicationException(joynr.exceptions.ApplicationException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Reply(joynr.Reply) Test(org.junit.Test)

Example 29 with ApplicationException

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

the class SerializationTest method serializeReplyWithJoynrApplicationException.

@Test
public void serializeReplyWithJoynrApplicationException() throws IOException {
    ApplicationException error = new ApplicationException(TestEnum.ONE, "detail message");
    Reply reply = new Reply(UUID.randomUUID().toString(), error);
    String writeValueAsString = objectMapper.writeValueAsString(reply);
    System.out.println(writeValueAsString);
    Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
    Assert.assertEquals(reply, receivedReply);
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) Reply(joynr.Reply) Test(org.junit.Test)

Example 30 with ApplicationException

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

the class AbstractBroadcastEnd2EndTest method subscribeAndUnsubscribeFromBroadcast.

@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeAndUnsubscribeFromBroadcast() throws InterruptedException {
    final Semaphore broadcastReceived = new Semaphore(0);
    Future<String> subscriptionId = proxy.subscribeToLocationUpdateWithSpeedBroadcast(new testBroadcastInterface.LocationUpdateWithSpeedBroadcastAdapter() {

        @Override
        public void onReceive(GpsLocation location, Float speed) {
            assertEquals(expectedLocation, location);
            assertEquals(expectedSpeed, speed);
            broadcastReceived.release();
        }
    }, new MulticastSubscriptionQos());
    Thread.sleep(300);
    provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
    broadcastReceived.acquire();
    // unsubscribe correct subscription -> now, no more broadcast shall be received
    proxy.unsubscribeFromLocationUpdateWithSpeedBroadcast(UUID.randomUUID().toString());
    provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
    broadcastReceived.acquire();
    // unsubscribe correct subscription -> now, no more broadcast shall be received
    try {
        proxy.unsubscribeFromLocationUpdateWithSpeedBroadcast(subscriptionId.get());
    } catch (JoynrRuntimeException | ApplicationException e) {
        logger.error(e.getMessage());
    }
    Thread.sleep(300);
    provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
    assertFalse(broadcastReceived.tryAcquire(300, TimeUnit.MILLISECONDS));
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) GpsLocation(joynr.types.Localisation.GpsLocation) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Ignore(org.junit.Ignore) 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