User: d_jencks
  Date: 01/09/11 21:55:41

  Added:       src/main/org/jboss/test/xa/test XAUnitTestCase.java
  Removed:     src/main/org/jboss/test/xa/test Main.java
  Log:
  Changed naming scheme of tests to *UnitTestCase.java for short running tests and 
*StressTestCase.java for lengthy tests.  Made tests-unit and tests-stress targets in 
build.xml
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/xa/test/XAUnitTestCase.java
  
  Index: XAUnitTestCase.java
  ===================================================================
  package org.jboss.test.xa.test;
  
  import java.rmi.*;
  
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.ejb.DuplicateKeyException;
  import javax.ejb.Handle;
  import javax.ejb.EJBMetaData;
  import javax.ejb.FinderException;
  
  import java.util.Date;
  import java.util.Properties;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Enumeration;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.test.util.Deploy;
  
  import org.jboss.test.xa.interfaces.CantSeeDataException;
  import org.jboss.test.xa.interfaces.XATest;
  import org.jboss.test.xa.interfaces.XATestHome;
  
  public class XAUnitTestCase
      extends TestCase
  {
      public XAUnitTestCase(String name)
      {
          super(name);
      }
  
      public void testXABean() throws Exception {
          int test = 0;
  
          Context ctx = new InitialContext();
  
          System.out.println();
          System.out.print(++test+"- "+"Looking up the XATest home...");
  
          XATestHome home;
  
          try {
              home = (XATestHome) ctx.lookup("XATest");
  
              if (home == null) throw new Exception("No Home!");
              System.out.println("OK");
          } catch (Exception e) {
              System.out.println();
              System.out.println("Could not lookup the context:  the beans are 
probably not deployed");
              System.out.println("Check the server trace for details");
  
              throw e;
          }
  
          System.out.println();
          System.out.print(++test+"- "+"Creating an the XATest bean...");
          XATest bean;
          try {
              bean = home.create();
              if(bean == null) throw new Exception("No Bean!");
              System.out.println("OK");
          } catch (Exception e) {
              System.out.println();
              System.out.println("Could not create the bean!");
              System.out.println("Check the server trace for details");
              e.printStackTrace();
  
  
              throw e;
          }
  
          System.out.println();
          System.out.print(++test+"- "+"Creating required tables...");
          try {
              bean.createTables();
              System.out.println("OK");            
          }
          catch (Exception e) {
              System.out.println("\nFailed to create tables");
              throw e;
          }
          
          System.out.println();
          System.out.print(++test+"- "+"Clearing any old data...");
          try {
              bean.clearData();
              System.out.println("OK");
          } catch(Exception e) {
              System.out.println();
              System.out.println("Could not clear the data: did you create the table 
in both data sources?");
              System.out.println("CREATE TABLE XA_TEST(ID INTEGER NOT NULL PRIMARY 
KEY, DATA INTEGER NOT NULL)");
  
              throw e;
          }
  
          System.out.println();
          System.out.print(++test+"- "+"Testing DB connections...");
          try {
              bean.doWork();
              System.out.println("OK");
          } catch(CantSeeDataException e) {
              System.out.println("sort of worked.");
              System.out.println(e.getMessage());
          } catch(Exception e) {
              System.out.println();
              System.out.println("Error during DB test!");
              System.out.println("Check the server trace for details");
  
              throw e;
          }
      }
  
      protected void setUp() throws Exception
      {
      }
  
     /**
      * Setup the test suite.
      */
     public static Test suite() {
        TestSuite suite = new TestSuite();
          
        // add a test case to deploy our support applications
        String filename = "xatest.jar";
        suite.addTest(new Deploy.Deployer(filename));
  
        suite.addTest(new TestSuite(XAUnitTestCase.class));
        
        // add a test case to undeploy our support applications
        suite.addTest(new Deploy.Undeployer("../deploy/xatest.jar"));
  
        return suite;
     }
  }
  
  
  

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

Reply via email to