qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1544237 - in /qpid/jms/trunk/src: main/java/org/apache/qpid/jms/engine/ main/java/org/apache/qpid/jms/impl/ test/java/org/apache/qpid/jms/ test/java/org/apache/qpid/jms/engine/ test/java/org/apache/qpid/jms/impl/ test/java/org/apache/qpid/...
Date Thu, 21 Nov 2013 16:11:00 GMT
Author: robbie
Date: Thu Nov 21 16:10:59 2013
New Revision: 1544237

URL: http://svn.apache.org/r1544237
Log:
QPIDJMS-9: start on basic application properties support

Added:
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/TestAmqpMessage.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TestMessageImpl.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/describedtypes/sections/ApplicationPropertiesDescribedType.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/ApplicationPropertiesSectionMatcher.java
Modified:
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/SessionIntegrationTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageFactoryTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/TransferPayloadCompositeMatcher.java

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java Thu Nov 21 16:10:59
2013
@@ -20,11 +20,14 @@
  */
 package org.apache.qpid.jms.engine;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.qpid.proton.Proton;
 import org.apache.qpid.proton.amqp.messaging.Accepted;
+import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
 import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
 import org.apache.qpid.proton.engine.Delivery;
 import org.apache.qpid.proton.engine.impl.DeliveryImpl;
@@ -43,6 +46,8 @@ public abstract class AmqpMessage
     private volatile MessageAnnotations _messageAnnotations;
     private volatile Map<Object,Object> _messageAnnotationsMap;
 
+    private volatile Map<String,Object> _applicationPropertiesMap;
+
     /**
      * Used when creating a message that we intend to send
      */
@@ -66,6 +71,11 @@ public abstract class AmqpMessage
         {
             _messageAnnotationsMap = _messageAnnotations.getValue();
         }
+
+        if(_message.getApplicationProperties() != null)
+        {
+            _applicationPropertiesMap = _message.getApplicationProperties().getValue();
+        }
     }
 
     Message getMessage()
@@ -175,4 +185,63 @@ public abstract class AmqpMessage
         _message.setMessageAnnotations(_messageAnnotations);
     }
 
+    //===== Application Properties ======
+
+    private void createApplicationProperties()
+    {
+        _applicationPropertiesMap = new HashMap<String,Object>();
+        _message.setApplicationProperties(new ApplicationProperties(_applicationPropertiesMap));
+    }
+
+    public Set<String> getApplicationPropertyNames()
+    {
+        if(_applicationPropertiesMap != null)
+        {
+           return _applicationPropertiesMap.keySet();
+        }
+        else
+        {
+            return Collections.emptySet();
+        }
+    }
+
+    public boolean applicationPropertyExists(String key)
+    {
+        if(_applicationPropertiesMap != null)
+        {
+           return _applicationPropertiesMap.containsKey(key);
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    public Object getApplicationProperty(String key)
+    {
+        if(_applicationPropertiesMap != null)
+        {
+           return _applicationPropertiesMap.get(key);
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    public void setApplicationProperty(String key, Object value)
+    {
+        if(_applicationPropertiesMap == null)
+        {
+            createApplicationProperties();
+        }
+
+        _applicationPropertiesMap.put(key, value);
+    }
+
+    public void clearAllApplicationProperties()
+    {
+        _applicationPropertiesMap = null;
+        _message.setApplicationProperties(null);
+    }
 }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java Thu Nov 21 16:10:59
2013
@@ -60,6 +60,7 @@ public class AmqpSender extends AmqpLink
                 }
                 catch (java.nio.BufferOverflowException e)
                 {
+                    //TODO: if this gets really large, should we reduce it again later?
                     _buffer = new byte[_buffer.length * 2];
                 }
             }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/BytesMessageImpl.java Thu Nov 21
16:10:59 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.qpid.jms.impl;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
@@ -37,7 +36,6 @@ public class BytesMessageImpl extends Me
     private ByteArrayOutputStream _bytesOut;
     private DataOutputStream _dataAsOutput;
     private DataInputStream _dataIn;
-    private ByteArrayInputStream _bytesIn;
 
     //message to be sent
     public BytesMessageImpl(SessionImpl sessionImpl, ConnectionImpl connectionImpl) throws
JMSException

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java Thu Nov 21 16:10:59
2013
@@ -18,11 +18,13 @@
  */
 package org.apache.qpid.jms.impl;
 
+import java.util.Collections;
 import java.util.Enumeration;
 
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.Message;
+import javax.jms.MessageFormatException;
 
 import org.apache.qpid.jms.engine.AmqpMessage;
 
@@ -49,6 +51,34 @@ public abstract class MessageImpl<T exte
 
     protected abstract T prepareUnderlyingAmqpMessageForSending(T amqpMessage);
 
+    private void checkPropertyNameIsValid(String propertyName) throws IllegalArgumentException
+    {
+        if (propertyName == null)
+        {
+            throw new IllegalArgumentException("Property name must not be null");
+        }
+        else if (propertyName.length() == 0)
+        {
+            throw new IllegalArgumentException("Property name must not be the empty string");
+        }
+
+        //TODO: validate name format?
+        //checkPropertyNameFormat(propertyName);
+    }
+
+    private boolean checkObjectPropertyValueIsValid(Object object) throws MessageFormatException
+    {
+        boolean valid = object instanceof Boolean || object instanceof Byte || object instanceof
Short ||
+                        object instanceof Integer || object instanceof Long || object instanceof
Float ||
+                        object instanceof Double || object instanceof String|| object ==
null;
+        if(!valid)
+        {
+            throw new MessageFormatException("Invalid object property value type: " + object.getClass());
+        }
+
+        return true;
+    }
+
     //======= JMS Methods =======
 
     @Override
@@ -215,8 +245,7 @@ public abstract class MessageImpl<T exte
     @Override
     public boolean propertyExists(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        return _amqpMessage.applicationPropertyExists(name);
     }
 
     @Override
@@ -278,15 +307,17 @@ public abstract class MessageImpl<T exte
     @Override
     public Object getObjectProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        checkPropertyNameIsValid(name);
+
+        //TODO: type conversion if any?
+        //TODO: handle non-JMS types?
+        return _amqpMessage.getApplicationProperty(name);
     }
 
     @Override
     public Enumeration<?> getPropertyNames() throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        return Collections.enumeration(_amqpMessage.getApplicationPropertyNames());
     }
 
     @Override
@@ -348,8 +379,10 @@ public abstract class MessageImpl<T exte
     @Override
     public void setObjectProperty(String name, Object value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        checkPropertyNameIsValid(name);
+        checkObjectPropertyValueIsValid(value);
+
+        _amqpMessage.setApplicationProperty(name, value);
     }
 
     @Override

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java Thu Nov 21
16:10:59 2013
@@ -0,0 +1,112 @@
+/*
+ * 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.jms;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
+import org.apache.qpid.jms.test.testpeer.describedtypes.sections.AmqpValueDescribedType;
+import org.apache.qpid.jms.test.testpeer.describedtypes.sections.ApplicationPropertiesDescribedType;
+import org.apache.qpid.jms.test.testpeer.matchers.sections.ApplicationPropertiesSectionMatcher;
+import org.apache.qpid.jms.test.testpeer.matchers.sections.TransferPayloadCompositeMatcher;
+import org.apache.qpid.jms.test.testpeer.matchers.types.EncodedAmqpValueMatcher;
+import org.apache.qpid.proton.amqp.DescribedType;
+import org.junit.Test;
+
+public class MessageIntegrationTest extends QpidJmsTestCase
+{
+    private final IntegrationTestFixture _testFixture = new IntegrationTestFixture();
+
+    @Test
+    public void testSendTextMessageWithApplicationProperties() throws Exception
+    {
+        try(TestAmqpPeer testPeer = new TestAmqpPeer(IntegrationTestFixture.PORT);)
+        {
+            Connection connection = _testFixture.establishConnecton(testPeer);
+            testPeer.expectBegin();
+            testPeer.expectSenderAttach();
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue("myQueue");
+            MessageProducer producer = session.createProducer(queue);
+
+            String propertyName = "prop";
+            boolean propertyValue = true;
+
+            TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
+            ApplicationPropertiesSectionMatcher appPropsMatcher = new ApplicationPropertiesSectionMatcher(true);
+            appPropsMatcher.withEntry(propertyName, equalTo(propertyValue));
+            messageMatcher.setApplicationPropertiesMatcher(appPropsMatcher);
+            messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(null));
+            testPeer.expectTransfer(messageMatcher);
+
+            Message message = session.createTextMessage();
+            message.setObjectProperty(propertyName, propertyValue);
+
+            producer.send(message);
+        }
+    }
+
+    @Test
+    public void testReceiveTextMessageWithApplicationProperties() throws Exception
+    {
+        try(TestAmqpPeer testPeer = new TestAmqpPeer(IntegrationTestFixture.PORT);)
+        {
+            Connection connection = _testFixture.establishConnecton(testPeer);
+            connection.start();
+
+            testPeer.expectBegin();
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue("myQueue");
+
+            String propertyName = "name";
+            String propertyValue = "value";
+            ApplicationPropertiesDescribedType appProperties = new ApplicationPropertiesDescribedType();
+            appProperties.setApplicationProperty(propertyName, propertyValue);
+            DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
+
+            testPeer.expectReceiverAttach();
+            testPeer.expectLinkFlowRespondWithTransfer(null, null, null, appProperties, amqpValueNullContent);
+            testPeer.expectDispositionThatIsAcceptedAndSettled();
+
+            MessageConsumer messageConsumer = session.createConsumer(queue);
+            Message receivedMessage = messageConsumer.receive(1000);
+            testPeer.waitForAllHandlersToComplete(3000);
+
+            assertNotNull(receivedMessage);
+            assertTrue(receivedMessage instanceof TextMessage);
+            assertNull(((TextMessage)receivedMessage).getText());
+
+            assertTrue(receivedMessage.propertyExists(propertyName));
+            assertTrue(propertyValue.equals(receivedMessage.getObjectProperty(propertyName)));
+        }
+    }
+}

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/SessionIntegrationTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/SessionIntegrationTest.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/SessionIntegrationTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/SessionIntegrationTest.java Thu Nov 21
16:10:59 2013
@@ -36,14 +36,10 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 
 import org.apache.qpid.jms.engine.AmqpBytesMessage;
-import org.apache.qpid.jms.engine.AmqpMessage;
-import org.apache.qpid.jms.engine.AmqpTextMessage;
 import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.AmqpValueDescribedType;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.DataDescribedType;
-import org.apache.qpid.jms.test.testpeer.describedtypes.sections.MessageAnnotationsDescribedType;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.PropertiesDescribedType;
-import org.apache.qpid.jms.test.testpeer.matchers.sections.MessageAnnotationsSectionMatcher;
 import org.apache.qpid.jms.test.testpeer.matchers.sections.MessagePropertiesSectionMatcher;
 import org.apache.qpid.jms.test.testpeer.matchers.sections.TransferPayloadCompositeMatcher;
 import org.apache.qpid.jms.test.testpeer.matchers.types.EncodedAmqpValueMatcher;
@@ -86,7 +82,9 @@ public class SessionIntegrationTest exte
             MessageProducer producer = session.createProducer(queue);
 
             String text = "myMessage";
-            testPeer.expectTransfer(new EncodedAmqpValueMatcher(text));
+            TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
+            messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(text));
+            testPeer.expectTransfer(messageMatcher);
 
             Message message = session.createTextMessage(text);
 
@@ -111,7 +109,7 @@ public class SessionIntegrationTest exte
             DescribedType amqpValueStringContent = new AmqpValueDescribedType(expectedMessageContent);
 
             testPeer.expectReceiverAttach();
-            testPeer.expectLinkFlowRespondWithTransfer(null, null, null, amqpValueStringContent);
+            testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueStringContent);
             testPeer.expectDispositionThatIsAcceptedAndSettled();
 
             MessageConsumer messageConsumer = session.createConsumer(queue);
@@ -163,7 +161,7 @@ public class SessionIntegrationTest exte
             DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
 
             testPeer.expectReceiverAttach();
-            testPeer.expectLinkFlowRespondWithTransfer(null, null, null, amqpValueNullContent);
+            testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent);
             testPeer.expectDispositionThatIsAcceptedAndSettled();
 
             MessageConsumer messageConsumer = session.createConsumer(queue);
@@ -226,7 +224,7 @@ public class SessionIntegrationTest exte
             DescribedType dataContent = new DataDescribedType(new Binary(expectedContent));
 
             testPeer.expectReceiverAttach();
-            testPeer.expectLinkFlowRespondWithTransfer(null, null, properties, dataContent);
+            testPeer.expectLinkFlowRespondWithTransfer(null, null, properties, null, dataContent);
             testPeer.expectDispositionThatIsAcceptedAndSettled();
 
             MessageConsumer messageConsumer = session.createConsumer(queue);

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageFactoryTest.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageFactoryTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageFactoryTest.java Thu
Nov 21 16:10:59 2013
@@ -31,10 +31,8 @@ import org.apache.qpid.jms.engine.AmqpMe
 import org.apache.qpid.jms.engine.AmqpTextMessage;
 import org.apache.qpid.proton.Proton;
 import org.apache.qpid.proton.amqp.Binary;
-import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.amqp.messaging.AmqpValue;
 import org.apache.qpid.proton.amqp.messaging.Data;
-import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
 import org.apache.qpid.proton.engine.Delivery;
 import org.apache.qpid.proton.message.Message;
 import org.junit.Before;

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java Thu Nov 21
16:10:59 2013
@@ -0,0 +1,142 @@
+/*
+ *
+ * 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.jms.engine;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
+import org.apache.qpid.proton.engine.Delivery;
+import org.apache.qpid.proton.message.Message;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class AmqpMessageTest
+{
+    private static final String TEST_PROP_A = "TEST_PROP_A";
+    private static final String TEST_PROP_B = "TEST_PROP_B";
+    private static final String TEST_VALUE_STRING_A = "TEST_VALUE_STRING_A";
+    private static final String TEST_VALUE_STRING_B = "TEST_VALUE_STRING_B";
+
+    private AmqpConnection _mockAmqpConnection;
+    private Delivery _mockDelivery;
+
+    @Before
+    public void setUp() throws Exception
+    {
+        _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
+        _mockDelivery = Mockito.mock(Delivery.class);
+    }
+
+    @Test
+    public void testGetApplicationPropertyNames()
+    {
+        //Check a Proton Message without any application properties section
+        Message message1 = Proton.message();
+        TestAmqpMessage testAmqpMessage1 = new TestAmqpMessage(message1, _mockDelivery, _mockAmqpConnection);
+
+        Set<String> applicationPropertyNames = testAmqpMessage1.getApplicationPropertyNames();
+        assertNotNull(applicationPropertyNames);
+        assertTrue(applicationPropertyNames.isEmpty());
+
+        //Check a Proton Message with some application properties
+        Map<Object,Object> applicationPropertiesMap = new HashMap<Object,Object>();
+        applicationPropertiesMap.put(TEST_PROP_A, TEST_VALUE_STRING_A);
+        applicationPropertiesMap.put(TEST_PROP_B, TEST_VALUE_STRING_B);
+
+        Message message2 = Proton.message();
+        message2.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap
));
+
+        TestAmqpMessage testAmqpMessage2 = new TestAmqpMessage(message2, _mockDelivery, _mockAmqpConnection);
+
+        Set<String> applicationPropertyNames2 = testAmqpMessage2.getApplicationPropertyNames();
+        assertEquals(2, applicationPropertyNames2.size());
+        assertTrue(applicationPropertyNames2.contains(TEST_PROP_A));
+        assertTrue(applicationPropertyNames2.contains(TEST_PROP_B));
+    }
+
+    @Test
+    public void testClearAllApplicationProperties()
+    {
+        Map<Object,Object> applicationPropertiesMap = new HashMap<Object,Object>();
+        applicationPropertiesMap.put(TEST_PROP_A, TEST_VALUE_STRING_A);
+
+        Message message = Proton.message();
+        message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap
));
+
+        TestAmqpMessage testAmqpMessage = new TestAmqpMessage(message, _mockDelivery, _mockAmqpConnection);
+
+        Set<String> applicationPropertyNames = testAmqpMessage.getApplicationPropertyNames();
+        assertEquals(1, applicationPropertyNames.size());
+        assertTrue(applicationPropertyNames.contains(TEST_PROP_A));
+
+        //Now empty the application properties
+        testAmqpMessage.clearAllApplicationProperties();
+        applicationPropertyNames = testAmqpMessage.getApplicationPropertyNames();
+        assertTrue(applicationPropertyNames.isEmpty());
+    }
+
+    @Test
+    public void testApplicationPropertyExists()
+    {
+        Map<Object,Object> applicationPropertiesMap = new HashMap<Object,Object>();
+        applicationPropertiesMap.put(TEST_PROP_A, TEST_VALUE_STRING_A);
+
+        Message message = Proton.message();
+        message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap
));
+
+        TestAmqpMessage testAmqpMessage = new TestAmqpMessage(message, _mockDelivery, _mockAmqpConnection);
+
+        assertTrue(testAmqpMessage.applicationPropertyExists(TEST_PROP_A));
+        assertFalse(testAmqpMessage.applicationPropertyExists(TEST_PROP_B));
+    }
+
+    @Test
+    public void testGetApplicationProperty()
+    {
+        Map<Object,Object> applicationPropertiesMap = new HashMap<Object,Object>();
+        applicationPropertiesMap.put(TEST_PROP_A, TEST_VALUE_STRING_A);
+
+        Message message = Proton.message();
+        message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap
));
+
+        TestAmqpMessage testAmqpMessage = new TestAmqpMessage(message, _mockDelivery, _mockAmqpConnection);
+
+        assertEquals(TEST_VALUE_STRING_A, testAmqpMessage.getApplicationProperty(TEST_PROP_A));
+        assertNull(testAmqpMessage.getApplicationProperty(TEST_PROP_B));
+    }
+
+    @Test
+    public void testSetApplicationProperty()
+    {
+        Message message = Proton.message();
+        TestAmqpMessage testAmqpMessage = new TestAmqpMessage(message, _mockDelivery, _mockAmqpConnection);
+
+        assertNull(testAmqpMessage.getApplicationProperty(TEST_PROP_A));
+        testAmqpMessage.setApplicationProperty(TEST_PROP_A, TEST_VALUE_STRING_A);
+        assertEquals(TEST_VALUE_STRING_A, testAmqpMessage.getApplicationProperty(TEST_PROP_A));
+    }
+}

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/TestAmqpMessage.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/TestAmqpMessage.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/TestAmqpMessage.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/TestAmqpMessage.java Thu Nov 21
16:10:59 2013
@@ -0,0 +1,16 @@
+package org.apache.qpid.jms.engine;
+
+import org.apache.qpid.proton.engine.Delivery;
+import org.apache.qpid.proton.message.Message;
+
+public class TestAmqpMessage extends AmqpMessage
+{
+    public TestAmqpMessage()
+    {
+    }
+
+    public TestAmqpMessage(Message message, Delivery delivery, AmqpConnection amqpConnection)
+    {
+        super(message, delivery, amqpConnection);
+    }
+}
\ No newline at end of file

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java Thu Nov 21
16:10:59 2013
@@ -0,0 +1,152 @@
+/*
+ *
+ * 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.jms.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+
+import javax.jms.MessageFormatException;
+
+import org.apache.qpid.jms.engine.TestAmqpMessage;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class MessageImplTest
+{
+    private ConnectionImpl _mockConnectionImpl;
+    private SessionImpl _mockSessionImpl;
+    private TestMessageImpl _testMessage;
+
+    @Before
+    public void setUp() throws Exception
+    {
+        _mockConnectionImpl = Mockito.mock(ConnectionImpl.class);
+        _mockSessionImpl = Mockito.mock(SessionImpl.class);
+        _testMessage = new TestMessageImpl(new TestAmqpMessage(), _mockSessionImpl, _mockConnectionImpl);
+    }
+
+    @Test
+    public void testSetPropertyWithNullOrEmptyNameThrowsIAE() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty(null, "value");
+            fail("Expected exception not thrown");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+
+        try
+        {
+            _testMessage.setObjectProperty("", "value");
+            fail("Expected exception not thrown");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    @Test
+    public void testSetObjectPropertyWithIllegalTypeThrowsMFE() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("myProperty", new Exception());
+            fail("Expected exception not thrown");
+        }
+        catch(MessageFormatException mfe)
+        {
+            //expected
+        }
+    }
+
+    @Test
+    public void testSetObjectProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+
+        Object propertyValue = null;
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Boolean.valueOf(false);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Byte.valueOf((byte)1);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Short.valueOf((short)2);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Integer.valueOf(3);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Long.valueOf(4);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Float.valueOf(5.01F);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = Double.valueOf(6.01);
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+
+        propertyValue = "string";
+        _testMessage.setObjectProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getObjectProperty(propertyName));
+    }
+
+    @Test
+    public void testPropertyExists() throws Exception
+    {
+        String propertyName = "myProperty";
+
+        assertFalse(_testMessage.propertyExists(propertyName));
+        _testMessage.setObjectProperty(propertyName, "string");
+        assertTrue(_testMessage.propertyExists(propertyName));
+    }
+
+    @Test
+    public void testGetPropertyNames() throws Exception
+    {
+        String propertyName = "myProperty";
+
+        _testMessage.setObjectProperty(propertyName, "string");
+        Enumeration<?> names = _testMessage.getPropertyNames();
+
+        assertTrue(names.hasMoreElements());
+        Object name1 = names.nextElement();
+        assertTrue(name1 instanceof String);
+        assertTrue(propertyName.equals(name1));
+        assertFalse(names.hasMoreElements());
+    }
+}

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TestMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TestMessageImpl.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TestMessageImpl.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TestMessageImpl.java Thu Nov 21
16:10:59 2013
@@ -0,0 +1,19 @@
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.TestAmqpMessage;
+
+public class TestMessageImpl extends MessageImpl<TestAmqpMessage>
+{
+    public TestMessageImpl(TestAmqpMessage amqpMessage, SessionImpl sessionImpl, ConnectionImpl
connectionImpl)
+    {
+        super(amqpMessage,sessionImpl,connectionImpl);
+    }
+
+    @Override
+    protected TestAmqpMessage prepareUnderlyingAmqpMessageForSending(
+            TestAmqpMessage amqpMessage)
+    {
+        //TODO
+        throw new UnsupportedOperationException("Not Implemented");
+    }
+}
\ No newline at end of file

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java Thu Nov
21 16:10:59 2013
@@ -40,6 +40,7 @@ import org.apache.qpid.jms.test.testpeer
 import org.apache.qpid.jms.test.testpeer.describedtypes.SaslMechanismsFrame;
 import org.apache.qpid.jms.test.testpeer.describedtypes.SaslOutcomeFrame;
 import org.apache.qpid.jms.test.testpeer.describedtypes.TransferFrame;
+import org.apache.qpid.jms.test.testpeer.describedtypes.sections.ApplicationPropertiesDescribedType;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.HeaderDescribedType;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.MessageAnnotationsDescribedType;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.PropertiesDescribedType;
@@ -410,6 +411,7 @@ public class TestAmqpPeer implements Aut
     public void expectLinkFlowRespondWithTransfer(final HeaderDescribedType headerDescribedType,
                                                   final MessageAnnotationsDescribedType messageAnnotationsDescribedType,
                                                   final PropertiesDescribedType propertiesDescribedType,
+                                                  final ApplicationPropertiesDescribedType
appPropertiesDescribedType,
                                                   final DescribedType content)
     {
         final FlowMatcher flowMatcher = new FlowMatcher()
@@ -439,6 +441,11 @@ public class TestAmqpPeer implements Aut
             payloadData.putDescribedType(propertiesDescribedType);
         }
 
+        if(appPropertiesDescribedType != null)
+        {
+            payloadData.putDescribedType(appPropertiesDescribedType);
+        }
+
         if(content != null)
         {
             payloadData.putDescribedType(content);

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/describedtypes/sections/ApplicationPropertiesDescribedType.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/describedtypes/sections/ApplicationPropertiesDescribedType.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/describedtypes/sections/ApplicationPropertiesDescribedType.java
(added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/describedtypes/sections/ApplicationPropertiesDescribedType.java
Thu Nov 21 16:10:59 2013
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.jms.test.testpeer.describedtypes.sections;
+
+import org.apache.qpid.jms.test.testpeer.MapDescribedType;
+import org.apache.qpid.proton.amqp.Symbol;
+
+public class ApplicationPropertiesDescribedType extends MapDescribedType
+{
+    private static final Symbol DESCIPTOR_SYMBOL = Symbol.valueOf("amqp:application-properties:map");
+
+    @Override
+    public Object getDescriptor()
+    {
+        return DESCIPTOR_SYMBOL;
+    }
+
+    public void setApplicationProperty(String name, Object value)
+    {
+        if(name == null)
+        {
+            throw new RuntimeException("ApplicationProperties maps must use non-null String
keys");
+        }
+
+        getDescribed().put(name, value);
+    }
+}

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/ApplicationPropertiesSectionMatcher.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/ApplicationPropertiesSectionMatcher.java?rev=1544237&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/ApplicationPropertiesSectionMatcher.java
(added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/ApplicationPropertiesSectionMatcher.java
Thu Nov 21 16:10:59 2013
@@ -0,0 +1,53 @@
+/*
+ * 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.jms.test.testpeer.matchers.sections;
+
+import java.util.HashMap;
+
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.hamcrest.Matcher;
+
+public class ApplicationPropertiesSectionMatcher extends MessageMapSectionMatcher
+{
+    public static final Symbol DESCRIPTOR_SYMBOL = Symbol.valueOf("amqp:application-properties:map");
+    public static final UnsignedLong DESCRIPTOR_CODE = UnsignedLong.valueOf(0x0000000000000074L);
+
+    public ApplicationPropertiesSectionMatcher(boolean expectTrailingBytes)
+    {
+        super(DESCRIPTOR_CODE,
+              DESCRIPTOR_SYMBOL,
+              new HashMap<Object, Matcher<?>>(),
+              expectTrailingBytes);
+    }
+
+    @Override
+    public ApplicationPropertiesSectionMatcher withEntry(Object key, Matcher<?> m)
+    {
+        if(!(key instanceof String))
+        {
+            throw new RuntimeException("ApplicationProperties maps must use non-null String
keys");
+        }
+
+        return (ApplicationPropertiesSectionMatcher) super.withEntry(key, m);
+    }
+}
+

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/TransferPayloadCompositeMatcher.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/TransferPayloadCompositeMatcher.java?rev=1544237&r1=1544236&r2=1544237&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/TransferPayloadCompositeMatcher.java
(original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/sections/TransferPayloadCompositeMatcher.java
Thu Nov 21 16:10:59 2013
@@ -39,6 +39,8 @@ public class TransferPayloadCompositeMat
     private String _propsMatcherFailureDescription;
     private Matcher<Binary> _msgContentMatcher;
     private String _msgContentMatcherFailureDescription;
+    private ApplicationPropertiesSectionMatcher _appPropsMatcher;
+    private String _appPropsMatcherFailureDescription;
 
     public TransferPayloadCompositeMatcher()
     {
@@ -84,6 +86,22 @@ public class TransferPayloadCompositeMat
             }
         }
 
+        //Application Properties Section
+        if(_appPropsMatcher != null)
+        {
+            Binary appPropsEtcSubBinary = receivedBinary.subBinary(bytesConsumed, origLength
- bytesConsumed);
+            try
+            {
+                bytesConsumed += _appPropsMatcher.verify(appPropsEtcSubBinary);
+            }
+            catch(Throwable t)
+            {
+                _propsMatcherFailureDescription = "\nActual encoded form of remaining bytes
passed to ApplicationPropertiesMatcher: " + appPropsEtcSubBinary;
+                _propsMatcherFailureDescription += "\nApplicationPropertiesMatcher generated
throwable: " + t;
+
+                return false;
+            }
+        }
         //Message Content Body Section, already a Matcher<Binary>
         if(_msgContentMatcher != null)
         {
@@ -134,6 +152,14 @@ public class TransferPayloadCompositeMat
             return;
         }
 
+        //Application Properties Section
+        if(_appPropsMatcherFailureDescription != null)
+        {
+            mismatchDescription.appendText("\nApplicationPropertiesMatcherFailed!");
+            mismatchDescription.appendText(_appPropsMatcherFailureDescription);
+            return;
+        }
+
         //Message Content Body Section
         if(_msgContentMatcherFailureDescription != null)
         {
@@ -157,4 +183,9 @@ public class TransferPayloadCompositeMat
     {
         _msgContentMatcher = msgContentMatcher;
     }
+
+    public void setApplicationPropertiesMatcher(ApplicationPropertiesSectionMatcher appPropsMatcher)
+    {
+        _appPropsMatcher = appPropsMatcher;
+    }
 }
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message