Search in sources :

Example 51 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testCompressedFlagIsSet.

@Test
public void testCompressedFlagIsSet() {
    MutableMessage message;
    MessagingQos messagingQos = new MessagingQos();
    messagingQos.setCompress(true);
    message = mutableMessageFactory.createRequest("from", "to", request, messagingQos);
    assertEquals(true, message.getCompressed());
    messagingQos.setCompress(false);
    message = mutableMessageFactory.createRequest("from", "to", request, messagingQos);
    assertEquals(false, message.getCompressed());
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Example 52 with MutableMessage

use of joynr.MutableMessage 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)

Example 53 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testCreateOneWayRequestWithCustomHeader.

@Test
public void testCreateOneWayRequestWithCustomHeader() throws Exception {
    final Map<String, String> myCustomHeaders = new HashMap<>();
    final String headerName = "header";
    final String headerValue = "value";
    myCustomHeaders.put(headerName, headerValue);
    messagingQos.getCustomMessageHeaders().putAll(myCustomHeaders);
    MutableMessage message = mutableMessageFactory.createOneWayRequest(fromParticipantId, toParticipantId, request, messagingQos);
    assertNotNull(message);
    assertEquals(Message.VALUE_MESSAGE_TYPE_ONE_WAY, message.getType());
    assertExpiryDateEquals(expiryDate.getValue(), message);
    final String expectedCustomHeaderName = Message.CUSTOM_HEADER_PREFIX + headerName;
    assertTrue(message.getImmutableMessage().getHeaders().containsKey(expectedCustomHeaderName));
    Map<String, String> customHeaders = message.getCustomHeaders();
    assertTrue(customHeaders.size() == 2);
    assertTrue(customHeaders.containsKey(headerName));
}
Also used : HashMap(java.util.HashMap) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Example 54 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testCreateMulticastSubscriptionRequest.

@Test
public void testCreateMulticastSubscriptionRequest() {
    String multicastId = "multicastId";
    String subscriptionId = "subscriptionId";
    String multicastName = "multicastName";
    SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
    MulticastSubscriptionRequest multicastSubscriptionRequest = new MulticastSubscriptionRequest(multicastId, subscriptionId, multicastName, subscriptionQos);
    MutableMessage result = mutableMessageFactory.createSubscriptionRequest(fromParticipantId, toParticipantId, multicastSubscriptionRequest, messagingQos);
    assertNotNull(result);
    assertEquals(Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST, result.getType());
    assertExpiryDateEquals(expiryDate.getValue(), result);
}
Also used : MutableMessage(joynr.MutableMessage) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) Test(org.junit.Test)

Example 55 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testCreateOneWayRequest.

@Test
public void testCreateOneWayRequest() {
    MutableMessage message = mutableMessageFactory.createOneWayRequest(fromParticipantId, toParticipantId, request, messagingQos);
    assertNotNull(message);
    assertEquals(Message.VALUE_MESSAGE_TYPE_ONE_WAY, message.getType());
    assertEquals(fromParticipantId, message.getSender());
    assertEquals(toParticipantId, message.getRecipient());
    assertExpiryDateEquals(expiryDate.getValue(), message);
    assertNotNull(message.getPayload());
}
Also used : MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Aggregations

MutableMessage (joynr.MutableMessage)60 Test (org.junit.Test)35 MessagingQos (io.joynr.messaging.MessagingQos)15 ImmutableMessage (joynr.ImmutableMessage)9 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)7 SubscriptionRequest (joynr.SubscriptionRequest)6 Request (joynr.Request)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Reply (joynr.Reply)4 Injector (com.google.inject.Injector)3 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)3 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)3 MulticastPublication (joynr.MulticastPublication)3 OneWayRequest (joynr.OneWayRequest)3 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 Multibinder (com.google.inject.multibindings.Multibinder)2 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)2