You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2017/03/08 07:51:32 UTC
svn commit: r1785923 [2/2] - in /qpid/java/trunk:
broker-core/src/main/java/org/apache/qpid/server/message/mimecontentconverter/
broker-core/src/main/java/org/apache/qpid/server/protocol/v0_10/transport/mimecontentconverter/
broker-core/src/main/java/o...
Modified: qpid/java/trunk/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10.java?rev=1785923&r1=1785922&r2=1785923&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10.java (original)
+++ qpid/java/trunk/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10.java Wed Mar 8 07:51:31 2017
@@ -26,6 +26,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter;
+import org.apache.qpid.server.message.mimecontentconverter.MimeContentConverterRegistry;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.NamedAddressSpace;
import org.apache.qpid.server.plugin.MessageConverter;
@@ -74,11 +76,13 @@ public class MessageConverter_1_0_to_v0_
{
Object bodyObject = MessageConverter_from_1_0.convertBodyToObject(serverMsg);
- final byte[] messageContent = MessageConverter_from_1_0.convertToBody(bodyObject);
+ final ObjectToMimeContentConverter converter = MimeContentConverterRegistry.getBestFitObjectToMimeContentConverter(bodyObject);
+ final byte[] messageContent = converter == null ? new byte[] {} : converter.toMimeContent(bodyObject);
+ final String mimeType = converter == null ? null : converter.getMineType();
final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(serverMsg,
addressSpace,
- MessageConverter_from_1_0.getBodyMimeType(bodyObject),
+ mimeType,
messageContent.length);
return new StoredMessage<MessageMetaData_0_10>()
Modified: qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/pom.xml
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/pom.xml?rev=1785923&r1=1785922&r2=1785923&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/pom.xml (original)
+++ qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/pom.xml Wed Mar 8 07:51:31 2017
@@ -55,6 +55,13 @@
<artifactId>qpid-broker-plugins-amqp-1-0-protocol</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>qpid-test-utils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8.java?rev=1785923&r1=1785922&r2=1785923&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8.java (original)
+++ qpid/java/trunk/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8.java Wed Mar 8 07:51:31 2017
@@ -26,6 +26,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter;
+import org.apache.qpid.server.message.mimecontentconverter.MimeContentConverterRegistry;
import org.apache.qpid.server.protocol.v0_8.AMQShortString;
import org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties;
import org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody;
@@ -74,12 +76,12 @@ public class MessageConverter_1_0_to_v0_
{
Object bodyObject = MessageConverter_from_1_0.convertBodyToObject(serverMsg);
+ final ObjectToMimeContentConverter converter = MimeContentConverterRegistry.getBestFitObjectToMimeContentConverter(bodyObject);
-
-
- final byte[] messageContent = MessageConverter_from_1_0.convertToBody(bodyObject);
+ final byte[] messageContent = converter == null ? new byte[] {} : converter.toMimeContent(bodyObject);
+ final String mimeType = converter == null ? null : converter.getMineType();
final MessageMetaData messageMetaData_0_8 = convertMetaData(serverMsg,
- MessageConverter_from_1_0.getBodyMimeType(bodyObject),
+ mimeType,
messageContent.length);
return new StoredMessage<MessageMetaData>()
Added: qpid/java/trunk/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
URL: http://svn.apache.org/viewvc/qpid/java/trunk/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?rev=1785923&view=auto
==============================================================================
--- qpid/java/trunk/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 (added)
+++ qpid/java/trunk/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 Wed Mar 8 07:51:31 2017
@@ -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);
+ }
+ });
+ }
+
+}
Added: qpid/java/trunk/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
URL: http://svn.apache.org/viewvc/qpid/java/trunk/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?rev=1785923&view=auto
==============================================================================
--- qpid/java/trunk/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 (added)
+++ qpid/java/trunk/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 Wed Mar 8 07:51:31 2017
@@ -0,0 +1,196 @@
+/*
+ *
+ * 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();
+ }
+}
Modified: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PublishMessageRestTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PublishMessageRestTest.java?rev=1785923&r1=1785922&r2=1785923&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PublishMessageRestTest.java (original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PublishMessageRestTest.java Wed Mar 8 07:51:31 2017
@@ -36,6 +36,7 @@ import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
+import javax.jms.StreamMessage;
import javax.jms.TextMessage;
import javax.servlet.http.HttpServletResponse;
@@ -169,6 +170,20 @@ public class PublishMessageRestTest exte
assertEquals("Unexpected number of key/value pairs in map message", content.size(), entryCount);
}
+ public void testPublishListMessage() throws Exception
+ {
+ final List<Object> content = new ArrayList<>();
+ content.add("astring");
+ content.add(Integer.MIN_VALUE);
+ content.add(Long.MAX_VALUE);
+ content.add(null);
+ StreamMessage message = publishMessageWithContent(content, StreamMessage.class);
+ assertEquals("astring", message.readString());
+ assertEquals(Integer.MIN_VALUE, message.readInt());
+ assertEquals(Long.MAX_VALUE, message.readLong());
+ assertNull(message.readObject());
+ }
+
public void testPublishRouting() throws Exception
{
final String queueName = UUID.randomUUID().toString();
Modified: qpid/java/trunk/test-profiles/Java10BrokenTestsExcludes
URL: http://svn.apache.org/viewvc/qpid/java/trunk/test-profiles/Java10BrokenTestsExcludes?rev=1785923&r1=1785922&r2=1785923&view=diff
==============================================================================
--- qpid/java/trunk/test-profiles/Java10BrokenTestsExcludes (original)
+++ qpid/java/trunk/test-profiles/Java10BrokenTestsExcludes Wed Mar 8 07:51:31 2017
@@ -34,6 +34,7 @@ org.apache.qpid.test.unit.topic.TopicSes
// the received message is being treated as an object message (because it lacks the necessary JMS annotation?)
org.apache.qpid.systest.rest.PublishMessageRestTest#testPublishMapMessage
+org.apache.qpid.systest.rest.PublishMessageRestTest#testPublishListMessage
// this test fails - likely a client bug with the modification racing the send
org.apache.qpid.test.unit.basic.BytesMessageTest#testModificationAfterSend
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org