User: d_jencks
Date: 01/09/17 10:33:53
Modified: src/main/org/jboss/test JBossTestCase.java
Added: src/main/org/jboss/test JBossTestServices.java
JBossTestSetup.java
Log:
Finished converting to JBossTestCase for deploy and logging. Security tests still
do not work due to deploy problems
Revision Changes Path
1.3 +26 -119 jbosstest/src/main/org/jboss/test/JBossTestCase.java
Index: JBossTestCase.java
===================================================================
RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/JBossTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JBossTestCase.java 2001/09/15 00:12:16 1.2
+++ JBossTestCase.java 2001/09/17 17:33:52 1.3
@@ -42,22 +42,14 @@
* ../lib).
*
* @author <a href="[EMAIL PROTECTED]">David Jencks</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class JBossTestCase
extends TestCase
{
- // Constants -----------------------------------------------------
- private final static String serviceDeployerName =
"JBOSS-SYSTEM:service=ServiceDeployer";
- private final static String j2eeDeployerName = "J2EE:service=J2eeDeployer";
-
- // Attributes ----------------------------------------------------
- private RMIConnector server;
- private Category log;
- private InitialContext initialContext;
+ private JBossTestServices delegate;
- private HashSet deployed = new HashSet();
// Static --------------------------------------------------------
@@ -70,50 +62,45 @@
public JBossTestCase(String name)
{
super(name);
+ delegate = new JBossTestServices(getClass().getName());
}
// Public --------------------------------------------------------
/**
- * The JUnit setup method
+ * This just checks the server is there... so you should get at least one
+ * success!
*
* @exception Exception Description of Exception
*/
- protected void setUp() throws Exception
+ public void testServerFound() throws Exception
{
- log = Category.getInstance(getClass().getName());
- String serverName = System.getProperty("jbosstest.server.name");
- if (serverName == null)
- {
- serverName = InetAddress.getLocalHost().getHostName();
- }
- initialContext = new InitialContext();
- server = (RMIConnector)getInitialContext().lookup("jmx:" + serverName +
":rmi");
+ assertTrue("Server was not found", getServer() != null);
}
/**
- * The teardown method for JUnit
+ * The JUnit setup method
*
* @exception Exception Description of Exception
*/
- protected void tearDown() throws Exception
+ protected void setUp() throws Exception
{
- server = null;
+ delegate.setUp();
}
/**
- * This just checks the server is there... so you should get at least one
- * success!
+ * The teardown method for JUnit
*
* @exception Exception Description of Exception
*/
- public void testServerFound() throws Exception
+ protected void tearDown() throws Exception
{
- assertTrue("Server was not found", server != null);
+ delegate.tearDown();
}
+
//protected---------
/**
@@ -123,7 +110,7 @@
*/
protected InitialContext getInitialContext()
{
- return initialContext;
+ return delegate.getInitialContext();
}
/**
@@ -133,7 +120,7 @@
*/
protected RMIConnector getServer()
{
- return server;
+ return delegate.getServer();
}
/**
@@ -143,7 +130,7 @@
*/
protected Category getLog()
{
- return log;
+ return delegate.getLog();
}
/**
@@ -154,7 +141,7 @@
*/
protected ObjectName getServiceDeployerName() throws MalformedObjectNameException
{
- return new ObjectName(serviceDeployerName);
+ return delegate.getServiceDeployerName();
}
/**
@@ -165,7 +152,7 @@
*/
protected ObjectName getJ2eeDeployerName() throws MalformedObjectNameException
{
- return new ObjectName(j2eeDeployerName);
+ return delegate.getJ2eeDeployerName();
}
@@ -182,30 +169,7 @@
*/
protected String getDeployURL(final String filename) throws MalformedURLException
{
- //First see if it is already a complete url.
- try
- {
- return new URL(filename).toString();
- }
- catch (MalformedURLException mue)
- {
- }
- //OK, lets see if we can figure out what it might be.
- String deployDir = System.getProperty("jbosstest.deploy.dir");
- if (deployDir == null)
- {
- deployDir = "../lib";
- }
- String url = deployDir + "/" + filename;
- //try to canonicalize the strings a bit.
- if (new File(url).exists())
- {
- return new File(url).toURL().toString();
- }
- else
- {
- return new URL(url).toString();
- }
+ return delegate.getDeployURL(filename);
}
@@ -218,7 +182,7 @@
*/
protected boolean isDeployed(String name)
{
- return deployed.contains(name);
+ return delegate.isDeployed(name);
}
/**
@@ -234,35 +198,7 @@
*/
protected Object invoke(ObjectName name, String method, Object[] args, String[]
sig) throws Exception
{
- try
- {
- return getServer().invoke(name, method, args, sig);
- }
- catch (MBeanException e)
- {
- log.error("MbeanException", e.getTargetException());
- throw e.getTargetException();
- }
- catch (ReflectionException e)
- {
- log.error("ReflectionException", e.getTargetException());
- throw e.getTargetException();
- }
- catch (RuntimeOperationsException e)
- {
- log.error("RuntimeOperationsException", e.getTargetException());
- throw e.getTargetException();
- }
- catch (RuntimeMBeanException e)
- {
- log.error("RuntimeMbeanException", e.getTargetException());
- throw e.getTargetException();
- }
- catch (RuntimeErrorException e)
- {
- log.error("RuntimeErrorException", e.getTargetError());
- throw e.getTargetError();
- }
+ return delegate.invoke(name, method, args, sig);
}
/**
@@ -274,12 +210,7 @@
*/
protected void deployJ2ee(String name) throws Exception
{
- String deployName = getDeployURL(name);
- invoke(getJ2eeDeployerName(),
- "deploy",
- new Object[]{deployName},
- new String[]{"java.lang.String"});
- setDeployed(deployName);
+ delegate.deployJ2ee(name);
}
/**
@@ -291,12 +222,7 @@
*/
protected void undeployJ2ee(String name) throws Exception
{
- String deployName = getDeployURL(name);
- invoke(getJ2eeDeployerName(),
- "undeploy",
- new Object[]{deployName},
- new String[]{"java.lang.String"});
- setUnDeployed(deployName);
+ delegate.undeployJ2ee(name);
}
/**
@@ -309,12 +235,7 @@
*/
protected void deployService(String name) throws Exception
{
- String deployName = getDeployURL(name);
- invoke(getServiceDeployerName(),
- "deploy",
- new Object[]{deployName},
- new String[]{"java.lang.String"});
- setDeployed(deployName);
+ delegate.deployService(name);
}
/**
@@ -327,24 +248,10 @@
*/
protected void undeployService(String name) throws Exception
{
- String deployName = getDeployURL(name);
- invoke(getServiceDeployerName(),
- "undeploy",
- new Object[]{deployName},
- new String[]{"java.lang.String"});
- setUnDeployed(deployName);
+ delegate.undeployService(name);
}
//private methods--------------
- private void setDeployed(String name)
- {
- deployed.add(name);
- }
-
- private void setUnDeployed(String name)
- {
- deployed.remove(name);
- }
}
1.1 jbosstest/src/main/org/jboss/test/JBossTestServices.java
Index: JBossTestServices.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test;
import java.io.File;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import javax.management.MBeanException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import org.apache.log4j.Category;
import org.jboss.jmx.connector.rmi.RMIConnector;
/**
* This is provides services for jboss junit test cases and TestSetups. It supplies
* access to log4j logging, the jboss jmx server, jndi, and a method for
* deploying ejb packages. You may supply the name of the machine the jboss
* server is on with the system property jbosstest.server.name (default
* getInetAddress().getLocalHost().getHostName()) and the directory for
* deployable packages with the system property jbosstest.deploy.dir (default
* ../lib).
*
* @author <a href="[EMAIL PROTECTED]">David Jencks</a>
* @version $Revision: 1.1 $
*/
public class JBossTestServices
{
// Constants -----------------------------------------------------
private final static String serviceDeployerName =
"JBOSS-SYSTEM:service=ServiceDeployer";
private final static String j2eeDeployerName = "J2EE:service=J2eeDeployer";
// Attributes ----------------------------------------------------
private RMIConnector server;
private Category log;
private InitialContext initialContext;
private HashSet deployed = new HashSet();
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Constructor for the JBossTestCase object
*
* @param name Test case name
*/
public JBossTestServices(String className)
{
log = Category.getInstance(className);
}
// Public --------------------------------------------------------
/**
* The JUnit setup method
*
* @exception Exception Description of Exception
*/
void setUp() throws Exception
{
String serverName = System.getProperty("jbosstest.server.name");
if (serverName == null)
{
serverName = InetAddress.getLocalHost().getHostName();
}
initialContext = new InitialContext();
server = (RMIConnector)getInitialContext().lookup("jmx:" + serverName +
":rmi");
}
/**
* The teardown method for JUnit
*
* @exception Exception Description of Exception
*/
void tearDown() throws Exception
{
server = null;
}
//protected---------
/**
* Gets the InitialContext attribute of the JBossTestCase object
*
* @return The InitialContext value
*/
InitialContext getInitialContext()
{
return initialContext;
}
/**
* Gets the Server attribute of the JBossTestCase object
*
* @return The Server value
*/
RMIConnector getServer()
{
return server;
}
/**
* Gets the Log attribute of the JBossTestCase object
*
* @return The Log value
*/
Category getLog()
{
return log;
}
/**
* Gets the ServiceDeployerName attribute of the JBossTestCase object
*
* @return The ServiceDeployerName value
* @exception MalformedObjectNameException Description of Exception
*/
ObjectName getServiceDeployerName() throws MalformedObjectNameException
{
return new ObjectName(serviceDeployerName);
}
/**
* Gets the J2eeDeployerName attribute of the JBossTestCase object
*
* @return The J2eeDeployerName value
* @exception MalformedObjectNameException Description of Exception
*/
ObjectName getJ2eeDeployerName() throws MalformedObjectNameException
{
return new ObjectName(j2eeDeployerName);
}
/**
* Returns the deployment directory to use. This does it's best to figure out
* where you are looking. If you supply a complete url, it returns it.
* Otherwise, it looks for jbosstest.deploy.dir or if missing ../lib. Then it
* tries to construct a file url or a url.
*
* @param filename name of the file/url you want
* @return A more or less canonical string for the
* url.
* @exception MalformedURLException Description of Exception
*/
String getDeployURL(final String filename) throws MalformedURLException
{
//First see if it is already a complete url.
try
{
return new URL(filename).toString();
}
catch (MalformedURLException mue)
{
}
//OK, lets see if we can figure out what it might be.
String deployDir = System.getProperty("jbosstest.deploy.dir");
if (deployDir == null)
{
deployDir = "../lib";
}
String url = deployDir + "/" + filename;
//try to canonicalize the strings a bit.
if (new File(url).exists())
{
return new File(url).toURL().toString();
}
else
{
return new URL(url).toString();
}
}
//is this good for something??????
/**
* Gets the Deployed attribute of the JBossTestCase object
*
* @param name Description of Parameter
* @return The Deployed value
*/
boolean isDeployed(String name)
{
return deployed.contains(name);
}
/**
* invoke wraps an invoke call to the mbean server in a lot of exception
* unwrapping.
*
* @param name ObjectName of the mbean to be called
* @param method mbean method to be called
* @param args Object[] of arguments for the mbean method.
* @param sig String[] of types for the mbean methods parameters.
* @return Object returned by mbean method invocation.
* @exception Exception Description of Exception
*/
Object invoke(ObjectName name, String method, Object[] args, String[] sig) throws
Exception
{
try
{
return getServer().invoke(name, method, args, sig);
}
catch (MBeanException e)
{
log.error("MbeanException", e.getTargetException());
throw e.getTargetException();
}
catch (ReflectionException e)
{
log.error("ReflectionException", e.getTargetException());
throw e.getTargetException();
}
catch (RuntimeOperationsException e)
{
log.error("RuntimeOperationsException", e.getTargetException());
throw e.getTargetException();
}
catch (RuntimeMBeanException e)
{
log.error("RuntimeMbeanException", e.getTargetException());
throw e.getTargetException();
}
catch (RuntimeErrorException e)
{
log.error("RuntimeErrorException", e.getTargetError());
throw e.getTargetError();
}
}
/**
* Deploy a j2ee package with the J2E deployer. The supplied name is
* interpreted as a url, or as a filename in jbosstest.deploy.lib or ../lib.
*
* @param name filename/url of package to deploy.
* @exception Exception Description of Exception
*/
void deployJ2ee(String name) throws Exception
{
String deployName = getDeployURL(name);
invoke(getJ2eeDeployerName(),
"deploy",
new Object[]{deployName},
new String[]{"java.lang.String"});
setDeployed(deployName);
}
/**
* Undeploy a j2ee package with the J2E deployer. The supplied name is
* interpreted as a url, or as a filename in jbosstest.deploy.lib or ../lib.
*
* @param name filename/url of package to undeploy.
* @exception Exception Description of Exception
*/
void undeployJ2ee(String name) throws Exception
{
String deployName = getDeployURL(name);
invoke(getJ2eeDeployerName(),
"undeploy",
new Object[]{deployName},
new String[]{"java.lang.String"});
setUnDeployed(deployName);
}
/**
* Deploy a jboss service package with the service deployer. The supplied
* name is interpreted as a url, or as a filename in jbosstest.deploy.lib or
* ../lib.
*
* @param name filename/url of package to deploy.
* @exception Exception Description of Exception
*/
void deployService(String name) throws Exception
{
String deployName = getDeployURL(name);
invoke(getServiceDeployerName(),
"deploy",
new Object[]{deployName},
new String[]{"java.lang.String"});
setDeployed(deployName);
}
/**
* Undeploy a jboss service package with the service deployer. The supplied
* name is interpreted as a url, or as a filename in jbosstest.deploy.lib or
* ../lib.
*
* @param name filename/url of package to undeploy.
* @exception Exception Description of Exception
*/
void undeployService(String name) throws Exception
{
String deployName = getDeployURL(name);
invoke(getServiceDeployerName(),
"undeploy",
new Object[]{deployName},
new String[]{"java.lang.String"});
setUnDeployed(deployName);
}
//private methods--------------
private void setDeployed(String name)
{
deployed.add(name);
}
private void setUnDeployed(String name)
{
deployed.remove(name);
}
}
1.1 jbosstest/src/main/org/jboss/test/JBossTestSetup.java
Index: JBossTestSetup.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test;
import java.io.File;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import javax.management.MBeanException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import junit.extensions.TestSetup;
import junit.framework.Test;
import org.apache.log4j.Category;
import org.jboss.jmx.connector.rmi.RMIConnector;
/**
* This is a TestSetup class for jboss junit test cases that provides the
*jboss test services. It supplies
* access to log4j logging, the jboss jmx server, jndi, and a method for
* deploying ejb packages. You may supply the name of the machine the jboss
* server is on with the system property jbosstest.server.name (default
* getInetAddress().getLocalHost().getHostName()) and the directory for
* deployable packages with the system property jbosstest.deploy.dir (default
* ../lib).
*
* @author <a href="[EMAIL PROTECTED]">David Jencks</a>
* @version $Revision: 1.1 $
*/
public class JBossTestSetup
extends TestSetup
{
private JBossTestServices delegate;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Constructor for the JBossTestCase object
*
* @param name Test case name
*/
public JBossTestSetup(Test test)
{
super(test);
delegate = new JBossTestServices(getClass().getName());
}
// Public --------------------------------------------------------
/**
* The JUnit setup method
*
* @exception Exception Description of Exception
*/
protected void setUp() throws Exception
{
delegate.setUp();
}
/**
* The teardown method for JUnit
*
* @exception Exception Description of Exception
*/
protected void tearDown() throws Exception
{
delegate.tearDown();
}
//protected---------
/**
* Gets the InitialContext attribute of the JBossTestCase object
*
* @return The InitialContext value
*/
protected InitialContext getInitialContext()
{
return delegate.getInitialContext();
}
/**
* Gets the Server attribute of the JBossTestCase object
*
* @return The Server value
*/
protected RMIConnector getServer()
{
return delegate.getServer();
}
/**
* Gets the Log attribute of the JBossTestCase object
*
* @return The Log value
*/
protected Category getLog()
{
return delegate.getLog();
}
/**
* Gets the ServiceDeployerName attribute of the JBossTestCase object
*
* @return The ServiceDeployerName value
* @exception MalformedObjectNameException Description of Exception
*/
protected ObjectName getServiceDeployerName() throws MalformedObjectNameException
{
return delegate.getServiceDeployerName();
}
/**
* Gets the J2eeDeployerName attribute of the JBossTestCase object
*
* @return The J2eeDeployerName value
* @exception MalformedObjectNameException Description of Exception
*/
protected ObjectName getJ2eeDeployerName() throws MalformedObjectNameException
{
return delegate.getJ2eeDeployerName();
}
/**
* Returns the deployment directory to use. This does it's best to figure out
* where you are looking. If you supply a complete url, it returns it.
* Otherwise, it looks for jbosstest.deploy.dir or if missing ../lib. Then it
* tries to construct a file url or a url.
*
* @param filename name of the file/url you want
* @return A more or less canonical string for the
* url.
* @exception MalformedURLException Description of Exception
*/
protected String getDeployURL(final String filename) throws MalformedURLException
{
return delegate.getDeployURL(filename);
}
//is this good for something??????
/**
* Gets the Deployed attribute of the JBossTestCase object
*
* @param name Description of Parameter
* @return The Deployed value
*/
protected boolean isDeployed(String name)
{
return delegate.isDeployed(name);
}
/**
* invoke wraps an invoke call to the mbean server in a lot of exception
* unwrapping.
*
* @param name ObjectName of the mbean to be called
* @param method mbean method to be called
* @param args Object[] of arguments for the mbean method.
* @param sig String[] of types for the mbean methods parameters.
* @return Object returned by mbean method invocation.
* @exception Exception Description of Exception
*/
protected Object invoke(ObjectName name, String method, Object[] args, String[]
sig) throws Exception
{
return delegate.invoke(name, method, args, sig);
}
/**
* Deploy a j2ee package with the J2E deployer. The supplied name is
* interpreted as a url, or as a filename in jbosstest.deploy.lib or ../lib.
*
* @param name filename/url of package to deploy.
* @exception Exception Description of Exception
*/
protected void deployJ2ee(String name) throws Exception
{
delegate.deployJ2ee(name);
}
/**
* Undeploy a j2ee package with the J2E deployer. The supplied name is
* interpreted as a url, or as a filename in jbosstest.deploy.lib or ../lib.
*
* @param name filename/url of package to undeploy.
* @exception Exception Description of Exception
*/
protected void undeployJ2ee(String name) throws Exception
{
delegate.undeployJ2ee(name);
}
/**
* Deploy a jboss service package with the service deployer. The supplied
* name is interpreted as a url, or as a filename in jbosstest.deploy.lib or
* ../lib.
*
* @param name filename/url of package to deploy.
* @exception Exception Description of Exception
*/
protected void deployService(String name) throws Exception
{
delegate.deployService(name);
}
/**
* Undeploy a jboss service package with the service deployer. The supplied
* name is interpreted as a url, or as a filename in jbosstest.deploy.lib or
* ../lib.
*
* @param name filename/url of package to undeploy.
* @exception Exception Description of Exception
*/
protected void undeployService(String name) throws Exception
{
delegate.undeployService(name);
}
//private methods--------------
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development