Search in sources :

Example 21 with ImmutableMessage

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);
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 22 with ImmutableMessage

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);
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 23 with ImmutableMessage

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);
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 24 with ImmutableMessage

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);
}
Also used : MutableMessage(joynr.MutableMessage) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 25 with ImmutableMessage

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

ImmutableMessage (joynr.ImmutableMessage)63 Test (org.junit.Test)42 Response (com.jayway.restassured.response.Response)12 FailureAction (io.joynr.messaging.FailureAction)11 SuccessAction (io.joynr.messaging.SuccessAction)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 EncodingException (io.joynr.smrf.EncodingException)9 MutableMessage (joynr.MutableMessage)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 UnsuppportedVersionException (io.joynr.smrf.UnsuppportedVersionException)8 Semaphore (java.util.concurrent.Semaphore)7 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)6 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)6 MessagingQos (io.joynr.messaging.MessagingQos)6 Ignore (org.junit.Ignore)6 AbstractModule (com.google.inject.AbstractModule)5 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)5 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)4 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)4