Search in sources :

Example 11 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractBroadcastEnd2EndTest method subscribeToBroadcastOneOutput.

@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToBroadcastOneOutput() throws InterruptedException {
    final Semaphore broadcastReceived = new Semaphore(0);
    proxy.subscribeToLocationUpdateBroadcast(new testBroadcastInterface.LocationUpdateBroadcastAdapter() {

        @Override
        public void onReceive(GpsLocation location) {
            assertEquals(expectedLocation, location);
            broadcastReceived.release();
        }
    }, new MulticastSubscriptionQos());
    Thread.sleep(300);
    provider.fireLocationUpdate(expectedLocation);
    broadcastReceived.acquire();
}
Also used : GpsLocation(joynr.types.Localisation.GpsLocation) Semaphore(java.util.concurrent.Semaphore) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractBroadcastEnd2EndTest method subscribeToSelectiveBroadcast_FilterFalse.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToSelectiveBroadcast_FilterFalse() throws InterruptedException {
    final Semaphore broadcastReceived = new Semaphore(0);
    final LocationUpdateSelectiveBroadcastFilterParameters testFilterParameters = new LocationUpdateSelectiveBroadcastFilterParameters();
    testFilterParameters.setCountry("Germany");
    testFilterParameters.setStartTime("4.00 pm");
    testLocationUpdateSelectiveBroadcastFilter filter1 = new testLocationUpdateSelectiveBroadcastFilter() {

        @Override
        public boolean filter(GpsLocation location, LocationUpdateSelectiveBroadcastFilterParameters filterParameters) {
            assertEquals(testFilterParameters, filterParameters);
            return true;
        }
    };
    testLocationUpdateSelectiveBroadcastFilter filter2 = new testLocationUpdateSelectiveBroadcastFilter() {

        @Override
        public boolean filter(GpsLocation location, LocationUpdateSelectiveBroadcastFilterParameters filterParameters) {
            assertEquals(testFilterParameters, filterParameters);
            return false;
        }
    };
    getSubscriptionTestsPublisher().addBroadcastFilter(filter1);
    getSubscriptionTestsPublisher().addBroadcastFilter(filter2);
    OnChangeSubscriptionQos subscriptionQos = createDefaultOnChangeSubscriptionQos();
    proxy.subscribeToLocationUpdateSelectiveBroadcast(new testBroadcastInterface.LocationUpdateSelectiveBroadcastAdapter() {

        @Override
        public void onReceive(GpsLocation location) {
            assertEquals(expectedLocation, location);
            broadcastReceived.release();
        }
    }, subscriptionQos, testFilterParameters);
    Thread.sleep(300);
    provider.fireLocationUpdateSelective(expectedLocation);
    assertFalse(broadcastReceived.tryAcquire(500, TimeUnit.MILLISECONDS));
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) GpsLocation(joynr.types.Localisation.GpsLocation) LocationUpdateSelectiveBroadcastFilterParameters(joynr.tests.testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Semaphore(java.util.concurrent.Semaphore) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) Test(org.junit.Test)

Example 13 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method calledMethodReturnsMultipleOutputParametersAsyncFuture.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void calledMethodReturnsMultipleOutputParametersAsyncFuture() throws Exception {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    Future<MethodWithMultipleOutputParametersReturned> future = proxy.methodWithMultipleOutputParameters(new MethodWithMultipleOutputParametersCallback() {

        @Override
        public void onFailure(JoynrRuntimeException error) {
            logger.error("error in calledMethodReturnsMultipleOutputParametersAsyncCallback", error);
        }

        @Override
        public void onSuccess(String aString, Integer aNumber, GpsLocation aComplexDataType, TestEnum anEnumResult) {
            assertEquals(TEST_INTEGER, aNumber);
            assertEquals(TEST_STRING, aString);
            assertEquals(TEST_COMPLEXTYPE, aComplexDataType);
            assertEquals(TEST_ENUM, anEnumResult);
        }
    });
    MethodWithMultipleOutputParametersReturned reply = future.get();
    assertEquals(TEST_INTEGER, reply.aNumber);
    assertEquals(TEST_STRING, reply.aString);
    assertEquals(TEST_COMPLEXTYPE, reply.aComplexDataType);
    assertEquals(TEST_ENUM, reply.anEnumResult);
}
Also used : MethodWithMultipleOutputParametersReturned(joynr.tests.testSync.MethodWithMultipleOutputParametersReturned) joynr.tests.testProxy(joynr.tests.testProxy) GpsLocation(joynr.types.Localisation.GpsLocation) TestEnum(joynr.tests.testTypes.TestEnum) MethodWithMultipleOutputParametersCallback(joynr.tests.testAsync.MethodWithMultipleOutputParametersCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 14 with GpsLocation

use of joynr.types.Localisation.GpsLocation 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 15 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class SerializationTest method serializeAndDeserializeRequestWithVariousTypesTest.

@Test
public void serializeAndDeserializeRequestWithVariousTypesTest() throws Exception {
    String methodName = "methodName";
    GpsLocation gpsLocation = new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0);
    GpsLocation[] gpsLocations = { new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0), new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0), new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0) };
    TestClass testObject = new TestClass();
    testObject.setMyByte((byte) 4);
    testObject.setObjects(new Object[] { gpsLocation, "hello" });
    String[][] stringArray = new String[][] { { "test1", "test2", "test3" }, { "test4", "test5", "test6" } };
    Boolean[] booleanArray = { true, false };
    Boolean[] emptyArray = {};
    Object[] mixedArray = new Object[] { "one", gpsLocation, stringArray };
    Object[] params = new Object[] { true, Integer.MAX_VALUE, Long.MAX_VALUE, Double.MAX_VALUE, gpsLocation, "param1", gpsLocations, stringArray, booleanArray, emptyArray, mixedArray };
    String[] paramDatatypes = new String[params.length];
    for (int i = 0; i < params.length; i++) {
        paramDatatypes[i] = ReflectionUtils.toDatatypeNames(params[i].getClass())[0];
    }
    Request request = new Request(methodName, params, paramDatatypes, null);
    String valueAsString = objectMapper.writeValueAsString(request);
    System.out.println(valueAsString);
    Request request2 = objectMapper.readValue(valueAsString, Request.class);
    assertEquals(request, request2);
}
Also used : OneWayRequest(joynr.OneWayRequest) SubscriptionRequest(joynr.SubscriptionRequest) PersistedSubscriptionRequest(io.joynr.dispatching.subscription.PersistedSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Request(joynr.Request) GpsLocation(joynr.types.Localisation.GpsLocation) Test(org.junit.Test)

Aggregations

GpsLocation (joynr.types.Localisation.GpsLocation)22 Test (org.junit.Test)18 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)9 Semaphore (java.util.concurrent.Semaphore)7 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)6 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 MessagingQos (io.joynr.messaging.MessagingQos)5 ArrayList (java.util.ArrayList)5 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)5 SubscriptionRequest (joynr.SubscriptionRequest)5 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)4 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)4 SubscriptionPublication (joynr.SubscriptionPublication)4 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)4 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 joynr.tests.testProxy (joynr.tests.testProxy)3 Ignore (org.junit.Ignore)3 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2