You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2017/07/26 06:35:26 UTC
[1/2] qpid-broker-j git commit: QPID-7434: Add missing properties
conversion for message conversion layer from 0-8 to 1-0 and add unit tests
Repository: qpid-broker-j
Updated Branches:
refs/heads/master 7da6ca8f2 -> 3ecdc824a
QPID-7434: Add missing properties conversion for message conversion layer from 0-8 to 1-0 and add unit tests
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/3ecdc824
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/3ecdc824
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/3ecdc824
Branch: refs/heads/master
Commit: 3ecdc824a65139e11523ba8fa21ba35520b83feb
Parents: 61066b2
Author: Alex Rudyy <or...@apache.org>
Authored: Tue Jul 25 17:04:48 2017 +0100
Committer: Alex Rudyy <or...@apache.org>
Committed: Wed Jul 26 07:35:02 2017 +0100
----------------------------------------------------------------------
.../transport/BasicContentHeaderProperties.java | 6 +
.../v0_8_v1_0/MessageConverter_0_8_to_1_0.java | 76 +++-
.../PropertyConverter_0_8_to_1_0Test.java | 433 +++++++++++++++++++
3 files changed, 493 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/3ecdc824/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderProperties.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderProperties.java b/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderProperties.java
index 59e65b7..50bf982 100644
--- a/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderProperties.java
+++ b/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderProperties.java
@@ -810,6 +810,12 @@ public class BasicContentHeaderProperties
nullEncodedForm();
}
+
+ public boolean hasTimestamp()
+ {
+ return (_propertyFlags & TIMESTAMP_MASK) != 0;
+ }
+
public String getTypeAsString()
{
return (_type == null) ? null : _type.toString();
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/3ecdc824/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0.java b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0.java
index 2300171..868fa9d 100644
--- a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0.java
+++ b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0.java
@@ -21,6 +21,7 @@
package org.apache.qpid.server.protocol.converter.v0_8_v1_0;
import java.net.URISyntaxException;
+import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -29,6 +30,7 @@ import org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperti
import org.apache.qpid.server.protocol.v0_8.FieldTable;
import org.apache.qpid.server.plugin.PluggableService;
import org.apache.qpid.server.protocol.v0_8.AMQMessage;
+import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
import org.apache.qpid.server.protocol.v1_0.MessageConverter_to_1_0;
import org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0;
import org.apache.qpid.server.protocol.v1_0.messaging.SectionEncoder;
@@ -38,6 +40,7 @@ import org.apache.qpid.server.protocol.v1_0.type.UnsignedByte;
import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
import org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties;
import org.apache.qpid.server.protocol.v1_0.type.messaging.Data;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection;
import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection;
import org.apache.qpid.server.protocol.v1_0.type.messaging.Header;
import org.apache.qpid.server.protocol.v1_0.type.messaging.Properties;
@@ -59,7 +62,7 @@ public class MessageConverter_0_8_to_1_0 extends MessageConverter_to_1_0<AMQMess
SectionEncoder sectionEncoder)
{
Header header = new Header();
-
+ Properties props = new Properties();
header.setDurable(serverMessage.isPersistent());
BasicContentHeaderProperties contentHeader =
@@ -72,22 +75,10 @@ public class MessageConverter_0_8_to_1_0 extends MessageConverter_to_1_0<AMQMess
if(expiration > arrivalTime)
{
header.setTtl(UnsignedInteger.valueOf(expiration - arrivalTime));
+ props.setAbsoluteExpiryTime(new Date(expiration));
}
-
- Properties props = new Properties();
-
- /*
- TODO: The following properties are not currently set:
-
- creationTime
- groupId
- groupSequence
- replyToGroupId
- to
- */
-
- if(!GZIPUtils.GZIP_CONTENT_ENCODING.equals(contentHeader.getEncodingAsString()) && bodySection instanceof Data)
+ if(!GZIPUtils.GZIP_CONTENT_ENCODING.equals(contentHeader.getEncodingAsString()) && bodySection instanceof DataSection)
{
props.setContentEncoding(Symbol.valueOf(contentHeader.getEncodingAsString()));
}
@@ -103,14 +94,15 @@ public class MessageConverter_0_8_to_1_0 extends MessageConverter_to_1_0<AMQMess
final AMQShortString correlationId = contentHeader.getCorrelationId();
if(correlationId != null)
{
- props.setCorrelationId(new Binary(correlationId.getBytes()));
+ props.setCorrelationId(correlationId.toString());
}
final AMQShortString messageId = contentHeader.getMessageId();
if(messageId != null)
{
- props.setMessageId(new Binary(messageId.getBytes()));
+ props.setMessageId(messageId.toString());
}
+
final String originalReplyTo = String.valueOf(contentHeader.getReplyTo());
try
{
@@ -147,22 +139,62 @@ public class MessageConverter_0_8_to_1_0 extends MessageConverter_to_1_0<AMQMess
props.setReplyTo(originalReplyTo);
}
-
-
- props.setSubject(serverMessage.getInitialRoutingAddress());
if(contentHeader.getUserId() != null)
{
props.setUserId(new Binary(contentHeader.getUserId().getBytes()));
}
- Map<String, Object> applicationPropertiesMap = FieldTable.convertToMap(contentHeader.getHeaders());
+ if (contentHeader.hasTimestamp())
+ {
+ props.setCreationTime(new Date(contentHeader.getTimestamp()));
+ }
+
+ if (contentHeader.getType() != null)
+ {
+ props.setSubject(contentHeader.getType().toString());
+ }
+
+ Map<String, Object> applicationPropertiesMap = new LinkedHashMap<>(FieldTable.convertToMap(contentHeader.getHeaders()));
if(applicationPropertiesMap.containsKey("qpid.subject"))
{
props.setSubject(String.valueOf(applicationPropertiesMap.get("qpid.subject")));
- applicationPropertiesMap = new LinkedHashMap<>(applicationPropertiesMap);
applicationPropertiesMap.remove("qpid.subject");
}
+
+ if(applicationPropertiesMap.containsKey("JMSXGroupID"))
+ {
+ props.setGroupId(String.valueOf(applicationPropertiesMap.get("JMSXGroupID")));
+ applicationPropertiesMap.remove("JMSXGroupID");
+ }
+
+ if(applicationPropertiesMap.containsKey("JMSXGroupSeq"))
+ {
+ Object jmsxGroupSeq = applicationPropertiesMap.get("JMSXGroupSeq");
+ if (jmsxGroupSeq instanceof Integer)
+ {
+ props.setGroupSequence(UnsignedInteger.valueOf((Integer)jmsxGroupSeq));
+ applicationPropertiesMap.remove("JMSXGroupSeq");
+ }
+ }
+
+ MessagePublishInfo messagePublishInfo = serverMessage.getMessagePublishInfo();
+ String to = AMQShortString.toString(messagePublishInfo.getExchange());
+ if (messagePublishInfo.getRoutingKey() != null)
+ {
+ String routingKey = AMQShortString.toString(messagePublishInfo.getRoutingKey());
+ if (to != null)
+ {
+ to += "/" + routingKey;
+ }
+ else
+ {
+ to = routingKey;
+ }
+ }
+ props.setTo(to);
+
+
// TODO: http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-application
// Adhere to "the values are restricted to be of simple types only, that is, excluding map, list, and array types".
// 0-8..0-91 for instance supported field tables with maps as values.
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/3ecdc824/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/PropertyConverter_0_8_to_1_0Test.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/PropertyConverter_0_8_to_1_0Test.java b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/PropertyConverter_0_8_to_1_0Test.java
new file mode 100644
index 0000000..af150a3
--- /dev/null
+++ b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/PropertyConverter_0_8_to_1_0Test.java
@@ -0,0 +1,433 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol.converter.v0_8_v1_0;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.model.NamedAddressSpace;
+import org.apache.qpid.server.protocol.v0_8.AMQMessage;
+import org.apache.qpid.server.protocol.v0_8.AMQShortString;
+import org.apache.qpid.server.protocol.v0_8.FieldTable;
+import org.apache.qpid.server.protocol.v0_8.MessageMetaData;
+import org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties;
+import org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody;
+import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
+import org.apache.qpid.server.protocol.v1_0.Message_1_0;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.Header;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.Properties;
+import org.apache.qpid.server.store.StoredMessage;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class PropertyConverter_0_8_to_1_0Test extends QpidTestCase
+{
+ private NamedAddressSpace _namedAddressSpace;
+ private MessageConverter_0_8_to_1_0 _messageConverter;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ _namedAddressSpace = mock(NamedAddressSpace.class);
+ _messageConverter = new MessageConverter_0_8_to_1_0();
+ }
+
+ public void testContentTypeConversion()
+ {
+ String contentType = "test-content-type";
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setContentType(contentType);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected content type", contentType, properties.getContentType().toString());
+ }
+
+ public void testContentTypeJavaObjectStreamConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setContentType("application/java-object-stream");
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected content type",
+ "application/x-java-serialized-object",
+ properties.getContentType().toString());
+ }
+
+ public void testContentEncodingConversion()
+ {
+ String contentEncoding = "my-test-encoding";
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setEncoding(contentEncoding);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties, new byte[]{(byte) 1}, 0);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected content encoding", contentEncoding, properties.getContentEncoding().toString());
+ }
+
+ public void testHeaderConversion()
+ {
+ Map<String, Object> headers = new HashMap<>();
+ headers.put("testProperty1", "testProperty1Value");
+ headers.put("intProperty", 1);
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(headers));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Map<String, Object> applicationProperties = convertedMessage.getApplicationPropertiesSection().getValue();
+ assertEquals("Unexpected application applicationProperties", headers, new HashMap<>(applicationProperties));
+ }
+
+ public void testHeaderConversionWhenQpidSubjectIsPresent()
+ {
+ String testSubject = "testSubject";
+ Map<String, Object> headers = new HashMap<>();
+ headers.put("testProperty1", "testProperty1Value");
+ headers.put("qpid.subject", testSubject);
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(headers));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected subject", testSubject, properties.getSubject());
+ Map<String, Object> applicationProperties = convertedMessage.getApplicationPropertiesSection().getValue();
+ assertFalse("Unexpected subject in application properties", applicationProperties.containsKey("qpid.subject"));
+ }
+
+ public void testPersistentDeliveryModeConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setDeliveryMode(BasicContentHeaderProperties.PERSISTENT);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Header header = convertedMessage.getHeaderSection().getValue();
+ assertTrue("Unexpected durable header", header.getDurable());
+ }
+
+ public void testNonPersistentDeliveryModeConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setDeliveryMode(BasicContentHeaderProperties.NON_PERSISTENT);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Header header = convertedMessage.getHeaderSection().getValue();
+ assertFalse("Unexpected durable header", header.getDurable());
+ }
+
+ public void testPriorityConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ final byte priority = 5;
+ basicContentHeaderProperties.setPriority(priority);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Header header = convertedMessage.getHeaderSection().getValue();
+ assertEquals("Unexpected priority", priority, header.getPriority().byteValue());
+ }
+
+ public void testCorrelationIdConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ final String correlationId = "testCorrelationId";
+ basicContentHeaderProperties.setCorrelationId(AMQShortString.valueOf(correlationId));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected correlationId", correlationId, properties.getCorrelationId());
+ }
+
+ public void testReplyToConversionWhenBindingURLFormatIsUsed()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+
+ final String replyTo = "direct://amq.direct/destination_name/queue_name?routingkey='test_routing_key'";
+ basicContentHeaderProperties.setReplyTo(replyTo);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected reply-to", "amq.direct/test_routing_key", properties.getReplyTo());
+ }
+
+ public void testReplyToConversionWhenBindingURLFormatIsUsed2()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+
+ final String replyTo = "direct://amq.direct//queue_name";
+ basicContentHeaderProperties.setReplyTo(replyTo);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected reply-to", "amq.direct/queue_name", properties.getReplyTo());
+ }
+
+ public void testReplyToConversionWhenBindingURLFormatIsUsed3()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+
+ final String replyTo = "direct:////queue_name";
+ basicContentHeaderProperties.setReplyTo(replyTo);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected reply-to", "queue_name", properties.getReplyTo());
+ }
+
+ public void testReplyToConversionWhenBindingURLFormatIsUsed4()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+
+ final String replyTo = "direct:////?routingkey='test_routing_key'";
+ basicContentHeaderProperties.setReplyTo(replyTo);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected reply-to", "test_routing_key", properties.getReplyTo());
+ }
+
+ public void testReplyToConversionWhenNonBindingURLFormatIsUsed()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+
+ final String replyTo = "test";
+ basicContentHeaderProperties.setReplyTo(replyTo);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected reply-to", "test", properties.getReplyTo());
+ }
+
+ public void testExpirationConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ long timestamp = System.currentTimeMillis();
+ int ttl = 100000;
+ final long expiration = timestamp + ttl;
+ basicContentHeaderProperties.setExpiration(expiration);
+ basicContentHeaderProperties.setTimestamp(timestamp);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties, timestamp);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Header header = convertedMessage.getHeaderSection().getValue();
+ assertEquals("Unexpected TTL", ttl, header.getTtl().longValue());
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected expiration", expiration, properties.getAbsoluteExpiryTime().getTime());
+ }
+
+ public void testMessageIdConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ final String messageId = "testMessageId";
+ basicContentHeaderProperties.setMessageId(messageId);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected messageId", messageId, properties.getMessageId());
+ }
+
+ public void testTimestampConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ final long timestamp = System.currentTimeMillis() - 10000;
+ basicContentHeaderProperties.setTimestamp(timestamp);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected creation timestamp", timestamp, properties.getCreationTime().getTime());
+ }
+
+ public void testTypeConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ final String type = "test-type";
+ basicContentHeaderProperties.setType(String.valueOf(type));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected subject", type, properties.getSubject());
+ }
+
+ public void testUserIdConversion()
+ {
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ final String userId = "test-userId";
+ basicContentHeaderProperties.setUserId(userId);
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+ assertEquals("Unexpected user-id", userId, new String(properties.getUserId().getArray(), UTF_8));
+ }
+
+ public void testHeaderJMSXGroupIdConversion()
+ {
+ Map<String, Object> headers = new HashMap<>();
+ String testGroupId = "testGroupId";
+ headers.put("JMSXGroupID", testGroupId);
+ headers.put("intProperty", 1);
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(headers));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+
+ assertEquals("Unexpected group-id", testGroupId, properties.getGroupId());
+
+ Map<String, Object> applicationProperties = convertedMessage.getApplicationPropertiesSection().getValue();
+ assertFalse("Unexpected JMSXGroupID in application properties",
+ applicationProperties.containsKey("JMSXGroupID"));
+ }
+
+ public void testHeaderJMSXGroupSeqConversion()
+ {
+ Map<String, Object> headers = new HashMap<>();
+ int testGroupSequenceNumber = 1;
+ headers.put("JMSXGroupSeq", testGroupSequenceNumber);
+ headers.put("intProperty", 1);
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(headers));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+
+ assertEquals("Unexpected group-sequence", testGroupSequenceNumber, properties.getGroupSequence().intValue());
+
+ Map<String, Object> applicationProperties = convertedMessage.getApplicationPropertiesSection().getValue();
+ assertFalse("Unexpected JMSXGroupSeq in application properties",
+ applicationProperties.containsKey("JMSXGroupSeq"));
+ }
+
+ public void testHeaderJMSXGroupSeqConversionWhenWrongType()
+ {
+ Map<String, Object> headers = new HashMap<>();
+ short testGroupSequenceNumber = (short) 1;
+ headers.put("JMSXGroupSeq", testGroupSequenceNumber);
+ headers.put("intProperty", 1);
+ BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
+ basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(headers));
+ AMQMessage message = createTestMessage(basicContentHeaderProperties);
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+
+ assertEquals("Unexpected group-sequence", null, properties.getGroupSequence());
+
+ Map<String, Object> applicationProperties = convertedMessage.getApplicationPropertiesSection().getValue();
+
+ assertTrue("JMSXGroupSeq was removed from application properties",
+ applicationProperties.containsKey("JMSXGroupSeq"));
+ }
+
+ public void testExchangeRoutingKeyConversion()
+ {
+ final String testExchange = "testExchange";
+ final String testRoutingKey = "testRoutingKey";
+ AMQMessage message = createTestMessage(new BasicContentHeaderProperties());
+ message.getMessagePublishInfo().setExchange(AMQShortString.valueOf(testExchange));
+ message.getMessagePublishInfo().setRoutingKey(AMQShortString.valueOf(testRoutingKey));
+
+ final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+ Properties properties = convertedMessage.getPropertiesSection().getValue();
+
+ assertEquals("Unexpected to", testExchange + "/" + testRoutingKey, properties.getTo());
+ }
+
+ private AMQMessage createTestMessage(final BasicContentHeaderProperties basicContentHeaderProperties)
+ {
+ return createTestMessage(basicContentHeaderProperties, null, 0);
+ }
+
+ private AMQMessage createTestMessage(final BasicContentHeaderProperties basicContentHeaderProperties,
+ long arrivalTime)
+ {
+ return createTestMessage(basicContentHeaderProperties, null, arrivalTime);
+ }
+
+ private AMQMessage createTestMessage(final BasicContentHeaderProperties basicContentHeaderProperties,
+ final byte[] content, final long arrivalTime)
+ {
+ final ContentHeaderBody contentHeaderBody = mock(ContentHeaderBody.class);
+ when(contentHeaderBody.getProperties()).thenReturn(basicContentHeaderProperties);
+
+ final StoredMessage<MessageMetaData> storedMessage = mock(StoredMessage.class);
+ when(storedMessage.getMetaData()).thenReturn(new MessageMetaData(new MessagePublishInfo(),
+ contentHeaderBody,
+ arrivalTime));
+
+ if (content != null)
+ {
+ when(storedMessage.getContentSize()).thenReturn(content.length);
+ when(storedMessage.getContent(0, content.length)).thenReturn(Collections.singleton(QpidByteBuffer.wrap(
+ content)));
+ }
+
+ return new AMQMessage(storedMessage);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/2] qpid-broker-j git commit: QPID-7434: Move tests into canonical
location
Posted by or...@apache.org.
QPID-7434: Move tests into canonical location
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/61066b27
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/61066b27
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/61066b27
Branch: refs/heads/master
Commit: 61066b27f6a5776808c478fd2ce49ffc47468a60
Parents: 7da6ca8
Author: Alex Rudyy <or...@apache.org>
Authored: Tue Jul 25 13:27:10 2017 +0100
Committer: Alex Rudyy <or...@apache.org>
Committed: Wed Jul 26 07:35:02 2017 +0100
----------------------------------------------------------------------
.../MessageConverter_0_8_to_1_0Test.java | 244 -------------------
.../MessageConverter_1_0_to_v0_8Test.java | 196 ---------------
.../MessageConverter_0_8_to_1_0Test.java | 244 +++++++++++++++++++
.../MessageConverter_1_0_to_v0_8Test.java | 186 ++++++++++++++
4 files changed, 430 insertions(+), 440 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/61066b27/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java
deleted file mode 100644
index 3ef2e7d..0000000
--- a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.server.protocol.converter.v0_8_v1_0;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import com.google.common.collect.Lists;
-import org.mockito.ArgumentCaptor;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
-import org.apache.qpid.server.message.AMQMessageHeader;
-import org.apache.qpid.server.model.NamedAddressSpace;
-import org.apache.qpid.server.protocol.v0_8.AMQMessage;
-import org.apache.qpid.server.protocol.v0_8.MessageMetaData;
-import org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties;
-import org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody;
-import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
-import org.apache.qpid.server.protocol.v1_0.Message_1_0;
-import org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoder;
-import org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl;
-import org.apache.qpid.server.protocol.v1_0.type.Binary;
-import org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry;
-import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection;
-import org.apache.qpid.server.store.StoredMessage;
-import org.apache.qpid.server.typedmessage.TypedBytesContentWriter;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-public class MessageConverter_0_8_to_1_0Test extends QpidTestCase
-{
- private final MessageConverter_0_8_to_1_0 _converter = new MessageConverter_0_8_to_1_0();
- private final AMQPDescribedTypeRegistry _typeRegistry = AMQPDescribedTypeRegistry.newInstance()
- .registerTransportLayer()
- .registerMessagingLayer()
- .registerTransactionLayer()
- .registerSecurityLayer();
-
- private final StoredMessage<MessageMetaData> _handle = mock(StoredMessage.class);
-
- private final MessageMetaData _metaData = mock(MessageMetaData.class);
- private final AMQMessageHeader _header = mock(AMQMessageHeader.class);
- private final ContentHeaderBody _contentHeaderBody = mock(ContentHeaderBody.class);
- private final BasicContentHeaderProperties _basicContentHeaderProperties = mock(BasicContentHeaderProperties.class);
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- when(_handle.getMetaData()).thenReturn(_metaData);
- when(_metaData.getMessageHeader()).thenReturn(_header);
- when(_metaData.getMessagePublishInfo()).thenReturn(new MessagePublishInfo());
- when(_metaData.getContentHeaderBody()).thenReturn(_contentHeaderBody);
- when(_contentHeaderBody.getProperties()).thenReturn(_basicContentHeaderProperties);
- }
-
- public void testConvertStringMessageBody() throws Exception
- {
- final String expected = "helloworld";
-
- final AMQMessage sourceMessage = getAmqMessage(expected.getBytes(), "text/plain");
-
- final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
- assertEquals(expected, sections.get(0).getValue());
- }
-
- public void testConvertBytesMessageBody() throws Exception
- {
- final byte[] expected = "helloworld".getBytes();
-
- final AMQMessage sourceMessage = getAmqMessage(expected, "application/octet-stream");
-
- final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
- final Binary value = (Binary) sections.get(0).getValue();
- assertArrayEquals(expected, value.getArray());
- }
-
- public void testConvertListMessageBody() throws Exception
- {
- final List<Object> expected = Lists.<Object>newArrayList("apple", 43, 31.42D);
- final byte[] messageBytes = getJmsStreamMessageBytes(expected);
-
- final AMQMessage sourceMessage = getAmqMessage(messageBytes, "jms/stream-message");
-
- final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
- assertEquals(expected, sections.get(0).getValue());
- }
-
- public void testConvertMapMessageBody() throws Exception
- {
- final Map<String, Object> expected = Collections.<String, Object>singletonMap("key", "value");
- final byte[] messageBytes = getJmsMapMessageBytes(expected);
-
- final AMQMessage sourceMessage = getAmqMessage(messageBytes, "jms/map-message");
-
- final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
- assertEquals(expected, sections.get(0).getValue());
- }
-
- public void testConvertObjectStreamMessageBody() throws Exception
- {
- final byte[] messageBytes = getObjectStreamMessageBytes(UUID.randomUUID());
-
- final AMQMessage sourceMessage = getAmqMessage(messageBytes, "application/java-object-stream");
-
- final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
- final Binary value = (Binary) sections.get(0).getValue();
- assertArrayEquals(messageBytes, value.getArray());
- }
-
- private byte[] getObjectStreamMessageBytes(final Serializable o) throws Exception
- {
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos))
- {
- oos.writeObject(o);
- return bos.toByteArray();
- }
- }
-
- private byte[] getJmsStreamMessageBytes(List<Object> objects) throws Exception
- {
- TypedBytesContentWriter writer = new TypedBytesContentWriter();
- for(Object o : objects)
- {
- writer.writeObject(o);
- }
- return getBytes(writer);
- }
-
- private byte[] getJmsMapMessageBytes(Map<String,Object> map) throws Exception
- {
- TypedBytesContentWriter writer = new TypedBytesContentWriter();
- writer.writeIntImpl(map.size());
- for(Map.Entry<String, Object> entry : map.entrySet())
- {
- writer.writeNullTerminatedStringImpl(entry.getKey());
- writer.writeObject(entry.getValue());
- }
- return getBytes(writer);
- }
-
- private byte[] getBytes(final TypedBytesContentWriter writer)
- {
- ByteBuffer buf = writer.getData();
- final byte[] expected = new byte[buf.remaining()];
- buf.get(expected);
- return expected;
- }
-
- private List<EncodingRetainingSection<?>> getEncodingRetainingSections(final Collection<QpidByteBuffer> content,
- final int expectedNumberOfSections)
- throws Exception
- {
- SectionDecoder sectionDecoder = new SectionDecoderImpl(_typeRegistry.getSectionDecoderRegistry());
- final List<EncodingRetainingSection<?>> sections = sectionDecoder.parseAll(new ArrayList<>(content));
- assertEquals("Unexpected number of sections", expectedNumberOfSections, sections.size());
- return sections;
-
- }
-
- protected AMQMessage getAmqMessage(final byte[] expected, final String mimeType)
- {
- configureMessageContent(expected);
- configureMessageHeader(mimeType);
-
- return new AMQMessage(_handle);
- }
-
- private void configureMessageHeader(final String mimeType)
- {
- when(_header.getMimeType()).thenReturn(mimeType);
- }
-
- private void configureMessageContent(final byte[] section)
- {
- final QpidByteBuffer combined = QpidByteBuffer.wrap(section);
- when(_handle.getContentSize()).thenReturn((int) section.length);
- final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
- final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
-
- when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(new Answer<Collection<QpidByteBuffer>>()
- {
- @Override
- public Collection<QpidByteBuffer> answer(final InvocationOnMock invocation) throws Throwable
- {
- final QpidByteBuffer view = combined.view(offsetCaptor.getValue(), sizeCaptor.getValue());
- return Collections.singleton(view);
- }
- });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/61066b27/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
deleted file mode 100644
index f993227..0000000
--- a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/test/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.server.protocol.converter.v0_8_v1_0;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayOutputStream;
-import java.io.EOFException;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
-import org.mockito.ArgumentCaptor;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
-import org.apache.qpid.server.model.NamedAddressSpace;
-import org.apache.qpid.server.protocol.v0_8.AMQMessage;
-import org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0;
-import org.apache.qpid.server.protocol.v1_0.Message_1_0;
-import org.apache.qpid.server.protocol.v1_0.messaging.SectionEncoder;
-import org.apache.qpid.server.protocol.v1_0.messaging.SectionEncoderImpl;
-import org.apache.qpid.server.protocol.v1_0.type.Binary;
-import org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry;
-import org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue;
-import org.apache.qpid.server.protocol.v1_0.type.messaging.Data;
-import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection;
-import org.apache.qpid.server.store.StoredMessage;
-import org.apache.qpid.server.typedmessage.TypedBytesContentReader;
-import org.apache.qpid.server.util.ByteBufferUtils;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-public class MessageConverter_1_0_to_v0_8Test extends QpidTestCase
-{
- private final MessageConverter_1_0_to_v0_8 _converter = new MessageConverter_1_0_to_v0_8();
- private final AMQPDescribedTypeRegistry _typeRegistry = AMQPDescribedTypeRegistry.newInstance()
- .registerTransportLayer()
- .registerMessagingLayer()
- .registerTransactionLayer()
- .registerSecurityLayer();
-
- private final SectionEncoder _encoder = new SectionEncoderImpl(_typeRegistry);
- private final StoredMessage<MessageMetaData_1_0> _handle = mock(StoredMessage.class);
-
- private final MessageMetaData_1_0 _metaData = mock(MessageMetaData_1_0.class);
- private final MessageMetaData_1_0.MessageHeader_1_0 _header = mock(MessageMetaData_1_0.MessageHeader_1_0.class);
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- when(_handle.getMetaData()).thenReturn(_metaData);
- when(_metaData.getMessageHeader()).thenReturn(_header);
- }
-
- public void testConvertStringMessageBody() throws Exception
- {
- final String expected = "helloworld";
-
- final AmqpValue value = new AmqpValue(expected);
- configureMessageContent(value.createEncodingRetainingSection(_encoder));
- final Message_1_0 sourceMessage = new Message_1_0(_handle);
-
- final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
- assertEquals("text/plain", convertedMessage.getMessageHeader().getMimeType());
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
- assertArrayEquals(expected.getBytes(), getBytes(content));
- }
-
- public void testConvertListMessageBody() throws Exception
- {
- final List<Object> expected = Lists.<Object>newArrayList("helloworld", 43, 1L);
-
- final AmqpValue value = new AmqpValue(expected);
- configureMessageContent(value.createEncodingRetainingSection(_encoder));
- final Message_1_0 sourceMessage = new Message_1_0(_handle);
-
- final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
- assertEquals("jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(getBytes(content)));
- assertEquals(expected.get(0), reader.readObject());
- assertEquals(expected.get(1), reader.readObject());
- assertEquals(expected.get(2), reader.readObject());
-
- try
- {
- reader.readObject();
- fail("Exception not thrown");
- }
- catch (EOFException e)
- {
- // PASS
- }
- }
-
- public void testConvertMapMessageBody() throws Exception
- {
- final Map<String, String> expected = Collections.singletonMap("key", "value");
-
- final AmqpValue value = new AmqpValue(expected);
- configureMessageContent(value.createEncodingRetainingSection(_encoder));
- final Message_1_0 sourceMessage = new Message_1_0(_handle);
-
- final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
- assertEquals("jms/map-message", convertedMessage.getMessageHeader().getMimeType());
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
-
- TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(getBytes(content)));
- assertEquals(expected.size(), reader.readIntImpl());
- assertEquals("key", reader.readStringImpl());
- assertEquals(expected.get("key"), reader.readObject());
- try
- {
- reader.readString();
- fail("Exception not thrown");
- }
- catch (EOFException e)
- {
- // PASS
- }
- }
-
- public void testConvertBytesMessageBody() throws Exception
- {
- final String expected = "helloworld";
-
- final Data value = new Data(new Binary(expected.getBytes()));
- configureMessageContent(value.createEncodingRetainingSection(_encoder));
- final Message_1_0 sourceMessage = new Message_1_0(_handle);
-
- final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
- assertEquals("application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
-
- final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
- assertArrayEquals(expected.getBytes(), getBytes(content));
- }
-
- private void configureMessageContent(final EncodingRetainingSection section)
- {
- final QpidByteBuffer combined = QpidByteBuffer.wrap(ByteBufferUtils.combine(section.getEncodedForm()));
- when(_handle.getContentSize()).thenReturn((int) section.getEncodedSize());
- final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
- final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
-
- when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(new Answer<Collection<QpidByteBuffer>>()
- {
- @Override
- public Collection<QpidByteBuffer> answer(final InvocationOnMock invocation) throws Throwable
- {
- final QpidByteBuffer view = combined.view(offsetCaptor.getValue(), sizeCaptor.getValue());
- return Collections.singleton(view);
- }
- });
- }
-
- private byte[] getBytes(final Collection<QpidByteBuffer> content) throws Exception
- {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- for (QpidByteBuffer buf: content)
- {
- ByteStreams.copy(buf.asInputStream(), bos);
- buf.dispose();
- }
- return bos.toByteArray();
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/61066b27/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java
new file mode 100644
index 0000000..3ef2e7d
--- /dev/null
+++ b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_0_8_to_1_0Test.java
@@ -0,0 +1,244 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol.converter.v0_8_v1_0;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import com.google.common.collect.Lists;
+import org.mockito.ArgumentCaptor;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.message.AMQMessageHeader;
+import org.apache.qpid.server.model.NamedAddressSpace;
+import org.apache.qpid.server.protocol.v0_8.AMQMessage;
+import org.apache.qpid.server.protocol.v0_8.MessageMetaData;
+import org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties;
+import org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody;
+import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
+import org.apache.qpid.server.protocol.v1_0.Message_1_0;
+import org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoder;
+import org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl;
+import org.apache.qpid.server.protocol.v1_0.type.Binary;
+import org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection;
+import org.apache.qpid.server.store.StoredMessage;
+import org.apache.qpid.server.typedmessage.TypedBytesContentWriter;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class MessageConverter_0_8_to_1_0Test extends QpidTestCase
+{
+ private final MessageConverter_0_8_to_1_0 _converter = new MessageConverter_0_8_to_1_0();
+ private final AMQPDescribedTypeRegistry _typeRegistry = AMQPDescribedTypeRegistry.newInstance()
+ .registerTransportLayer()
+ .registerMessagingLayer()
+ .registerTransactionLayer()
+ .registerSecurityLayer();
+
+ private final StoredMessage<MessageMetaData> _handle = mock(StoredMessage.class);
+
+ private final MessageMetaData _metaData = mock(MessageMetaData.class);
+ private final AMQMessageHeader _header = mock(AMQMessageHeader.class);
+ private final ContentHeaderBody _contentHeaderBody = mock(ContentHeaderBody.class);
+ private final BasicContentHeaderProperties _basicContentHeaderProperties = mock(BasicContentHeaderProperties.class);
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ when(_handle.getMetaData()).thenReturn(_metaData);
+ when(_metaData.getMessageHeader()).thenReturn(_header);
+ when(_metaData.getMessagePublishInfo()).thenReturn(new MessagePublishInfo());
+ when(_metaData.getContentHeaderBody()).thenReturn(_contentHeaderBody);
+ when(_contentHeaderBody.getProperties()).thenReturn(_basicContentHeaderProperties);
+ }
+
+ public void testConvertStringMessageBody() throws Exception
+ {
+ final String expected = "helloworld";
+
+ final AMQMessage sourceMessage = getAmqMessage(expected.getBytes(), "text/plain");
+
+ final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
+ assertEquals(expected, sections.get(0).getValue());
+ }
+
+ public void testConvertBytesMessageBody() throws Exception
+ {
+ final byte[] expected = "helloworld".getBytes();
+
+ final AMQMessage sourceMessage = getAmqMessage(expected, "application/octet-stream");
+
+ final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
+ final Binary value = (Binary) sections.get(0).getValue();
+ assertArrayEquals(expected, value.getArray());
+ }
+
+ public void testConvertListMessageBody() throws Exception
+ {
+ final List<Object> expected = Lists.<Object>newArrayList("apple", 43, 31.42D);
+ final byte[] messageBytes = getJmsStreamMessageBytes(expected);
+
+ final AMQMessage sourceMessage = getAmqMessage(messageBytes, "jms/stream-message");
+
+ final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
+ assertEquals(expected, sections.get(0).getValue());
+ }
+
+ public void testConvertMapMessageBody() throws Exception
+ {
+ final Map<String, Object> expected = Collections.<String, Object>singletonMap("key", "value");
+ final byte[] messageBytes = getJmsMapMessageBytes(expected);
+
+ final AMQMessage sourceMessage = getAmqMessage(messageBytes, "jms/map-message");
+
+ final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
+ assertEquals(expected, sections.get(0).getValue());
+ }
+
+ public void testConvertObjectStreamMessageBody() throws Exception
+ {
+ final byte[] messageBytes = getObjectStreamMessageBytes(UUID.randomUUID());
+
+ final AMQMessage sourceMessage = getAmqMessage(messageBytes, "application/java-object-stream");
+
+ final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
+ final Binary value = (Binary) sections.get(0).getValue();
+ assertArrayEquals(messageBytes, value.getArray());
+ }
+
+ private byte[] getObjectStreamMessageBytes(final Serializable o) throws Exception
+ {
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos))
+ {
+ oos.writeObject(o);
+ return bos.toByteArray();
+ }
+ }
+
+ private byte[] getJmsStreamMessageBytes(List<Object> objects) throws Exception
+ {
+ TypedBytesContentWriter writer = new TypedBytesContentWriter();
+ for(Object o : objects)
+ {
+ writer.writeObject(o);
+ }
+ return getBytes(writer);
+ }
+
+ private byte[] getJmsMapMessageBytes(Map<String,Object> map) throws Exception
+ {
+ TypedBytesContentWriter writer = new TypedBytesContentWriter();
+ writer.writeIntImpl(map.size());
+ for(Map.Entry<String, Object> entry : map.entrySet())
+ {
+ writer.writeNullTerminatedStringImpl(entry.getKey());
+ writer.writeObject(entry.getValue());
+ }
+ return getBytes(writer);
+ }
+
+ private byte[] getBytes(final TypedBytesContentWriter writer)
+ {
+ ByteBuffer buf = writer.getData();
+ final byte[] expected = new byte[buf.remaining()];
+ buf.get(expected);
+ return expected;
+ }
+
+ private List<EncodingRetainingSection<?>> getEncodingRetainingSections(final Collection<QpidByteBuffer> content,
+ final int expectedNumberOfSections)
+ throws Exception
+ {
+ SectionDecoder sectionDecoder = new SectionDecoderImpl(_typeRegistry.getSectionDecoderRegistry());
+ final List<EncodingRetainingSection<?>> sections = sectionDecoder.parseAll(new ArrayList<>(content));
+ assertEquals("Unexpected number of sections", expectedNumberOfSections, sections.size());
+ return sections;
+
+ }
+
+ protected AMQMessage getAmqMessage(final byte[] expected, final String mimeType)
+ {
+ configureMessageContent(expected);
+ configureMessageHeader(mimeType);
+
+ return new AMQMessage(_handle);
+ }
+
+ private void configureMessageHeader(final String mimeType)
+ {
+ when(_header.getMimeType()).thenReturn(mimeType);
+ }
+
+ private void configureMessageContent(final byte[] section)
+ {
+ final QpidByteBuffer combined = QpidByteBuffer.wrap(section);
+ when(_handle.getContentSize()).thenReturn((int) section.length);
+ final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
+ final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
+
+ when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(new Answer<Collection<QpidByteBuffer>>()
+ {
+ @Override
+ public Collection<QpidByteBuffer> answer(final InvocationOnMock invocation) throws Throwable
+ {
+ final QpidByteBuffer view = combined.view(offsetCaptor.getValue(), sizeCaptor.getValue());
+ return Collections.singleton(view);
+ }
+ });
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/61066b27/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
new file mode 100644
index 0000000..d97950a
--- /dev/null
+++ b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
@@ -0,0 +1,186 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol.converter.v0_8_v1_0;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.ByteStreams;
+import org.mockito.ArgumentCaptor;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.model.NamedAddressSpace;
+import org.apache.qpid.server.protocol.v0_8.AMQMessage;
+import org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0;
+import org.apache.qpid.server.protocol.v1_0.Message_1_0;
+import org.apache.qpid.server.protocol.v1_0.type.Binary;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.Data;
+import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection;
+import org.apache.qpid.server.store.StoredMessage;
+import org.apache.qpid.server.typedmessage.TypedBytesContentReader;
+import org.apache.qpid.server.util.ByteBufferUtils;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class MessageConverter_1_0_to_v0_8Test extends QpidTestCase
+{
+ private final MessageConverter_1_0_to_v0_8 _converter = new MessageConverter_1_0_to_v0_8();
+ private final StoredMessage<MessageMetaData_1_0> _handle = mock(StoredMessage.class);
+
+ private final MessageMetaData_1_0 _metaData = mock(MessageMetaData_1_0.class);
+ private final MessageMetaData_1_0.MessageHeader_1_0 _header = mock(MessageMetaData_1_0.MessageHeader_1_0.class);
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ when(_handle.getMetaData()).thenReturn(_metaData);
+ when(_metaData.getMessageHeader()).thenReturn(_header);
+ }
+
+ public void testConvertStringMessageBody() throws Exception
+ {
+ final String expected = "helloworld";
+
+ final AmqpValue value = new AmqpValue(expected);
+ configureMessageContent(value.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = new Message_1_0(_handle);
+
+ final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+ assertEquals("text/plain", convertedMessage.getMessageHeader().getMimeType());
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+ assertArrayEquals(expected.getBytes(), getBytes(content));
+ }
+
+ public void testConvertListMessageBody() throws Exception
+ {
+ final List<Object> expected = Lists.<Object>newArrayList("helloworld", 43, 1L);
+
+ final AmqpValue value = new AmqpValue(expected);
+ configureMessageContent(value.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = new Message_1_0(_handle);
+
+ final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+ assertEquals("jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(getBytes(content)));
+ assertEquals(expected.get(0), reader.readObject());
+ assertEquals(expected.get(1), reader.readObject());
+ assertEquals(expected.get(2), reader.readObject());
+
+ try
+ {
+ reader.readObject();
+ fail("Exception not thrown");
+ }
+ catch (EOFException e)
+ {
+ // PASS
+ }
+ }
+
+ public void testConvertMapMessageBody() throws Exception
+ {
+ final Map<String, String> expected = Collections.singletonMap("key", "value");
+
+ final AmqpValue value = new AmqpValue(expected);
+ configureMessageContent(value.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = new Message_1_0(_handle);
+
+ final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+ assertEquals("jms/map-message", convertedMessage.getMessageHeader().getMimeType());
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+
+ TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(getBytes(content)));
+ assertEquals(expected.size(), reader.readIntImpl());
+ assertEquals("key", reader.readStringImpl());
+ assertEquals(expected.get("key"), reader.readObject());
+ try
+ {
+ reader.readString();
+ fail("Exception not thrown");
+ }
+ catch (EOFException e)
+ {
+ // PASS
+ }
+ }
+
+ public void testConvertBytesMessageBody() throws Exception
+ {
+ final String expected = "helloworld";
+
+ final Data value = new Data(new Binary(expected.getBytes()));
+ configureMessageContent(value.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = new Message_1_0(_handle);
+
+ final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+ assertEquals("application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
+
+ final Collection<QpidByteBuffer> content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
+ assertArrayEquals(expected.getBytes(), getBytes(content));
+ }
+
+ private void configureMessageContent(final EncodingRetainingSection section)
+ {
+ final QpidByteBuffer combined = QpidByteBuffer.wrap(ByteBufferUtils.combine(section.getEncodedForm()));
+ when(_handle.getContentSize()).thenReturn((int) section.getEncodedSize());
+ final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
+ final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
+
+ when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(new Answer<Collection<QpidByteBuffer>>()
+ {
+ @Override
+ public Collection<QpidByteBuffer> answer(final InvocationOnMock invocation) throws Throwable
+ {
+ final QpidByteBuffer view = combined.view(offsetCaptor.getValue(), sizeCaptor.getValue());
+ return Collections.singleton(view);
+ }
+ });
+ }
+
+ private byte[] getBytes(final Collection<QpidByteBuffer> content) throws Exception
+ {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ for (QpidByteBuffer buf: content)
+ {
+ ByteStreams.copy(buf.asInputStream(), bos);
+ buf.dispose();
+ }
+ return bos.toByteArray();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org