User: d_jencks
Date: 02/04/09 18:06:03
Added: src/main/org/jboss/test/jmx/test
DeployConnectionManagerUnitTestCase.java
Removed: src/main/org/jboss/test/jmx/test
ConnectionFactoryLoaderUnitTestCase.java
Log:
updated test case for how to construct a DataSource programatically
Revision Changes Path
1.1
jbosstest/src/main/org/jboss/test/jmx/test/DeployConnectionManagerUnitTestCase.java
Index: DeployConnectionManagerUnitTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* 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;
//test bean
import javax.ejb.*;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.MBeanRegistrationException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeMBeanException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import junit.framework.*;
import org.jboss.test.JBossTestCase;
import org.jboss.test.jmx.interfaces.*;
/**
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
* @version $Revision: 1.1 $
*/
public class DeployConnectionManagerUnitTestCase
extends JBossTestCase
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Constructor for the DeployConnectionManagerUnitTestCase object
*
* @param name Testcase name
*/
public DeployConnectionManagerUnitTestCase(String name)
{
super(name);
}
// Public --------------------------------------------------------
/**
* Test that a connection factory can be deployed after the rar it depends on
* is deployed. Use an ejb to make sure that the DataSource defined is
* actually bound in jndi. Undeploy and make sure the mbean is no longer
* registered.
*
* @exception Exception Description of Exception
*/
public void testAddRemoveConnectionManager() throws Exception
{
//the mbean we are trying to deploy/undeploy
ObjectName cmName = new ObjectName("jboss.jca:service=LocalTxCM,name=TestDS");
//try to remove mbean if leftover...
if (getServer().isRegistered(cmName))
{
getServer().unregisterMBean(cmName);
}
//check it isn't there already
assertTrue("test mbean already registered", !getServer().isRegistered(cmName));
//try to create the cm.
assertTrue("server did not return an objectInstance",
getServer().createMBean("org.jboss.resource.connectionmanager.LocalTxConnectionManager",
cmName) != null);
//check deployment registered cm
assertTrue("test mbean not registered", getServer().isRegistered(cmName));
ObjectName mcfName = new ObjectName("jboss.jca:service=LocalTxDS,name=TestDS");
//try to remove mbean if leftover...
if (getServer().isRegistered(mcfName))
{
getServer().unregisterMBean(mcfName);
}
//check it isn't there already
assertTrue("test mbean already registered",
!getServer().isRegistered(mcfName));
//try to create the RARDeployment.
assertTrue("server did not return an objectInstance",
getServer().createMBean("org.jboss.resource.connectionmanager.RARDeployment",
mcfName) != null);
//check deployment registered RARDeployment
assertTrue("test mbean not registered", getServer().isRegistered(mcfName));
ObjectName mcpName = new
ObjectName("jboss.jca:service=LocalTxPool,name=TestDS");
//try to remove mbean if leftover...
if (getServer().isRegistered(mcpName))
{
getServer().unregisterMBean(mcpName);
}
//check it isn't there already
assertTrue("test mbean already registered",
!getServer().isRegistered(mcpName));
//try to create the pool.
assertTrue("server did not return an objectInstance",
getServer().createMBean("org.jboss.resource.connectionmanager.JBossManagedConnectionPool",
mcpName) != null);
//check deployment registered connection factory loader
assertTrue("test mbean not registered", getServer().isRegistered(mcpName));
ObjectName serviceControllerName = new
ObjectName("jboss.system:service=ServiceController");
//anon block so I don't rename var al
{
AttributeList al = new AttributeList();
al.add(new Attribute("ManagedConnectionFactoryName", mcfName));
al.add(new Attribute("ManagedConnectionPool", mcpName));
al.add(new Attribute("CachedConnectionManager", new
ObjectName("jboss.jca:service=CachedConnectionManager")));
//al.add(new Attribute("SecurityDomainJndiName", "java:/jaas/TestRealm"));
al.add(new Attribute("TransactionManager", "java:/TransactionManager"));
//try to set the attributes on the bean
assertTrue("setAttributes returned null", getServer().setAttributes(cmName,
al) != null);
}//anon block so I don't rename var
//RARDeployment
{
AttributeList al = new AttributeList();
al.add(new Attribute("JndiName", "ConnectionManagerTestDS"));
al.add(new Attribute("ManagedConnectionFactoryClass",
"org.jboss.resource.adapter.jdbc.local.JDBCManagedConnectionFactory"));
//try to set the attributes on the bean
assertTrue("setAttributes returned null",
getServer().setAttributes(mcfName, al) != null);
}//anon block so I don't rename var
{
AttributeList al = new AttributeList();
al.add(new Attribute("MinSize", new Integer(0)));
al.add(new Attribute("MaxSize", new Integer(50)));
al.add(new Attribute("BlockingTimeoutMillis", new Long(5000)));
al.add(new Attribute("IdleTimeoutMinutes", new Integer(15)));
al.add(new Attribute("Criteria", "ByContainer"));
//try to set the attributes on the bean
assertTrue("setAttributes returned null",
getServer().setAttributes(mcpName, al) != null);
}//anon block so I don't rename var
//start the mbeans
/*
assertTrue("State is not started",
"Started".equals(getServer().getAttribute(cmName, "StateString")));
//invoke(cmName, "start", args, sig);
invoke(serviceControllerName,
"create",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"start",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
assertTrue("State is not started",
"Started".equals(getServer().getAttribute(cmName, "StateString")));*/
invoke(serviceControllerName,
"create",
new Object[] {mcpName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"start",
new Object[] {mcpName},
new String[] {"javax.management.ObjectName"});
assertTrue("State is not started",
"Started".equals(getServer().getAttribute(mcpName, "StateString")));
//invoke(cmName, "start", args, sig);
invoke(serviceControllerName,
"create",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"start",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
//Now set the important attributes:
invoke(mcfName, "setManagedConnectionFactoryAttribute",
new Object[] {"ConnectionURL", java.lang.String.class,
"jdbc:hsqldb:hsql://localhost:1476"},
new String[] {"java.lang.String", "java.lang.Class",
"java.lang.Object"});
invoke(mcfName, "setManagedConnectionFactoryAttribute",
new Object[] {"DriverClass", java.lang.String.class,
"org.hsqldb.jdbcDriver"},
new String[] {"java.lang.String", "java.lang.Class",
"java.lang.Object"});
invoke(mcfName, "setManagedConnectionFactoryAttribute",
new Object[] {"UserName", java.lang.String.class, "sa"},
new String[] {"java.lang.String", "java.lang.Class",
"java.lang.Object"});
invoke(mcfName, "setManagedConnectionFactoryAttribute",
new Object[] {"Password", java.lang.String.class, ""},
new String[] {"java.lang.String", "java.lang.Class",
"java.lang.Object"});
//deploy test session bean to look up datasource
deploy("jmxtest.jar");
//see if the ConnectionFactory was loaded and works
InitialContext ctx = getInitialContext();
TestDataSourceHome tdshome =
(TestDataSourceHome)ctx.lookup("test/TestDataSource");
TestDataSource tds = tdshome.create();
tds.testDataSource("java:ConnectionManagerTestDS");
//undeploy the test ejb
undeploy("jmxtest.jar");
//undeploy test connection factory loader.
invoke(serviceControllerName,
"stop",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"destroy",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"remove",
new Object[] {cmName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"stop",
new Object[] {mcfName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"destroy",
new Object[] {mcfName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"remove",
new Object[] {mcfName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"stop",
new Object[] {mcpName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"destroy",
new Object[] {mcpName},
new String[] {"javax.management.ObjectName"});
invoke(serviceControllerName,
"remove",
new Object[] {mcpName},
new String[] {"javax.management.ObjectName"});
//check that the connection factory loader is no longer registered
assertTrue("connection factory loader mbean still registered",
!getServer().isRegistered(cmName));
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development