User: pra     
  Date: 01/04/26 14:18:53

  Added:       src/main/org/jboss/test/jmsra/test AllJUnitTest.java
                        TestRa.java
  Log:
  Added small testsuite for JMS Connector ra, will only work against the current cvs 
JBoss
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/jmsra/test/AllJUnitTest.java
  
  Index: AllJUnitTest.java
  ===================================================================
  /*
   * Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
   *
   * 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
   */
  package org.jboss.test.jmsra.test;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  /**
   * TestSuite.java
   *
   *
   * Created: Mon Apr 23 22:08:13 2001
   *
   * @author 
   * @version
   */
  
  public class AllJUnitTest   extends TestCase{
      
      public AllJUnitTest(String name) {
        super(name);
      }
  
  
      public static Test suite ()
      {
        TestSuite suite = new TestSuite();
        
        try{
            System.out.println("Deploying");
                new org.jboss.jmx.client.Deployer().deploy("../deploy/jmsra.jar");
                
                System.out.println("Testing Queue publishing");
                suite.addTest(new TestRa("testSimple", "TxPublisher"));
                suite.addTest(new TestRa("testSimpleFail", "TxPublisher"));
                suite.addTest(new TestRa("testBeanOk", "TxPublisher"));
                suite.addTest(new TestRa("testBeanError", "TxPublisher"));
  
                System.out.println("Testing topic publishing");
                suite.addTest(new TestRa("testSimple", "TxTopicPublisher"));
                suite.addTest(new TestRa("testSimpleFail", "TxTopicPublisher"));
                suite.addTest(new TestRa("testBeanOk", "TxTopicPublisher"));
                suite.addTest(new TestRa("testBeanError", "TxTopicPublisher"));
        } catch (Exception ex) {
            ex.printStackTrace();
            System.exit(0);
            
        }
        return suite;
      }
      
      public static void main(String[] args) {
        
      }
      
  } // TestSuite
  
  
  
  1.1                  jbosstest/src/main/org/jboss/test/jmsra/test/TestRa.java
  
  Index: TestRa.java
  ===================================================================
  /*
   * Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
   *
   * 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
   */
  package org.jboss.test.jmsra.test;
  
  import org.jboss.test.jmsra.bean.*;
  
  import javax.jms.*;
  
  import javax.naming.InitialContext;
  import javax.naming.Context;
  
  /**
   * TestRa.java
   *
   *
   * Created: Mon Apr 23 21:35:25 2001
   *
   * @author 
   * @version
   */
  
  public class TestRa extends junit.framework.TestCase 
      implements MessageListener{
      private String QUEUE_FACTORY = "QueueConnectionFactory";
      private String QUEUE = "queue/testQueue";
  
      private String beanJNDI;
      private QueueConnection queueConnection;
      private QueueSession queueSession;
      private QueueReceiver queueReceiver;
      private Queue queue;
      private Publisher publisher;
      private String n;
  
      public TestRa(String name, String beanJNDI) throws Exception {
        super(name);
        n = name;
        this.beanJNDI = beanJNDI;
        setUp();
      }
  
      protected void printHeader() {
                System.out.println("\n---- Testing method " + n + 
                                   " for bean " + beanJNDI);
      }
  
      protected void printOK() {
                System.out.println("Test OK\n----");
      }
  
      protected void setUp() throws Exception {
        // Get publisher
        Context context = new InitialContext();
        PublisherHome publisherH = (PublisherHome)context.lookup(beanJNDI);
        publisher = publisherH.create();
        
        QueueConnectionFactory factory = (QueueConnectionFactory)
            context.lookup(QUEUE_FACTORY);
        queueConnection = factory.createQueueConnection();
        queueSession = queueConnection.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
        queue = (Queue)context.lookup(QUEUE);
        queueReceiver = queueSession.createReceiver(queue);
        //queueSession.setMessageListener(this);
        queueConnection.start();
      }
      /**
       * Check if we got a message
       */
      private int getJmsMessage() throws Exception {
        Message m = queueReceiver.receive(5000L);
        if(m != null) {
            System.out.println("Recived message");
            return m.getIntProperty(Publisher.JMS_MESSAGE_NR);
        } else {
            System.out.println("NO message recived");
            return -1;
        }
      }
      
      public void testSimple() throws Exception {
        printHeader();
        System.out.println("Verify simple send of message");
        publisher.simple(1);
        
        assert(1 == getJmsMessage() );
        printOK();
      }
  
      public void testSimpleFail() throws Exception {
        printHeader();
        System.out.println("Verify simple failed transaction");
        publisher.simpleFail(2);
        
        assert(-1 == getJmsMessage() );
        printOK();
      }
  
      public void testBeanOk() throws Exception {
        printHeader();
        System.out.println("Verify bean ok");
        publisher.beanOk(3);
        
        assert(3 == getJmsMessage() );
        printOK();
      }
  
      public void testBeanError() throws Exception {
        printHeader();
        System.out.println("Verify bean eroor failed transaction");
        try {
            publisher.beanError(4);
        }catch(Exception ex) {}
        
        assert(-1 == getJmsMessage() );
        printOK();
      }
      public void onMessage(Message message) {
        System.out.println("Got message");
      }
  
      public static void main(String[] args) {
        
      }
      
  } // TestRa
  
  
  

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

Reply via email to