qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1545692 - in /qpid/jms/trunk/src: main/java/org/apache/qpid/jms/engine/ test/java/org/apache/qpid/jms/engine/ test/java/org/apache/qpid/jms/impl/
Date Tue, 26 Nov 2013 15:50:53 GMT
Author: robbie
Date: Tue Nov 26 15:50:52 2013
New Revision: 1545692

URL: http://svn.apache.org/r1545692
Log:
QPIDJMS-9: flesh out support for incoming TextMessages using amqp data section, add unit testing
of text messages and tweak the *Test class heirarchy and setUp overridding to ease examination
of console output

Added:
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpTextMessageTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TextMessageImplTest.java
Modified:
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpTextMessage.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageFactoryTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageFactoryImplTest.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/ReceiverImplTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpTextMessage.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpTextMessage.java?rev=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpTextMessage.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpTextMessage.java Tue Nov 26
15:50:52 2013
@@ -18,9 +18,13 @@
  */
 package org.apache.qpid.jms.engine;
 
+import java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.amqp.Binary;
 import org.apache.qpid.proton.amqp.messaging.AmqpValue;
 import org.apache.qpid.proton.amqp.messaging.Data;
 import org.apache.qpid.proton.amqp.messaging.Section;
+import org.apache.qpid.proton.codec.impl.DataImpl;
 import org.apache.qpid.proton.engine.Delivery;
 import org.apache.qpid.proton.message.Message;
 
@@ -53,9 +57,15 @@ public class AmqpTextMessage extends Amq
     {
         AmqpValue body = new AmqpValue(text);
         getMessage().setBody(body);
+
+        //TODO: clear the content-type in the case where we had received
+        //a message containing Data+ContentType
     }
 
-    public String getText()
+    /**
+     * @throws IllegalStateException if the underlying message content can't be retrieved
as a String or null
+     */
+    public String getText() throws IllegalStateException
     {
         Section body = getMessage().getBody();
 
@@ -65,8 +75,29 @@ public class AmqpTextMessage extends Amq
         }
         else if(body instanceof Data)
         {
-            //TODO
-            return null;
+            Data data = (Data) body;
+            if(data.getValue() == null || data.getValue().getLength() == 0)
+            {
+                return null;
+            }
+            else
+            {
+                Binary b = data.getValue();
+
+                ByteBuffer buf = ByteBuffer.wrap(b.getArray(), b.getArrayOffset(), b.getLength());
+                org.apache.qpid.proton.codec.Data codecData = new DataImpl();
+                codecData.decode(buf);
+
+                if(codecData.isNull())
+                {
+                    return null;
+                }
+                else
+                {
+                    return codecData.getString();
+                }
+            }
+
         }
         else if(body instanceof AmqpValue)
         {
@@ -78,12 +109,12 @@ public class AmqpTextMessage extends Amq
             }
             else
             {
-                throw new RuntimeException("Unexpected body content type: " + value.getClass().getSimpleName());
+                throw new IllegalStateException("Unexpected amqp-value body content type:
" + value.getClass().getSimpleName());
             }
         }
         else
         {
-            throw new RuntimeException("Unexpected message body type: " + body.getClass().getSimpleName());
+            throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName());
         }
     }
 }

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=1545692&r1=1545691&r2=1545692&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 Tue
Nov 26 15:50:52 2013
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.qpid.jms.QpidJmsTestCase;
 import org.apache.qpid.jms.engine.AmqpMessage;
 import org.apache.qpid.jms.engine.AmqpTextMessage;
 import org.apache.qpid.proton.Proton;
@@ -39,15 +40,17 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class AmqpMessageFactoryTest
+public class AmqpMessageFactoryTest extends QpidJmsTestCase
 {
    private AmqpConnection _mockAmqpConnection;
    private Delivery _mockDelivery;
    private AmqpMessageFactory _amqpMessageFactory;
 
    @Before
+   @Override
    public void setUp() throws Exception
    {
+       super.setUp();
        _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
        _mockDelivery = Mockito.mock(Delivery.class);
        _amqpMessageFactory = new AmqpMessageFactory();

Modified: 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=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java Tue Nov 26
15:50:52 2013
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.qpid.jms.QpidJmsTestCase;
 import org.apache.qpid.proton.Proton;
 import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
 import org.apache.qpid.proton.engine.Delivery;
@@ -34,7 +35,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class AmqpMessageTest
+public class AmqpMessageTest extends QpidJmsTestCase
 {
     private static final String TEST_PROP_A = "TEST_PROP_A";
     private static final String TEST_PROP_B = "TEST_PROP_B";
@@ -45,8 +46,10 @@ public class AmqpMessageTest
     private Delivery _mockDelivery;
 
     @Before
+    @Override
     public void setUp() throws Exception
     {
+        super.setUp();
         _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
         _mockDelivery = Mockito.mock(Delivery.class);
     }

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpTextMessageTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpTextMessageTest.java?rev=1545692&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpTextMessageTest.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpTextMessageTest.java Tue Nov
26 15:50:52 2013
@@ -0,0 +1,260 @@
+/*
+ *
+ * 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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+
+import org.apache.qpid.jms.QpidJmsTestCase;
+import org.apache.qpid.jms.test.testpeer.describedtypes.sections.DataDescribedType;
+import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.messaging.AmqpSequence;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
+import org.apache.qpid.proton.amqp.messaging.Data;
+import org.apache.qpid.proton.codec.impl.DataImpl;
+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 AmqpTextMessageTest extends QpidJmsTestCase
+{
+    private AmqpConnection _mockAmqpConnection;
+    private Delivery _mockDelivery;
+
+    @Before
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
+        _mockDelivery = Mockito.mock(Delivery.class);
+    }
+
+    @Test
+    public void testGetTextWithNewMessageToSendReturnsNull() throws Exception
+    {
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage();
+
+        assertNull("expected null string", amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testNewMessageToSendContainsAmqpValueBodyWithNull() throws Exception
+    {
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage();
+        assertTrue(amqpTextMessage.getMessage().getBody() instanceof AmqpValue);
+        assertNull(((AmqpValue)amqpTextMessage.getMessage().getBody()).getValue());
+    }
+
+    @Test
+    public void testSetGetTextWithNewMessageToSend() throws Exception
+    {
+        String text = "myTestText";
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage();
+
+        amqpTextMessage.setText(text);
+        assertNotNull(amqpTextMessage.getMessage().getBody());
+        assertTrue(amqpTextMessage.getMessage().getBody() instanceof AmqpValue);
+        assertEquals(text, ((AmqpValue)amqpTextMessage.getMessage().getBody()).getValue());
+
+        assertEquals(text, amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithNoBodySectionReturnsNull() throws Exception
+    {
+        Message message = Proton.message();
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertNull("expected null string", amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithAmqpValueSectionContainingString() throws
Exception
+    {
+        String text = "myString";
+
+        Message message = Proton.message();
+        message.setBody(new AmqpValue(text));
+
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertEquals(text, amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithAmqpValueSectionContainingNull() throws
Exception
+    {
+        Message message = Proton.message();
+        message.setBody(new AmqpValue(null));
+
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertNull("expected null string", amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithDataSectionContainingNullReturnsNull()
throws Exception
+    {
+        Message message = Proton.message();
+        message.setBody(new Data(null));
+
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertNull("expected null string", amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithDataSectionContainingBinaryEncodedNullReturnsNull()
throws Exception
+    {
+        org.apache.qpid.proton.codec.Data nullData = new DataImpl();
+        nullData.putNull();
+        Binary stringBinary = nullData.encode();
+
+        org.apache.qpid.proton.codec.Data payloadData = new DataImpl();
+        payloadData.putDescribedType(new DataDescribedType(stringBinary));
+        Binary b = payloadData.encode();
+
+        System.out.println("Using encoded AMQP message payload: " + b);
+
+        Message message = Proton.message();
+        int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
+        assertEquals(decoded, b.getLength());
+
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertNull("expected null string", amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithDataSectionContainingZeroLengthBinaryReturnsNull()
throws Exception
+    {
+        org.apache.qpid.proton.codec.Data payloadData = new DataImpl();
+        payloadData.putDescribedType(new DataDescribedType(new Binary(new byte[0])));
+        Binary b = payloadData.encode();
+
+        System.out.println("Using encoded AMQP message payload: " + b);
+
+        Message message = Proton.message();
+        int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
+        assertEquals(decoded, b.getLength());
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertNull("expected null string", amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextUsingReceivedMessageWithDataSectionContainingEncodedString() throws
Exception
+    {
+        String encodedString = "myEncodedString";
+
+        org.apache.qpid.proton.codec.Data stringData = new DataImpl();
+        stringData.putString(encodedString);
+        Binary stringBinary = stringData.encode();
+
+        org.apache.qpid.proton.codec.Data payloadData = new DataImpl();
+        payloadData.putDescribedType(new DataDescribedType(stringBinary));
+        Binary b = payloadData.encode();
+
+        System.out.println("Using encoded AMQP message payload: " + b);
+
+        Message message = Proton.message();
+        int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
+        assertEquals(decoded, b.getLength());
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        assertEquals(encodedString, amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextWithNonAmqpValueOrDataSectionThrowsISE() throws Exception
+    {
+        Message message = Proton.message();
+        message.setBody(new AmqpSequence(new ArrayList<Object>()));
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        try
+        {
+            amqpTextMessage.getText();
+            fail("expected exception not thrown");
+        }
+        catch(IllegalStateException ise)
+        {
+            //expected
+        }
+    }
+
+    @Test
+    public void testGetTextWithAmqpValueContainingNonNullNonStringValueThrowsISE() throws
Exception
+    {
+        Message message = Proton.message();
+        message.setBody(new AmqpValue(true));
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        try
+        {
+            amqpTextMessage.getText();
+            fail("expected exception not thrown");
+        }
+        catch(IllegalStateException ise)
+        {
+            //expected
+        }
+    }
+
+    @Test
+    public void testGetTextWithDataSectionContainingNonNullNonStringContentThrowsISE() throws
Exception
+    {
+        org.apache.qpid.proton.codec.Data booleanData = new DataImpl();
+        booleanData.putBoolean(true);
+        Binary booleanBinary = booleanData.encode();
+
+        org.apache.qpid.proton.codec.Data payloadData = new DataImpl();
+        payloadData.putDescribedType(new DataDescribedType(booleanBinary));
+        Binary b = payloadData.encode();
+
+        System.out.println("Using encoded AMQP message payload: " + b);
+
+        Message message = Proton.message();
+        int decoded = message.decode(b.getArray(), b.getArrayOffset(), b.getLength());
+        assertEquals(decoded, b.getLength());
+
+        AmqpTextMessage amqpTextMessage = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+
+        try
+        {
+            amqpTextMessage.getText();
+            fail("expected exception not thrown");
+        }
+        catch(IllegalStateException ise)
+        {
+            //expected
+        }
+    }
+}

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageFactoryImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageFactoryImplTest.java?rev=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageFactoryImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageFactoryImplTest.java Tue
Nov 26 15:50:52 2013
@@ -25,6 +25,7 @@ import static org.junit.Assert.*;
 import javax.jms.JMSException;
 import javax.jms.Message;
 
+import org.apache.qpid.jms.QpidJmsTestCase;
 import org.apache.qpid.jms.engine.AmqpBytesMessage;
 import org.apache.qpid.jms.engine.AmqpGenericMessage;
 import org.apache.qpid.jms.engine.AmqpListMessage;
@@ -36,7 +37,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class MessageFactoryImplTest
+public class MessageFactoryImplTest extends QpidJmsTestCase
 {
 
     private ConnectionImpl _mockConnection;
@@ -44,8 +45,10 @@ public class MessageFactoryImplTest
     private MessageFactoryImpl _messageFactoryImpl;
 
     @Before
+    @Override
     public void setUp() throws Exception
     {
+        super.setUp();
         _mockConnection = Mockito.mock(ConnectionImpl.class);
         _mockSession = Mockito.mock(SessionImpl.class);
         _messageFactoryImpl = new MessageFactoryImpl();

Modified: 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=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java Tue Nov 26
15:50:52 2013
@@ -27,20 +27,23 @@ import java.util.Enumeration;
 import javax.jms.JMSException;
 import javax.jms.MessageFormatException;
 
+import org.apache.qpid.jms.QpidJmsTestCase;
 import org.apache.qpid.jms.engine.TestAmqpMessage;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class MessageImplTest
+public class MessageImplTest extends QpidJmsTestCase
 {
     private ConnectionImpl _mockConnectionImpl;
     private SessionImpl _mockSessionImpl;
     private TestMessageImpl _testMessage;
 
     @Before
+    @Override
     public void setUp() throws Exception
     {
+        super.setUp();
         _mockConnectionImpl = Mockito.mock(ConnectionImpl.class);
         _mockSessionImpl = Mockito.mock(SessionImpl.class);
         _testMessage = new TestMessageImpl(new TestAmqpMessage(), _mockSessionImpl, _mockConnectionImpl);

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java?rev=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java Tue Nov 26
15:50:52 2013
@@ -44,8 +44,10 @@ public class ReceiverImplTest extends Qp
     private AmqpMessage _mockAmqpMessage;
 
     @Before
+    @Override
     public void setUp() throws Exception
     {
+        super.setUp();
         _mockConnection = Mockito.mock(ConnectionImpl.class);
         _mockAmqpReceiver = Mockito.mock(AmqpReceiver.class);
         _mockSession = Mockito.mock(SessionImpl.class);

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java?rev=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java Tue Nov 26 15:50:52
2013
@@ -41,8 +41,10 @@ public class SenderImplTest extends Qpid
     private SessionImpl _mockSession;
 
     @Before
+    @Override
     public void setUp() throws Exception
     {
+        super.setUp();
         _mockConnection = Mockito.mock(ConnectionImpl.class);
         _mockAmqpSender = Mockito.mock(AmqpSender.class);
         _mockSession = Mockito.mock(SessionImpl.class);

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java?rev=1545692&r1=1545691&r2=1545692&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java Tue Nov
26 15:50:52 2013
@@ -22,9 +22,10 @@ import static org.hamcrest.Matchers.cont
 import static org.hamcrest.Matchers.not;
 import static org.junit.Assert.assertThat;
 
+import org.apache.qpid.jms.QpidJmsTestCase;
 import org.junit.Test;
 
-public class SimplePredicateTest
+public class SimplePredicateTest extends QpidJmsTestCase
 {
     private static final String DESCRIPTION = "description1";
     private static final String PREDICATED_OBJECT = "predicatedObject1";

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TextMessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TextMessageImplTest.java?rev=1545692&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TextMessageImplTest.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/TextMessageImplTest.java Tue Nov
26 15:50:52 2013
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.qpid.jms.QpidJmsTestCase;
+import org.apache.qpid.jms.engine.AmqpConnection;
+import org.apache.qpid.jms.engine.AmqpTextMessage;
+import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
+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 TextMessageImplTest extends QpidJmsTestCase
+{
+    private Delivery _mockDelivery;
+    private ConnectionImpl _mockConnectionImpl;
+    private SessionImpl _mockSessionImpl;
+    private AmqpConnection _mockAmqpConnection;
+
+    @Before
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
+        _mockConnectionImpl = Mockito.mock(ConnectionImpl.class);
+        _mockSessionImpl = Mockito.mock(SessionImpl.class);
+    }
+
+    @Test
+    public void testSetGetTextWithNewMessageToSend() throws Exception
+    {
+        String text = "myTestText";
+        TextMessageImpl textMessageImpl = new TextMessageImpl(_mockSessionImpl,_mockConnectionImpl);
+
+        textMessageImpl.setText(text);
+        assertEquals(text, textMessageImpl.getText());
+
+        AmqpTextMessage amqpTextMessage = textMessageImpl.getUnderlyingAmqpMessage(false);
+        assertEquals(text, amqpTextMessage.getText());
+    }
+
+    @Test
+    public void testGetTextDefaultWithNewMessageToSend() throws Exception
+    {
+        TextMessageImpl textMessageImpl = new TextMessageImpl(_mockSessionImpl,_mockConnectionImpl);
+
+        assertNull("expected null string", textMessageImpl.getText());
+    }
+
+    @Test
+    public void testGetTextWithReceivedMessageNoBodySectionReturnsNull() throws Exception
+    {
+        Message message = Proton.message();
+        AmqpTextMessage testAmqpMessage1 = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+        TextMessageImpl textMessageImpl = new TextMessageImpl(testAmqpMessage1, _mockSessionImpl,_mockConnectionImpl);
+
+        assertNull("expected null string", textMessageImpl.getText());
+    }
+
+    @Test
+    public void testGetTextWithReceivedMessageAmqpValueSectionReturnsString() throws Exception
+    {
+        Message message = Proton.message();
+        String value = "myAmqpValueString";
+        message.setBody(new AmqpValue(value));
+        AmqpTextMessage testAmqpMessage1 = new AmqpTextMessage(_mockDelivery, message, _mockAmqpConnection);
+        TextMessageImpl textMessageImpl = new TextMessageImpl(testAmqpMessage1, _mockSessionImpl,_mockConnectionImpl);
+
+        assertEquals(value, textMessageImpl.getText());
+    }
+}



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


Mime
View raw message