Package org.hornetq.jms.tests

Source Code of org.hornetq.jms.tests.MessageWithReadResolveTest$TestEnum

/*
* Copyright 2009 Red Hat, Inc.
* Red Hat 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.hornetq.jms.tests;

import java.io.Serializable;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.hornetq.jms.tests.util.ProxyAssertSupport;

/**
* A MessageWithReadResolveTest
*
* See http://jira.jboss.com/jira/browse/JBMESSAGING-442
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
* @version <tt>$Revision: 8611 $</tt>
*
* $Id: MessageWithReadResolveTest.java 8611 2009-12-08 01:06:31Z timfox $
*
*/
public class MessageWithReadResolveTest extends JMSTestCase
{

   // Constants -----------------------------------------------------

   // Static --------------------------------------------------------

   // Attributes ----------------------------------------------------

   // Constructors --------------------------------------------------

   // TestCase overrides -------------------------------------------

   // Public --------------------------------------------------------

   public void testSendReceiveMessage() throws Exception
   {
      Connection conn = null;

      try
      {
         conn = JMSTestCase.cf.createConnection();

         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageProducer prod = sess.createProducer(HornetQServerTestCase.queue1);

         // Make persistent to make sure message gets serialized
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);

         MessageConsumer cons = sess.createConsumer(HornetQServerTestCase.queue1);

         TestMessage tm = new TestMessage(123, false);

         ObjectMessage om = sess.createObjectMessage();

         om.setObject(tm);

         conn.start();

         prod.send(om);

         ObjectMessage om2 = (ObjectMessage)cons.receive(1000);

         ProxyAssertSupport.assertNotNull(om2);

         TestMessage tm2 = (TestMessage)om2.getObject();

         ProxyAssertSupport.assertEquals(123, tm2.getID());

         conn.close();
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }

   }

   // Package protected ---------------------------------------------

   // Protected -----------------------------------------------------

   // Private -------------------------------------------------------

   /* This class would trigger the exception when serialized with jboss serialization */
   public static class TestMessage implements Serializable
   {
      private static final long serialVersionUID = -5932581134414145967L;

      private final long id;

      private Object clazz;

      public TestMessage(final long id, final boolean useSimpleObject)
      {
         this.id = id;
         if (useSimpleObject)
         {
            clazz = String.class;
         }
         else
         {
            clazz = TestEnum.class;
         }
      }

      @Override
      public String toString()
      {
         StringBuffer sb = new StringBuffer();
         sb.append("TestMessage(");
         sb.append("id=" + id);
         sb.append(", clazz=" + clazz);
         sb.append(")");
         return sb.toString();
      }

      public long getID()
      {
         return id;
      }

   }

   public static class TestEnum implements Serializable
   {

      private static final long serialVersionUID = 4306026990380393029L;

      public Object readResolve()
      {
         return null;
      }
   }

   // Inner classes -------------------------------------------------
}
TOP

Related Classes of org.hornetq.jms.tests.MessageWithReadResolveTest$TestEnum

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.