[jboss-cvs] JBoss Messaging SVN: r4512 - in trunk: tests/src/org/jboss/messaging/tests/integration/core/remoting/mina and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 18 05:08:00 EDT 2008


Author: jmesnil
Date: 2008-06-18 05:08:00 -0400 (Wed, 18 Jun 2008)
New Revision: 4512

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossBytesMessageTest.java
Removed:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/CodecAssert.java
Modified:
   trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
   trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/mina/MinaProtocolCodecFilterTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/util/TypedPropertiesTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMapMessageTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossObjectMessageTest.java
   trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java
   trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
added unit tests for JBossBytesMessage
moved assertXXX helper methods from CodecAssert to UnitTestCase

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -353,6 +353,10 @@
       {
          writeBoolean((Boolean) value);
       }
+      else if (value instanceof Character)
+      {
+         writeChar((Character) value);
+      }
       else if (value instanceof Byte)
       {
          writeByte((Byte) value);

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -22,10 +22,17 @@
 
 package org.jboss.messaging.tests.integration.core.remoting.mina;
 
+import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
+import static org.jboss.messaging.tests.util.RandomUtil.randomDouble;
+import static org.jboss.messaging.tests.util.RandomUtil.randomFloat;
+import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
 import junit.framework.TestCase;
-import static org.jboss.messaging.tests.unit.core.remoting.impl.CodecAssert.assertEqualsByteArrays;
+
 import org.jboss.messaging.tests.util.RandomUtil;
-import static org.jboss.messaging.tests.util.RandomUtil.*;
 import org.jboss.messaging.util.MessagingBuffer;
 import org.jboss.messaging.util.SimpleString;
 

Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/CodecAssert.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/CodecAssert.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
-
-package org.jboss.messaging.tests.unit.core.remoting.impl;
-
-import junit.framework.Assert;
-
-import javax.transaction.xa.Xid;
-import java.util.List;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- * 
- */
-public class CodecAssert extends Assert
-{
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   public static void assertSameXids(List<Xid> expected, List<Xid> actual)
-   {
-      assertNotNull(expected);
-      assertNotNull(actual);
-      assertEquals(expected.size(), actual.size());
-
-      for (int i = 0; i < expected.size(); i++)
-      {
-         Xid expectedXid = expected.get(i);
-         Xid actualXid = actual.get(i);
-         assertEqualsByteArrays(expectedXid.getBranchQualifier(), actualXid
-               .getBranchQualifier());
-         assertEquals(expectedXid.getFormatId(), actualXid.getFormatId());
-         assertEqualsByteArrays(expectedXid.getGlobalTransactionId(), actualXid
-               .getGlobalTransactionId());
-      }
-   }
-
-   public static void assertEqualsByteArrays(byte[] expected, byte[] actual)
-   {
-      assertEquals(expected.length, actual.length);
-      for (int i = 0; i < expected.length; i++)
-      {
-         assertEquals("byte at index " + i, expected[i], actual[i]);
-      }
-   }
-
-   public static void assertEqualsByteArrays(int length, byte[] expected, byte[] actual)
-   {
-      // we check only for the given length (the arrays might be
-      // larger)
-      assertTrue(expected.length >= length);
-      assertTrue(actual.length >= length);
-      for (int i = 0; i < length; i++)
-      {
-         assertEquals("byte at index " + i, expected[i], actual[i]);
-      }
-   }
-
-   
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-}

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/mina/MinaProtocolCodecFilterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/mina/MinaProtocolCodecFilterTest.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/mina/MinaProtocolCodecFilterTest.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -22,6 +22,71 @@
 
 package org.jboss.messaging.tests.unit.core.remoting.impl.mina;
 
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CLOSE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CONN_CREATESESSION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CONN_CREATESESSION_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CONN_START;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CONN_STOP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CONS_FLOWTOKEN;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CREATECONNECTION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CREATECONNECTION_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.EXCEPTION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.NULL;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.PING;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.PONG;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.PROD_RECEIVETOKENS;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_ACKNOWLEDGE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_ADD_DESTINATION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_BINDINGQUERY;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_BINDINGQUERY_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_BROWSER_HASNEXTMESSAGE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_BROWSER_HASNEXTMESSAGE_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_BROWSER_NEXTMESSAGE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_BROWSER_RESET;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CANCEL;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_COMMIT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATEBROWSER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATEBROWSER_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATECONSUMER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATECONSUMER_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATEPRODUCER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATEPRODUCER_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_CREATEQUEUE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_DELETE_QUEUE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_QUEUEQUERY;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_QUEUEQUERY_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_RECOVER;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_REMOVE_DESTINATION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_ROLLBACK;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_COMMIT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_END;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_FORGET;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_GET_TIMEOUT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_GET_TIMEOUT_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_INDOUBT_XIDS;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_INDOUBT_XIDS_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_JOIN;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_PREPARE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_RESUME;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_ROLLBACK;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_SET_TIMEOUT;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_SET_TIMEOUT_RESP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_START;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.SESS_XA_SUSPEND;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import static org.jboss.messaging.tests.util.RandomUtil.randomXid;
+import static org.jboss.messaging.util.DataConstants.SIZE_BYTE;
+import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.xa.Xid;
+
 import org.apache.mina.common.IoBuffer;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.jboss.messaging.core.exception.MessagingException;
@@ -29,22 +94,52 @@
 import org.jboss.messaging.core.remoting.Packet;
 import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
 import org.jboss.messaging.core.remoting.impl.mina.MinaProtocolCodecFilter;
-import org.jboss.messaging.core.remoting.impl.wireformat.*;
-import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.*;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowCreditMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
+import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
+import org.jboss.messaging.core.remoting.impl.wireformat.MessagingExceptionMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
+import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
+import org.jboss.messaging.core.remoting.impl.wireformat.Pong;
+import org.jboss.messaging.core.remoting.impl.wireformat.ProducerFlowCreditMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionAcknowledgeMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionAddDestinationMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCancelMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateQueueMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionDeleteQueueMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionRemoveDestinationMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXACommitMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAEndMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetInDoubtXidsResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetTimeoutResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.XidCodecSupport;
 import org.jboss.messaging.core.version.impl.VersionImpl;
-import org.jboss.messaging.tests.unit.core.remoting.impl.CodecAssert;
-import static org.jboss.messaging.tests.unit.core.remoting.impl.CodecAssert.assertSameXids;
-import static org.jboss.messaging.tests.util.RandomUtil.*;
 import org.jboss.messaging.tests.util.UnitTestCase;
-import static org.jboss.messaging.util.DataConstants.SIZE_BYTE;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
 import org.jboss.messaging.util.MessagingBuffer;
 import org.jboss.messaging.util.SimpleString;
 
-import javax.transaction.xa.Xid;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -153,7 +248,7 @@
       byte[] actualBody = new byte[bodyLength];
       buffer.getBytes(actualBody);
       MessagingBuffer expectedBody = encode(actualBody.length, bodyObjects);
-      CodecAssert.assertEqualsByteArrays(bodyLength, expectedBody.array(), actualBody);
+      UnitTestCase.assertEqualsByteArrays(bodyLength, expectedBody.array(), actualBody);
       // check the buffer has been wholly read
       assertEquals(0, buffer.remaining());
    }
@@ -712,7 +807,7 @@
       SessionXAGetInDoubtXidsResponseMessage decodedMessage = (SessionXAGetInDoubtXidsResponseMessage) decodedPacket;
       assertEquals(SESS_XA_INDOUBT_XIDS_RESP, decodedMessage.getType());
 
-      assertSameXids(message.getXids(), decodedMessage.getXids());
+      UnitTestCase.assertSameXids(message.getXids(), decodedMessage.getXids());
    }
 
    public void testSessionXAGetTimeoutMessage() throws Exception

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/TypedPropertiesTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/TypedPropertiesTest.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/TypedPropertiesTest.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -22,17 +22,28 @@
 
 package org.jboss.messaging.tests.unit.core.util;
 
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
+import static org.jboss.messaging.tests.util.RandomUtil.randomChar;
+import static org.jboss.messaging.tests.util.RandomUtil.randomDouble;
+import static org.jboss.messaging.tests.util.RandomUtil.randomFloat;
+import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+import static org.jboss.messaging.tests.util.RandomUtil.randomShort;
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
+
+import java.util.Iterator;
+
 import junit.framework.TestCase;
+
 import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
-import static org.jboss.messaging.tests.unit.core.remoting.impl.CodecAssert.assertEqualsByteArrays;
-import org.jboss.messaging.tests.util.RandomUtil;
-import static org.jboss.messaging.tests.util.RandomUtil.*;
+import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.util.MessagingBuffer;
 import org.jboss.messaging.util.SimpleString;
 import org.jboss.messaging.util.TypedProperties;
 
-import java.util.Iterator;
-
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
  * 
@@ -65,7 +76,7 @@
          {
             byte[] expectedBytes = (byte[]) expectedValue;
             byte[] actualBytes = (byte[]) actualValue;
-            assertEqualsByteArrays(expectedBytes, actualBytes);
+            UnitTestCase.assertEqualsByteArrays(expectedBytes, actualBytes);
          } else
          {
             assertEquals(expectedValue, actualValue);
@@ -170,7 +181,7 @@
 
    public void testBytesProperty() throws Exception
    {
-      byte[] b = RandomUtil.randomBytes();
+      byte[] b = randomBytes();
       props.putBytesProperty(key, b);
       byte[] bb = (byte[]) props.getProperty(key);
       assertEqualsByteArrays(b, bb);

Added: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossBytesMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossBytesMessageTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossBytesMessageTest.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -0,0 +1,625 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.tests.unit.jms.client;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
+import static org.jboss.messaging.tests.util.RandomUtil.randomChar;
+import static org.jboss.messaging.tests.util.RandomUtil.randomDouble;
+import static org.jboss.messaging.tests.util.RandomUtil.randomFloat;
+import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+import static org.jboss.messaging.tests.util.RandomUtil.randomShort;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
+
+import java.util.ArrayList;
+
+import javax.jms.MessageEOFException;
+import javax.jms.MessageFormatException;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.jms.client.JBossBytesMessage;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.MessagingBuffer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class JBossBytesMessageTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testForeignBytesMessage() throws Exception
+   {
+      byte[] foreignBytes = randomBytes(3000);
+      JBossBytesMessage foreignMessage = new JBossBytesMessage();
+      foreignMessage.writeBytes(foreignBytes);
+      foreignMessage.reset();
+
+      JBossBytesMessage message = new JBossBytesMessage(foreignMessage);
+      byte[] b = new byte[(int) foreignMessage.getBodyLength()];
+      message.reset();
+
+      message.readBytes(b);
+
+      assertEqualsByteArrays(foreignBytes, b);
+   }
+   
+   public void testGetType() throws Exception
+   {
+      JBossBytesMessage message = new JBossBytesMessage();
+      assertEquals(JBossBytesMessage.TYPE, message.getType());
+   }
+
+   public void testGetBodyLength() throws Exception
+   {
+      byte[] value = randomBytes(3000);
+
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeBytes(value);
+      message.reset();
+
+      assertEquals(3000, message.getBodyLength());
+
+   }
+   
+   public void testClearBody() throws Exception
+   {
+      byte[] value = randomBytes();
+
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeBytes(value);
+      message.reset();
+
+      assertTrue(message.getBodyLength() > 0);
+      
+      message.clearBody();
+      message.reset();
+      assertEquals(0, message.getBodyLength());
+   }
+
+
+   public void testWriteBoolean() throws Exception
+   {
+      boolean value = randomBoolean();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeBoolean(value);
+
+      message.reset();
+
+      assertEquals(value, message.readBoolean());
+   }
+
+   public void testReadBoolean() throws Exception
+   {
+      boolean value = randomBoolean();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putBoolean(value);
+      message.reset();
+
+      assertEquals(value, message.readBoolean());
+   }
+
+   public void testReadBooleanFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readBoolean();
+         }
+      });
+   }
+
+   public void testWriteByte() throws Exception
+   {
+      byte value = randomByte();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeByte(value);
+
+      message.reset();
+
+      assertEquals(value, message.readByte());
+   }
+
+   public void testReadByte() throws Exception
+   {
+      byte value = randomByte();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putByte(value);
+      message.reset();
+
+      assertEquals(value, message.readByte());
+   }
+
+   public void testReadByteFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readByte();
+         }
+      });
+   }
+
+   public void testWriteBytes() throws Exception
+   {
+      byte[] value = randomBytes();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeBytes(value);
+
+      message.reset();
+
+      byte[] v = new byte[value.length];
+      message.readBytes(v);
+      assertEqualsByteArrays(value, v);
+   }
+
+   public void testReadBytes() throws Exception
+   {
+      byte[] value = randomBytes();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putBytes(value);
+      message.reset();
+
+      byte[] v = new byte[value.length];
+      message.readBytes(v);
+      assertEqualsByteArrays(value, v);
+   }
+
+   public void testReadBytesFromEmptyMessage() throws Exception
+   {
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.reset();
+
+      byte[] v = new byte[1];
+      int read = message.readBytes(v);
+      assertEquals(-1, read);
+   }
+
+   public void testWriteShort() throws Exception
+   {
+      short value = randomShort();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeShort(value);
+
+      message.reset();
+
+      assertEquals(value, message.readShort());
+   }
+
+   public void testReadShort() throws Exception
+   {
+      short value = randomShort();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putShort(value);
+      message.reset();
+
+      assertEquals(value, message.readShort());
+   }
+
+   public void testReadShortFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readShort();
+         }
+      });
+   }
+
+   public void testWriteChar() throws Exception
+   {
+      char value = randomChar();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeChar(value);
+
+      message.reset();
+
+      assertEquals(value, message.readChar());
+   }
+
+   public void testReadChar() throws Exception
+   {
+      char value = randomChar();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putChar(value);
+      message.reset();
+
+      assertEquals(value, message.readChar());
+   }
+
+   public void testReadCharFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readChar();
+         }
+      });
+   }
+
+   public void testWriteInt() throws Exception
+   {
+      int value = randomInt();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeInt(value);
+
+      message.reset();
+
+      assertEquals(value, message.readInt());
+   }
+
+   public void testReadInt() throws Exception
+   {
+      int value = randomInt();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putInt(value);
+      message.reset();
+
+      assertEquals(value, message.readInt());
+   }
+
+   public void testReadIntFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readInt();
+         }
+      });
+   }
+
+   public void testWriteLong() throws Exception
+   {
+      long value = randomLong();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeLong(value);
+
+      message.reset();
+
+      assertEquals(value, message.readLong());
+   }
+
+   public void testReadLong() throws Exception
+   {
+      long value = randomLong();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putLong(value);
+      message.reset();
+
+      assertEquals(value, message.readLong());
+   }
+
+   public void testReadLongFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readLong();
+         }
+      });
+   }
+
+   public void testWriteFloat() throws Exception
+   {
+      float value = randomFloat();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeFloat(value);
+
+      message.reset();
+
+      assertEquals(value, message.readFloat());
+   }
+
+   public void testReadFloat() throws Exception
+   {
+      float value = randomFloat();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putFloat(value);
+      message.reset();
+
+      assertEquals(value, message.readFloat());
+   }
+
+   public void testReadFloatFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readFloat();
+         }
+      });
+   }
+
+   public void testWriteDouble() throws Exception
+   {
+      double value = randomDouble();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeDouble(value);
+
+      message.reset();
+
+      assertEquals(value, message.readDouble());
+   }
+
+   public void testReadDouble() throws Exception
+   {
+      double value = randomDouble();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putDouble(value);
+      message.reset();
+
+      assertEquals(value, message.readDouble());
+   }
+
+   public void testReadDoubleFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readDouble();
+         }
+      });
+   }
+
+   public void testWriteUTF() throws Exception
+   {
+      String value = randomString();
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.writeUTF(value);
+
+      message.reset();
+
+      assertEquals(value, message.readUTF());
+   }
+
+   public void testReadUTF() throws Exception
+   {
+      String value = randomString();
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      MessagingBuffer body = message.getCoreMessage().getBody();
+      body.putUTF(value);
+      message.reset();
+
+      assertEquals(value, message.readUTF());
+   }
+
+   public void testReadUTFFromEmptyMessage() throws Exception
+   {
+      doReadFromEmptyMessage(new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readUTF();
+         }
+      });
+   }
+
+   public void testWriteObjectWithNull() throws Exception
+   {
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      try
+      {
+         message.writeObject(null);
+         fail("NullPointerException");
+      } catch (NullPointerException e)
+      {
+      }
+   }
+
+   public void testWriteObjectWithString() throws Exception
+   {
+      doWriteObjectWithType(randomString(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readUTF();
+         }
+      });
+   }
+
+   public void testWriteObjectWithBoolean() throws Exception
+   {
+      doWriteObjectWithType(randomBoolean(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readBoolean();
+         }
+      });
+   }
+
+   public void testWriteObjectWithByte() throws Exception
+   {
+      doWriteObjectWithType(randomByte(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readByte();
+         }
+      });
+   }
+
+   public void testWriteObjectWithBytes() throws Exception
+   {
+      doWriteObjectWithType(randomBytes(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            byte[] bytes = new byte[(int) message.getBodyLength()];
+            message.readBytes(bytes);
+            return bytes;
+         }
+      });
+   }
+
+   public void testWriteObjectWithShort() throws Exception
+   {
+      doWriteObjectWithType(randomShort(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readShort();
+         }
+      });
+   }
+
+   public void testWriteObjectWithChar() throws Exception
+   {
+      doWriteObjectWithType(randomChar(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readChar();
+         }
+      });
+   }
+
+   public void testWriteObjectWithInt() throws Exception
+   {
+      doWriteObjectWithType(randomInt(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readInt();
+         }
+      });
+   }
+
+   public void testWriteObjectWithLong() throws Exception
+   {
+      doWriteObjectWithType(randomLong(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readLong();
+         }
+      });
+   }
+
+   public void testWriteObjectWithFloat() throws Exception
+   {
+      doWriteObjectWithType(randomFloat(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readFloat();
+         }
+      });
+   }
+
+   public void testWriteObjectWithDouble() throws Exception
+   {
+      doWriteObjectWithType(randomDouble(), new TypeReader()
+      {
+         public Object readType(JBossBytesMessage message) throws Exception
+         {
+            return message.readDouble();
+         }
+      });
+   }
+
+   public void testWriteObjectWithInvalidType() throws Exception
+   {
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      try
+      {
+         message.writeObject(new ArrayList());
+         fail("MessageFormatException");
+      } catch (MessageFormatException e)
+      {
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private void doReadFromEmptyMessage(TypeReader reader) throws Exception
+   {
+      JBossBytesMessage message = new JBossBytesMessage();
+      message.reset();
+
+      try
+      {
+         reader.readType(message);
+         fail("must throw a MessageEOFException");
+      } catch (MessageEOFException e)
+      {
+      }
+   }
+
+   private void doWriteObjectWithType(Object value, TypeReader reader)
+         throws Exception
+   {
+      JBossBytesMessage message = new JBossBytesMessage();
+
+      message.writeObject(value);
+      message.reset();
+
+      Object v = reader.readType(message);
+      if (v instanceof byte[])
+      {
+         assertEqualsByteArrays((byte[]) value, (byte[]) v);
+      } else
+      {
+         assertEquals(value, v);
+      }
+   }
+
+   // Inner classes -------------------------------------------------
+
+   private interface TypeReader
+   {
+      Object readType(JBossBytesMessage message) throws Exception;
+   }
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMapMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMapMessageTest.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMapMessageTest.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -22,7 +22,6 @@
 
 package org.jboss.messaging.tests.unit.jms.client;
 
-import static org.jboss.messaging.tests.unit.core.remoting.impl.CodecAssert.assertEqualsByteArrays;
 import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
 import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
 import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
@@ -33,6 +32,7 @@
 import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
 import static org.jboss.messaging.tests.util.RandomUtil.randomShort;
 import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
 
 import javax.jms.MessageFormatException;
 

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossObjectMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossObjectMessageTest.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossObjectMessageTest.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -27,6 +27,7 @@
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
 
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectOutputStream;
@@ -39,7 +40,6 @@
 import junit.framework.TestCase;
 
 import org.jboss.messaging.jms.client.JBossObjectMessage;
-import org.jboss.messaging.tests.unit.core.remoting.impl.CodecAssert;
 import org.jboss.messaging.util.MessagingBuffer;
 
 /**
@@ -125,7 +125,7 @@
       byte[] bytes = new byte[data.length];
       body.getBytes(bytes);
       
-      CodecAssert.assertEqualsByteArrays(data, bytes);
+      assertEqualsByteArrays(data, bytes);
    }
    
    public void testDoBeforeReceive() throws Exception

Modified: trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -92,6 +92,16 @@
       return randomString().getBytes();
    }
    
+   public static byte[] randomBytes(int length)
+   {
+      byte[] bytes = new byte[length];
+      for (int i = 0; i < bytes.length; i++)
+      {
+        bytes[i] = randomByte();
+      }
+      return bytes;
+   }
+   
    public static double randomDouble()
    {
       return random.nextDouble();

Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2008-06-18 09:07:23 UTC (rev 4511)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2008-06-18 09:08:00 UTC (rev 4512)
@@ -34,6 +34,8 @@
 import java.util.Map;
 import java.util.UUID;
 
+import javax.transaction.xa.Xid;
+
 import junit.framework.TestCase;
 
 import org.jboss.messaging.core.server.MessageReference;
@@ -264,4 +266,43 @@
       return ((size / alignment) + (size % alignment != 0 ? 1 : 0)) * alignment;
    }
 
+   public static void assertEqualsByteArrays(byte[] expected, byte[] actual)
+   {
+      assertEquals(expected.length, actual.length);
+      for (int i = 0; i < expected.length; i++)
+      {
+         assertEquals("byte at index " + i, expected[i], actual[i]);
+      }
+   }
+
+   public static void assertEqualsByteArrays(int length, byte[] expected, byte[] actual)
+   {
+      // we check only for the given length (the arrays might be
+      // larger)
+      assertTrue(expected.length >= length);
+      assertTrue(actual.length >= length);
+      for (int i = 0; i < length; i++)
+      {
+         assertEquals("byte at index " + i, expected[i], actual[i]);
+      }
+   }
+
+   public static void assertSameXids(List<Xid> expected, List<Xid> actual)
+   {
+      assertNotNull(expected);
+      assertNotNull(actual);
+      assertEquals(expected.size(), actual.size());
+   
+      for (int i = 0; i < expected.size(); i++)
+      {
+         Xid expectedXid = expected.get(i);
+         Xid actualXid = actual.get(i);
+         UnitTestCase.assertEqualsByteArrays(expectedXid.getBranchQualifier(), actualXid
+               .getBranchQualifier());
+         assertEquals(expectedXid.getFormatId(), actualXid.getFormatId());
+         UnitTestCase.assertEqualsByteArrays(expectedXid.getGlobalTransactionId(), actualXid
+               .getGlobalTransactionId());
+      }
+   }
+
 }




More information about the jboss-cvs-commits mailing list