Search in sources :

Example 61 with InternalMessage

use of org.apache.qpid.server.message.internal.InternalMessage in project qpid-broker-j by apache.

the class MessageConverter_0_8_to_InternalTest method doTest.

private void doTest(final byte[] messageBytes, final String mimeType, final Object expectedContent, final String expectedMimeType) throws Exception {
    final AMQMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    if (expectedContent instanceof byte[]) {
        assertArrayEquals("Unexpected content", ((byte[]) expectedContent), ((byte[]) convertedMessage.getMessageBody()));
    } else if (expectedContent instanceof List) {
        assertEquals("Unexpected content", new ArrayList((Collection) expectedContent), new ArrayList((Collection) convertedMessage.getMessageBody()));
    } else if (expectedContent instanceof Map) {
        assertEquals("Unexpected content", new HashMap((Map) expectedContent), new HashMap((Map) convertedMessage.getMessageBody()));
    } else {
        assertEquals("Unexpected content", expectedContent, convertedMessage.getMessageBody());
    }
    String convertedMimeType = convertedMessage.getMessageHeader().getMimeType();
    assertEquals("Unexpected content type", expectedMimeType, convertedMimeType);
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) HashMap(java.util.HashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 62 with InternalMessage

use of org.apache.qpid.server.message.internal.InternalMessage in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_0_8Test method doTest.

private void doTest(final Serializable messageBytes, final String mimeType, final byte[] expectedContent, final String expectedContentType) throws Exception {
    final InternalMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    final QpidByteBuffer content = convertedMessage.getContent();
    assertArrayEquals("Unexpected content", expectedContent != null ? expectedContent : new byte[0], getBytes(content));
    assertEquals("Unexpected content type", expectedContentType, convertedMessage.getMessageHeader().getMimeType());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 63 with InternalMessage

use of org.apache.qpid.server.message.internal.InternalMessage in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testUserIdConversion.

public void testUserIdConversion() {
    final String userId = "testUserId";
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getUserId()).thenReturn(userId);
    InternalMessage originalMessage = createTestMessage(header);
    AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected userId", userId, convertedMessage.getContentHeaderBody().getProperties().getUserIdAsString());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Matchers.anyString(org.mockito.Matchers.anyString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 64 with InternalMessage

use of org.apache.qpid.server.message.internal.InternalMessage in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testReplyToConversionWhenNonExistingExchangeAndRoutingKeyAreSpecified.

public void testReplyToConversionWhenNonExistingExchangeAndRoutingKeyAreSpecified() {
    final String exchangeName = "testExchange";
    final String routingKey = "testKey";
    final String replyTo = String.format("%s/%s", exchangeName, routingKey);
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getReplyTo()).thenReturn(replyTo);
    InternalMessage originalMessage = createTestMessage(header);
    AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected reply-to", "direct:////?routingkey='" + replyTo + "'", convertedMessage.getContentHeaderBody().getProperties().getReplyToAsString());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Matchers.anyString(org.mockito.Matchers.anyString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 65 with InternalMessage

use of org.apache.qpid.server.message.internal.InternalMessage in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testToConversionWhenGlobalAddressIsKnown.

public void testToConversionWhenGlobalAddressIsKnown() {
    final String globalPrefix = "/testPrefix";
    final String queueName = "testQueue";
    final String globalAddress = globalPrefix + "/" + queueName;
    InternalMessage message = createTestMessage(globalAddress);
    Queue<?> queue = mock(Queue.class);
    when(queue.getName()).thenReturn(queueName);
    when(_addressSpace.getAttainedMessageDestination(queueName)).thenReturn(queue);
    when(_addressSpace.getLocalAddress(globalAddress)).thenReturn(queueName);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
    final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
    assertEquals("Unexpected exchange", "", messagePublishInfo.getExchange().toString());
    assertEquals("Unexpected routing key", queueName, messagePublishInfo.getRoutingKey().toString());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)185 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)60 Matchers.anyString (org.mockito.Matchers.anyString)45 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)36 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)25 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)24 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)23 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)18 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)18 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)17 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)15 HashMap (java.util.HashMap)13 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)12 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)9 UUID (java.util.UUID)8 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)8 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)7 Map (java.util.Map)6 Exchange (org.apache.qpid.server.model.Exchange)6 ArrayList (java.util.ArrayList)5