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 testDataWithContentTypeOther.
public void testDataWithContentTypeOther() throws Exception {
final byte[] expected = "helloworld".getBytes(UTF_8);
final Data value = new Data(new Binary(expected));
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("application/bin"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", expected, 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 doTestConvertOfDataSectionForTextualType.
private void doTestConvertOfDataSectionForTextualType(final String contentType) throws Exception {
final String expected = "testContent";
final Data value = new Data(new Binary(expected.getBytes(UTF_8)));
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(contentType));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected content", expected, new String(getBytes(content), UTF_8));
assertEquals("Unexpected mime type", "text/plain", convertedMessage.getMessageHeader().getMimeType());
}
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 testDataWithStreamMessageAnnotationAndContentTypeAmqpList.
public void testDataWithStreamMessageAnnotationAndContentTypeAmqpList() throws Exception {
List<Object> originalList = Collections.singletonList("testValue");
byte[] data = new ListToAmqpListConverter().toMimeContent(originalList);
String expectedMimeType = "amqp/list";
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 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"));
}
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 testDataWithContentTypeAmqpList.
public void testDataWithContentTypeAmqpList() throws Exception {
List<Object> originalMap = Collections.singletonList("testValue");
byte[] bytes = new ListToAmqpListConverter().toMimeContent(originalMap);
final Data value = new Data(new Binary(bytes));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("amqp/list"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "amqp/list", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
Aggregations