[jboss-cvs] JBoss Messaging SVN: r4612 - in trunk: src/main/org/jboss/messaging/core/server/impl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 27 10:34:01 EDT 2008


Author: ataylor
Date: 2008-06-27 10:34:01 -0400 (Fri, 27 Jun 2008)
New Revision: 4612

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionPacketHandlerTest.java
Modified:
   trunk/src/main/org/jboss/messaging/core/server/ServerSession.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionPacketHandler.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionImplTest.java
Log:
more tests and tweaks

Modified: trunk/src/main/org/jboss/messaging/core/server/ServerSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ServerSession.java	2008-06-27 14:09:22 UTC (rev 4611)
+++ trunk/src/main/org/jboss/messaging/core/server/ServerSession.java	2008-06-27 14:34:01 UTC (rev 4612)
@@ -22,21 +22,13 @@
 
 package org.jboss.messaging.core.server;
 
-import java.util.List;
-
-import javax.transaction.xa.Xid;
-
-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.SessionCreateBrowserResponseMessage;
-import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerResponseMessage;
-import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerResponseMessage;
-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.SessionXAResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.*;
 import org.jboss.messaging.core.server.impl.ServerBrowserImpl;
 import org.jboss.messaging.util.SimpleString;
 
+import javax.transaction.xa.Xid;
+import java.util.List;
+
 /**
  * 
  * A ServerSession
@@ -109,9 +101,9 @@
    
    SessionCreateProducerResponseMessage createProducer(long clientTargetID, SimpleString address, int windowSize, int maxRate) throws Exception;   
 
-   SessionQueueQueryResponseMessage executeQueueQuery(SessionQueueQueryMessage request) throws Exception;
+   SessionQueueQueryResponseMessage executeQueueQuery(SimpleString queueName) throws Exception;
 
-   SessionBindingQueryResponseMessage executeBindingQuery(SessionBindingQueryMessage request) throws Exception;
+   SessionBindingQueryResponseMessage executeBindingQuery(SimpleString address) throws Exception;
 
    SessionCreateBrowserResponseMessage createBrowser(SimpleString queueName, SimpleString filterString) throws Exception;
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2008-06-27 14:09:22 UTC (rev 4611)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2008-06-27 14:34:01 UTC (rev 4612)
@@ -981,14 +981,14 @@
       return response;
    }
 
-   public SessionQueueQueryResponseMessage executeQueueQuery(final SessionQueueQueryMessage request) throws Exception
+   public SessionQueueQueryResponseMessage executeQueueQuery(final SimpleString queueName) throws Exception
    {
-      if (request.getQueueName() == null)
+      if (queueName == null)
       {
          throw new IllegalArgumentException("Queue name is null");
       }
 
-      Binding binding = postOffice.getBinding(request.getQueueName());
+      Binding binding = postOffice.getBinding(queueName);
 
       SessionQueueQueryResponseMessage response;
 
@@ -1012,20 +1012,20 @@
       return response;
    }
 
-   public SessionBindingQueryResponseMessage executeBindingQuery(final SessionBindingQueryMessage request) throws Exception
+   public SessionBindingQueryResponseMessage executeBindingQuery(final SimpleString address) throws Exception
    {
-      if (request.getAddress() == null)
+      if (address == null)
       {
          throw new IllegalArgumentException("Address is null");
       }
 
-      boolean exists = postOffice.containsDestination(request.getAddress());
+      boolean exists = postOffice.containsDestination(address);
 
       List<SimpleString> queueNames = new ArrayList<SimpleString>();
 
       if (exists)
       {
-         List<Binding> bindings = postOffice.getBindingsForAddress(request.getAddress());
+         List<Binding> bindings = postOffice.getBindingsForAddress(address);
 
          for (Binding binding : bindings)
          {

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionPacketHandler.java	2008-06-27 14:09:22 UTC (rev 4611)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionPacketHandler.java	2008-06-27 14:34:01 UTC (rev 4612)
@@ -22,42 +22,17 @@
 
 package org.jboss.messaging.core.server.impl;
 
-import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.NO_ID_SET;
-
-import java.util.List;
-
-import javax.transaction.xa.Xid;
-
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.Packet;
 import org.jboss.messaging.core.remoting.PacketReturner;
-import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
-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.SessionCancelMessage;
-import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserMessage;
-import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerMessage;
-import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerMessage;
-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.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.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.*;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.NO_ID_SET;
 import org.jboss.messaging.core.server.ServerSession;
 
+import javax.transaction.xa.Xid;
+import java.util.List;
+
 /**
  * 
  * A ServerSessionPacketHandler
@@ -81,18 +56,6 @@
    {
       return session.getID();
    }
-   
-   public boolean equals(ServerSessionPacketHandler other)
-   {
-      if (other instanceof ServerSessionPacketHandler == false)
-      {
-         return false;
-      }
-      
-      ServerSessionPacketHandler sother = (ServerSessionPacketHandler)other;
-      
-      return sother.session.getID() == session.getID();
-   }
 
    public Packet doHandle(final Packet packet, final PacketReturner sender) throws Exception
    {
@@ -128,13 +91,13 @@
       case PacketImpl.SESS_QUEUEQUERY:
       {
          SessionQueueQueryMessage request = (SessionQueueQueryMessage) packet;
-         response = session.executeQueueQuery(request);
+         response = session.executeQueueQuery(request.getQueueName());
          break;
       }
       case PacketImpl.SESS_BINDINGQUERY:
       {
          SessionBindingQueryMessage request = (SessionBindingQueryMessage)packet;
-         response = session.executeBindingQuery(request);
+         response = session.executeBindingQuery(request.getAddress());
          break;
       }
       case PacketImpl.SESS_CREATEBROWSER:

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionImplTest.java	2008-06-27 14:09:22 UTC (rev 4611)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionImplTest.java	2008-06-27 14:34:01 UTC (rev 4612)
@@ -1503,7 +1503,7 @@
       expect(binding.getAddress()).andReturn(address);
       replay(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue);
       SessionQueueQueryMessage message = new SessionQueueQueryMessage(address);
-      SessionQueueQueryResponseMessage resp = session.executeQueueQuery(message);
+      SessionQueueQueryResponseMessage resp = session.executeQueueQuery(address);
       verify(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue);
       assertEquals(resp.isDurable(),true);
       assertEquals(resp.isTemporary(),true);
@@ -1535,7 +1535,7 @@
       expect(binding.getAddress()).andReturn(address);
       replay(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue, filter);
       SessionQueueQueryMessage message = new SessionQueueQueryMessage(address);
-      SessionQueueQueryResponseMessage resp = session.executeQueueQuery(message);
+      SessionQueueQueryResponseMessage resp = session.executeQueueQuery(address);
       verify(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue, filter);
       assertEquals(resp.isDurable(),true);
       assertEquals(resp.isTemporary(),true);
@@ -1556,7 +1556,7 @@
       expect(po.getBinding(address)).andReturn(null);
       replay(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue);
       SessionQueueQueryMessage message = new SessionQueueQueryMessage(address);
-      SessionQueueQueryResponseMessage resp = session.executeQueueQuery(message);
+      SessionQueueQueryResponseMessage resp = session.executeQueueQuery(address);
       verify(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue);
       assertEquals(resp.isExists(),false);
    }
@@ -1570,7 +1570,7 @@
       SessionQueueQueryMessage message = new SessionQueueQueryMessage();
       try
       {
-         session.executeQueueQuery(message);
+         session.executeQueueQuery(null);
          fail("should throw exception");
       }
       catch (IllegalArgumentException e)
@@ -1601,7 +1601,7 @@
       expect(queue2.getName()).andReturn(qName2);
       replay(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue, binding2, queue2);
       SessionBindingQueryMessage message = new SessionBindingQueryMessage(address);
-      SessionBindingQueryResponseMessage resp = session.executeBindingQuery(message);
+      SessionBindingQueryResponseMessage resp = session.executeBindingQuery(address);
       verify(conn, returner, sm, po, qs, rm, ss, pd, executor, binding, queue, binding2, queue2);
       assertEquals(resp.isExists(),true);
       assertEquals(resp.getQueueNames().size(),2);
@@ -1617,7 +1617,7 @@
       expect(po.containsDestination(address)).andReturn(false);
       replay(conn, returner, sm, po, qs, rm, ss, pd, executor);
       SessionBindingQueryMessage message = new SessionBindingQueryMessage(address);
-      SessionBindingQueryResponseMessage resp = session.executeBindingQuery(message);
+      SessionBindingQueryResponseMessage resp = session.executeBindingQuery(address);
       verify(conn, returner, sm, po, qs, rm, ss, pd, executor);
       assertEquals(resp.isExists(),false);
       assertEquals(resp.getQueueNames().size(),0);
@@ -1631,7 +1631,7 @@
       SessionBindingQueryMessage message = new SessionBindingQueryMessage();
       try
       {
-         session.executeBindingQuery(message);
+         session.executeBindingQuery(null);
          fail("should throw exception");
       }
       catch (IllegalArgumentException e)

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionPacketHandlerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionPacketHandlerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/ServerSessionPacketHandlerTest.java	2008-06-27 14:34:01 UTC (rev 4612)
@@ -0,0 +1,359 @@
+/*
+ * 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.server.impl;
+
+import static org.easymock.EasyMock.*;
+import org.easymock.classextension.EasyMock;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.PacketReturner;
+import org.jboss.messaging.core.remoting.impl.wireformat.*;
+import org.jboss.messaging.core.server.ServerSession;
+import org.jboss.messaging.core.server.impl.ServerSessionPacketHandler;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.util.SimpleString;
+
+import javax.transaction.xa.Xid;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class ServerSessionPacketHandlerTest extends UnitTestCase
+{
+   private ServerSession session;
+   private ServerSessionPacketHandler handler;
+   private PacketReturner sender;
+   private SimpleString queueName;
+   private SimpleString filterString;
+
+   protected void setUp() throws Exception
+   {
+      session = createStrictMock(ServerSession.class);
+      sender = createStrictMock(PacketReturner.class);
+      handler = new ServerSessionPacketHandler(session);
+      queueName = new SimpleString("qname");
+      filterString = new SimpleString("test = 'foo'");
+   }
+
+   protected void tearDown() throws Exception
+   {
+      session = null;
+      handler = null;
+   }
+
+   public void testGetId()
+   {
+      expect(handler.getID()).andReturn(999l);
+      replay(session);
+      assertEquals(handler.getID(), 999l);
+      verify(session);
+   }
+
+   public void testCreateConsumer() throws Exception
+   {
+      SessionCreateConsumerResponseMessage resp = EasyMock.createStrictMock(SessionCreateConsumerResponseMessage.class);
+      expect(session.createConsumer(1, queueName, filterString, true, true, 10, 100)).andReturn(resp);
+      replay(session, sender);
+      SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(1, queueName, filterString, true, true, 10, 100);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testCreateQueue() throws Exception
+   {
+      session.createQueue(queueName, queueName, filterString, true, true);
+      replay(session, sender);
+      SessionCreateQueueMessage request = new SessionCreateQueueMessage(queueName, queueName, filterString, true, true);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testDeleteQueue() throws Exception
+   {
+      session.deleteQueue(queueName);
+      replay(session, sender);
+      SessionDeleteQueueMessage request = new SessionDeleteQueueMessage(queueName);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testQueueQuery() throws Exception
+   {
+      SessionQueueQueryResponseMessage resp = EasyMock.createStrictMock(SessionQueueQueryResponseMessage.class);
+      expect(session.executeQueueQuery(queueName)).andReturn(resp);
+      replay(session, sender);
+      SessionQueueQueryMessage request = new SessionQueueQueryMessage(queueName);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testBindingQuery() throws Exception
+   {
+      SessionBindingQueryResponseMessage resp = EasyMock.createStrictMock(SessionBindingQueryResponseMessage.class);
+      expect(session.executeBindingQuery(queueName)).andReturn(resp);
+      replay(session, sender);
+      SessionBindingQueryMessage request = new SessionBindingQueryMessage(queueName);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testCreateBrowser() throws Exception
+   {
+      SessionCreateBrowserResponseMessage resp = EasyMock.createStrictMock(SessionCreateBrowserResponseMessage.class);
+      expect(session.createBrowser(queueName, filterString)).andReturn(resp);
+      replay(session, sender);
+      SessionCreateBrowserMessage request = new SessionCreateBrowserMessage(queueName, filterString);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testCreateProducer() throws Exception
+   {
+      SessionCreateProducerResponseMessage resp = EasyMock.createStrictMock(SessionCreateProducerResponseMessage.class);
+      expect(session.createProducer(4, queueName, 33, 44)).andReturn(resp);
+      replay(session, sender);
+      SessionCreateProducerMessage request = new SessionCreateProducerMessage(4, queueName, 33, 44);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testClose() throws Exception
+   {
+      session.close();
+      replay(session, sender);
+      PacketImpl request = new PacketImpl(PacketImpl.CLOSE);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testSessionAck() throws Exception
+   {
+      session.acknowledge(44, true);
+      replay(session, sender);
+      SessionAcknowledgeMessage request = new SessionAcknowledgeMessage(44, true);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testCommit() throws Exception
+   {
+      session.commit();
+      replay(session, sender);
+      PacketImpl request = new PacketImpl(PacketImpl.SESS_COMMIT);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testRollback() throws Exception
+   {
+      session.rollback();
+      replay(session, sender);
+      PacketImpl request = new PacketImpl(PacketImpl.SESS_ROLLBACK);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testCancel() throws Exception
+   {
+      session.cancel(55, true);
+      replay(session, sender);
+      SessionCancelMessage request = new SessionCancelMessage(55, true);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaCommit() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XACommit(true, xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXACommitMessage request = new SessionXACommitMessage(xid, true);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaEnd() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XAEnd(xid, true)).andReturn(resp);
+      replay(session, sender);
+      SessionXAEndMessage request = new SessionXAEndMessage(xid, true);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaForget() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XAForget(xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXAForgetMessage request = new SessionXAForgetMessage(xid);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaJoin() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XAJoin(xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXAJoinMessage request = new SessionXAJoinMessage(xid);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaResume() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XAResume(xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXAResumeMessage request = new SessionXAResumeMessage(xid);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaRollback() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XARollback(xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXARollbackMessage request = new SessionXARollbackMessage(xid);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaStart() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XAStart(xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXAStartMessage request = new SessionXAStartMessage(xid);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaSuspend() throws Exception
+   {
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XASuspend()).andReturn(resp);
+      replay(session, sender);
+      PacketImpl request = new PacketImpl(PacketImpl.SESS_XA_SUSPEND);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaPrepare() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      SessionXAResponseMessage resp = EasyMock.createStrictMock(SessionXAResponseMessage.class);
+      expect(session.XAPrepare(xid)).andReturn(resp);
+      replay(session, sender);
+      SessionXAPrepareMessage request = new SessionXAPrepareMessage(xid);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaInDoubt() throws Exception
+   {
+      Xid xid = createStrictMock(Xid.class);
+      Xid xid2 = createStrictMock(Xid.class);
+      List<Xid> xids = new ArrayList<Xid>();
+      xids.add(xid);
+      xids.add(xid2);
+      expect(session.getInDoubtXids()).andReturn(xids);
+      replay(session, sender);
+      PacketImpl request = new PacketImpl(PacketImpl.SESS_XA_INDOUBT_XIDS);
+      SessionXAGetInDoubtXidsResponseMessage resp = (SessionXAGetInDoubtXidsResponseMessage) handler.doHandle(request, sender);
+      assertEquals(resp.getXids().size(), 2);
+      assertEquals(resp.getXids().get(0), xid);
+      assertEquals(resp.getXids().get(1), xid2);
+      verify(session, sender);
+   }
+
+   public void testXaGetTimeout() throws Exception
+   {
+      expect(session.getXATimeout()).andReturn(2000);
+      replay(session, sender);
+      PacketImpl request = new PacketImpl(PacketImpl.SESS_XA_GET_TIMEOUT);
+      SessionXAGetTimeoutResponseMessage resp = (SessionXAGetTimeoutResponseMessage) handler.doHandle(request, sender);
+      assertEquals(resp.getTimeoutSeconds(), 2000);
+      verify(session, sender);
+   }
+
+   public void testXaSetTimeout() throws Exception
+   {
+      expect(session.setXATimeout(5000)).andReturn(true);
+      replay(session, sender);
+      SessionXASetTimeoutMessage request = new SessionXASetTimeoutMessage(5000);
+      SessionXASetTimeoutResponseMessage resp = (SessionXASetTimeoutResponseMessage) handler.doHandle(request, sender);
+      assertEquals(resp.isOK(), true);
+      verify(session, sender);
+   }
+
+   public void testXaAddDestination() throws Exception
+   {
+      session.addDestination(queueName, true);
+      replay(session, sender);
+      SessionAddDestinationMessage request = new SessionAddDestinationMessage(queueName, true);
+      request.setResponseTargetID(12345);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+   public void testXaRemoveDestination() throws Exception
+   {
+      session.removeDestination(queueName, true);
+      replay(session, sender);
+      SessionRemoveDestinationMessage request = new SessionRemoveDestinationMessage(queueName, true);
+      request.setResponseTargetID(12345);
+      handler.doHandle(request, sender);
+      verify(session, sender);
+   }
+
+    public void testUnsupportedPacket() throws Exception
+   {
+      Packet packet = EasyMock.createStrictMock(Packet.class);
+      expect(packet.getType()).andReturn(Byte.MAX_VALUE);
+      replay(session, sender);
+      try
+      {
+         handler.doHandle(packet, sender);
+         fail("should throw exception");
+      }
+      catch (Exception e)
+      {
+         MessagingException messagingException = (MessagingException) e;
+         assertEquals(messagingException.getCode(), MessagingException.UNSUPPORTED_PACKET);
+      }
+
+      verify(session, sender);
+   }
+}




More information about the jboss-cvs-commits mailing list