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);
}
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);
}
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"));
}
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());
}
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();
}
Aggregations