Search in sources :

Example 1 with RequestCallerFactory

use of io.joynr.dispatching.RequestCallerFactory in project joynr by bmwcarit.

the class PublicationManagerTest method setUp.

@Before
public void setUp() {
    Deferred<String> valueToPublishDeferred = new Deferred<String>();
    valueToPublishDeferred.resolve(valueToPublish);
    Promise<Deferred<String>> valueToPublishPromise = new Promise<Deferred<String>>(valueToPublishDeferred);
    cleanupScheduler = new ScheduledThreadPoolExecutor(1);
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    requestCaller = new RequestCallerFactory().create(provider);
    when(providerContainer.getProviderProxy()).thenReturn(requestCaller.getProxy());
    when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
    when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(false);
    doReturn(valueToPublishPromise).when(attributePollInterpreter).execute(any(ProviderContainer.class), any(Method.class));
}
Also used : Promise(io.joynr.provider.Promise) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Deferred(io.joynr.provider.Deferred) Matchers.anyString(org.mockito.Matchers.anyString) Method(java.lang.reflect.Method) ProviderContainer(io.joynr.provider.ProviderContainer) RequestCallerFactory(io.joynr.dispatching.RequestCallerFactory) Before(org.junit.Before)

Example 2 with RequestCallerFactory

use of io.joynr.dispatching.RequestCallerFactory 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 3 with RequestCallerFactory

use of io.joynr.dispatching.RequestCallerFactory in project joynr by bmwcarit.

the class RequestInterpreterTest method setup.

@Before
public void setup() {
    RequestCallerFactory requestCallerFactory = new RequestCallerFactory();
    requestCaller = requestCallerFactory.create(new DefaulttestProvider());
    subject = new RequestInterpreter(joynrMessageScope, joynrMessageCreatorProvider, joynrMessageContextProvider);
    request = new OneWayRequest("getTestAttribute", new Object[0], new Class[0]);
    request.setCreatorUserId("creator");
    Mockito.when(joynrMessageCreatorProvider.get()).thenReturn(joynrMessageCreator);
    Mockito.when(joynrMessageContextProvider.get()).thenReturn(joynrMessageContext);
}
Also used : OneWayRequest(joynr.OneWayRequest) DefaulttestProvider(joynr.tests.DefaulttestProvider) RequestCallerFactory(io.joynr.dispatching.RequestCallerFactory) Before(org.junit.Before)

Example 4 with RequestCallerFactory

use of io.joynr.dispatching.RequestCallerFactory in project joynr by bmwcarit.

the class PushingPublicationTest method setUp.

@Before
public void setUp() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
    provider = new SubscriptionTestsProviderImpl();
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    subscriptionId = "subscriptionId";
    proxyId = "proxyId";
    providerId = "providerId";
    attributeName = "testAttribute";
    publication = new SubscriptionPublication(Arrays.asList(testAttribute), subscriptionId);
    testSubscriptionPublisherImpl testSubscriptionPublisher = new testSubscriptionPublisherImpl();
    provider.setSubscriptionPublisher(testSubscriptionPublisher);
    when(providerContainer.getProviderProxy()).thenReturn(new RequestCallerFactory().create(provider).getProxy());
    when(providerContainer.getSubscriptionPublisher()).thenReturn(testSubscriptionPublisher);
    setupMocks();
}
Also used : SubscriptionPublication(joynr.SubscriptionPublication) joynr.tests.testSubscriptionPublisherImpl(joynr.tests.testSubscriptionPublisherImpl) RequestCallerFactory(io.joynr.dispatching.RequestCallerFactory) Before(org.junit.Before)

Aggregations

RequestCallerFactory (io.joynr.dispatching.RequestCallerFactory)4 Before (org.junit.Before)4 Deferred (io.joynr.provider.Deferred)2 AbstractModule (com.google.inject.AbstractModule)1 TypeLiteral (com.google.inject.TypeLiteral)1 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)1 JoynrMessageScopeModule (io.joynr.context.JoynrMessageScopeModule)1 RequestCaller (io.joynr.dispatching.RequestCaller)1 RequestInterpreter (io.joynr.dispatching.rpc.RequestInterpreter)1 SynchronizedReplyCaller (io.joynr.dispatching.rpc.SynchronizedReplyCaller)1 JoynrException (io.joynr.exceptions.JoynrException)1 AbstractMiddlewareMessagingStubFactory (io.joynr.messaging.AbstractMiddlewareMessagingStubFactory)1 IMessagingStub (io.joynr.messaging.IMessagingStub)1 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)1 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)1 DeferredVoid (io.joynr.provider.DeferredVoid)1 Promise (io.joynr.provider.Promise)1 ProviderCallback (io.joynr.provider.ProviderCallback)1 ProviderContainer (io.joynr.provider.ProviderContainer)1 Method (java.lang.reflect.Method)1