User: d_jencks
  Date: 01/09/14 19:53:25

  Modified:    src/main/org/jboss/test/jmsra/test RaTest.java
  Added:       src/main/org/jboss/test/jmsra/test RaQueueUnitTestCase.java
                        RaTopicUnitTestCase.java
  Removed:     src/main/org/jboss/test/jmsra/test AllJMSRAUnitTestCase.java
                        RaQueueTest.java RaTopicTest.java
  Log:
  Fixed jmsra tests, converted to JBossTestCase and logging
  
  Revision  Changes    Path
  1.8       +262 -172  jbosstest/src/main/org/jboss/test/jmsra/test/RaTest.java
  
  Index: RaTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/test/RaTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RaTest.java       2001/09/07 10:26:43     1.7
  +++ RaTest.java       2001/09/15 02:53:25     1.8
  @@ -1,191 +1,281 @@
   /*
  - * Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
  + * JBoss, the OpenSource J2EE webOS
    *
  - * This library 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 of the License, or (at your option) any later version
  - *
  - * This library 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 library; if not, write to the Free Software
  - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
    */
   package org.jboss.test.jmsra.test;
  -
  -import javax.naming.InitialContext;
  -import javax.naming.Context;
  +import javax.jms.Connection;
  +import javax.jms.Message;
   
   import javax.jms.MessageConsumer;
  -import javax.jms.Message;
  -import javax.jms.Connection;
   import javax.jms.Session;
  +import javax.naming.Context;
   
  -import junit.framework.TestCase;
  +import javax.naming.InitialContext;
   import junit.framework.Assert;
   
  +import junit.framework.TestCase;
  +
  +import org.jboss.test.JBossTestCase;
  +
   import org.jboss.test.jmsra.bean.*;
   
   /**
  - * Abstract test cases for JMS Resource Adapter.
  + * Abstract test cases for JMS Resource Adapter. <p>
    *
  - * <p>Created: Mon Apr 23 21:35:25 2001
  + * Created: Mon Apr 23 21:35:25 2001
    *
  - * @author  <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>
  - * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  - * @version $Revision: 1.7 $
  + * @author    <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>
  + * @author    <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version   $Revision: 1.8 $
    */
   public abstract class RaTest
  -    extends TestCase
  +       extends JBossTestCase
   {
  -    public static final long DEFAULT_TIMEOUT = 500L;    
  -    public static final long FLUSH_TIMEOUT = 500L;
  -    
  -    protected String beanJNDI;
  -    protected MessageConsumer consumer;
  -    protected Publisher publisher;
  -    protected Connection connection;
  -    protected Session session;
  -    
  -    protected RaTest(final String name, final String beanJNDI)
  -        throws Exception
  -    {
  -        super(name);
  -        this.beanJNDI = beanJNDI;
  -    }
  -
  -    protected abstract void init(final Context context) throws Exception;
  -    
  -    protected void setUp() throws Exception {
  -        // Create a publisher
  -        Context context = new InitialContext();
  -        try {
  -            PublisherHome home = (PublisherHome)context.lookup(beanJNDI);
  -            publisher = home.create();
  -
  -            init(context);
  -        }
  -        finally {
  -            context.close();
  -        }
  -
  -        // start up the session
  -        connection.start();
  -        
  -        // flush the destination
  -        flush();
  -    }
  -
  -    protected void tearDown() throws Exception {
  -        if (consumer != null) {
  -            consumer.close();
  -        }
  -        if (connection != null) {
  -            connection.close();
  -        }
  -    }
  -    
  -    protected void printHeader() {
  -        System.out.println("\n---- Testing method " + getName() +
  -                           " for bean " + beanJNDI);
  -    }
  -
  -    protected void printOK() {
  -        System.out.println("---- Test OK\n");
  -    }
  -    
  -    /**
  -     * Check if we got a message.
  -     *
  -     * @return  Publisher.JMS_MESSAGE_NR int property or -1 if no message
  -     *          was received.
  -     */
  -    protected int getJmsMessage() throws Exception {
  -        return getJmsMessage(DEFAULT_TIMEOUT);
  -    }
  -
  -    /**
  -     * Check if we got a message.
  -     *
  -     * @param timeout   The time to wait for a message.
  -     *
  -     * @return  Publisher.JMS_MESSAGE_NR int property or -1 if no message
  -     *          was received.
  -     */
  -    protected int getJmsMessage(long timeout) throws Exception {
  -        Message msg = consumer.receive(timeout);
  -        if (msg != null) {
  -            System.out.println("Recived message: " + msg);
  -            int nr = msg.getIntProperty(Publisher.JMS_MESSAGE_NR);
  -            System.out.println("nr: " + nr);
  -            return nr;
  -        }
  -        else {
  -            System.out.println("NO message recived");
  -            return -1;
  -        }
  -    }
  -    
  -    /**
  -     * Flush the destiniation so we know that it contains no
  -     * messages which might mess up the test.
  -     */
  -    protected void flush() throws Exception {
  -        // System.out.println(" > Flushing Destination");
  -
  -        int nr = 0;
  -        do {
  -            try {
  -                nr = getJmsMessage(FLUSH_TIMEOUT);
  -            }
  -            catch (Exception ignore) {}
  -        }
  -        while (nr != -1);
  -
  -        // System.out.println(" > Flushed");
  -    }
  -    
  -    public void testSimple() throws Exception {
  -        printHeader();
  -        System.out.println("Verify simple send of message");
  -        publisher.simple(1);
  -
  -        Assert.assertEquals(1, getJmsMessage());
  -        printOK();
  -    }
  -
  -    public void testSimpleFail() throws Exception {
  -        printHeader();
  -        System.out.println("Verify simple failed transaction");
  -        publisher.simpleFail(2);
  -
  -        Assert.assertEquals(-1, getJmsMessage());
  -        printOK();
  -    }
  -
  -    public void testBeanOk() throws Exception {
  -        printHeader();
  -        System.out.println("Verify bean ok");
  -        publisher.beanOk(3);
  -
  -        Assert.assertEquals(3, getJmsMessage());
  -        printOK();
  -    }
  -
  -    public void testBeanError() throws Exception {
  -        printHeader();
  -        System.out.println("Verify bean eroor failed transaction");
  -        
  -        try {
  -            publisher.beanError(4);
  -        }
  -        catch (Exception ignore) {}
  -
  -        Assert.assertEquals(-1, getJmsMessage());
  -        printOK();
  -    }
  +   /**
  +    * Description of the Field
  +    */
  +   public final static long DEFAULT_TIMEOUT = 500L;
  +   /**
  +    * Description of the Field
  +    */
  +   public final static long FLUSH_TIMEOUT = 500L;
  +
  +   /**
  +    * Description of the Field
  +    */
  +   protected String beanJNDI;
  +   /**
  +    * Description of the Field
  +    */
  +   protected MessageConsumer consumer;
  +   /**
  +    * Description of the Field
  +    */
  +   protected Publisher publisher;
  +   /**
  +    * Description of the Field
  +    */
  +   protected Connection connection;
  +   /**
  +    * Description of the Field
  +    */
  +   protected Session session;
  +
  +   /**
  +    * Constructor for the RaTest object
  +    *
  +    * @param name           Description of Parameter
  +    * @param beanJNDI       Description of Parameter
  +    * @exception Exception  Description of Exception
  +    */
  +   protected RaTest(final String name, final String beanJNDI)
  +          throws Exception
  +   {
  +      super(name);
  +      this.beanJNDI = beanJNDI;
  +   }
  +
  +   /**
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   public void testSimple() throws Exception
  +   {
  +      printHeader();
  +      getLog().debug("Verify simple send of message");
  +      publisher.simple(1);
  +
  +      Assert.assertEquals(1, getJmsMessage());
  +      printOK();
  +   }
  +
  +   /**
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   public void testSimpleFail() throws Exception
  +   {
  +      printHeader();
  +      getLog().debug("Verify simple failed transaction");
  +      publisher.simpleFail(2);
  +
  +      Assert.assertEquals(-1, getJmsMessage());
  +      printOK();
  +   }
  +
  +   /**
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   public void testBeanOk() throws Exception
  +   {
  +      printHeader();
  +      getLog().debug("Verify bean ok");
  +      publisher.beanOk(3);
  +
  +      Assert.assertEquals(3, getJmsMessage());
  +      printOK();
  +   }
  +
  +   /**
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   public void testBeanError() throws Exception
  +   {
  +      printHeader();
  +      getLog().debug("Verify bean eroor failed transaction");
  +
  +      try
  +      {
  +         publisher.beanError(4);
  +      }
  +      catch (Exception ignore)
  +      {
  +      }
  +
  +      Assert.assertEquals(-1, getJmsMessage());
  +      printOK();
  +   }
  +
  +   /**
  +    * The JUnit setup method
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   protected void setUp() throws Exception
  +   {
  +      super.setUp();
  +      deployJ2ee("jmsra.jar");
  +      // Create a publisher
  +      Context context = new InitialContext();
  +      try
  +      {
  +         PublisherHome home = (PublisherHome)context.lookup(beanJNDI);
  +         publisher = home.create();
  +
  +         init(context);
  +      }
  +      finally
  +      {
  +         context.close();
  +      }
  +
  +      // start up the session
  +      connection.start();
  +
  +      // flush the destination
  +      flush();
  +   }
  +
  +   /**
  +    * Check if we got a message.
  +    *
  +    * @return               Publisher.JMS_MESSAGE_NR int property or -1 if no
  +    *      message was received.
  +    * @exception Exception  Description of Exception
  +    */
  +   protected int getJmsMessage() throws Exception
  +   {
  +      return getJmsMessage(DEFAULT_TIMEOUT);
  +   }
  +
  +   /**
  +    * Check if we got a message.
  +    *
  +    * @param timeout        The time to wait for a message.
  +    * @return               Publisher.JMS_MESSAGE_NR int property or -1 if no
  +    *      message was received.
  +    * @exception Exception  Description of Exception
  +    */
  +   protected int getJmsMessage(long timeout) throws Exception
  +   {
  +      Message msg = consumer.receive(timeout);
  +      if (msg != null)
  +      {
  +         getLog().debug("Recived message: " + msg);
  +         int nr = msg.getIntProperty(Publisher.JMS_MESSAGE_NR);
  +         getLog().debug("nr: " + nr);
  +         return nr;
  +      }
  +      else
  +      {
  +         getLog().debug("NO message recived");
  +         return -1;
  +      }
  +   }
  +
  +   /**
  +    * #Description of the Method
  +    *
  +    * @param context        Description of Parameter
  +    * @exception Exception  Description of Exception
  +    */
  +   protected abstract void init(final Context context) throws Exception;
  +
  +   /**
  +    * The teardown method for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   protected void tearDown() throws Exception
  +   {
  +      if (consumer != null)
  +      {
  +         consumer.close();
  +      }
  +      if (connection != null)
  +      {
  +         connection.close();
  +      }
  +      undeployJ2ee("jmsra.jar");
  +      super.tearDown();
  +   }
  +
  +   /**
  +    * #Description of the Method
  +    */
  +   protected void printHeader()
  +   {
  +      getLog().debug("\n---- Testing method " + getName() +
  +            " for bean " + beanJNDI);
  +   }
  +
  +   /**
  +    * #Description of the Method
  +    */
  +   protected void printOK()
  +   {
  +      getLog().debug("---- Test OK\n");
  +   }
  +
  +   /**
  +    * Flush the destiniation so we know that it contains no messages which might
  +    * mess up the test.
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   protected void flush() throws Exception
  +   {
  +      // getLog().debug(" > Flushing Destination");
  +
  +      int nr = 0;
  +      do
  +      {
  +         try
  +         {
  +            nr = getJmsMessage(FLUSH_TIMEOUT);
  +         }
  +         catch (Exception ignore)
  +         {
  +         }
  +      } while (nr != -1);
  +      // getLog().debug(" > Flushed");
  +   }
   }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/jmsra/test/RaQueueUnitTestCase.java
  
  Index: RaQueueUnitTestCase.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.test.jmsra.test;
  import javax.jms.MessageConsumer;
  import javax.jms.Queue;
  import javax.jms.QueueConnection;
  
  import javax.jms.QueueConnectionFactory;
  import javax.jms.QueueSession;
  import javax.jms.Session;
  
  import javax.naming.Context;
  
  /**
   * Test cases for JMS Resource Adapter use a <em>Queue</em> . <p>
   *
   * Created: Mon Apr 23 21:35:25 2001
   *
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   * @version   $Revision: 1.1 $
   */
  public class RaQueueUnitTestCase
         extends RaTest
  {
     private final static String QUEUE_FACTORY = "ConnectionFactory";
     private final static String QUEUE = "queue/testQueue";
     private final static String JNDI = "TxPublisher";
  
     /**
      * Constructor for the RaQueueUnitTestCase object
      *
      * @param name           Description of Parameter
      * @exception Exception  Description of Exception
      */
     public RaQueueUnitTestCase(String name) throws Exception
     {
        super(name, JNDI);
     }
  
     /**
      * #Description of the Method
      *
      * @param context        Description of Parameter
      * @exception Exception  Description of Exception
      */
     protected void init(final Context context) throws Exception
     {
        QueueConnectionFactory factory =
              (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
  
        connection = factory.createQueueConnection();
  
        session = ((QueueConnection)connection).createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
  
        Queue queue = (Queue)context.lookup(QUEUE);
  
        consumer = ((QueueSession)session).createReceiver(queue);
     }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/jmsra/test/RaTopicUnitTestCase.java
  
  Index: RaTopicUnitTestCase.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.test.jmsra.test;
  import javax.jms.MessageConsumer;
  import javax.jms.Session;
  import javax.jms.Topic;
  import javax.jms.TopicConnection;
  
  import javax.jms.TopicConnectionFactory;
  import javax.jms.TopicSession;
  
  import javax.naming.Context;
  
  /**
   * Test cases for JMS Resource Adapter using a <em>Topic</em> . <p>
   *
   * Created: Mon Apr 23 21:35:25 2001
   *
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   * @version   $Revision: 1.1 $
   */
  public class RaTopicUnitTestCase
         extends RaTest
  {
     private final static String TOPIC_FACTORY = "ConnectionFactory";
     private final static String TOPIC = "topic/testTopic";
     private final static String JNDI = "TxTopicPublisher";
  
     /**
      * Constructor for the RaTopicUnitTestCase object
      *
      * @param name           Description of Parameter
      * @exception Exception  Description of Exception
      */
     public RaTopicUnitTestCase(String name) throws Exception
     {
        super(name, JNDI);
     }
  
     /**
      * #Description of the Method
      *
      * @param context        Description of Parameter
      * @exception Exception  Description of Exception
      */
     protected void init(final Context context) throws Exception
     {
        TopicConnectionFactory factory =
              (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
  
        connection = factory.createTopicConnection();
  
        session = ((TopicConnection)connection).createTopicSession(false, 
Session.AUTO_ACKNOWLEDGE);
  
        Topic topic = (Topic)context.lookup(TOPIC);
  
        consumer = ((TopicSession)session).createSubscriber(topic);
     }
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to