User: starksm
Date: 01/09/03 15:57:14
Modified: src/main/org/jboss/test/web/test Tag: Branch_2_4
TestWebIntegration.java
Log:
Additional tests for accessing secure content
Revision Changes Path
No revision
No revision
1.7.2.3 +231 -199
jbosstest/src/main/org/jboss/test/web/test/TestWebIntegration.java
Index: TestWebIntegration.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/web/test/TestWebIntegration.java,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -r1.7.2.2 -r1.7.2.3
--- TestWebIntegration.java 2001/07/29 16:32:43 1.7.2.2
+++ TestWebIntegration.java 2001/09/03 22:57:14 1.7.2.3
@@ -16,210 +16,242 @@
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.7.2.2 $
-*/
+ 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.7.2.3 $
+ */
public class TestWebIntegration extends TestCase
{
- private static boolean setUp;
- private static boolean webServerAvailable;
- private static String baseURL;
-
- public TestWebIntegration(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
+ private static boolean setUp;
+ private static boolean webServerAvailable;
+ private static String baseURL;
+
+ public TestWebIntegration(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
{
- System.out.println("No war deployer found, skipping tests");
+ Deploy.deploy("jbosstest-web.ear");
}
- }
- catch(Exception x)
- {
- webServerAvailable = false;
- x.printStackTrace();
- if (x instanceof RuntimeMBeanException)
+ catch(Exception e)
{
- ((RuntimeMBeanException)x).getTargetException().printStackTrace();
+ 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");
- }
- }
-
- /** 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);
- }
-
- private void accessURL(URL url) 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);
- 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(TestWebIntegration.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;
- }
-
+ }
+ }
+ 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(TestWebIntegration.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