You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/12/22 17:56:13 UTC
[05/16] qpid-jms git commit: remove tmp module with old client work
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6f106f64/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ObjectMessageImplTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ObjectMessageImplTest.java b/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ObjectMessageImplTest.java
deleted file mode 100644
index 93be404..0000000
--- a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ObjectMessageImplTest.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jms.MessageFormatException;
-import javax.jms.MessageNotWriteableException;
-
-import org.apache.qpid.jms.QpidJmsTestCase;
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpObjectMessage;
-import org.apache.qpid.proton.Proton;
-import org.apache.qpid.proton.amqp.Binary;
-import org.apache.qpid.proton.amqp.messaging.Data;
-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 ObjectMessageImplTest 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);
- Mockito.when(_mockSessionImpl.getDestinationHelper()).thenReturn(new DestinationHelper());
- }
-
- /**
- * Test that attempting to write bytes to a received message (without calling {@link ObjectMessage#clearBody()} first)
- * causes a {@link MessageNotWriteableException} to be thrown due to being read-only.
- */
- @Test
- public void testReceivedObjectMessageThrowsMessageNotWriteableExceptionOnSetObject() throws Exception
- {
- String content = "myStringContent";
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(content);
- oos.flush();
- oos.close();
- byte[] bytes = baos.toByteArray();
-
- Message message = Proton.message();
- message.setBody(new Data(new Binary(bytes)));
-
- AmqpObjectMessage amqpSerializedObjectMessage = new AmqpObjectMessage(message, _mockDelivery, _mockAmqpConnection, false);
- ObjectMessageImpl objectMessageImpl = new ObjectMessageImpl(amqpSerializedObjectMessage, _mockSessionImpl,_mockConnectionImpl, null);
-
- try
- {
- objectMessageImpl.setObject("newObject");
- fail("Expected exception to be thrown");
- }
- catch(MessageNotWriteableException mnwe)
- {
- //expected
- }
- }
-
- /**
- * Test that calling {@link ObjectMessage#clearBody()} causes a received
- * message to become writable
- */
- @Test
- public void testClearBodyOnReceivedObjectMessageMakesMessageWritable() throws Exception
- {
- String content = "myStringContent";
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(content);
- oos.flush();
- oos.close();
- byte[] bytes = baos.toByteArray();
-
- Message message = Proton.message();
- message.setBody(new Data(new Binary(bytes)));
-
- AmqpObjectMessage amqpSerializedObjectMessage = new AmqpObjectMessage(message, _mockDelivery, _mockAmqpConnection, false);
- ObjectMessageImpl objectMessageImpl = new ObjectMessageImpl(amqpSerializedObjectMessage, _mockSessionImpl,_mockConnectionImpl, null);
-
- assertFalse("Message should not be writable", objectMessageImpl.isBodyWritable());
-
- objectMessageImpl.clearBody();
-
- assertTrue("Message should be writable", objectMessageImpl.isBodyWritable());
- }
-
- /**
- * Test that calling {@link ObjectMessage#clearBody()} of a received message
- * causes the body of the underlying {@link AmqpObjectMessage} to be emptied.
- */
- @Test
- public void testClearBodyOnReceivedObjectMessageClearsUnderlyingMessageBody() throws Exception
- {
- String content = "myStringContent";
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(content);
- oos.flush();
- oos.close();
- byte[] bytes = baos.toByteArray();
-
- Message message = Proton.message();
- message.setBody(new Data(new Binary(bytes)));
-
- AmqpObjectMessage amqpSerializedObjectMessage = new AmqpObjectMessage(message, _mockDelivery, _mockAmqpConnection, false);
- ObjectMessageImpl objectMessageImpl = new ObjectMessageImpl(amqpSerializedObjectMessage, _mockSessionImpl,_mockConnectionImpl, null);
-
- assertNotNull("Expected body section but none was present", message.getBody());
-
- objectMessageImpl.clearBody();
-
- //check that the returned object is now null
- assertNull("Unexpected object value", objectMessageImpl.getObject());
-
- //verify the underlying message has no body section
- //TODO: this test assumes we can omit the body section. If we decide otherwise it
- //should instead check for e.g. a data section containing a serialized null object
- assertNull("Expected no body section", message.getBody());
- }
-
- /**
- * Test that setting an object on a new message and later getting the value, returns an
- * equal but different object that does not pick up intermediate changes to the set object.
- */
- @Test
- public void testSetThenGetObjectReturnsSnapshot() throws Exception
- {
- Map<String,String> origMap = new HashMap<String,String>();
- origMap.put("key1", "value1");
-
- ObjectMessageImpl objectMessageImpl = new ObjectMessageImpl(_mockSessionImpl,_mockConnectionImpl);
- objectMessageImpl.setObject((Serializable) origMap);
-
- //verify we get a different-but-equal object back
- Serializable serialized = objectMessageImpl.getObject();
- assertTrue("Unexpected object type returned", serialized instanceof Map<?,?>);
- Map<?,?> returnedObject1 = (Map<?,?>) serialized;
- assertNotSame("Expected different objects, due to snapshot being taken", origMap, returnedObject1);
- assertEquals("Expected equal objects, due to snapshot being taken", origMap, returnedObject1);
-
- //mutate the original object
- origMap.put("key2", "value2");
-
- //verify we get a different-but-equal object back when compared to the previously retrieved object
- Serializable serialized2 = objectMessageImpl.getObject();
- assertTrue("Unexpected object type returned", serialized2 instanceof Map<?,?>);
- Map<?,?> returnedObject2 = (Map<?,?>) serialized2;
- assertNotSame("Expected different objects, due to snapshot being taken", origMap, returnedObject2);
- assertEquals("Expected equal objects, due to snapshot being taken", returnedObject1, returnedObject2);
-
- //verify the mutated map is a different and not equal object
- assertNotSame("Expected different objects, due to snapshot being taken", returnedObject1, returnedObject2);
- assertNotEquals("Expected objects to differ, due to snapshot being taken", origMap, returnedObject2);
- }
-
- /**
- * Test that setting an object on a new message which contains non-serializable content results
- * in an {@link MessageFormatException} being thrown due to failure to encode the object.
- */
- @Test
- public void testSetObjectWithNonSerializableThrowsJMSMFE() throws Exception
- {
- Map<String,Object> origMap = new HashMap<String,Object>();
- origMap.put("key1", "value1");
- origMap.put("notSerializable", new NotSerializable());
-
- ObjectMessageImpl objectMessageImpl = new ObjectMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- try
- {
- objectMessageImpl.setObject((Serializable) origMap);
- fail("Expected exception to be thrown");
- }
- catch(MessageFormatException mfe)
- {
- //expected
- }
- }
-
- //Test class
- private static class NotSerializable
- {
- public NotSerializable()
- {
- }
- }
-
- /**
- * Test that failure during deserialization of an object in a message results
- * in an {@link MessageFormatException} being throw.
- */
- @Test
- public void testGetObjectWithFailedDeserialisationThrowsJMSMFE() throws Exception
- {
- Map<String,Object> origMap = new HashMap<String,Object>();
- origMap.put("key1", "value1");
- origMap.put("notSerializable", new NotSerializable());
-
- AmqpObjectMessage amqpSerializedObjectMessage = Mockito.mock(AmqpObjectMessage.class);
- Mockito.when(amqpSerializedObjectMessage.getObject()).thenThrow(new ClassNotFoundException());
-
- ObjectMessageImpl objectMessageImpl = new ObjectMessageImpl(amqpSerializedObjectMessage, _mockSessionImpl,_mockConnectionImpl, null);
-
- try
- {
- objectMessageImpl.getObject();
- fail("Expected exception to be thrown");
- }
- catch(MessageFormatException mfe)
- {
- //expected
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6f106f64/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/QueueImplTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/QueueImplTest.java b/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/QueueImplTest.java
deleted file mode 100644
index ea49197..0000000
--- a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/QueueImplTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import static org.junit.Assert.*;
-
-import javax.jms.Queue;
-
-import org.apache.qpid.jms.QpidJmsTestCase;
-import org.junit.Before;
-import org.junit.Test;
-
-public class QueueImplTest extends QpidJmsTestCase
-{
- private String _testQueueName;
- private QueueImpl _testQueue;
-
- @Before
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- _testQueueName = "testQueueName";
- _testQueue = new QueueImpl(_testQueueName);
- }
-
- @Test
- public void testGetQueueName() throws Exception
- {
- assertEquals(_testQueueName, _testQueue.getQueueName());
- }
-
- @Test
- public void testToString() throws Exception
- {
- assertEquals(_testQueueName, _testQueue.toString());
- }
-
- @Test
- public void testEqualsAndHashCode() throws Exception
- {
- Queue anotherEqualQueue = new QueueImpl(_testQueueName);
- Queue unequalQueue = new QueueImpl("otherName");
-
- assertFalse(_testQueue == anotherEqualQueue);
- assertFalse(_testQueue.equals(unequalQueue));
-
- assertTrue(_testQueue.equals(anotherEqualQueue));
- assertEquals(_testQueue.hashCode(), anotherEqualQueue.hashCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6f106f64/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java b/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java
deleted file mode 100644
index 4a55639..0000000
--- a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/ReceiverImplTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-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 javax.jms.Message;
-import javax.jms.Session;
-
-import org.apache.qpid.jms.QpidJmsTestCase;
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpGenericMessage;
-import org.apache.qpid.jms.engine.AmqpMessage;
-import org.apache.qpid.jms.engine.AmqpReceiver;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class ReceiverImplTest extends QpidJmsTestCase
-{
- private ConnectionImpl _mockConnection;
- private AmqpConnection _mockAmqpConnection;
- private AmqpReceiver _mockAmqpReceiver;
- private SessionImpl _mockSession;
- private AmqpMessage _mockAmqpMessage;
-
- @Before
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- _mockConnection = Mockito.mock(ConnectionImpl.class);
- _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
- _mockAmqpReceiver = Mockito.mock(AmqpReceiver.class);
- _mockSession = Mockito.mock(SessionImpl.class);
- Mockito.when(_mockSession.getDestinationHelper()).thenReturn(new DestinationHelper());
- _mockAmqpMessage = Mockito.mock(AmqpGenericMessage.class);
- }
-
- @Test
- public void testNoMessageReceivedWhenConnectionNotStarted() throws Exception
- {
- Mockito.when(_mockConnection.isStarted()).thenReturn(false);
- Mockito.when(_mockAmqpReceiver.receiveNoWait()).thenReturn(_mockAmqpMessage);
-
- ImmediateWaitUntil.mockWaitUntil(_mockConnection);
-
- ReceiverImpl receiver = new ReceiverImpl(_mockConnection, _mockSession, _mockAmqpReceiver, null);
-
- assertNull("Should not receive a message when connection is not started", receiver.receive(1));
- }
-
- @Test
- public void testMessageReceivedWhenConnectionIsStarted() throws Exception
- {
- Mockito.when(_mockConnection.isStarted()).thenReturn(true);
- Mockito.when(_mockAmqpReceiver.receiveNoWait()).thenReturn(_mockAmqpMessage);
- Mockito.when(_mockSession.getConnectionImpl()).thenReturn(_mockConnection);
- Mockito.when(_mockConnection.getAmqpConnection()).thenReturn(_mockAmqpConnection);
- Mockito.when(_mockSession.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);
-
- ImmediateWaitUntil.mockWaitUntil(_mockConnection);
-
- ReceiverImpl receiver = new ReceiverImpl(_mockConnection, _mockSession, _mockAmqpReceiver, null);
-
- Message message = receiver.receive(1);
- assertNotNull("Should receive a message when connection is started", message);
- assertTrue("Unexpected message implementation", message instanceof MessageImpl<?>);
- assertEquals("Underlying AmqpMessage should be the one provided", _mockAmqpMessage, ((MessageImpl<?>)message).getUnderlyingAmqpMessage(false));
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6f106f64/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java b/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java
deleted file mode 100644
index 5495d16..0000000
--- a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SenderImplTest.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
-import java.io.IOException;
-
-import javax.jms.DeliveryMode;
-import javax.jms.Message;
-import javax.jms.Queue;
-
-import org.apache.qpid.jms.QpidJmsTestCase;
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpMessage;
-import org.apache.qpid.jms.engine.AmqpResourceRequest;
-import org.apache.qpid.jms.engine.AmqpSender;
-import org.apache.qpid.jms.engine.AmqpSentMessageToken;
-import org.apache.qpid.jms.engine.TestAmqpMessage;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class SenderImplTest extends QpidJmsTestCase
-{
- private static final String JMS_AMQP_TTL = "JMS_AMQP_TTL";
- private ConnectionImpl _mockConnection;
- private AmqpConnection _mockAmqpConnection;
- private AmqpSender _mockAmqpSender;
- private SessionImpl _mockSession;
- private Queue _mockQueue;
- private String _mockQueueName = "mockQueueName";
-
- @Before
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- _mockConnection = Mockito.mock(ConnectionImpl.class);
- _mockAmqpConnection = Mockito.mock(AmqpConnection.class);
- Mockito.when(_mockConnection.getAmqpConnection()).thenReturn(_mockAmqpConnection);
- _mockAmqpSender = Mockito.mock(AmqpSender.class);
- _mockSession = Mockito.mock(SessionImpl.class);
- Mockito.when(_mockSession.getDestinationHelper()).thenReturn(new DestinationHelper());
- Mockito.when(_mockSession.getMessageIdHelper()).thenReturn(new MessageIdHelper());
-
- _mockQueueName = "mockQueueName";
- _mockQueue = Mockito.mock(Queue.class);
- Mockito.when(_mockQueue.getQueueName()).thenReturn(_mockQueueName);
- }
-
- @Test
- public void testSenderOverriddesMessageDeliveryMode() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- //explicitly flip the DeliveryMode to NON_PERSISTENT, later verifying it gets changed back to PERSISTENT
- testMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
- assertEquals(DeliveryMode.NON_PERSISTENT, testMessage.getJMSDeliveryMode());
-
- senderImpl.send(testMessage);
-
- assertEquals(DeliveryMode.PERSISTENT, testMessage.getJMSDeliveryMode());
- }
-
- @Test
- public void testSenderSetsJMSDestinationOnMessage() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertNull(testMessage.getJMSDestination());
-
- senderImpl.send(testMessage);
-
- assertSame(_mockQueue, testMessage.getJMSDestination());
- }
-
- @Test
- public void testSenderSetsJMSTimestampOnMessage() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertEquals(0, testMessage.getJMSTimestamp());
- long timestamp = System.currentTimeMillis();
-
- senderImpl.send(testMessage);
-
- //verify the timestamp was set, allowing for a 3second delta
- assertEquals(timestamp, testMessage.getJMSTimestamp(), 3000);
- }
-
- @Test
- public void testSenderSetsJMSMessageIDOnMessage() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertNull("JMSMessageID should not be set yet", testMessage.getJMSMessageID());
-
- senderImpl.send(testMessage);
-
- String msgId = testMessage.getJMSMessageID();
- assertNotNull("JMSMessageID should be set", msgId);
- assertTrue("MessageId does not have the expected prefix", msgId.startsWith(MessageIdHelper.JMS_ID_PREFIX));
- }
-
- @Test
- public void testSenderSetsJMSPriorityOnMessage() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertEquals(Message.DEFAULT_PRIORITY, testMessage.getJMSPriority());
-
- int priority = 9;
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, priority, Message.DEFAULT_TIME_TO_LIVE);
-
- //verify the priority used to send the message was set
- assertEquals("sender failed to set JMSPriority", priority, testMessage.getJMSPriority());
- }
-
- @Test
- public void testSenderSetsAbsoluteExpiryAndTtlFieldsOnUnderlyingMessage() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertEquals(0, testMessage.getJMSTimestamp());
- long timestamp = System.currentTimeMillis();
- long ttl = 100_000;
-
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, ttl);
-
- //verify the JMSExpiration is now set, allowing for a 3second delta
- assertEquals(timestamp + ttl, testMessage.getJMSExpiration(), 3000);
-
- //more specifically, check the creation-time, ttl, and absolute-expiry fields on the message are set
- Long creationTime = testMessage.getUnderlyingAmqpMessage(false).getCreationTime();
- assertNotNull(creationTime);
- assertEquals(timestamp, creationTime, 3000);
-
- Long underlyingTtl = testMessage.getUnderlyingAmqpMessage(false).getTtl();
- assertNotNull(underlyingTtl);
- assertEquals(ttl, underlyingTtl.longValue());
-
- Long absoluteExpiryTime = testMessage.getUnderlyingAmqpMessage(false).getAbsoluteExpiryTime();
- assertNotNull(absoluteExpiryTime);
- assertEquals(ttl + creationTime, absoluteExpiryTime.longValue());
- }
-
- @Test
- public void testSenderSetsTtlOnUnderlyingAmqpMessage() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertEquals(0, testMessage.getJMSTimestamp());
- long timestamp = System.currentTimeMillis();
- long ttl = 100_000;
-
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, ttl);
-
- //verify the expiration was set, allowing for a 3second delta
- assertEquals(timestamp + ttl, testMessage.getJMSExpiration(), 3000);
- }
-
- @Test
- public void testSenderClearsExistingJMSExpirationAndTtlFieldOnUnderlyingAmqpMessageWhenNotUsingTtl() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- AmqpMessage testAmqpMessage = TestAmqpMessage.createNewMessage();
-
- Long oldTtl = 456L;
- testAmqpMessage.setTtl(oldTtl);
-
- long expiration = System.currentTimeMillis();
- testAmqpMessage.setAbsoluteExpiryTime(expiration);
- MessageImpl<?> testMessage = TestMessageImpl.createReceivedMessage(testAmqpMessage, _mockSession, _mockConnection, null);
-
- //verify JMSExpiration is non-zero
- assertEquals(expiration, testMessage.getJMSExpiration());
-
- //send the message without any TTL
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
-
- //verify the expiration was cleared, along with the underlying amqp message fields
- assertEquals(0, testMessage.getJMSExpiration());
- assertNull(testMessage.getUnderlyingAmqpMessage(false).getTtl());
- assertNull(testMessage.getUnderlyingAmqpMessage(false).getAbsoluteExpiryTime());
- }
-
- @Test
- public void testSenderUsesJMS_AMQP_TTLPropertyToSetUnderlyingTtlFieldWhenNoProducerTTLInEffect() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- Long ttlPropValue = 789L;
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, _mockConnection);
- testMessage.setLongProperty(JMS_AMQP_TTL, ttlPropValue);
-
- //send the message without any TTL
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
-
- //verify the expiration was clear
- assertEquals(0, testMessage.getJMSExpiration());
- assertNull(testMessage.getUnderlyingAmqpMessage(false).getAbsoluteExpiryTime());
-
- //Verify that the underlying amqp message ttl field was set to the value from the property
- assertEquals(ttlPropValue, testMessage.getUnderlyingAmqpMessage(false).getTtl());
- }
-
- @Test
- public void testSenderUsesJMS_AMQP_TTLPropertyToSetUnderlyingTtlFieldWhenProducerTTLInEffect() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- long timestamp = System.currentTimeMillis();
- Long ttlPropValue = 789L;
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, _mockConnection);
- testMessage.setLongProperty(JMS_AMQP_TTL, ttlPropValue);
-
- //send the message with a different TTL
- long timeToLive = 999999L;
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, timeToLive);
-
- //verify the expiration was set, allowing a delta
- Long jmsExpiration = testMessage.getJMSExpiration();
- assertEquals(timestamp + timeToLive, jmsExpiration, 3000);
- assertEquals(jmsExpiration, testMessage.getUnderlyingAmqpMessage(false).getAbsoluteExpiryTime());
-
- //Verify that the underlying amqp message ttl field was set to the value from the property, not the producer
- assertEquals(ttlPropValue, testMessage.getUnderlyingAmqpMessage(false).getTtl());
- }
-
- @Test
- public void testSenderUsesJMS_AMQP_TTLPropertyValueZeroToClearUnderlyingTtlField() throws Exception
- {
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- long timestamp = System.currentTimeMillis();
- Long ttlPropValue = 0L;
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, _mockConnection);
- testMessage.setLongProperty(JMS_AMQP_TTL, ttlPropValue);
-
- //send the message with a different TTL
- long timeToLive = 999999L;
- senderImpl.send(testMessage, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, timeToLive);
-
- //verify the expiration was set, allowing a delta
- Long jmsExpiration = testMessage.getJMSExpiration();
- assertEquals(timestamp + timeToLive, jmsExpiration, 3000);
- assertEquals(jmsExpiration, testMessage.getUnderlyingAmqpMessage(false).getAbsoluteExpiryTime());
-
- //Verify that the underlying amqp message ttl field was NOT set, as requested by the property value being 0
- assertNull(testMessage.getUnderlyingAmqpMessage(false).getTtl());
- }
-
- /**
- * Test that the producer sets the JMSXUserID property with the
- * user name for the connection the message is being sent on.
- */
- @Test
- public void testSenderSetsJMSUserIDOnMessage() throws Exception
- {
- senderSetsJMSXUserIDOnMessageTestImpl(true);
- }
-
- /**
- * Test that the producer does not set the JMSXUserID property on the message
- * when the {@link ClientProperties#QPID_SET_JMSXUSERID_ON_SEND} system property
- * is set false.
- */
- @Test
- public void testDisableSenderSettingJMSXUserIDOnMessageUsingSystemProperty() throws Exception
- {
- senderSetsJMSXUserIDOnMessageTestImpl(false);
- }
-
- private void senderSetsJMSXUserIDOnMessageTestImpl(boolean enabled) throws Exception
- {
- if(!enabled)
- {
- setTestSystemProperty(ClientProperties.QPID_SET_JMSXUSERID_ON_SEND, "false");
- }
-
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- String myUserId = "testUser";
- Mockito.when(_mockConnection.getUserName()).thenReturn(myUserId);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- assertNull("expected JMSUserID to be null", testMessage.getStringProperty(ClientProperties.JMSXUSERID));
-
- senderImpl.send(testMessage);
-
- if(enabled)
- {
- //verify the sender stamped the message with the user
- assertTrue("JMSXUserID property should exist", testMessage.propertyExists(ClientProperties.JMSXUSERID));
- assertEquals("sender failed to set JMSXUserID", myUserId, testMessage.getStringProperty(ClientProperties.JMSXUSERID));
- }
- else
- {
- //verify the sender didnt stamp the message with the user
- assertNull("expected JMSXUserID to still be null", testMessage.getStringProperty(ClientProperties.JMSXUSERID));
- assertFalse("JMSXUserID property should not exist", testMessage.propertyExists(ClientProperties.JMSXUSERID));
- }
- }
-
- /**
- * Test that the producer clears any existing JMSXUserID value on a message
- * when the {@link ClientProperties#QPID_SET_JMSXUSERID_ON_SEND} system property
- * is set false.
- */
- @Test
- public void testSenderClearsExistingJMSXUserIDValueOnSendWhenSetOnSendIsDisabled() throws Exception
- {
- //disable setting the user-id on send
- setTestSystemProperty(ClientProperties.QPID_SET_JMSXUSERID_ON_SEND, "false");
-
- basePreparationForMockSending();
-
- SenderImpl senderImpl = new SenderImpl(_mockSession, _mockConnection, _mockAmqpSender, _mockQueue);
-
- String myUserId = "testUser";
- Mockito.when(_mockConnection.getUserName()).thenReturn(myUserId);
-
- MessageImpl<?> testMessage = TestMessageImpl.createNewMessage(_mockSession, null);
-
- testMessage.setStringProperty(ClientProperties.JMSXUSERID, "value");
- assertNotNull("expected JMSUserID to be null", testMessage.getStringProperty(ClientProperties.JMSXUSERID));
-
- senderImpl.send(testMessage);
-
- //verify the sender cleared the existing value
- String value = testMessage.getStringProperty(ClientProperties.JMSXUSERID);
- assertNull("expected JMSXUserID be null, but was: " + value, value);
- assertFalse("JMSXUserID property should not exist", testMessage.propertyExists(ClientProperties.JMSXUSERID));
- }
-
- private void basePreparationForMockSending() throws JmsTimeoutException, JmsInterruptedException, IOException
- {
- //Create mock request, ensuring that it immediately returns as completed
- AmqpResourceRequest<?> mockRequest = Mockito.mock(AmqpResourceRequest.class);
- AmqpSentMessageToken _mockToken = Mockito.mock(AmqpSentMessageToken.class);
- Mockito.when(_mockAmqpSender.sendMessage(Mockito.any(AmqpMessage.class), Mockito.any(AmqpResourceRequest.class))).thenReturn(_mockToken);
- Mockito.when(mockRequest.getResult()).thenReturn(null);
- ImmediateWaitUntil.mockWaitUntil(_mockConnection);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6f106f64/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java b/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java
deleted file mode 100644
index c887d4a..0000000
--- a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/SimplePredicateTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.qpid.jms.impl;
-
-import static org.hamcrest.Matchers.containsString;
-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 extends QpidJmsTestCase
-{
- private static final String DESCRIPTION = "description1";
- private static final String PREDICATED_OBJECT = "predicatedObject1";
-
- @Test
- public void testGetCurrentStateWithDefaultPredicate()
- {
- SimplePredicate predicate = new SimplePredicate()
- {
- @Override
- public boolean test()
- {
- return true;
- }
- };
- String currentState = predicate.getCurrentState();
- assertThat(currentState, containsString(predicate.getClass().getName()));
- }
-
- @Test
- public void testGetCurrentStateWithAPredicatedObject()
- {
- SimplePredicate predicate = new SimplePredicate(DESCRIPTION, PREDICATED_OBJECT)
- {
- @Override
- public boolean test()
- {
- return true;
- }
- };
-
- String currentState = predicate.getCurrentState();
- assertThat(currentState, containsString(DESCRIPTION));
- assertThat(currentState, containsString(PREDICATED_OBJECT));
- }
-
- @Test
- public void testToStringWithDefaultPredicate()
- {
- SimplePredicate predicate = new SimplePredicate()
- {
- @Override
- public boolean test()
- {
- return true;
- }
- };
-
- assertThat(predicate.toString(), containsString(predicate.getClass().getName()));
- }
-
- @Test
- public void testToStringWithAPredicatedObject()
- {
- SimplePredicate predicate = new SimplePredicate(DESCRIPTION, PREDICATED_OBJECT)
- {
- @Override
- public boolean test()
- {
- return true;
- }
- };
-
- assertThat(predicate.toString(), containsString(DESCRIPTION));
- assertThat(
- "toString should not return the predicated object because " +
- "this is too verbose for the usual toString use cases",
- predicate.toString(),
- not(containsString(PREDICATED_OBJECT)));
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6f106f64/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/StreamMessageImplTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/StreamMessageImplTest.java b/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/StreamMessageImplTest.java
deleted file mode 100644
index f0bff79..0000000
--- a/qpid-jms-client-tmp/src/test/java/org/apache/qpid/jms/impl/StreamMessageImplTest.java
+++ /dev/null
@@ -1,1167 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.math.BigInteger;
-import java.util.Arrays;
-
-import javax.jms.JMSException;
-import javax.jms.MessageEOFException;
-import javax.jms.MessageFormatException;
-import javax.jms.MessageNotReadableException;
-
-import org.apache.qpid.jms.QpidJmsTestCase;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class StreamMessageImplTest extends QpidJmsTestCase
-{
- private ConnectionImpl _mockConnectionImpl;
- private SessionImpl _mockSessionImpl;
-
- @Before
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- _mockConnectionImpl = Mockito.mock(ConnectionImpl.class);
- _mockSessionImpl = Mockito.mock(SessionImpl.class);
- Mockito.when(_mockSessionImpl.getDestinationHelper()).thenReturn(new DestinationHelper());
- }
-
- // ======= general =========
-
- @Test
- public void testReadWithEmptyStreamThrowsMEOFE() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
- //make it readable
- streamMessageImpl.reset();
-
- try
- {
- streamMessageImpl.readBoolean();
- fail("Expected exception to be thrown as message has no content");
- }
- catch(MessageEOFException meofe)
- {
- //expected
- }
- }
-
- @Test
- public void testClearBodyOnNewMessageRemovesExistingValues() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
- streamMessageImpl.writeBoolean(true);
-
- streamMessageImpl.clearBody();
-
- streamMessageImpl.writeBoolean(false);
- streamMessageImpl.reset();
-
- //check we get only the value added after the clear
- assertFalse("expected value added after the clear", streamMessageImpl.readBoolean());
-
- try
- {
- streamMessageImpl.readBoolean();
- fail("Expected exception to be thrown");
- }
- catch(MessageEOFException meofe)
- {
- //expected
- }
- }
-
- @Test
- public void testNewMessageIsWriteOnlyThrowsMNRE() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- try
- {
- streamMessageImpl.readBoolean();
- fail("Expected exception to be thrown as message is not readable");
- }
- catch(MessageNotReadableException mnre)
- {
- //expected
- }
- }
-
- /**
- * Verify the stream position is not incremented during illegal type conversion failure.
- * This covers every read method except readObject (which doesn't do type conversion)
- * and readBytes(), which is tested by {@link #testIllegalTypeConvesionFailureDoesNotIncrementPosition2}
- *
- * Write bytes, then deliberately try to retrieve them as illegal types, then
- * check they can be successfully read.
- */
- @Test
- public void testIllegalTypeConvesionFailureDoesNotIncrementPosition1() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)0, (byte)255, (byte)78};
-
- streamMessageImpl.writeBytes(bytes);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Long.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, String.class);
-
- byte[] retrievedByteArray = new byte[bytes.length];
- int readBytesLength = streamMessageImpl.readBytes(retrievedByteArray);
-
- assertEquals("Number of bytes read did not match original array length", bytes.length, readBytesLength);
- assertArrayEquals("Expected array to equal retrieved bytes", bytes, retrievedByteArray);
- assertEquals("Expected completion return value", -1, streamMessageImpl.readBytes(retrievedByteArray));
- }
-
- /**
- * Verify the stream position is not incremented during illegal type conversion failure.
- * This test covers only readBytes, other methods are tested by
- * {@link #testIllegalTypeConvesionFailureDoesNotIncrementPosition1}
- *
- * Write String, then deliberately try illegal retrieval as bytes, then
- * check it can be successfully read.
- */
- @Test
- public void testIllegalTypeConvesionFailureDoesNotIncrementPosition2() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- String stringVal = "myString";
- streamMessageImpl.writeString(stringVal);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
-
- assertEquals("Expected written string", stringVal, streamMessageImpl.readString());
- }
-
- /**
- * When a null stream entry is encountered, the accessor methods is type dependent and should
- * either return null, throw NPE, or behave in the same fashion as <primitive>.valueOf(String).
- *
- * Test that this is the case, and in doing show demonstrate that primitive type conversion failure
- * does not increment the stream position, as shown by not hitting the end of the stream unexpectedly.
- */
- @Test
- public void testNullStreamEntryResultsInExpectedBehaviour() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- streamMessageImpl.writeObject(null);
- streamMessageImpl.reset();
-
- //expect an NFE from the primitive integral <type>.valueOf(null) conversions
- assertGetStreamEntryThrowsNumberFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsNumberFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsNumberFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsNumberFormatException(streamMessageImpl, Long.class);
-
- //expect an NPE from the primitive float, double, and char <type>.valuleOf(null) conversions
- assertGetStreamEntryThrowsNullPointerException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsNullPointerException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsNullPointerException(streamMessageImpl, Character.class);
-
- //expect null
- assertNull(streamMessageImpl.readObject());
- streamMessageImpl.reset(); //need to reset as read was a success
- assertNull(streamMessageImpl.readString());
- streamMessageImpl.reset(); //need to reset as read was a success
-
- //expect completion value.
- assertEquals(-1, streamMessageImpl.readBytes(new byte[1]));
- streamMessageImpl.reset(); //need to reset as read was a success
-
- //expect false from Boolean.valueOf(null).
- assertFalse(streamMessageImpl.readBoolean());
- streamMessageImpl.reset(); //need to reset as read was a success
- }
-
- // ======= object =========
-
- @Test
- public void testWriteObjectWithIllegalTypeThrowsMFE() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
- try
- {
- streamMessageImpl.writeObject(BigInteger.ONE);
- fail("Expected exception to be thrown");
- }
- catch(MessageFormatException mfe)
- {
- //expected
- }
- }
-
- @Test
- public void testWriteReadObject() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- Object nullEntryValue = null;
- Boolean boolEntryValue = Boolean.valueOf(false);
- Byte byteEntryValue = Byte.valueOf((byte)1);
- Short shortEntryValue = Short.valueOf((short)2);
- Integer intEntryValue = Integer.valueOf(3);
- Long longEntryValue = Long.valueOf(4);
- Float floatEntryValue = Float.valueOf(5.01F);
- Double doubleEntryValue = Double.valueOf(6.01);
- String stringEntryValue = "string";
- Character charEntryValue = Character.valueOf('c');
- byte[] bytes = new byte[] { (byte)1, (byte) 170, (byte)65};
-
- streamMessageImpl.writeObject(nullEntryValue);
- streamMessageImpl.writeObject(boolEntryValue);
- streamMessageImpl.writeObject(byteEntryValue);
- streamMessageImpl.writeObject(shortEntryValue);
- streamMessageImpl.writeObject(intEntryValue);
- streamMessageImpl.writeObject(longEntryValue);
- streamMessageImpl.writeObject(floatEntryValue);
- streamMessageImpl.writeObject(doubleEntryValue);
- streamMessageImpl.writeObject(stringEntryValue);
- streamMessageImpl.writeObject(charEntryValue);
- streamMessageImpl.writeObject(bytes);
-
- streamMessageImpl.reset();
-
- assertEquals("Got unexpected value from stream", nullEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", boolEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", byteEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", shortEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", intEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", longEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", floatEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", doubleEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", stringEntryValue, streamMessageImpl.readObject());
- assertEquals("Got unexpected value from stream", charEntryValue, streamMessageImpl.readObject());
- assertArrayEquals("Got unexpected value from stream", bytes, (byte[])streamMessageImpl.readObject());
- }
-
- // ======= bytes =========
-
- /**
- * Write bytes, then retrieve them as all of the legal type combinations
- */
- @Test
- public void testWriteBytesReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] value = new byte[]{(byte)0, (byte)255, (byte)78};
-
- streamMessageImpl.writeBytes(value);
- streamMessageImpl.reset();
-
- byte[] dest = new byte[value.length];
-
- int readBytesLength = streamMessageImpl.readBytes(dest);
- assertEquals("Number of bytes read did not match expectation", value.length, readBytesLength);
- assertArrayEquals("value not as expected", value, dest);
- }
-
- /**
- * Write bytes, then retrieve them as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteBytesReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] value = new byte[]{(byte)0, (byte)255, (byte)78};
-
- streamMessageImpl.writeBytes(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Long.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, String.class);
- }
-
- @Test
- public void testReadBytesWithNullSignalsCompletion() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
- streamMessageImpl.writeObject(null);
-
- streamMessageImpl.reset();
-
- assertEquals("Expected immediate completion signal", -1, streamMessageImpl.readBytes(new byte[1]));
- }
-
- @Test
- public void testReadBytesWithZeroLengthSource() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- streamMessageImpl.writeBytes(new byte[0]);
-
- streamMessageImpl.reset();
-
- byte[] fullRetrievedBytes = new byte[1];
-
- assertEquals("Expected no bytes to be read, as none were written", 0, streamMessageImpl.readBytes(fullRetrievedBytes));
- }
-
- @Test
- public void testReadBytesWithZeroLengthDestination() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)11, (byte)44, (byte)99};
- streamMessageImpl.writeBytes(bytes);
-
- streamMessageImpl.reset();
-
- byte[] zeroDestination = new byte[0];
- byte[] fullRetrievedBytes = new byte[bytes.length];
-
- assertEquals("Expected no bytes to be read", 0, streamMessageImpl.readBytes(zeroDestination));
- assertEquals("Expected all bytes to be read", bytes.length, streamMessageImpl.readBytes(fullRetrievedBytes));
- assertArrayEquals("Expected arrays to be equal", bytes, fullRetrievedBytes);
- assertEquals("Expected completion signal", -1, streamMessageImpl.readBytes(zeroDestination));
- }
-
- @Test
- public void testReadObjectForBytesReturnsNewArray() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)11, (byte)44, (byte)99};
- streamMessageImpl.writeBytes(bytes);
-
- streamMessageImpl.reset();
-
- byte[] retrievedBytes = (byte[]) streamMessageImpl.readObject();
-
- assertNotSame("Expected different array objects", bytes, retrievedBytes);
- assertArrayEquals("Expected arrays to be equal", bytes, retrievedBytes);
- }
-
- @Test
- public void testReadBytesFullWithUndersizedDestinationArrayUsingMultipleReads() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)3, (byte)78, (byte)253, (byte) 26, (byte) 8};
- assertEquals("bytes should be odd length", 1, bytes.length % 2);
- int undersizedLength = 2;
- int remaining = 1;
-
- streamMessageImpl.writeBytes(bytes);
- streamMessageImpl.reset();
-
- byte[] undersizedDestination = new byte[undersizedLength];
- byte[] fullRetrievedBytes = new byte[bytes.length];
-
- assertEquals("Number of bytes read did not match destination array length", undersizedLength, streamMessageImpl.readBytes(undersizedDestination));
- int read = undersizedLength;
- System.arraycopy(undersizedDestination, 0, fullRetrievedBytes, 0, undersizedLength);
- assertEquals("Number of bytes read did not match destination array length", undersizedLength, streamMessageImpl.readBytes(undersizedDestination));
- System.arraycopy(undersizedDestination, 0, fullRetrievedBytes, read, undersizedLength);
- read += undersizedLength;
- assertEquals("Number of bytes read did not match expectation", remaining, streamMessageImpl.readBytes(undersizedDestination));
- System.arraycopy(undersizedDestination, 0, fullRetrievedBytes, read, remaining);
- read += remaining;
- assertArrayEquals("Expected array to equal retrieved bytes", bytes, fullRetrievedBytes);
- }
-
- @Test
- public void testReadBytesFullWithPreciselySizedDestinationArray() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)11, (byte)44, (byte)99};
- streamMessageImpl.writeBytes(bytes);
-
- streamMessageImpl.reset();
-
- byte[] retrievedByteArray = new byte[bytes.length];
- int readBytesLength = streamMessageImpl.readBytes(retrievedByteArray);
-
- assertEquals("Number of bytes read did not match original array length", bytes.length, readBytesLength);
- assertArrayEquals("Expected array to equal retrieved bytes", bytes, retrievedByteArray);
- assertEquals("Expected completion return value", -1, streamMessageImpl.readBytes(retrievedByteArray));
- }
-
- @Test
- public void testReadBytesFullWithOversizedDestinationArray() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)4, (byte)115, (byte)255};
- streamMessageImpl.writeBytes(bytes);
-
- streamMessageImpl.reset();
-
- byte[] oversizedDestination = new byte[bytes.length + 1];
- int readBytesLength = streamMessageImpl.readBytes(oversizedDestination);
-
- assertEquals("Number of bytes read did not match original array length", bytes.length, readBytesLength);
- assertArrayEquals("Expected array subset to equal retrieved bytes", bytes, Arrays.copyOfRange(oversizedDestination, 0, readBytesLength));
- }
-
- /**
- * {@link StreamMessage#readBytes(byte[])} indicates:
- *
- * "Once the first readBytes call on a byte[] field value has been made, the full value of the field must be read
- * before it is valid to read the next field. An attempt to read the next field before that has been done will
- * throw a MessageFormatException."
- *
- * {@link StreamMessage#readObject()} indicates:
- * "An attempt to call readObject to read a byte field value into a new byte[] object before the full value
- * of the byte field has been read will throw a MessageFormatException."
- *
- * Test that these restrictions are met, and don't interfere with completing the readBytes usage.
- */
- @Test
- public void testReadObjectAfterPartialReadBytesThrowsMFE() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] bytes = new byte[]{(byte)11, (byte)44, (byte)99};
- streamMessageImpl.writeBytes(bytes);
-
- streamMessageImpl.reset();
-
- //start reading via readBytes
- int partialLength = 2;
- byte[] retrievedByteArray = new byte[partialLength];
- int readBytesLength = streamMessageImpl.readBytes(retrievedByteArray);
-
- assertEquals(partialLength, readBytesLength);
- assertArrayEquals("Expected array subset to equal retrieved bytes", Arrays.copyOf(bytes, partialLength), retrievedByteArray);
-
- //check that using readObject does not return the full/remaining bytes as a new array
- try
- {
- streamMessageImpl.readObject();
- fail("expected exception to be thrown");
- }
- catch(MessageFormatException mfe)
- {
- //expected
- }
-
- //finish reading via reaBytes to ensure it can be completed
- readBytesLength = streamMessageImpl.readBytes(retrievedByteArray);
- assertEquals(bytes.length - partialLength, readBytesLength);
- assertArrayEquals("Expected array subset to equal retrieved bytes",
- Arrays.copyOfRange(bytes, partialLength, bytes.length), Arrays.copyOfRange(retrievedByteArray, 0, readBytesLength));
- }
-
- /**
- * Verify that setting bytes takes a copy of the array.
- * Set bytes subset, then retrieve the entry and verify the are different arrays and the subsets are equal.
- */
- @Test
- public void testWriteBytesWithOffsetAndLength() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte[] orig = "myBytesAll".getBytes();
-
- //extract the segment containing 'Bytes'
- int offset = 2;
- int length = 5;
- byte[] segment = Arrays.copyOfRange(orig, offset, offset + length);
-
- //set the same section from the original bytes
- streamMessageImpl.writeBytes(orig, offset, length);
- streamMessageImpl.reset();
-
- byte[] retrieved = (byte[]) streamMessageImpl.readObject();
-
- //verify the retrieved bytes from the stream equal the segment but are not the same
- assertNotSame(orig, retrieved);
- assertNotSame(segment, retrieved);
- assertArrayEquals(segment, retrieved);
- }
-
- //========= boolean ========
-
- @Test
- public void testWriteReadBoolean() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- boolean value = true;
-
- streamMessageImpl.writeBoolean(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readBoolean());
- }
-
- /**
- * Set a boolean, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteBooleanReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- boolean value = true;
-
- streamMessageImpl.writeBoolean(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, value, Boolean.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a boolean, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testSetBooleanGetIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- boolean value = true;
-
- streamMessageImpl.writeBoolean(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Long.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= string ========
-
- @Test
- public void testWriteReadString() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- String value = "myString";
-
- streamMessageImpl.writeString(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readString());
- }
-
- /**
- * Set a string, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteStringReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- String integralValue = String.valueOf(Byte.MAX_VALUE);
- streamMessageImpl.writeString(integralValue);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(integralValue), String.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Boolean.valueOf(integralValue), Boolean.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Byte.valueOf(integralValue), Byte.class);
-
- streamMessageImpl.clearBody();
- integralValue = String.valueOf(Short.MAX_VALUE);
- streamMessageImpl.writeString(integralValue);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Short.valueOf(integralValue), Short.class);
-
- streamMessageImpl.clearBody();
- integralValue = String.valueOf(Integer.MAX_VALUE);
- streamMessageImpl.writeString(integralValue);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Integer.valueOf(integralValue), Integer.class);
-
- streamMessageImpl.clearBody();
- integralValue = String.valueOf(Long.MAX_VALUE);
- streamMessageImpl.writeString(integralValue);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Long.valueOf(integralValue), Long.class);
-
- streamMessageImpl.clearBody();
- String fpValue = String.valueOf(Float.MAX_VALUE);
- streamMessageImpl.writeString(fpValue);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Float.valueOf(fpValue), Float.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Double.valueOf(fpValue), Double.class);
- }
-
- /**
- * Set a string, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteStringReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- String stringValue = "myString";
-
- streamMessageImpl.writeString(stringValue);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= byte ========
-
- @Test
- public void testWriteReadByte() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte value = (byte)6;
-
- streamMessageImpl.writeByte(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readByte());
- }
-
- /**
- * Set a byte, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteByteReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte value = (byte)6;
-
- streamMessageImpl.writeByte(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Byte.valueOf(value), Byte.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Short.valueOf(value), Short.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Integer.valueOf(value), Integer.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Long.valueOf(value), Long.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a byte, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteByteReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- byte value = (byte)6;
-
- streamMessageImpl.writeByte(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= short ========
-
- @Test
- public void testWriteReadShort() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- short value = (short)302;
-
- streamMessageImpl.writeShort(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readShort());
- }
-
- /**
- * Set a short, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteShortReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- short value = (short)302;
-
- streamMessageImpl.writeShort(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Short.valueOf(value), Short.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Integer.valueOf(value), Integer.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Long.valueOf(value), Long.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a short, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteShortReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- short value = (short)302;
-
- streamMessageImpl.writeShort(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= char ========
-
- @Test
- public void testWriteReadChar() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- char value = 'c';
-
- streamMessageImpl.writeChar(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readChar());
- }
-
- /**
- * Set a char, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteCharReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- char value = 'c';
-
- streamMessageImpl.writeChar(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, value, Character.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a char, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteCharReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- char value = 'c';
-
- streamMessageImpl.writeChar(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Long.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= int ========
-
- @Test
- public void testWriteReadInt() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- int value = Integer.MAX_VALUE;
-
- streamMessageImpl.writeInt(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readInt());
- }
-
- /**
- * Set an int, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteIntReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- int value = Integer.MAX_VALUE;
-
- streamMessageImpl.writeInt(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Integer.valueOf(value), Integer.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Long.valueOf(value), Long.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set an int, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteIntReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- int value = Integer.MAX_VALUE;
-
- streamMessageImpl.writeInt(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= long ========
-
- @Test
- public void testWriteReadLong() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- long value = Long.MAX_VALUE;
-
- streamMessageImpl.writeLong(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readLong());
- }
-
- /**
- * Set a long, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteLongReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- long value = Long.MAX_VALUE;
-
- streamMessageImpl.writeLong(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Long.valueOf(value), Long.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a long, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteLongReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- long value = Long.MAX_VALUE;
-
- streamMessageImpl.writeLong(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Double.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= float ========
-
- @Test
- public void testWriteReadFloat() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- float value = Float.MAX_VALUE;
-
- streamMessageImpl.writeFloat(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readFloat(), 0.0);
- }
-
- /**
- * Set a float, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteFloatReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- float value = Float.MAX_VALUE;
-
- streamMessageImpl.writeFloat(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Float.valueOf(value), Float.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, Double.valueOf(value), Double.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a float, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteFloatReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- float value = Float.MAX_VALUE;
-
- streamMessageImpl.writeFloat(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Long.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= double ========
-
- @Test
- public void testWriteReadDouble() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- double value = Double.MAX_VALUE;
-
- streamMessageImpl.writeDouble(value);
- streamMessageImpl.reset();
-
- assertEquals("Value not as expected", value, streamMessageImpl.readDouble(), 0.0);
- }
-
- /**
- * Set a double, then retrieve it as all of the legal type combinations to verify it is parsed correctly
- */
- @Test
- public void testWriteDoubleReadLegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- double value = Double.MAX_VALUE;
-
- streamMessageImpl.writeDouble(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryEquals(streamMessageImpl, true, Double.valueOf(value), Double.class);
- assertGetStreamEntryEquals(streamMessageImpl, true, String.valueOf(value), String.class);
- }
-
- /**
- * Set a double, then retrieve it as all of the illegal type combinations to verify it fails as expected
- */
- @Test
- public void testWriteDoubleReadIllegal() throws Exception
- {
- StreamMessageImpl streamMessageImpl = new StreamMessageImpl(_mockSessionImpl,_mockConnectionImpl);
-
- double value = Double.MAX_VALUE;
-
- streamMessageImpl.writeDouble(value);
- streamMessageImpl.reset();
-
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Boolean.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Byte.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Short.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Character.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Integer.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Long.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, Float.class);
- assertGetStreamEntryThrowsMessageFormatException(streamMessageImpl, byte[].class);
- }
-
- //========= utility methods ========
-
- private void assertGetStreamEntryEquals(StreamMessageImpl testMessage,
- boolean resetStreamAfter,
- Object expectedValue,
- Class<?> clazz) throws JMSException
- {
- if(clazz == byte[].class)
- {
- throw new IllegalArgumentException("byte[] values not suported");
- }
-
- Object actualValue = getStreamEntryUsingTypeMethod(testMessage, clazz, null);
- assertEquals(expectedValue, actualValue);
-
- if(resetStreamAfter)
- {
- testMessage.reset();
- }
- }
-
- private void assertGetStreamEntryThrowsMessageFormatException(StreamMessageImpl testMessage,
- Class<?> clazz) throws JMSException
- {
- try
- {
- getStreamEntryUsingTypeMethod(testMessage, clazz, new byte[0]);
-
- fail("expected exception to be thrown");
- }
- catch(MessageFormatException jmsMFE)
- {
- //expected
- }
- }
-
- private void assertGetStreamEntryThrowsNullPointerException(StreamMessageImpl testMessage, Class<?> clazz) throws JMSException
- {
- try
- {
- getStreamEntryUsingTypeMethod(testMessage, clazz, new byte[0]);
-
- fail("expected exception to be thrown");
- }
- catch(NullPointerException npe)
- {
- //expected
- }
- }
-
- private void assertGetStreamEntryThrowsNumberFormatException(StreamMessageImpl testMessage,
- Class<?> clazz) throws JMSException
- {
- assertGetStreamEntryThrowsNumberFormatException(testMessage, clazz, null);
- }
-
- private void assertGetStreamEntryThrowsNumberFormatException(StreamMessageImpl testMessage,
- Class<?> clazz,
- byte[] destination) throws JMSException
- {
- if(clazz == byte[].class && destination == null)
- {
- throw new IllegalArgumentException("Destinatinon byte[] must be supplied");
- }
-
- try
- {
- getStreamEntryUsingTypeMethod(testMessage, clazz, destination);
-
- fail("expected exception to be thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
- }
-
- private Object getStreamEntryUsingTypeMethod(StreamMessageImpl testMessage, Class<?> clazz, byte[] destination) throws JMSException
- {
- if(clazz == Boolean.class)
- {
- return testMessage.readBoolean();
- }
- else if(clazz == Byte.class)
- {
- return testMessage.readByte();
- }
- else if(clazz == Character.class)
- {
- return testMessage.readChar();
- }
- else if(clazz == Short.class)
- {
- return testMessage.readShort();
- }
- else if(clazz == Integer.class)
- {
- return testMessage.readInt();
- }
- else if(clazz == Long.class)
- {
- return testMessage.readLong();
- }
- else if(clazz == Float.class)
- {
- return testMessage.readFloat();
- }
- else if(clazz == Double.class)
- {
- return testMessage.readDouble();
- }
- else if(clazz == String.class)
- {
- return testMessage.readString();
- }
- else if(clazz == byte[].class)
- {
- return testMessage.readBytes(destination);
- }
- else
- {
- throw new RuntimeException("Unexpected entry type class");
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org