[jboss-cvs] JBossAS SVN: r58481 - projects/test/trunk/test/src/main/org/jboss/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 16 22:36:16 EST 2006
Author: scott.stark at jboss.org
Date: 2006-11-16 22:36:13 -0500 (Thu, 16 Nov 2006)
New Revision: 58481
Modified:
projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCaseWithSetup.java
projects/test/trunk/test/src/main/org/jboss/test/JBossTestCase.java
projects/test/trunk/test/src/main/org/jboss/test/JBossTestServices.java
projects/test/trunk/test/src/main/org/jboss/test/JBossTestSetup.java
Log:
Change JBossTestCase to extend AbstractTestCaseWithSetup to better match the usage pattern and add support for legacy JBossTestCase apis
Modified: projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCaseWithSetup.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCaseWithSetup.java 2006-11-17 00:46:32 UTC (rev 58480)
+++ projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCaseWithSetup.java 2006-11-17 03:36:13 UTC (rev 58481)
@@ -28,8 +28,8 @@
/**
* An extension of AbstractTestCase that adds AbstractTestDelegate and
- * AbstractTestSetup delegate notions. The AbstractTestSetup is integrates
- * with the junit junit.extensions.TestSetup setUp/tearDown callbacks to
+ * AbstractTestSetup delegate notions. The AbstractTestSetup integrates
+ * with the junit.extensions.TestSetup setUp/tearDown callbacks to
* create an AbstractTestDelegate. When a testcase is run as a class with
* all conforming unit test methods run, a single class wide
* AbstractTestDelegate is created by either the fist call to the setUp
@@ -54,11 +54,18 @@
super(name);
}
+ /**
+ * Get the jboss logger.
+ */
public Logger getLog()
{
return getDelegate().getLog();
}
+ /**
+ * Enable trace logging for the given category name.
+ * @param name - the logging category to enable trace level logging for.
+ */
protected void enableTrace(String name)
{
getDelegate().enableTrace(name);
Modified: projects/test/trunk/test/src/main/org/jboss/test/JBossTestCase.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/JBossTestCase.java 2006-11-17 00:46:32 UTC (rev 58480)
+++ projects/test/trunk/test/src/main/org/jboss/test/JBossTestCase.java 2006-11-17 03:36:13 UTC (rev 58481)
@@ -30,6 +30,8 @@
import javax.management.ObjectName;
import javax.naming.InitialContext;
+import org.jboss.logging.Logger;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -47,7 +49,7 @@
* @version $Revision$
*/
public class JBossTestCase
- extends BaseTestCase
+ extends AbstractTestCaseWithSetup
{
/**
@@ -56,9 +58,19 @@
protected static Exception deploymentException = null;
protected JBossTestServices delegate;
+ /** Local variable for backward compatibility */
+ protected Logger log;
+ // Static --------------------------------------------------------
+ /**
+ * Overriden to return JBossTestServices as the test delegate.
+ */
+ public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+ {
+ AbstractTestDelegate delegate = new JBossTestServices(clazz);
+ return delegate;
+ }
- // Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Constructor for the JBossTestCase object
@@ -68,21 +80,31 @@
public JBossTestCase(String name)
{
super(name);
- initDelegate();
}
- public void initDelegate()
+ /**
+ * Create a delegate by calling AbstractTestDelegate.getDelegate(clazz)
+ * to allow for a test specific delegate.
+ * This method then delegates to the AbstractTestDelegate.setUp method.
+ * @throws Exception
+ */
+ protected void setUp() throws Exception
{
- delegate = new JBossTestServices(getClass().getName());
- try
- {
- delegate.init();
- }
- catch (Exception e)
- {
- log.error("Failed to init delegate", e);
- }
+ super.setUp();
+ log = getLog();
+ delegate = (JBossTestServices) AbstractTestSetup.delegate;
}
+
+ /**
+ * This method then delegates to the AbstractTestDelegate.tearDown method.
+ * @throws Exception
+ */
+ protected void tearDown() throws Exception
+ {
+ if (delegate != null)
+ delegate.tearDown();
+ }
+
public void resetDelegate()
{
try
@@ -241,9 +263,9 @@
* @return the wrapping test that does the setup
* @throws Exception for any error
*/
- public static Test getDeploySetup(final Test test, final String jarNames) throws Exception
+ public static Test getDeploySetup(final Class clazz, final Test test, final String jarNames) throws Exception
{
- JBossTestSetup wrapper = new JBossTestSetup(test)
+ JBossTestSetup wrapper = new JBossTestSetup(clazz, test)
{
protected void setUp() throws Exception
{
@@ -296,12 +318,17 @@
return wrapper;
}
+ public static Test getDeploySetup(final Test test, final String jarName)
+ throws Exception
+ {
+ return getDeploySetup(JBossTestCase.class, test, jarName);
+ }
public static Test getDeploySetup(final Class clazz, final String jarName)
throws Exception
{
TestSuite suite = new TestSuite();
suite.addTest(new TestSuite(clazz));
- return getDeploySetup(suite, jarName);
+ return getDeploySetup(clazz, suite, jarName);
}
protected String getJndiURL()
Modified: projects/test/trunk/test/src/main/org/jboss/test/JBossTestServices.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/JBossTestServices.java 2006-11-17 00:46:32 UTC (rev 58480)
+++ projects/test/trunk/test/src/main/org/jboss/test/JBossTestServices.java 2006-11-17 03:36:13 UTC (rev 58481)
@@ -53,7 +53,7 @@
* @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
* @version $Revision$
*/
-public class JBossTestServices
+public class JBossTestServices extends AbstractTestDelegate
{
// Constants -----------------------------------------------------
public final static String DEPLOYER_NAME = "jboss.system:service=MainDeployer";
@@ -66,11 +66,23 @@
// Attributes ----------------------------------------------------
protected MBeanServerConnection server;
- protected Logger log;
protected InitialContext initialContext;
protected Hashtable jndiEnv;
protected LoginContext lc;
+ private static Class getClass(String className)
+ {
+ Class clazz;
+ try
+ {
+ clazz = Class.forName(className);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ return clazz;
+ }
/**
* Constructor for the JBossTestCase object
*
@@ -78,9 +90,12 @@
*/
public JBossTestServices(String className)
{
- log = Logger.getLogger(className);
- log.debug("JBossTestServices(), className=" + className);
+ super(getClass(className));
}
+ public JBossTestServices(Class clazz)
+ {
+ super(clazz);
+ }
// Public --------------------------------------------------------
@@ -91,6 +106,8 @@
*/
public void setUp() throws Exception
{
+ super.setUp();
+ log = getLog();
log.debug("JBossTestServices.setUp()");
init();
log.info("jbosstest.beancount: " + System.getProperty("jbosstest.beancount"));
@@ -141,16 +158,6 @@
}
/**
- * Gets the Log attribute of the JBossTestCase object
- *
- * @return The Log value
- */
- Logger getLog()
- {
- return log;
- }
-
- /**
* Gets the Main Deployer Name attribute of the JBossTestCase object
*
* @return The Main DeployerName value
Modified: projects/test/trunk/test/src/main/org/jboss/test/JBossTestSetup.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/JBossTestSetup.java 2006-11-17 00:46:32 UTC (rev 58480)
+++ projects/test/trunk/test/src/main/org/jboss/test/JBossTestSetup.java 2006-11-17 03:36:13 UTC (rev 58481)
@@ -52,7 +52,7 @@
* @version $Revision$
*/
public class JBossTestSetup
- extends TestSetup
+ extends AbstractTestSetup
{
protected JBossTestServices delegate;
@@ -62,18 +62,30 @@
* @param test the test
* @throws Exception for any error
*/
+ public JBossTestSetup(final Class clazz, Test test) throws Exception
+ {
+ super(clazz, test);
+ }
public JBossTestSetup(Test test) throws Exception
{
- super(test);
- delegate = createTestServices();
- delegate.init();
+ super(JBossTestCase.class, test);
}
- protected JBossTestServices createTestServices()
+ @Override
+ protected void setUp() throws Exception
{
- return new JBossTestServices(getClass().getName());
+ super.setUp();
+ this.delegate = (JBossTestServices) AbstractTestSetup.delegate;
}
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // TODO Auto-generated method stub
+ super.tearDown();
+ }
+
+
/**
* Gets the InitialContext attribute of the JBossTestCase object
*
More information about the jboss-cvs-commits
mailing list