use of org.apache.qpid.amqp_1_0.type.Binary 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);
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class PropertyConverter_v1_0_to_InternalTest method testUserIdConversion.
public void testUserIdConversion() {
final byte[] data = new byte[] { (byte) 0xc3, 0x28 };
final Binary userId = new Binary(data);
Properties properties = new Properties();
properties.setUserId(userId);
Message_1_0 originalMessage = createTestMessage(properties);
InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("Unexpected userId", new String(data, UTF_8), convertedMessage.getMessageHeader().getUserId());
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_10Test method testDataWithStreamMessageAnnotationAndContentTypeJmsStreamMessage.
public void testDataWithStreamMessageAnnotationAndContentTypeJmsStreamMessage() throws Exception {
List<Object> originalList = Collections.singletonList("testValue");
byte[] data = new ListToJmsStreamMessage().toMimeContent(originalList);
String expectedMimeType = "jms/stream-message";
final Data value = new Data(new Binary(data));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(expectedMimeType));
Message_1_0 sourceMessage = createTestMessage(properties, STREAM_MESSAGE_MESSAGE_ANNOTATION, value.createEncodingRetainingSection());
final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", data, getBytes(content));
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_10Test method doTestDataWithAnnotation.
private void doTestDataWithAnnotation(final byte[] data, final MessageAnnotations messageAnnotations, final String expectedMimeType) throws Exception {
final Data value = new Data(new Binary(data));
Message_1_0 sourceMessage = createTestMessage(messageAnnotations, value.createEncodingRetainingSection());
final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent();
assertArrayEquals("Unexpected content", data, getBytes(content));
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_10Test method testDataWithContentTypeAmqpMap.
public void testDataWithContentTypeAmqpMap() throws Exception {
Map<String, Object> originalMap = Collections.singletonMap("testKey", "testValue");
byte[] bytes = new MapToAmqpMapConverter().toMimeContent(originalMap);
final Data value = new Data(new Binary(bytes));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("amqp/map"));
Message_1_0 sourceMessage = createTestMessage(properties, value.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());
assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
Aggregations