Search in sources :

Example 1 with JmsMapMessageToMap

use of org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithMap.

public void testAmqpValueWithMap() throws Exception {
    final Map<String, Object> originalMap = new LinkedHashMap<>();
    originalMap.put("binaryEntry", new Binary(new byte[] { 0x00, (byte) 0xFF }));
    originalMap.put("intEntry", 42);
    originalMap.put("nullEntry", null);
    final AmqpValue amqpValue = new AmqpValue(originalMap);
    Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "jms/map-message", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    Map<String, Object> convertedMap = new JmsMapMessageToMap().toObject(getBytes(content));
    assertEquals("Unexpected size", originalMap.size(), convertedMap.size());
    assertArrayEquals("Unexpected binary entry", ((Binary) originalMap.get("binaryEntry")).getArray(), (byte[]) convertedMap.get("binaryEntry"));
    assertEquals("Unexpected int entry", originalMap.get("intEntry"), convertedMap.get("intEntry"));
    assertEquals("Unexpected null entry", originalMap.get("nullEntry"), convertedMap.get("nullEntry"));
}
Also used : JmsMapMessageToMap(org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue) LinkedHashMap(java.util.LinkedHashMap) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 2 with JmsMapMessageToMap

use of org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testAmqpValueWithMap.

public void testAmqpValueWithMap() throws Exception {
    final Map<String, Object> originalMap = new LinkedHashMap<>();
    originalMap.put("binaryEntry", new Binary(new byte[] { 0x00, (byte) 0xFF }));
    originalMap.put("intEntry", 42);
    originalMap.put("nullEntry", null);
    final AmqpValue amqpValue = new AmqpValue(originalMap);
    Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "jms/map-message", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    Map<String, Object> convertedMap = new JmsMapMessageToMap().toObject(getBytes(content));
    assertEquals("Unexpected size", originalMap.size(), convertedMap.size());
    assertArrayEquals("Unexpected binary entry", ((Binary) originalMap.get("binaryEntry")).getArray(), (byte[]) convertedMap.get("binaryEntry"));
    assertEquals("Unexpected int entry", originalMap.get("intEntry"), convertedMap.get("intEntry"));
    assertEquals("Unexpected null entry", originalMap.get("nullEntry"), convertedMap.get("nullEntry"));
}
Also used : JmsMapMessageToMap(org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)2 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)2 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)2 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)2 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)2 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)1 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)1