Search in sources :

Example 6 with PromiseListener

use of io.joynr.provider.PromiseListener in project joynr by bmwcarit.

the class ProviderWrapperTest method assertPromiseEquals.

private void assertPromiseEquals(Object result, Object value) {
    assertTrue(((Promise<?>) result).isFulfilled());
    Boolean[] ensureFulfilled = new Boolean[] { false };
    ((Promise<?>) result).then(new PromiseListener() {

        @Override
        public void onRejection(JoynrException error) {
            Assert.fail();
        }

        @Override
        public void onFulfillment(Object... values) {
            assertEquals(value, values[0]);
            ensureFulfilled[0] = true;
        }
    });
    assertTrue(ensureFulfilled[0]);
}
Also used : Promise(io.joynr.provider.Promise) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException)

Example 7 with PromiseListener

use of io.joynr.provider.PromiseListener 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)

Example 8 with PromiseListener

use of io.joynr.provider.PromiseListener in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method addGlobalCapFails_NextAddShallAddGlobalAgain.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void addGlobalCapFails_NextAddShallAddGlobalAgain() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.GLOBAL);
    String participantId = LocalCapabilitiesDirectoryTest.class.getName() + ".addLocalAndThanGlobalShallWork";
    String domain = "testDomain";
    final DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    Mockito.doAnswer(createAddAnswerWithError()).when(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
    Promise<DeferredVoid> promise = localCapabilitiesDirectory.add(discoveryEntry);
    promise.then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            verify(globalDiscoveryEntryCacheMock, never()).add(eq(globalDiscoveryEntry));
            verify(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
            reset(globalCapabilitiesClient);
            localCapabilitiesDirectory.add(discoveryEntry);
            verify(globalCapabilitiesClient, timeout(200)).add(any(Callback.class), eq(globalDiscoveryEntry));
        }

        @Override
        public void onRejection(JoynrException error) {
        }
    });
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) PromiseListener(io.joynr.provider.PromiseListener) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) JoynrException(io.joynr.exceptions.JoynrException) Matchers.anyString(org.mockito.Matchers.anyString) DeferredVoid(io.joynr.provider.DeferredVoid) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

JoynrException (io.joynr.exceptions.JoynrException)8 PromiseListener (io.joynr.provider.PromiseListener)8 Test (org.junit.Test)5 Promise (io.joynr.provider.Promise)4 ProviderWrapper (io.joynr.jeeintegration.ProviderWrapper)3 JoynrProvider (io.joynr.provider.JoynrProvider)3 Method (java.lang.reflect.Method)3 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)3 Version (joynr.types.Version)3 DeferredVoid (io.joynr.provider.DeferredVoid)2 DiscoveryEntry (joynr.types.DiscoveryEntry)2 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)2 ProviderQos (joynr.types.ProviderQos)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JoynrVersion (io.joynr.JoynrVersion)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 Callback (io.joynr.proxy.Callback)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ApplicationException (joynr.exceptions.ApplicationException)1 MethodInvocationException (joynr.exceptions.MethodInvocationException)1