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