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