[jboss-cvs] JBossAS SVN: r111520 - branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 3 16:28:03 EDT 2011
Author: jiwils
Date: 2011-06-03 16:28:02 -0400 (Fri, 03 Jun 2011)
New Revision: 111520
Modified:
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/CommonsLoggingBaseTestCase.java
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLFalseTestCase.java
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLTrueTestCase.java
Log:
Refactored tests to be host agnostic and de-duplicate common code for JBPAPP-6523.
Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/CommonsLoggingBaseTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/CommonsLoggingBaseTestCase.java 2011-06-03 17:39:18 UTC (rev 111519)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/CommonsLoggingBaseTestCase.java 2011-06-03 20:28:02 UTC (rev 111520)
@@ -22,7 +22,12 @@
package org.jboss.test.commons_logging.jbpapp6523.test;
import java.io.File;
+import java.io.IOException;
+
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.URL;
+
import java.util.Properties;
import javax.management.MalformedObjectNameException;
@@ -30,13 +35,14 @@
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
-import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import junit.framework.TestCase;
+import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.MainDeployerMBean;
+
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
/**
@@ -51,45 +57,46 @@
*/
public abstract class CommonsLoggingBaseTestCase extends TestCase
{
- private String host = "localhost";
-
- protected final String DEPLOYMENT_URL =
+ private final String DEPLOYMENT_URL =
"file://" + new File("lib/jbpapp6523.war").getAbsolutePath();
-
- /**
- * Tests that the test servlet is available and that the response code
- * is as expected.
- */
- protected void assertServlet(int expectedResponseCode)
+
+ /* TestCase Overrides */
+
+ protected void setUp()
+ throws DeploymentException, MalformedObjectNameException,
+ MalformedURLException, NamingException
{
+ getMainDeployer().deploy(DEPLOYMENT_URL);
}
+ protected void tearDown()
+ throws DeploymentException, MalformedObjectNameException,
+ MalformedURLException, NamingException
+ {
+ getMainDeployer().undeploy(DEPLOYMENT_URL);
+ }
+
/**
- * Retrieves the initial JNDI context from which to retrieve the RMIAdapter.
+ * Retrieves the HTTP response code for the jbpapp6523 servlet.
*/
- protected InitialContext getInitialContext(String host)
- throws NamingException
+ protected int getHTTPResponseCode()
+ throws IOException, MalformedURLException
{
- if (host == null)
- {
- return new InitialContext();
- }
- else
- {
- Properties props = new Properties();
- props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
- props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
- props.put(Context.PROVIDER_URL, "jnp://"+host+":1099");
- props.put("jnp.disableDiscovery", "true");
+ // Set by the test framework.
+ final String HTTP_HOST = System.getProperty("jbosstest.server.host");
- return new InitialContext(props);
- }
+ URL servletURL = new URL("http://" + HTTP_HOST + ":8080/jbpapp6523/");
+ HttpURLConnection connection = (HttpURLConnection) servletURL.openConnection();
+ int responseCode = connection.getResponseCode();
+ connection.disconnect();
+
+ return responseCode;
}
/**
* Retrieves the MainDeployer MBean proxy.
*/
- protected MainDeployerMBean getMainDeployer()
+ private MainDeployerMBean getMainDeployer()
throws MalformedObjectNameException, NamingException
{
final String MAIN_DEPLOYER_OBJECT_NAME_STR =
@@ -112,12 +119,16 @@
/**
* Retrieves the RMIAdapter from JNDI.
*/
- protected MBeanServerConnection getRMIServer()
+ private MBeanServerConnection getRMIServer()
throws NamingException
{
final String CONNECTOR_NAME = "jmx/rmi/RMIAdaptor";
+
+ // Uses system property java.naming.provider.url which is set by
+ // the test framework.
+ InitialContext context = new InitialContext();
- RMIAdaptor server = (RMIAdaptor) getInitialContext(host).lookup(CONNECTOR_NAME);
+ RMIAdaptor server = (RMIAdaptor) context.lookup(CONNECTOR_NAME);
return server;
}
Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLFalseTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLFalseTestCase.java 2011-06-03 17:39:18 UTC (rev 111519)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLFalseTestCase.java 2011-06-03 20:28:02 UTC (rev 111520)
@@ -23,36 +23,19 @@
import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.management.MalformedObjectNameException;
-
-import javax.naming.NamingException;
-
-import junit.framework.TestCase;
-
-import org.jboss.deployment.DeploymentException;
-import org.jboss.deployment.MainDeployerMBean;
-
/**
+ * This test case's only method tests that the jbpapp6523 servlet compiles by
+ * checking for an HTTP response code of 200. It uses the
+ * jbpapp6523-use_tccl-false server configuration which sets
+ * org.apache.commons.logging.use_tccl to false.
+ *
* @author jiwils
*/
public class UseTCCLFalseTestCase extends CommonsLoggingBaseTestCase
{
public void testUseTCCLFalse()
- throws DeploymentException, IOException, MalformedObjectNameException,
- MalformedURLException, NamingException
+ throws IOException
{
- MainDeployerMBean mainDeployer = getMainDeployer();
- mainDeployer.deploy(DEPLOYMENT_URL);
-
- URL servletURL = new URL("http://" + "localhost" + ":8080/" + "jbpapp6523/");
- HttpURLConnection connection = (HttpURLConnection) servletURL.openConnection();
- int responseCode = connection.getResponseCode();
- connection.disconnect();
- mainDeployer.undeploy(DEPLOYMENT_URL);
- assertEquals(200, responseCode);
+ assertEquals(200, getHTTPResponseCode());
}
}
\ No newline at end of file
Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLTrueTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLTrueTestCase.java 2011-06-03 17:39:18 UTC (rev 111519)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/commons_logging/jbpapp6523/test/UseTCCLTrueTestCase.java 2011-06-03 20:28:02 UTC (rev 111520)
@@ -23,36 +23,19 @@
import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.management.MalformedObjectNameException;
-
-import javax.naming.NamingException;
-
-import junit.framework.TestCase;
-
-import org.jboss.deployment.DeploymentException;
-import org.jboss.deployment.MainDeployerMBean;
-
/**
+ * This test case's only method tests that the jbpapp6523 servlet does not
+ * compile by checking for an HTTP response code of 500. It uses the
+ * jbpapp6523-use_tccl-true server configuration which sets
+ * org.apache.commons.logging.use_tccl to true.
+ *
* @author jiwils
*/
public class UseTCCLTrueTestCase extends CommonsLoggingBaseTestCase
{
public void testUseTCCLTrue()
- throws DeploymentException, IOException, MalformedObjectNameException,
- MalformedURLException, NamingException
+ throws IOException
{
- MainDeployerMBean mainDeployer = getMainDeployer();
- mainDeployer.deploy(DEPLOYMENT_URL);
-
- URL servletURL = new URL("http://" + "localhost" + ":8080/" + "jbpapp6523/");
- HttpURLConnection connection = (HttpURLConnection) servletURL.openConnection();
- int responseCode = connection.getResponseCode();
- connection.disconnect();
- mainDeployer.undeploy(DEPLOYMENT_URL);
- assertEquals(500, responseCode);
+ assertEquals(500, getHTTPResponseCode());
}
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list