use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.
the class DefaultMqttTopicPrefixProviderTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
Properties properties = PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE);
properties.put(MessagingPropertyKeys.MQTT_TOPIC_PREFIX_MULTICAST, expectedMulticastPrefix);
properties.put(MessagingPropertyKeys.MQTT_TOPIC_PREFIX_REPLYTO, expectedReplyToPrefix);
properties.put(MessagingPropertyKeys.MQTT_TOPIC_PREFIX_UNICAST, expectedUnicastPrefix);
Module testModule = Modules.override(new MqttPahoModule()).with(new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), JoynrMessageProcessor.class);
bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
bind(MessageRouter.class).toInstance(mockMessageRouter);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
}
});
Injector injector = Guice.createInjector(testModule, new JoynrPropertiesModule(properties));
mqttTopicProviderInstance = injector.getInstance(MqttTopicPrefixProvider.class);
}
use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.
the class RpcStubbingTest method setUp.
@Before
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "NPE in test would fail test")
public void setUp() throws JoynrCommunicationException, JoynrSendBufferFullException, JsonGenerationException, JsonMappingException, IOException, JoynrMessageNotSentException {
Deferred<GpsLocation> deferredGpsLocation = new Deferred<GpsLocation>();
deferredGpsLocation.resolve(gpsValue);
when(testMock.returnsGpsLocation()).thenReturn(new Promise<Deferred<GpsLocation>>(deferredGpsLocation));
Deferred<List<GpsLocation>> deferredGpsLocationList = new Deferred<List<GpsLocation>>();
deferredGpsLocationList.resolve(gpsList);
when(testMock.returnsGpsLocationList()).thenReturn(new Promise<Deferred<List<GpsLocation>>>(deferredGpsLocationList));
DeferredVoid deferredVoid = new DeferredVoid();
deferredVoid.resolve();
when(testMock.noParamsNoReturnValue()).thenReturn(new Promise<DeferredVoid>(deferredVoid));
when(testMock.takesTwoSimpleParams(any(Integer.class), any(String.class))).thenReturn(new Promise<DeferredVoid>(deferredVoid));
fromParticipantId = UUID.randomUUID().toString();
toParticipantId = UUID.randomUUID().toString();
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
// required to inject static members of JoynMessagingConnectorFactory
injector = Guice.createInjector(new JoynrPropertiesModule(PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE)), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(RpcUtils.class);
install(new JoynrMessageScopeModule());
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
messagingStubFactory.addBinding(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
}
});
final RequestInterpreter requestInterpreter = injector.getInstance(RequestInterpreter.class);
final RequestCallerFactory requestCallerFactory = injector.getInstance(RequestCallerFactory.class);
when(requestReplyManager.sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), any(Request.class), any(SynchronizedReplyCaller.class), eq(messagingQos))).thenAnswer(new Answer<Reply>() {
@Override
public Reply answer(InvocationOnMock invocation) throws Throwable {
RequestCaller requestCaller = requestCallerFactory.create(testMock);
Object[] args = invocation.getArguments();
Request request = null;
for (Object arg : args) {
if (arg instanceof Request) {
request = (Request) arg;
break;
}
}
final Future<Reply> future = new Future<Reply>();
ProviderCallback<Reply> callback = new ProviderCallback<Reply>() {
@Override
public void onSuccess(Reply result) {
future.onSuccess(result);
}
@Override
public void onFailure(JoynrException error) {
future.onFailure(error);
}
};
requestInterpreter.execute(callback, requestCaller, request);
return future.get();
}
});
JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
connector = joynrMessagingConnectorFactory.create(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), messagingQos);
}
use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryClientTest method setup.
@Before
public void setup() {
final String domainMock = "domainMock";
when(capabilitiesDirectoryEntryMock.getDomain()).thenReturn(domainMock);
Properties properties = new Properties();
properties.put(PROPERTY_CAPABILITIES_FRESHNESS_UPDATE_INTERVAL_MS, String.valueOf(FRESHNESS_UPDATE_INTERVAL_MS));
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
public void configure() {
bind(ProxyBuilderFactory.class).toInstance(proxyBuilderFactoryMock);
bind(GlobalDiscoveryEntry.class).annotatedWith(Names.named(MessagingPropertyKeys.CAPABILITIES_DIRECTORY_DISCOVERY_ENTRY)).toInstance(capabilitiesDirectoryEntryMock);
}
}, new JoynrPropertiesModule(properties));
subject = injector.getInstance(GlobalCapabilitiesDirectoryClient.class);
when(proxyBuilderFactoryMock.get(domainMock, GlobalCapabilitiesDirectoryProxy.class)).thenReturn(capabilitiesProxyBuilderMock);
when(capabilitiesProxyBuilderMock.setDiscoveryQos(any(DiscoveryQos.class))).thenReturn(capabilitiesProxyBuilderMock);
when(capabilitiesProxyBuilderMock.setMessagingQos(any(MessagingQos.class))).thenReturn(capabilitiesProxyBuilderMock);
when(capabilitiesProxyBuilderMock.build()).thenReturn(globalCapabilitiesDirectoryProxyMock);
}
use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryClientTest method getClientWithCustomTTL.
private GlobalCapabilitiesDirectoryClient getClientWithCustomTTL(long ttl) {
Properties properties = new Properties();
properties.put(ConfigurableMessagingSettings.PROPERTY_DISCOVERY_GLOBAL_ADD_AND_REMOVE_TTL_MS, String.valueOf(ttl));
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
public void configure() {
bind(ProxyBuilderFactory.class).toInstance(proxyBuilderFactoryMock);
bind(GlobalDiscoveryEntry.class).annotatedWith(Names.named(MessagingPropertyKeys.CAPABILITIES_DIRECTORY_DISCOVERY_ENTRY)).toInstance(capabilitiesDirectoryEntryMock);
}
}, new JoynrPropertiesModule(properties));
return injector.getInstance(GlobalCapabilitiesDirectoryClient.class);
}
use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.
the class MutableMessageFactoryTest method setUp.
@Before
public void setUp() throws NoSuchMethodException, SecurityException {
fromParticipantId = "sender";
toParticipantId = "receiver";
Injector injector = Guice.createInjector(new JoynrPropertiesModule(new Properties()), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
requestStaticInjection(Request.class);
Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {
@Override
public MutableMessage processOutgoing(MutableMessage joynrMessage) {
joynrMessage.getCustomHeaders().put("test", "test");
return joynrMessage;
}
@Override
public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
return joynrMessage;
}
});
}
});
objectMapper = injector.getInstance(ObjectMapper.class);
payload = "payload";
Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
String requestReplyId = request.getRequestReplyId();
reply = new Reply(requestReplyId, objectMapper.<JsonNode>valueToTree(payload));
messagingQos = new MessagingQos(TTL);
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
String subscriptionId = "subscription";
String attributeName = "attribute";
PeriodicSubscriptionQos subscriptionqos = new PeriodicSubscriptionQos();
subscriptionqos.setPeriodMs(1000).setValidityMs(10).setAlertAfterIntervalMs(1500).setPublicationTtlMs(1000);
subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, subscriptionqos);
String response = "response";
publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
mutableMessageFactory = injector.getInstance(MutableMessageFactory.class);
}
Aggregations