Search in sources :

Example 61 with Promise

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

the class ProviderWrapperTest method testInvokeMethodNoArgs.

@Test
public void testInvokeMethodNoArgs() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testServiceMethodNoArgs");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertTrue(result instanceof Promise);
    assertPromiseEquals(result, "test");
}
Also used : Promise(io.joynr.provider.Promise) Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Example 62 with Promise

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

the class ProviderWrapperTest method testInvokeMethodThrowingProviderRuntimeException.

@Test
public void testInvokeMethodThrowingProviderRuntimeException() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testThrowsProviderRuntimeException");
    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 ProviderRuntimeException);
        }
    });
}
Also used : Promise(io.joynr.provider.Promise) 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) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 63 with Promise

use of io.joynr.provider.Promise 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 64 with Promise

use of io.joynr.provider.Promise 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 65 with Promise

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

the class ProviderWrapperTest method testInvokeVoidReturnMethod.

@Test
public void testInvokeVoidReturnMethod() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testServiceMethodVoidReturn");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertTrue(result instanceof Promise);
}
Also used : Promise(io.joynr.provider.Promise) Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Aggregations

Promise (io.joynr.provider.Promise)79 DeferredVoid (io.joynr.provider.DeferredVoid)36 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)27 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)13 Method (java.lang.reflect.Method)9 ProviderWrapper (io.joynr.jeeintegration.ProviderWrapper)6 JoynrProvider (io.joynr.provider.JoynrProvider)6 Test (org.junit.Test)6 JoynrException (io.joynr.exceptions.JoynrException)5 Deferred (io.joynr.provider.Deferred)4 PromiseListener (io.joynr.provider.PromiseListener)4 ExtendedExtendedBaseStruct (joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct)4 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)4 StructWithStringArray (joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray)3 ExtendedTypeCollectionEnumerationInTypeCollection (joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection)3 DiscoveryEntry (joynr.types.DiscoveryEntry)3 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 DiscoveryScope (io.joynr.arbitration.DiscoveryScope)2 ProviderContainer (io.joynr.provider.ProviderContainer)2