User: d_jencks
  Date: 01/07/27 12:32:03

  Added:       src/main/org/jboss/test/jmx/test
                        TestConnectionFactoryLoader.java
  Log:
  Added test for ConnectionFactoryLoader load-after-rar-deployed functionality
  
  Revision  Changes    Path
  1.1                  
jbosstest/src/main/org/jboss/test/jmx/test/TestConnectionFactoryLoader.java
  
  Index: TestConnectionFactoryLoader.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.test.jmx.test;
  
  import java.net.InetAddress;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Set;
  import javax.management.Attribute;
  import javax.management.AttributeList;
  import javax.management.MBeanRegistrationException;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.RuntimeMBeanException;
  import javax.management.ReflectionException;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingEnumeration;
  import javax.naming.NamingException;
  
  //import org.jboss.jmx.interfaces.JMXAdaptor;
  import org.jboss.jmx.interfaces.RMIConnector;
  import org.jboss.jmx.interfaces.RMINotificationListener;
  
  import junit.framework.*;
  
  //test bean
  import javax.ejb.*;
  import org.jboss.test.jmx.interfaces.*;
  
  /**
   *      
   *   @see <related>
   *   @author $Author: d_jencks $
   *   @version $Revision: 1.1 $
   */
  public class TestConnectionFactoryLoader
     extends TestCase
  {
     // Constants -----------------------------------------------------
      
     // Attributes ----------------------------------------------------
     protected RMIConnector server;
     
     // Static --------------------------------------------------------
     // Constructors --------------------------------------------------
     public TestConnectionFactoryLoader(String name)
     {
        super(name);
     }
     
     // Public --------------------------------------------------------
     /**
      * Setup the test suite.
      */
     public static Test suite() {
        TestSuite suite = new TestSuite(TestConnectionFactoryLoader.class);
        
        
        return suite;
     }
  
  
     public void setUp() throws Exception {
        String serverName = InetAddress.getLocalHost().getHostName();
        server = (RMIConnector) new InitialContext().lookup("jmx:" + serverName + 
":rmi");
     }
  
     public void tearDown() throws Exception {
        server = null;
     }
  
     public void testServerFound() throws Exception {
        assert("Server was not found", server != null);
     }
  
     public void testAddRemoveConnectionFactory() throws Exception {
        
  
        //the mbean we are trying to deploy/undeploy
        ObjectName connectionFactoryLoaderName = new 
ObjectName("Test:service=ConnectionFactoryLoader,name=TestDS");
  
        //check it isn't there already
        assert("test mbean already registered", 
!server.isRegistered(connectionFactoryLoaderName));
        //try to create the connection factory loader.
        assert("server did not return an objectInstance", 
               server.createMBean("org.jboss.resource.ConnectionFactoryLoader", 
                                  connectionFactoryLoaderName) != null);
        
        //check deployment registered connection factory loader
        assert("test mbean not registered", 
server.isRegistered(connectionFactoryLoaderName));
  
        AttributeList al = new AttributeList();
        al.add(new Attribute("FactoryName", "ConnectionFactoryLoaderTestDS"));
        al.add(new Attribute("RARDeployerName", "JCA:service=RARDeployer"));
        al.add(new Attribute("ResourceAdapterName", "Minerva JDBC LocalTransaction 
ResourceAdapter"));
        al.add(new Attribute("Properties", 
"ConnectionURL=jdbc:HypersonicSQL:hsql://localhost:1476"));
        al.add(new Attribute("ConnectionManagerFactoryName", 
"MinervaSharedLocalCMFactory"));
        al.add(new Attribute("ConnectionManagerProperties", "MinSize=0\n"
           + " MaxSize=10\n"
           + " Blocking=true\n"
           + " GCEnabled=false\n"
           + " IdleTimeoutEnabled=false\n"
           + " InvalidateOnError=false\n"
           + " TrackLastUsed=false\n"
           + " GCIntervalMillis=120000\n"
           + " GCMinIdleMillis=1200000\n"
           + " IdleTimeoutMillis=1800000\n"
           + " MaxIdleTimeoutPercent=1.0"));
        al.add(new Attribute("PrincipalMappingClass", 
"org.jboss.resource.security.ManyToOnePrincipalMapping"));
        al.add(new Attribute("PrincipalMappingProperties", "userName=sa\n"
           + " password="));
        //try to set the attributes on the bean
        assert("setAttributes returned null", 
server.setAttributes(connectionFactoryLoaderName, al) != null);
  
        Object[] args = {};
        String[] sig = {};
  
        server.invoke(connectionFactoryLoaderName, "init", args, sig);
        server.invoke(connectionFactoryLoaderName, "start", args, sig);
  
        assert("State is not started", 
"Started".equals(server.getAttribute(connectionFactoryLoaderName, "StateString")));
  
        //deploy test session bean to look up datasource
        ObjectName j2eeDeployerName = new ObjectName("J2EE:service=J2eeDeployer");
  
        String ejbpath = System.getProperty("jbosstest.deploy.dir");
        ejbpath = (new java.io.File(ejbpath)).getCanonicalPath();
        assert("jbosstest.deploy.dir system property not set- cant deploy test jar", 
ejbpath != null);
        Object[] depArgs = {"file://" + ejbpath + "/jmxtestejb.jar"};
        String[] depSig = {"java.lang.String"};
        server.invoke(j2eeDeployerName, "deploy", depArgs, depSig);
  
        InitialContext ctx = new InitialContext();
        TestDataSourceHome tdshome = 
(TestDataSourceHome)ctx.lookup("test/TestDataSource");
        TestDataSource tds = tdshome.create();
        tds.testDataSource("java:ConnectionFactoryLoaderTestDS");
  
        server.invoke(j2eeDeployerName, "undeploy", depArgs, depSig);
  
  
        //undeploy test connection factory loader.
        server.invoke(connectionFactoryLoaderName, "stop",  args, sig);
        server.invoke(connectionFactoryLoaderName, "destroy",  args, sig);
  
        server.unregisterMBean(connectionFactoryLoaderName);
  
        //check it isn't there any more
        assert("connection factory loader mbean still registered", 
!server.isRegistered(connectionFactoryLoaderName));
     }
  
  }
  
  
  

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

Reply via email to