Search in sources :

Example 56 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method createRequestWithCustomHeaders.

@Test
public void createRequestWithCustomHeaders() 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.createRequest(fromParticipantId, toParticipantId, request, messagingQos);
    assertEquals(Message.VALUE_MESSAGE_TYPE_REQUEST, 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() == 3);
    assertTrue(customHeaders.containsKey(headerName));
}
Also used : HashMap(java.util.HashMap) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Example 57 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testCreateMulticastMessage.

@Test
public void testCreateMulticastMessage() {
    String multicastId = "multicastId";
    MulticastPublication multicastPublication = new MulticastPublication(Collections.emptyList(), multicastId);
    MutableMessage joynrMessage = mutableMessageFactory.createMulticast(fromParticipantId, multicastPublication, messagingQos);
    assertNotNull(joynrMessage);
    assertExpiryDateEquals(expiryDate.getValue(), joynrMessage);
    assertEquals(fromParticipantId, joynrMessage.getSender());
    assertEquals(multicastId, joynrMessage.getRecipient());
    assertEquals(Message.VALUE_MESSAGE_TYPE_MULTICAST, joynrMessage.getType());
    assertTrue(new String(joynrMessage.getPayload(), Charsets.UTF_8).contains(MulticastPublication.class.getName()));
}
Also used : MulticastPublication(joynr.MulticastPublication) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Example 58 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class TtlUpliftTest method testTtlUpliftMs_SubscriptionReply.

@Test
public void testTtlUpliftMs_SubscriptionReply() {
    SubscriptionReply subscriptionReply = new SubscriptionReply();
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    MutableMessage message = messageFactoryWithTtlUplift.createSubscriptionReply(fromParticipantId, toParticipantId, subscriptionReply, messagingQos);
    long expiryDateValue = expiryDate.getValue() + TTL_UPLIFT_MS;
    MutableMessageFactoryTest.assertExpiryDateEquals(expiryDateValue, message);
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Example 59 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class TtlUpliftTest method testTtlUpliftMs_SubscriptionStop.

@Test
public void testTtlUpliftMs_SubscriptionStop() {
    SubscriptionStop subscriptionStop = new SubscriptionStop();
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    MutableMessage message = messageFactoryWithTtlUplift.createSubscriptionStop(fromParticipantId, toParticipantId, subscriptionStop, messagingQos);
    long expiryDateValue = expiryDate.getValue() + TTL_UPLIFT_MS;
    MutableMessageFactoryTest.assertExpiryDateEquals(expiryDateValue, message);
}
Also used : MutableMessage(joynr.MutableMessage) SubscriptionStop(joynr.SubscriptionStop) Test(org.junit.Test)

Example 60 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class HttpCommunicationManagerTest method testCreateOpenAndDeleteChannel.

@Test
public void testCreateOpenAndDeleteChannel() throws Exception {
    MutableMessage mutableMessage = new MutableMessage();
    mutableMessage.setType(Message.VALUE_MESSAGE_TYPE_REQUEST);
    mutableMessage.setSender("testSender");
    mutableMessage.setRecipient("testRecipient");
    mutableMessage.setPayload(new byte[] { 0, 1, 2 });
    mutableMessage.setTtlAbsolute(true);
    mutableMessage.setTtlMs(ExpiryDate.fromRelativeTtl(30000).getValue());
    byte[] serializedMessage = mutableMessage.getImmutableMessage().getSerializedMessage();
    final Object waitForChannelCreated = new Object();
    longpollingMessageReceiver.start(dispatcher, new ReceiverStatusListener() {

        @Override
        public void receiverStarted() {
            synchronized (waitForChannelCreated) {
                waitForChannelCreated.notify();
            }
        }

        @Override
        public void receiverException(Throwable e) {
        }
    });
    synchronized (waitForChannelCreated) {
        waitForChannelCreated.wait(5000);
    }
    // post to the channel to see if it exists
    onrequest(1000).with().body(serializedMessage).expect().statusCode(201).when().post("channels/" + testChannelId + "/message/");
    longpollingMessageReceiver.shutdown(true);
    // post again; this time it should be missing (NO_CONTENT)
    onrequest(1000).with().body(serializedMessage).expect().statusCode(400).body(containsString("Channel not found")).when().post("channels/" + testChannelId + "/message/");
}
Also used : MutableMessage(joynr.MutableMessage) ReceiverStatusListener(io.joynr.messaging.ReceiverStatusListener) 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