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

  Added:       src/main/org/jboss/test/bmp/test BmpUnitTestCase.java
  Removed:     src/main/org/jboss/test/bmp/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/bmp/test/BmpUnitTestCase.java
  
  Index: BmpUnitTestCase.java
  ===================================================================
  package org.jboss.test.bmp.test;
  
  
  import javax.naming.*;
  import java.util.Collection;
  import java.util.Iterator;
  
  import org.jboss.test.bmp.interfaces.*;
  
  import junit.framework.*;
  import org.jboss.test.util.Deploy;
  
  public class BmpUnitTestCase
      extends TestCase
  {
      private boolean deployed;
  
      public BmpUnitTestCase(String name)
      {
          super(name);
      }
  
      public void testBMP() throws Exception
     {
        BMPHelperSessionHome sessionHome = (BMPHelperSessionHome)new InitialContext 
().lookup ("bmp.BMPHelperSession");
        BMPHelperSession session = sessionHome.create ();
        
        System.out.println ("looking up table:");
        boolean exists =  session.existsSimpleBeanTable ();
        
        if (exists)
        {
           System.out.println ("table exists.");
           System.out.print ("delete it...");
           session.dropSimpleBeanTable();
           System.out.println ("done.");
        }
        else
        {
           System.out.println ("table does not exist.");
           System.out.print ("create it...");
           session.createSimpleBeanTable();
           System.out.println ("done.");
           System.out.println ();
           
           System.out.println ("start playing with bmp beans.");
           System.out.println ();
           SimpleBMPHome home = (SimpleBMPHome)new InitialContext ().lookup 
("bmp.SimpleBMP");
           System.out.println ("create bean1: 1, Daniel");
           SimpleBMP b1 = home.create (1, "Daniel");
           System.out.println ("getName (): "+b1.getName ());
           System.out.println ();
  
           System.out.println ("create bean2: 2, Robert");
           b1 = home.create (2, "Robert");
           System.out.println ("getName (): "+b1.getName ());
           System.out.println ();
  
           try
           {
              System.out.println ("trying to create one with same primkey: 1, 
Patrick");
              b1 = home.create (1, "Patrick");
           }
           catch (Exception _e)
           {
              System.out.println (_e.toString ());
           }
           System.out.println ();
           
           System.out.println ("create some more dummys:");
           for (int i = 0; i < 50; ++i)
              home.create (i + 3, ("Dummy "+i));
  
           System.out.println ();
           try
           {
              System.out.println ("trying to find Robert again");
              b1 = home.findByPrimaryKey (new Integer (2));
              System.out.println ("getName (): "+b1.getName ());
           }
           catch (Exception _e)
           {
              System.out.println (_e.toString ());
           }
           System.out.println ();
  
           try
           {
              System.out.println ("trying to find an not existing bean");
              b1 = home.findByPrimaryKey (new Integer (0));
              System.out.println ("getName (): "+b1.getName ());
           }
           catch (Exception _e)
           {
              System.out.println (_e.toString ());
           }
           System.out.println ();
           
           
           System.out.println ("rename Daniel to Maria: 1, Daniel");
           b1 = home.findByPrimaryKey (new Integer (1));
           System.out.println ("name old: " + b1.getName ());
           b1.setName ("Maria");
           System.out.println ("name new: " + b1.getName ());
          
           System.out.println ();
           
           System.out.println ("find all beans:");
           Iterator it = home.findAll ().iterator ();
           while (it.hasNext ())
           {
              System.out.println ("found:"+((SimpleBMP)it.next ()).getName ());
           }            
  
           System.out.println ();
  
           System.out.println ("Now trying from within the Session bean (to be able to 
rollback):");
           System.out.println (session.doTest ());
  
           System.out.println ("removing all beans:");
           it = home.findAll ().iterator ();
           while (it.hasNext ())
              ((SimpleBMP)it.next ()).remove ();
        }
  
     }
  
     protected void setUp() throws Exception
     {
  //       if (deployed) return;
  //       String deployDir = System.getProperty("jbosstest.deploy.dir");
  //       if( deployDir == null )
  //           deployDir = "../deploy";
  //       System.out.println("deployDir = "+deployDir);
  //       new org.jboss.jmx.client.Deployer().deploy(deployDir+"/bmp.jar");
  //       deployed = true;
     }
  
     public static void main (String[] _args) throws Exception
     {
        BmpUnitTestCase m = new BmpUnitTestCase("BmpUnitTestCase");
        m.setUp();
        m.testBMP();
     }
  
     /**
      * Setup the test suite.
      */
     public static Test suite() {
        TestSuite suite = new TestSuite();
          
        // add a test case to deploy our support applications
        String filename = "bmp.jar";
        suite.addTest(new Deploy.Deployer(filename));
  
        suite.addTest(new TestSuite(BmpUnitTestCase.class));
  
        // add a test case to undeploy our support applications
        suite.addTest(new Deploy.Undeployer(filename));
        
        return suite;
     }
  }
  
  
  

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

Reply via email to