Search in sources :

Example 1 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testAmqpValueWithNull.

@Test
public void testAmqpValueWithNull() throws Exception {
    final Object expected = null;
    final AmqpValue amqpValue = new AmqpValue(expected);
    Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
    assertEquals("Unexpected content size", (long) 0, convertedMessage.getSize());
}
Also used : 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) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue) Test(org.junit.Test)

Example 2 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testAmqpSequenceWithUnsupportedType.

@Test
public void testAmqpSequenceWithUnsupportedType() throws Exception {
    final List<Object> originalList = Collections.singletonList(new Source());
    final AmqpSequence amqpSequence = new AmqpSequence(originalList);
    Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
    try {
        _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
        fail("expected exception not thrown.");
    } catch (MessageConversionException e) {
    // pass
    }
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) AmqpSequence(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Test(org.junit.Test)

Example 3 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method createTestMessage.

private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final EncodingRetainingSection section) {
    final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
    MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, 0);
    when(storedMessage.getMetaData()).thenReturn(metaData);
    if (section != null) {
        // TODO this seems to leak QBBs
        final QpidByteBuffer combined = section.getEncodedForm();
        when(storedMessage.getContentSize()).thenReturn((int) section.getEncodedSize());
        final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
        final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
        when(storedMessage.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
    } else {
        when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    }
    return new Message_1_0(storedMessage);
}
Also used : Footer(org.apache.qpid.server.protocol.v1_0.type.messaging.Footer) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 4 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testAmqpValueWithMapContainingMap.

@Test
public void testAmqpValueWithMapContainingMap() throws Exception {
    final Map<String, Object> originalMap = Collections.singletonMap("testMap", Collections.singletonMap("innerKey", "testValue"));
    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", "amqp/map", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    Map<String, Object> convertedMap = new AmqpMapToMapConverter().toObject(getBytes(content));
    assertEquals("Unexpected size", (long) originalMap.size(), (long) convertedMap.size());
    assertEquals("Unexpected binary entry", new HashMap((Map<String, Object>) originalMap.get("testMap")), new HashMap((Map<String, Object>) convertedMap.get("testMap")));
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) AmqpMapToMapConverter(org.apache.qpid.server.protocol.v0_10.transport.mimecontentconverter.AmqpMapToMapConverter) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) JmsMapMessageToMap(org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue) Test(org.junit.Test)

Example 5 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testNoBodyWithJmsMapContentType.

@Test
public void testNoBodyWithJmsMapContentType() throws Exception {
    final Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf("jms/map-message"));
    final Message_1_0 sourceMessage = createTestMessage(properties, null);
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertEquals("Unexpected mime type", "jms/map-message", convertedMessage.getMessageHeader().getMimeType());
    assertArrayEquals("Unexpected content size", new MapToJmsMapMessage().toMimeContent(Collections.emptyMap()), getBytes(content));
}
Also used : MapToJmsMapMessage(org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage) 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) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)297 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)258 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)204 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)157 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)125 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)118 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)114 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)77 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)75 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)71 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)71 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)67 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)58 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)56 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)52 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)49 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)36 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)26 HashMap (java.util.HashMap)21