User: user57  
  Date: 01/05/01 20:07:18

  Modified:    src/main/org/jboss/test/testbean/test Main.java
  Log:
   o Updated testbeantest.sh to use the correct classpath.
   o Updated jboss-client.jar so that testbeantest.sh would run correctly
     and not complain about serial version problems.
   o Updated testbean/test/Main to HomeHandles and getting the EJBHome
     from them.
   o Added installInvalidNamingProperties() and restoreValidNamingProperties()
     to validate that the bean and home handles "remeber" which container they
     came from.
  
  NOTE: This will cause errors if the tested container does not have the required
        properties setup to specify the handle-jndi properties.  Not really sure
        how to work around this.
  
  Revision  Changes    Path
  1.6       +70 -5     jbosstest/src/main/org/jboss/test/testbean/test/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/testbean/test/Main.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Main.java 2000/12/13 01:33:53     1.5
  +++ Main.java 2001/05/02 03:07:18     1.6
  @@ -8,6 +8,8 @@
   import javax.ejb.DuplicateKeyException;
   import javax.ejb.Handle;
   import javax.ejb.EJBMetaData;
  +import javax.ejb.EJBHome;
  +import javax.ejb.HomeHandle;
   
   import java.util.Date;
   import java.util.Properties;
  @@ -49,7 +51,7 @@
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Hugo Pinto</a>
  -* @version $Id: Main.java,v 1.5 2000/12/13 01:33:53 hugo Exp $
  +* @version $Id: Main.java,v 1.6 2001/05/02 03:07:18 user57 Exp $
   */
   public class Main 
      extends junit.framework.TestCase
  @@ -57,6 +59,9 @@
        static boolean deployed = false;
        static int test = 0;
        static Date startDate = new Date();
  +
  +    protected String namingFactory;
  +    protected String providerURL;
       
       public Main(String name) {
                super(name);
  @@ -735,8 +740,29 @@
           System.out.print(++test+"- "+"Looking up the home AllTypes...");
           AllTypesHome allTypesHome = (AllTypesHome) ctx.lookup("AllTypes");
           if (allTypesHome!= null ) System.out.println("ok");
  -        System.out.print(++test+"- "+"Calling findByPrimaryKey on AllTypesHome with 
name seb...");
  +
  +        System.out.print(++test+"- "+"Getting the home handle...");
  +        HomeHandle homeHandle = allTypesHome.getHomeHandle();
  +        System.out.println("OK");
  +        
  +        System.out.print(++test+"- "+"Getting the home back from the handle...");
  +        installInvalidNamingProperties();
  +        EJBHome aHome = homeHandle.getEJBHome();
  +        System.out.println("OK");        
  +        restoreValidNamingProperties();
  +
  +        System.out.print(++test+"- "+"Getting metadata from home...");
  +        EJBMetaData aMetaData = aHome.getEJBMetaData();
  +        System.out.println("OK");
           
  +        System.out.print(++test+"- "+"Getting home from metadata...");
  +        installInvalidNamingProperties();
  +        aHome = aMetaData.getEJBHome();
  +        System.out.println("OK");        
  +        restoreValidNamingProperties();
  +
  +        System.out.print(++test+"- "+"Calling findByPrimaryKey on AllTypesHome with 
name seb...");
  +
           AllTypes allTypes = null;
           try {
               allTypes = allTypesHome.findByPrimaryKey("seb");
  @@ -776,8 +802,10 @@
           System.out.println("OK");
                        
                System.out.print(++test+"- "+"getting the bean back from the 
handle...");
  +        installInvalidNamingProperties();
                StatefulSession sfBean = (StatefulSession)sfHandle.getEJBObject();
                System.out.println("OK");
  +        restoreValidNamingProperties();
                        
                System.out.print(++test+"- "+"calling business method A on stateful: 
");
                System.out.println("OK, result is " + sfBean.callBusinessMethodA());
  @@ -791,9 +819,11 @@
           System.out.println("OK");
                        
                System.out.print(++test+"- "+"getting the bean back from the 
handle...");
  -             StatelessSession slBean = (StatelessSession)slHandle.getEJBObject();
  +        installInvalidNamingProperties();
  +        StatelessSession slBean = (StatelessSession)slHandle.getEJBObject();
                System.out.println("OK");
  -                     
  +        restoreValidNamingProperties();
  +
                System.out.print(++test+"- "+"calling business method B on stateless: 
");
                System.out.println("OK, result is " + slBean.callBusinessMethodB());
                    
  @@ -806,9 +836,11 @@
           System.out.println("OK");
                        
                System.out.print(++test+"- "+"getting the bean back from the 
handle...");
  +        installInvalidNamingProperties();        
                EnterpriseEntity eeBean = (EnterpriseEntity)eeHandle.getEJBObject();
                System.out.println("OK");
  -                     
  +        restoreValidNamingProperties();
  +        
                System.out.print(++test+"- "+"calling business method A on stateless: 
");
                System.out.println("OK, result is" + eeBean.callBusinessMethodA());
                    
  @@ -1003,6 +1035,30 @@
           System.out.println(hello1.sayHello());
           */
       }
  +
  +    protected void installInvalidNamingProperties() {
  +        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "nosuchclass");
  +        System.setProperty(Context.PROVIDER_URL, "nosuchurl");
  +
  +        try {
  +            new InitialContext();
  +            fail("should have thrown an exception");
  +        }
  +        catch (Exception e) {}
  +    }
  +
  +    protected void restoreValidNamingProperties() {
  +        Properties props = System.getProperties();
  +        if (namingFactory == null)
  +            props.remove(Context.INITIAL_CONTEXT_FACTORY);
  +        else
  +            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, namingFactory);
  +        
  +        if (providerURL == null)
  +            props.remove(Context.PROVIDER_URL);
  +        else
  +            System.setProperty(Context.PROVIDER_URL, providerURL);
  +    }
       
      protected void setUp()
         throws Exception
  @@ -1025,5 +1081,14 @@
         new org.jboss.jmx.client.Deployer().deploy("../deploy/testbean2.jar");
         deployed = true;
         System.out.println("done!");
  +
  +      // save the basics to connect to the naming server so we can
  +      // test that the handle impls return when new InitialContext() fails
  +      namingFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
  +      providerURL = System.getProperty(Context.PROVIDER_URL);
  +   }
  +
  +   protected void tearDown() throws Exception {
  +       restoreValidNamingProperties();
      }
   }
  
  
  

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

Reply via email to