Author: borges
Date: 2011-10-07 08:25:28 -0400 (Fri, 07 Oct 2011)
New Revision: 11494
Added:
trunk/tests/integration-tests/src/test/java/org/hornetq/core/
trunk/tests/integration-tests/src/test/java/org/hornetq/core/message/
trunk/tests/integration-tests/src/test/java/org/hornetq/core/message/impl/
trunk/tests/integration-tests/src/test/java/org/hornetq/core/message/impl/MessagePropertyTest.java
Modified:
trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java
Log:
Add (rather trivial) unit-tests for all untested/unused calls in Message
Modified: trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java 2011-10-07
12:25:03 UTC (rev 11493)
+++ trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java 2011-10-07
12:25:28 UTC (rev 11494)
@@ -78,12 +78,12 @@
import org.hornetq.utils.UUIDGenerator;
/**
- *
- * Helper base class for our unit tests
- *
+ * Helper base class for our unit tests.
+ * <p>
+ * See {@code org.hornetq.tests.util.ServiceTestBase} for a test case with server
set-up.
+ * @see Service
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
* @author <a href="mailto:csuconic@redhat.com">Clebert</a>
- *
*/
public abstract class UnitTestCase extends TestCase
{
Added:
trunk/tests/integration-tests/src/test/java/org/hornetq/core/message/impl/MessagePropertyTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/core/message/impl/MessagePropertyTest.java
(rev 0)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/core/message/impl/MessagePropertyTest.java 2011-10-07
12:25:28 UTC (rev 11494)
@@ -0,0 +1,110 @@
+package org.hornetq.core.message.impl;
+
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.api.core.client.ClientConsumer;
+import org.hornetq.api.core.client.ClientMessage;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.ServerLocator;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.tests.util.ServiceTestBase;
+
+public class MessagePropertyTest extends ServiceTestBase
+{
+ private HornetQServer server;
+ private ServerLocator locator;
+ private ClientSessionFactory sf;
+ private final int numMessages = 20;
+
+ private static final String ADDRESS = "aAddress123";
+ private static final SimpleString SIMPLE_STRING_KEY = new
SimpleString("StringToSimpleString");
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ server = createServer(true);
+ server.start();
+ locator = createInVMNonHALocator();
+ sf = locator.createSessionFactory();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ sf.close();
+ locator.close();
+ server.stop();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ private void sendMessages() throws Exception
+ {
+ ClientSession session = sf.createSession(true, true);
+ session.createQueue(ADDRESS, ADDRESS, null, true);
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createMessage(true);
+ setBody(i, message);
+ message.putIntProperty("int", i);
+ message.putShortProperty("short", (short)i);
+ message.putByteProperty("byte", (byte)i);
+ message.putFloatProperty("float", floatValue(i));
+ message.putStringProperty(SIMPLE_STRING_KEY, new
SimpleString(Integer.toString(i)));
+ message.putBytesProperty("byte[]", byteArray(i));
+ producer.send(message);
+ }
+ session.commit();
+ }
+
+ private float floatValue(int i)
+ {
+ return (float)(i * 1.3);
+ }
+
+ private byte[] byteArray(int i)
+ {
+ return new byte[] { (byte)i, (byte)(i / 2) };
+ }
+
+ public void testProperties() throws Exception
+ {
+ sendMessages();
+ receiveMessages();
+ }
+
+
+ private void receiveMessages() throws Exception
+ {
+ ClientSession session = sf.createSession(true, true);
+ session.start();
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer.receive(100);
+ assertNotNull("Expecting a message " + i, message);
+ assertMessageBody(i, message);
+ assertEquals(i, message.getIntProperty("int").intValue());
+ assertEquals((short)i,
message.getShortProperty("short").shortValue());
+ assertEquals((byte)i, message.getByteProperty("byte").byteValue());
+ assertEquals(floatValue(i),
message.getFloatProperty("float").floatValue(), 0.001);
+ assertEquals(new SimpleString(Integer.toString(i)),
+ message.getSimpleStringProperty(SIMPLE_STRING_KEY.toString()));
+ assertEqualsByteArrays(byteArray(i),
message.getBytesProperty("byte[]"));
+ message.acknowledge();
+ }
+ assertNull("no more messages", consumer.receive(50));
+ consumer.close();
+ session.commit();
+ }
+
+}