Search in sources :

Example 1 with TransportReadyListener

use of io.joynr.messaging.routing.TransportReadyListener 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());
}
Also used : TransportReadyListener(io.joynr.messaging.routing.TransportReadyListener) ReplyToAddressProvider(io.joynr.runtime.ReplyToAddressProvider) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TransportReadyListener (io.joynr.messaging.routing.TransportReadyListener)1 ReplyToAddressProvider (io.joynr.runtime.ReplyToAddressProvider)1 ImmutableMessage (joynr.ImmutableMessage)1 MutableMessage (joynr.MutableMessage)1 MqttAddress (joynr.system.RoutingTypes.MqttAddress)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1