use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessagingTest method testPostMessageWithoutMessageReceivers.
@Test
public void testPostMessageWithoutMessageReceivers() throws Exception {
Mockito.when(mock.hasMessageReceiver("channel-123")).thenReturn(false);
Mockito.when(mock.isAssignedForChannel("channel-123")).thenReturn(true);
ImmutableMessage message = createJoynrMessage();
byte[] serializedMessage = message.getSerializedMessage();
//
Response response = //
given().contentType(ContentType.BINARY).when().body(serializedMessage).post(serverUrl + "/channels/channel-123/message");
assertEquals(204, /* No Content */
response.getStatusCode());
Mockito.verify(mock).hasMessageReceiver("channel-123");
Mockito.verify(mock, Mockito.never()).passMessageToReceiver("channel-123", serializedMessage);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessagingTest method testPostMessageChannelWasMigrated.
@Test
public void testPostMessageChannelWasMigrated() throws Exception {
Mockito.when(mock.isAssignedForChannel("channel-123")).thenReturn(false);
Mockito.when(mock.hasChannelAssignmentMoved("channel-123")).thenReturn(true);
ImmutableMessage message = createJoynrMessage();
byte[] serializedMessage = message.getSerializedMessage();
//
Response response = //
given().contentType(ContentType.BINARY).when().body(serializedMessage).post(serverUrl + "/channels/channel-123/message");
assertEquals(410, /* Gone */
response.getStatusCode());
assertNull(response.getHeader("Location"));
assertNull(response.getHeader("msgId"));
Mockito.verify(mock, Mockito.never()).passMessageToReceiver("channel-123", serializedMessage);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class MessagingTest method testPostMessageChannelWasNotRegistered.
@Test
public void testPostMessageChannelWasNotRegistered() throws Exception {
Mockito.when(mock.isAssignedForChannel("channel-123")).thenReturn(false);
Mockito.when(mock.hasChannelAssignmentMoved("channel-123")).thenReturn(false);
ImmutableMessage message = createJoynrMessage();
byte[] serializedMessage = message.getSerializedMessage();
//
Response response = //
given().contentType(ContentType.BINARY).when().body(serializedMessage).post(serverUrl + "/channels/channel-123/message");
assertEquals(404, /* Not Found */
response.getStatusCode());
assertNull(response.getHeader("Location"));
assertNull(response.getHeader("msgId"));
Mockito.verify(mock, Mockito.never()).passMessageToReceiver("channel-123", serializedMessage);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class AbstractMessageSenderTest method testReplyToMessageQueue.
@Test
public void testReplyToMessageQueue() throws Exception {
MutableMessage message = createTestRequestMessage();
message = spy(message);
subject.sendMessage(message);
verify(messageRouterMock, never()).route(any(ImmutableMessage.class));
ImmutableMessage immutableMessageMock = Mockito.mock(ImmutableMessage.class);
when(message.getImmutableMessage()).thenReturn(immutableMessageMock);
String expectedReplyTo = "expectedReplyTo";
subject.setReplyToAddress(expectedReplyTo);
verify(messageRouterMock, times(1)).route(immutableMessageMock);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class CcMessageSenderTest method testReplyToIsSet.
@Test
public void testReplyToIsSet() throws Exception {
MutableMessage message = createTestRequestMessage();
final MqttAddress replyToAddress = new MqttAddress("testBrokerUri", "testTopic");
ObjectMapper objectMapper = new ObjectMapper();
String serializedReplyToAddress = objectMapper.writeValueAsString(replyToAddress);
ReplyToAddressProvider replyToAddressProviderMock = Mockito.mock(ReplyToAddressProvider.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertEquals(1, invocation.getArguments().length);
assertThat(invocation.getArguments()[0], instanceOf(TransportReadyListener.class));
TransportReadyListener listener = (TransportReadyListener) invocation.getArguments()[0];
listener.transportReady(replyToAddress);
return null;
}
}).when(replyToAddressProviderMock).registerGlobalAddressesReadyListener(any(TransportReadyListener.class));
CcMessageSender subject = new CcMessageSender(messageRouterMock, replyToAddressProviderMock);
subject.sendMessage(message);
ArgumentCaptor<ImmutableMessage> argCaptor = ArgumentCaptor.forClass(ImmutableMessage.class);
verify(messageRouterMock).route(argCaptor.capture());
assertEquals(serializedReplyToAddress, argCaptor.getValue().getReplyTo());
}
Aggregations