User: d_jencks
  Date: 01/09/15 12:50:39

  Modified:    src/main/org/jboss/test/naming/test ENCUnitTestCase.java
                        ExternalContextUnitTestCase.java
                        SimpleUnitTestCase.java
  Log:
  Changed to descend from JBossTestCase and use logging
  
  Revision  Changes    Path
  1.2       +72 -59    
jbosstest/src/main/org/jboss/test/naming/test/ENCUnitTestCase.java
  
  Index: ENCUnitTestCase.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/naming/test/ENCUnitTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ENCUnitTestCase.java      2001/09/12 04:55:40     1.1
  +++ ENCUnitTestCase.java      2001/09/15 19:50:39     1.2
  @@ -1,3 +1,9 @@
  +/*
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.test.naming.test;
   
   import java.io.IOException;
  @@ -12,75 +18,82 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  -import org.jboss.test.util.Deploy;
  +import org.jboss.test.JBossTestCase;
   import org.jboss.test.naming.interfaces.TestENCHome;
   import org.jboss.test.naming.interfaces.TestENCHome2;
   
  -/** Tests of the secure access to EJBs.
  -@author [EMAIL PROTECTED]
  +/**
  + * Tests of the secure access to EJBs.
  + *
  + * @author   [EMAIL PROTECTED]
  + * @author   <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
    */
  -public class ENCUnitTestCase extends TestCase
  +public class ENCUnitTestCase extends JBossTestCase
   {
  -    public ENCUnitTestCase(String name)
  -    {
  -        super(name);
  -    }
  -
  -    /** Deploy the security ejb jar one time
  -     */
  -    protected void setUp() throws Exception
  -    {
  -        // Deploy.deploy("naming.jar");
  -    }
  -
  -    public void testENC() throws Exception
  -    {
  -        InitialContext jndiContext = new InitialContext();
  -        Object obj = jndiContext.lookup("ENCBean");
  -        obj = PortableRemoteObject.narrow(obj, TestENCHome.class);
  -        TestENCHome home = (TestENCHome) obj;
  -        System.out.println("Found TestENCHome");
  -
  -        EJBObject bean = home.create();
  -        System.out.println("Created ENCBean");
  -        bean.remove();
  -    }
  -
  -    public void testENC2() throws Exception
  -    {
  -        InitialContext jndiContext = new InitialContext();
  -        Object obj = jndiContext.lookup("ENCBean0");
  -        obj = PortableRemoteObject.narrow(obj, TestENCHome2.class);
  -        TestENCHome2 home = (TestENCHome2) obj;
  -        System.out.println("Found TestENCHome2");
  -
  -        EJBObject bean = home.create();
  -        System.out.println("Created ENCBean0");
  -        bean.remove();
  -    }
  -
  -    public static void main(java.lang.String[] args)
  -    {
  -        System.setErr(System.out);
  -        Test suite = suite();
  -        junit.textui.TestRunner.run(suite);
  -    }
  +   /**
  +    * Constructor for the ENCUnitTestCase object
  +    *
  +    * @param name  Testcase name
  +    */
  +   public ENCUnitTestCase(String name)
  +   {
  +      super(name);
  +   }
   
      /**
  -    * Setup the test suite.
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
       */
  -   public static Test suite() {
  -      TestSuite suite = new TestSuite();
  -        
  -      // add a test case to deploy our support applications
  -      String filename = "naming.jar";
  -      suite.addTest(new Deploy.Deployer(filename));
  +   public void testENC() throws Exception
  +   {
  +      Object obj = getInitialContext().lookup("ENCBean");
  +      obj = PortableRemoteObject.narrow(obj, TestENCHome.class);
  +      TestENCHome home = (TestENCHome)obj;
  +      getLog().debug("Found TestENCHome");
  +
  +      EJBObject bean = home.create();
  +      getLog().debug("Created ENCBean");
  +      bean.remove();
  +   }
   
  -      suite.addTest(new TestSuite(ENCUnitTestCase.class));
  +   /**
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   public void testENC2() throws Exception
  +   {
  +      Object obj = getInitialContext().lookup("ENCBean0");
  +      obj = PortableRemoteObject.narrow(obj, TestENCHome2.class);
  +      TestENCHome2 home = (TestENCHome2)obj;
  +      getLog().debug("Found TestENCHome2");
  +
  +      EJBObject bean = home.create();
  +      getLog().debug("Created ENCBean0");
  +      bean.remove();
  +   }
   
  -      // add a test case to undeploy our support applications
  -      suite.addTest(new Deploy.Undeployer(filename));
  +   /**
  +    * The setUp method for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   protected void setUp() throws Exception
  +   {
  +      super.setUp();
  +      deployJ2ee("naming.jar");
  +   }
   
  -      return suite;
  +   /**
  +    * The teardown method for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   protected void tearDown() throws Exception
  +   {
  +      undeployJ2ee("naming.jar");
  +      super.tearDown();
      }
  +
   }
  
  
  
  1.3       +107 -87   
jbosstest/src/main/org/jboss/test/naming/test/ExternalContextUnitTestCase.java
  
  Index: ExternalContextUnitTestCase.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/naming/test/ExternalContextUnitTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExternalContextUnitTestCase.java  2001/09/12 20:43:01     1.2
  +++ ExternalContextUnitTestCase.java  2001/09/15 19:50:39     1.3
  @@ -1,3 +1,9 @@
  +/*
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.test.naming.test;
   
   import java.net.InetAddress;
  @@ -14,10 +20,12 @@
   
   import org.jboss.jmx.connector.JMXConnector;
   
  -/** A test of the ExternalContext naming mbean. To test there needs to be
  -one or more ExternalContex mbeans setup. An example filesystem context
  -setup would be:
  +import org.jboss.test.JBossTestCase;
   
  +/**
  + * A test of the ExternalContext naming mbean. To test there needs to be one or
  + * more ExternalContex mbeans setup. An example filesystem context setup would
  + * be: 
     <mbean code="org.jboss.naming.ExternalContext" 
name="JBOSS-SYSTEM:service=ExternalContext,jndiName=external/fs/tmp">
       <attribute name="JndiName">external/fs/Scott</attribute>
       <attribute name="Properties">tmp.fs</attribute>
  @@ -29,91 +37,103 @@
   java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
   java.naming.provider.url=file:/tmp
   
  -@author [EMAIL PROTECTED]
  -@version $Revision: 1.2 $
  -*/
  -public class ExternalContextUnitTestCase extends junit.framework.TestCase
  + *
  + * @author    [EMAIL PROTECTED]
  + * @version   $Revision: 1.3 $
  + */
  +public class ExternalContextUnitTestCase extends JBossTestCase
   {
  -    private ObjectName[] contextNames;
  +   private ObjectName[] contextNames;
  +
   //    private JMXConnector server;
  +
  +   /**
  +    * Constructor for the ExternalContextUnitTestCase object
  +    *
  +    * @param name Testcase name
  +    */
  +   public ExternalContextUnitTestCase(String name)
  +   {
  +      super(name);
  +   }
  +
  +   /**
  +    * A unit test for JUnit
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   public void testExternalContexts() throws Exception
  +   {
  +      if (contextNames == null)
  +      {
  +         getLog().debug("No ExternalContext names exist");
  +         return;
  +      }
  +
  +      for (int n = 0; n < contextNames.length; n++)
  +      {
  +         ObjectName name = contextNames[n];
  +         String jndiName = name.getKeyProperty("jndiName");
  +         if (jndiName == null)
  +         {
  +            getLog().debug("Skipping " + name + " as it has no jndiName property");
  +            continue;
  +         }
  +         Context ctx = (Context)getInitialContext().lookup(jndiName);
  +         getLog().debug("+++ Listing for: " + ctx);
  +         list(ctx);
  +      }
  +   }
  +
  +   /**
  +    * The JUnit setup method
  +    *
  +    * @exception Exception  Description of Exception
  +    */
  +   protected void setUp() throws Exception
  +   {
  +      try
  +      {
  +         super.setUp();
  +         contextNames = null;
  +         ObjectName pattern = new ObjectName("*:service=ExternalContext,*");
  +         Set names = getServer().queryMBeans(pattern, null);
  +         Iterator iter = names.iterator();
  +         ArrayList tmp = new ArrayList();
  +         while (iter.hasNext())
  +         {
  +            ObjectInstance oi = (ObjectInstance)iter.next();
  +            ObjectName name = oi.getObjectName();
  +            getLog().debug(name);
  +            tmp.add(name);
  +         }
  +         if (tmp.size() > 0)
  +         {
  +            contextNames = new ObjectName[tmp.size()];
  +            tmp.toArray(contextNames);
  +         }
  +      }
  +      catch (Exception x)
  +      {
  +         if (x instanceof RuntimeMBeanException)
  +         {
  +            getLog().error("setUp 
RuntimeMBeanException:",((RuntimeMBeanException)x).getTargetException());
  +         }
  +         else
  +         {
  +            getLog().error("setUp Error:" , x);
  +         }
  +      }
  +   }
  +
  +   private void list(Context ctx) throws NamingException
  +   {
  +      NamingEnumeration enum = ctx.list("");
  +      while (enum.hasMore())
  +      {
  +         getLog().debug(enum.next());
  +      }
  +      enum.close();
  +   }
   
  -    public ExternalContextUnitTestCase(String name)
  -    {
  -        super(name);
  -    }
  -
  -    protected void setUp() throws Exception
  -    {
  -        try
  -        {
  -            contextNames = null;
  -            String serverName = InetAddress.getLocalHost().getHostName();
  -            JMXConnector server = (JMXConnector) new InitialContext().lookup( 
"jmx:" + serverName + ":rmi" );
  -            ObjectName pattern = new ObjectName("*:service=ExternalContext,*");
  -            Set names = server.queryMBeans(pattern, null);
  -            Iterator iter = names.iterator();
  -            ArrayList tmp = new ArrayList();
  -            while( iter.hasNext() )
  -            {
  -                ObjectInstance oi = (ObjectInstance) iter.next();
  -                ObjectName name = oi.getObjectName();
  -                System.out.println(name);
  -                tmp.add(name);
  -            }
  -            if( tmp.size() > 0 )
  -            {
  -                contextNames = new ObjectName[tmp.size()];
  -                tmp.toArray(contextNames);
  -            }
  -        }
  -        catch(Exception x)
  -        {
  -            x.printStackTrace();
  -            if (x instanceof RuntimeMBeanException)
  -            {
  -                ((RuntimeMBeanException)x).getTargetException().printStackTrace();
  -            }
  -        }
  -    }
  -
  -    public void testExternalContexts() throws Exception
  -    {
  -        if( contextNames == null )
  -        {
  -            System.out.println("No ExternalContext names exist");
  -            return;
  -        }
  -
  -        InitialContext iniCtx = new InitialContext();
  -        for(int n = 0; n < contextNames.length; n ++)
  -        {
  -            ObjectName name = contextNames[n];
  -            String jndiName = name.getKeyProperty("jndiName");
  -            if( jndiName == null )
  -            {
  -                System.out.println("Skipping "+name+" as it has no jndiName 
property");
  -                continue;
  -            }
  -            Context ctx = (Context) iniCtx.lookup(jndiName);
  -            System.out.println("+++ Listing for: "+ctx);
  -            list(ctx);
  -        }
  -    }
  -
  -    private void list(Context ctx) throws NamingException
  -    {
  -        NamingEnumeration enum = ctx.list("");
  -        while( enum.hasMore() )
  -            System.out.println(enum.next());
  -        enum.close();
  -    }
  -
  -    public static void main(String[] args) throws Exception
  -    {
  -        System.setErr(System.out);
  -        System.setSecurityManager(new SecurityManager());
  -        ExternalContextUnitTestCase test = new ExternalContextUnitTestCase("main");
  -        test.setUp();
  -        test.testExternalContexts();
  -    }
   }
  
  
  
  1.2       +25 -6     
jbosstest/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
  
  Index: SimpleUnitTestCase.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleUnitTestCase.java   2001/09/12 04:55:40     1.1
  +++ SimpleUnitTestCase.java   2001/09/15 19:50:39     1.2
  @@ -1,31 +1,50 @@
  +/*
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.test.naming.test;
   
   import javax.naming.InitialContext;
  -import javax.naming.NamingException;
   import javax.naming.NameAlreadyBoundException;
  +import javax.naming.NamingException;
   
   import junit.framework.Test;
  -import junit.framework.TestCase;
  +import org.jboss.test.JBossTestCase;
   
  -public class SimpleUnitTestCase extends TestCase
  +/**
  + * simple unit tests for the jndi implementation.
  + */
  +public class SimpleUnitTestCase extends JBossTestCase
   {
  +   /**
  +    * Constructor for the SimpleUnitTestCase object
  +    *
  +    * @param name  Test name
  +    */
      public SimpleUnitTestCase(String name)
      {
         super(name);
      }
   
  +   /**
  +    * Tests that the second time you create a subcontext you get an exception.
  +    *
  +    * @exception Exception  Description of Exception
  +    */
      public void testCreateSubcontext() throws Exception
      {
  -      InitialContext ctx = new InitialContext();
  +      InitialContext ctx = getInitialContext();
         ctx.createSubcontext("foo");
         try
         {
            ctx.createSubcontext("foo");
            fail("Second createSubcontext(foo) did NOT fail");
         }
  -      catch(NameAlreadyBoundException e)
  +      catch (NameAlreadyBoundException e)
         {
  -         System.out.println("Second createSubcontext(foo) failed as expected");
  +         getLog().debug("Second createSubcontext(foo) failed as expected");
         }
         ctx.createSubcontext("foo/bar");
         ctx.unbind("foo/bar");
  
  
  

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

Reply via email to