Search in sources :

Example 6 with JoynrPropertiesModule

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);
}
Also used : NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Properties(java.util.Properties) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) Module(com.google.inject.Module) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 7 with JoynrPropertiesModule

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);
}
Also used : InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Deferred(io.joynr.provider.Deferred) DeferredVoid(io.joynr.provider.DeferredVoid) TypeLiteral(com.google.inject.TypeLiteral) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) List(java.util.List) ProviderCallback(io.joynr.provider.ProviderCallback) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) Request(joynr.Request) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrException(io.joynr.exceptions.JoynrException) AbstractModule(com.google.inject.AbstractModule) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) RequestCaller(io.joynr.dispatching.RequestCaller) AbstractMiddlewareMessagingStubFactory(io.joynr.messaging.AbstractMiddlewareMessagingStubFactory) RequestInterpreter(io.joynr.dispatching.rpc.RequestInterpreter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Reply(joynr.Reply) IMessagingStub(io.joynr.messaging.IMessagingStub) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) RequestCallerFactory(io.joynr.dispatching.RequestCallerFactory) Before(org.junit.Before)

Example 8 with JoynrPropertiesModule

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);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Properties(java.util.Properties) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 9 with JoynrPropertiesModule

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);
}
Also used : Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule)

Example 10 with JoynrPropertiesModule

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);
}
Also used : Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) SubscriptionPublication(joynr.SubscriptionPublication) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

AbstractModule (com.google.inject.AbstractModule)13 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)13 Injector (com.google.inject.Injector)10 Properties (java.util.Properties)10 Before (org.junit.Before)10 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)6 TypeLiteral (com.google.inject.TypeLiteral)5 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)4 NoOpRawMessagingPreprocessor (io.joynr.messaging.NoOpRawMessagingPreprocessor)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Module (com.google.inject.Module)3 Singleton (com.google.inject.Singleton)3 MessagingQos (io.joynr.messaging.MessagingQos)3 Request (joynr.Request)3 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)3 RequestConfig (org.apache.http.client.config.RequestConfig)3 Multibinder (com.google.inject.multibindings.Multibinder)2 AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)2 MessagingTestModule (io.joynr.messaging.MessagingTestModule)2 RawMessagingPreprocessor (io.joynr.messaging.RawMessagingPreprocessor)2