User: d_jencks Date: 01/09/11 21:55:41 Added: src/main/org/jboss/test/web/test WebIntegrationUnitTestCase.java Removed: src/main/org/jboss/test/web/test TestWebIntegration.java Log: Changed naming scheme of tests to *UnitTestCase.java for short running tests and *StressTestCase.java for lengthy tests. Made tests-unit and tests-stress targets in build.xml Revision Changes Path 1.1 jbosstest/src/main/org/jboss/test/web/test/WebIntegrationUnitTestCase.java Index: WebIntegrationUnitTestCase.java =================================================================== package org.jboss.test.web.test; import java.io.IOException; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.URL; import javax.management.ObjectName; import javax.management.RuntimeMBeanException; import javax.naming.InitialContext; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jboss.jmx.connector.rmi.RMIConnector; import org.jboss.test.util.Deploy; /** Tests of servlet container integration into the JBoss server. This test requires than a web container be integrated into the JBoss server. The tests currently use the java.net.HttpURLConnection and associated http client and these do not return very good information on errors so if a failure occurs it is best to connect the webserver using a browser to look for additional error info. The secure access tests require a user named 'jduke' with a password of 'theduke' with a role of 'AuthorizedUser' in the servlet container. @author [EMAIL PROTECTED] @version $Revision: 1.1 $ */ public class WebIntegrationUnitTestCase extends TestCase { private static boolean setUp; private static boolean webServerAvailable; private static String baseURL; public WebIntegrationUnitTestCase(String name) { super(name); } /** Test for the availability of a local webserver and deploy the jbosstest-web.ear one time if a webserver is found. */ protected void setUp() throws Exception { if( setUp == true ) return; setUp = true; Integer port = Integer.getInteger("web.port", 8080); baseURL = "http://jduke:theduke@localhost:" + port + '/'; try { String serverName = InetAddress.getLocalHost().getHostName(); String connectorName = "jmx:" +serverName+ ":rmi"; RMIConnector server = (RMIConnector) new InitialContext().lookup(connectorName); ObjectName deployerName = new ObjectName("J2EE:service=J2eeDeployer"); // Ask the deployer for the getWarDeployerName Object[] params = {}; String[] signature = {}; String warDeployerName = (String) server.invoke(deployerName, "getWarDeployerName", params, signature); // See if the warDeployerName exists deployerName = new ObjectName(warDeployerName); webServerAvailable = server.isRegistered(deployerName); if( webServerAvailable == true ) { System.out.println("Found warDeployer named: "+warDeployerName); try { Deploy.deploy("jbosstest-web.ear"); } catch(Exception e) { e.printStackTrace(); fail("Failed to deploy jbosstest-web.ear"); } // Flush the security domain cache to avoid conflicts with other testcases ObjectName jaasMgr = new ObjectName("Security:name=JaasSecurityManager"); params = new Object[] {"other"}; signature = new String[] {"java.lang.String"}; server.invoke(jaasMgr, "flushAuthenticationCache", params, signature); } else { System.out.println("No war deployer found, skipping tests"); } } catch(Exception x) { webServerAvailable = false; x.printStackTrace(); if (x instanceof RuntimeMBeanException) { ((RuntimeMBeanException)x).getTargetException().printStackTrace(); } System.out.println("No war deployer found, skipping tests"); } } /** Access the http://localhost/jbosstest/EJBOnStartupServlet */ public void testEJBOnStartupServlet() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/EJBOnStartupServlet"); accessURL(url); } /** Access the http://localhost/jbosstest/ENCServlet */ public void testENCServlet() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/ENCServlet"); accessURL(url); } /** Access the http://localhost/jbosstest/EJBServlet */ public void testEJBServlet() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/EJBServlet"); accessURL(url); } /** Access the http://localhost/jbosstest/snoop.jsp */ public void testSnoopJSP() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/snoop.jsp"); accessURL(url); } /** Access the http://localhost/jbosstest/ClientLoginServlet */ public void testClientLoginServlet() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/ClientLoginServlet"); accessURL(url); } /** Access the http://localhost/jbosstest/restricted/SecureServlet */ public void testSecureServlet() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/restricted/SecureServlet"); accessURL(url); } /** Access the http://localhost/jbosstest/restricted/SecureEJBAccess */ public void testSecureEJBAccess() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/restricted/SecureEJBAccess"); accessURL(url); } /** Access the http://localhost/jbosstest/restricted/include_ejb.jsp */ public void testIncludeEJB() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/restricted/include_ejb.jsp"); accessURL(url); } /** Access the http://localhost/jbosstest/restricted/SecureEJBAccess */ public void testUnsecureEJBAccess() throws Exception { if( webServerAvailable == false ) return; URL url = new URL(baseURL+"jbosstest/UnsecureEJBAccess"); accessURL(url, true); } private void accessURL(URL url) throws Exception { accessURL(url, false); } private void accessURL(URL url, boolean shouldFail) throws Exception { try { System.out.println("Connecting to: "+url); HttpClient httpConn = new HttpClient(url); int responseCode = httpConn.getResponseCode(); String response = httpConn.getResponseMessage(); System.out.println("responseCode="+responseCode+", response="+response); if( responseCode != HttpURLConnection.HTTP_OK ) { StringBuffer content = httpConn.getContent(); System.out.println(content); if( shouldFail == false ) fail("Access to: "+url+" failed with responseCode="+responseCode); } } catch(IOException e) { throw e; } } public static void main(java.lang.String[] args) { System.setErr(System.out); Test suite = suite(); junit.textui.TestRunner.run(suite); } public static Test suite() { TestSuite suite = new TestSuite(); try { String filename = "../deploy/jbosstest-web.ear"; // deployment is done in setUp()... to complex to move out // System.out.println("Deploying..."); // Deploy.deploy(filename); suite.addTest(new TestSuite(WebIntegrationUnitTestCase.class)); // add a test case to undeploy our support applications suite.addTest(new Deploy.Undeployer(filename)); } catch (Throwable t) { t.printStackTrace(); System.exit(0); } return suite; } } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development