use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testAmqpSequenceWithSimpleTypes.
public void testAmqpSequenceWithSimpleTypes() throws Exception {
final List<Object> originalList = new ArrayList<>();
originalList.add(37);
originalList.add(42F);
final AmqpSequence amqpSequence = new AmqpSequence(originalList);
Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
assertEquals("Unexpected size", originalList.size(), convertedList.size());
assertEquals("Unexpected first item", originalList.get(0), convertedList.get(0));
assertEquals("Unexpected second item", originalList.get(1), convertedList.get(1));
}
use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testMessageAnnotationTakesPrecedenceOverContentType.
public void testMessageAnnotationTakesPrecedenceOverContentType() throws Exception {
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("application/octet-stream"));
final Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "application/x-java-serialized-object", convertedMessage.getMessageHeader().getMimeType());
assertEquals("Unexpected content", null, convertedMessage.getMessageBody());
}
use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v1_0Test method testContentEncodingConversion.
public void testContentEncodingConversion() {
String contentEncoding = "my-test-encoding";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getEncoding()).thenReturn(contentEncoding);
InternalMessage originalMessage = createTestMessage(header);
Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
Symbol convertedContentEncoding = MessageConverter_from_1_0.getContentEncoding(convertedMessage);
assertEquals("Unexpected content encoding", contentEncoding, convertedContentEncoding.toString());
}
use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.
the class PropertyConverter_v1_0_to_InternalTest method testAbsoluteExpiryTimeConversion.
public void testAbsoluteExpiryTimeConversion() {
long ttl = 10000;
long arrivalTime = System.currentTimeMillis();
long expiryTime = arrivalTime + ttl;
Properties properties = new Properties();
properties.setAbsoluteExpiryTime(new Date(expiryTime));
Message_1_0 originalMessage = createTestMessage(properties, arrivalTime);
InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("Unexpected expiration", 0, convertedMessage.getMessageHeader().getExpiration());
}
use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.
the class PropertyConverter_v1_0_to_InternalTest 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 byte[] content) {
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, content == null ? 0 : content.length);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (content != null) {
Binary binary = new Binary(content);
DataSection dataSection = new Data(binary).createEncodingRetainingSection();
QpidByteBuffer qbb = dataSection.getEncodedForm();
int length = qbb.remaining();
when(storedMessage.getContentSize()).thenReturn(length);
when(storedMessage.getContent(0, length)).thenReturn(qbb);
} else {
when(storedMessage.getContentSize()).thenReturn(0);
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
Aggregations