Search in sources :

Example 1 with ProviderWrapper

use of io.joynr.jeeintegration.ProviderWrapper in project joynr by bmwcarit.

the class ProviderWrapperTest method testMessageScopeActivated.

@Test
public void testMessageScopeActivated() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("assertMessageContextActive");
    assertFalse(JoynrJeeMessageContext.getInstance().isActive());
    subject.invoke(proxy, method, new Object[0]);
    assertFalse(JoynrJeeMessageContext.getInstance().isActive());
}
Also used : Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Example 2 with ProviderWrapper

use of io.joynr.jeeintegration.ProviderWrapper in project joynr by bmwcarit.

the class ProviderWrapperTest method createSubject.

@SuppressWarnings("rawtypes")
private ProviderWrapper createSubject(BeanManager beanManager) {
    Injector injector = mock(Injector.class);
    JoynrMessageCreator joynrMessageCreator = mock(JoynrMessageCreator.class);
    when(injector.getInstance(eq(JoynrMessageCreator.class))).thenReturn(joynrMessageCreator);
    when(joynrMessageCreator.getMessageCreatorId()).thenReturn(USERNAME);
    Bean<?> joynrCallingPrincipalBean = mock(Bean.class);
    when(beanManager.getBeans(JoynrCallingPrincipal.class)).thenReturn(Sets.newHashSet(joynrCallingPrincipalBean));
    when(beanManager.getReference(eq(joynrCallingPrincipalBean), eq(JoynrCallingPrincipal.class), Mockito.<CreationalContext>any())).thenReturn(joynrCallingPincipal);
    Bean<?> bean = mock(Bean.class);
    doReturn(TestServiceImpl.class).when(bean).getBeanClass();
    doReturn(new TestServiceImpl()).when(bean).create(null);
    JoynrMessageMetaInfo joynrMessageContext = mock(JoynrMessageMetaInfo.class);
    when(injector.getInstance(eq(JoynrMessageMetaInfo.class))).thenReturn(joynrMessageContext);
    when(joynrMessageContext.getMessageContext()).thenReturn(expectedMessageContext);
    Bean<?> joynrMessageContextBean = mock(Bean.class);
    when(beanManager.getBeans(JoynrJeeMessageMetaInfo.class)).thenReturn(Sets.newHashSet(joynrMessageContextBean));
    when(beanManager.getReference(eq(joynrMessageContextBean), eq(JoynrJeeMessageMetaInfo.class), Mockito.any())).thenReturn(joynrJeeMessageContext);
    // Setup mock SubscriptionPublisherProducer instance in mock bean manager
    Bean subscriptionPublisherProducerBean = mock(Bean.class);
    doReturn(Sets.newHashSet(subscriptionPublisherProducerBean)).when(beanManager).getBeans(eq(SubscriptionPublisherProducer.class));
    when(beanManager.getReference(eq(subscriptionPublisherProducerBean), eq(SubscriptionPublisherProducer.class), any())).thenReturn(subscriptionPublisherProducer);
    // Setup mock meta data so that subscription publisher can be injected
    InjectionPoint subscriptionPublisherInjectionPoint = mock(InjectionPoint.class);
    when(bean.getInjectionPoints()).thenReturn(Sets.newHashSet(subscriptionPublisherInjectionPoint));
    when(subscriptionPublisherInjectionPoint.getQualifiers()).thenReturn(Sets.newHashSet(SUBSCRIPTION_PUBLISHER_ANNOTATION_LITERAL));
    Annotated annotated = mock(Annotated.class);
    when(subscriptionPublisherInjectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getBaseType()).thenReturn(MySubscriptionPublisher.class);
    ProviderWrapper subject = new ProviderWrapper(bean, beanManager, injector);
    return subject;
}
Also used : Annotated(javax.enterprise.inject.spi.Annotated) JoynrMessageCreator(io.joynr.messaging.JoynrMessageCreator) JoynrMessageMetaInfo(io.joynr.messaging.JoynrMessageMetaInfo) JoynrJeeMessageMetaInfo(io.joynr.jeeintegration.JoynrJeeMessageMetaInfo) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Injector(com.google.inject.Injector) JoynrCallingPrincipal(io.joynr.jeeintegration.api.security.JoynrCallingPrincipal) SubscriptionPublisherProducer(io.joynr.jeeintegration.multicast.SubscriptionPublisherProducer) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Bean(javax.enterprise.inject.spi.Bean)

Example 3 with ProviderWrapper

use of io.joynr.jeeintegration.ProviderWrapper in project joynr by bmwcarit.

the class ProviderWrapperTest method testSetSubscriptionPublisherDoesNotActivateScope.

@Test
public void testSetSubscriptionPublisherDoesNotActivateScope() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceSubscriptionPublisherInjection.class.getMethod("setSubscriptionPublisher", new Class[] { SubscriptionPublisher.class });
    subject.invoke(proxy, method, new Object[] { mock(MySubscriptionPublisher.class) });
    assertFalse(JoynrJeeMessageContext.getInstance().isActive());
}
Also used : Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Example 4 with ProviderWrapper

use of io.joynr.jeeintegration.ProviderWrapper in project joynr by bmwcarit.

the class ProviderWrapperTest method testInvokeMultiOutMethod.

@Test
public void testInvokeMultiOutMethod() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testMultiOutMethod");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertTrue(result instanceof Promise);
    Promise<?> promise = (Promise<?>) result;
    assertTrue(promise.isFulfilled());
    promise.then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            assertArrayEquals(new Object[] { "one", "two" }, values);
        }

        @Override
        public void onRejection(JoynrException error) {
            fail("Shouldn't be here.");
        }
    });
}
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) Test(org.junit.Test)

Example 5 with ProviderWrapper

use of io.joynr.jeeintegration.ProviderWrapper in project joynr by bmwcarit.

the class ProviderWrapperTest method testSetSubscriptionPublisherRegistersWithProducer.

@Test
public void testSetSubscriptionPublisherRegistersWithProducer() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceSubscriptionPublisherInjection.class.getMethod("setSubscriptionPublisher", new Class[] { SubscriptionPublisher.class });
    subject.invoke(proxy, method, new Object[] { mock(MySubscriptionPublisher.class) });
    verify(subscriptionPublisherProducer).add(any(), eq(TestServiceImpl.class));
}
Also used : Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Aggregations

ProviderWrapper (io.joynr.jeeintegration.ProviderWrapper)12 JoynrProvider (io.joynr.provider.JoynrProvider)11 Method (java.lang.reflect.Method)11 Test (org.junit.Test)11 Promise (io.joynr.provider.Promise)6 JoynrException (io.joynr.exceptions.JoynrException)3 PromiseListener (io.joynr.provider.PromiseListener)3 Injector (com.google.inject.Injector)1 JoynrJeeMessageMetaInfo (io.joynr.jeeintegration.JoynrJeeMessageMetaInfo)1 JoynrCallingPrincipal (io.joynr.jeeintegration.api.security.JoynrCallingPrincipal)1 SubscriptionPublisherProducer (io.joynr.jeeintegration.multicast.SubscriptionPublisherProducer)1 JoynrMessageCreator (io.joynr.messaging.JoynrMessageCreator)1 JoynrMessageMetaInfo (io.joynr.messaging.JoynrMessageMetaInfo)1 Annotated (javax.enterprise.inject.spi.Annotated)1 Bean (javax.enterprise.inject.spi.Bean)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 ApplicationException (joynr.exceptions.ApplicationException)1 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)1