User: starksm
Date: 01/05/05 13:59:35
Added: src/main/org/jboss/test/web/test TestWebIntegration.java
Log:
Start of web container integration tests
Revision Changes Path
1.1
jbosstest/src/main/org/jboss/test/web/test/TestWebIntegration.java
Index: TestWebIntegration.java
===================================================================
package org.jboss.test.web.test;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import junit.framework.TestCase;
import junit.framework.TestSuite;
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.
@author [EMAIL PROTECTED]
@versioin $Revision: 1.1 $
*/
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;
// Test for the existence of a web server
Integer port = Integer.getInteger("web.port", 8080);
baseURL = "http://localhost:" + port;
URL url = new URL(baseURL);
try
{
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
int responseCode = httpConn.getResponseCode();
if( responseCode != HttpURLConnection.HTTP_OK )
{
System.out.println(baseURL+" did not result in HTTP OK, skipping
tests");
}
else
{
System.out.println("Found webserver at: "+baseURL);
Deploy.deploy("jbosstest-web.ear");
webServerAvailable = true;
}
}
catch(Exception e)
{
System.out.println("No webserver found at: "+baseURL);
}
}
/** 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);
}
private void accessURL(URL url) throws Exception
{
try
{
System.out.println("Connecting to: "+url);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
int responseCode = -1;
String response = null;
try
{
httpConn.connect();
responseCode = httpConn.getResponseCode();
response = httpConn.getResponseMessage();
}
catch(Exception e)
{
System.out.println("Failed to connect to: "+url);
response = e.toString();
}
System.out.println("responseCode="+responseCode+", response="+response);
if( responseCode != HttpURLConnection.HTTP_OK )
{
InputStream is = httpConn.getErrorStream();
if( is != null )
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
String line;
while( (line = reader.readLine()) != null )
{
System.out.println(line);
}
reader.close();
}
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);
TestSuite suite = new TestSuite(TestWebIntegration.class);
junit.textui.TestRunner.run(suite);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development