Search in sources :

Example 1 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testMulticastMessageIsDroppedIfNoAddressIsFound.

@Test
public void testMulticastMessageIsDroppedIfNoAddressIsFound() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    final MulticastPublication multicastPublication = new MulticastPublication(new JoynrRuntimeException("Test Exception"), "multicastId");
    final MutableMessage mutableMessage = messageFactory.createMulticast("fromParticipantId", multicastPublication, new MessagingQos());
    final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
    MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
    messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            semaphore.release();
            return null;
        }
    }).when(mockMsgProcessedListener).messageProcessed(anyString());
    messageRouter.route(immutableMessage);
    semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
    verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
    verifyNoMoreInteractions(messagingStubMock);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MulticastPublication(joynr.MulticastPublication) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 2 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testNotRoutableReplyDropped.

@Test
public void testNotRoutableReplyDropped() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    final String unknownParticipantId = "unknown_participant_id";
    final String requestReplyId = "some_request_reply_id";
    final Reply reply = new Reply(requestReplyId, new JoynrRuntimeException("TestException"));
    final MutableMessage mutableMessage = messageFactory.createReply(fromParticipantId, unknownParticipantId, reply, new MessagingQos());
    final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
    MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
    messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            semaphore.release();
            return null;
        }
    }).when(mockMsgProcessedListener).messageProcessed(anyString());
    messageRouter.route(immutableMessage);
    semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
    verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
    verifyNoMoreInteractions(messagingStubMock);
}
Also used : Semaphore(java.util.concurrent.Semaphore) Mockito.anyString(org.mockito.Mockito.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) Test(org.junit.Test)

Example 3 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class DefaultJoynrRuntimeFactoryTest method testJoynrMessageProcessorUsed.

@Test
public void testJoynrMessageProcessorUsed() throws Exception {
    createFixture();
    Injector injector = fixture.getInjector();
    MutableMessageFactory messageFactory = injector.getInstance(MutableMessageFactory.class);
    MutableMessage request = messageFactory.createRequest("from", "to", new Request("name", new Object[0], new Class[0]), new MessagingQos());
    assertEquals("test", request.getCustomHeaders().get("test"));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessageFactory(io.joynr.dispatching.MutableMessageFactory) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) Request(joynr.Request) Test(org.junit.Test)

Example 4 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class JeeMessagingEndpointTest method callPostMethod.

private void callPostMethod(PostMethodCaller postMethodCaller) throws Exception {
    SubjectData subjectData = createSubject();
    JeeMessagingEndpoint subject = subjectData.subject;
    byte[] payload = new byte[] { 1, 2, 3 };
    UriInfo uriInfo = mock(UriInfo.class);
    UriBuilder uriBuilder = mock(UriBuilder.class);
    UriBuilder pathBuilder = mock(UriBuilder.class);
    MutableMessage mutableMessage = new MutableMessage();
    mutableMessage.setSender("testSender");
    mutableMessage.setRecipient("testRecipient");
    mutableMessage.setTtlAbsolute(true);
    mutableMessage.setTtlMs(ExpiryDate.fromRelativeTtl(1000L).getValue());
    mutableMessage.setPayload(payload);
    when(uriBuilder.path("messages/" + mutableMessage.getId())).thenReturn(pathBuilder);
    when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
    postMethodCaller.call(subject, "channel-1", mutableMessage.getImmutableMessage().getSerializedMessage(), uriInfo);
    Mockito.verify(subjectData.messageReceiver).receive(Mockito.any());
}
Also used : JeeMessagingEndpoint(io.joynr.jeeintegration.messaging.JeeMessagingEndpoint) MutableMessage(joynr.MutableMessage) UriBuilder(javax.ws.rs.core.UriBuilder) UriInfo(javax.ws.rs.core.UriInfo)

Example 5 with MutableMessage

use of joynr.MutableMessage in project joynr by bmwcarit.

the class MqttMessagingSkeletonTestUtil method createTestMessage.

static ImmutableMessage createTestMessage(String messageType) throws Exception {
    MutableMessage message = new MutableMessage();
    ObjectMapper objectMapper = new ObjectMapper();
    MqttAddress address = new MqttAddress("testBrokerUri", "testTopic");
    message.setSender("someSender");
    message.setRecipient("someRecipient");
    message.setTtlAbsolute(true);
    message.setTtlMs(100000);
    message.setPayload(new byte[] { 0, 1, 2 });
    message.setType(messageType);
    message.setReplyTo(objectMapper.writeValueAsString(address));
    return message.getImmutableMessage();
}
Also used : MutableMessage(joynr.MutableMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

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