KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > anatom > ejbca > webdist > WebdistHttpTest


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package se.anatom.ejbca.webdist;
15
16 import junit.framework.TestCase;
17 import junit.framework.TestSuite;
18
19 import com.meterware.httpunit.GetMethodWebRequest;
20 import com.meterware.httpunit.HttpUnitOptions;
21 import com.meterware.httpunit.WebConversation;
22 import com.meterware.httpunit.WebRequest;
23 import com.meterware.httpunit.WebResponse;
24
25 /** Tests http pages of public webdist
26  **/

27 public class WebdistHttpTest extends TestCase {
28
29     public static void main( String JavaDoc args[] ) {
30         junit.textui.TestRunner.run( suite() );
31     }
32
33
34     public static TestSuite suite() {
35         return new TestSuite( WebdistHttpTest.class );
36     }
37
38
39     public WebdistHttpTest( String JavaDoc name ) {
40         super( name );
41     }
42
43     public void testJspCompile() throws Exception JavaDoc {
44         // We hit the pages and see that they return a 200 value, so we know they at least compile correctly
45
String JavaDoc httpReqPath = "http://127.0.0.1:8080/ejbca";
46         String JavaDoc resourceName = "publicweb/webdist";
47         String JavaDoc resourceName1 = "publicweb/webdist/cacert.jsp";
48         String JavaDoc resourceName2 = "publicweb/webdist/cacrl.jsp";
49         String JavaDoc resourceName3 = "publicweb/webdist/revoked.jsp";
50         String JavaDoc resourceName4 = "publicweb/webdist/listcerts.jsp";
51         String JavaDoc resourceName5 = "publicweb/webdist/certdist.jsp";
52
53         // We want to get a 404 response without exceptions
54
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
55         WebConversation wc = new WebConversation();
56         WebRequest request = new GetMethodWebRequest( httpReqPath + '/' + resourceName );
57         WebResponse response = wc.getResponse( request );
58         assertEquals( "Response code", 200, response.getResponseCode() );
59         request = new GetMethodWebRequest( httpReqPath + '/' + resourceName1 );
60         response = wc.getResponse( request );
61         assertEquals( "Response code", 200, response.getResponseCode() );
62         request = new GetMethodWebRequest( httpReqPath + '/' + resourceName2 );
63         response = wc.getResponse( request );
64         assertEquals( "Response code", 200, response.getResponseCode() );
65         request = new GetMethodWebRequest( httpReqPath + '/' + resourceName3 );
66         response = wc.getResponse( request );
67         assertEquals( "Response code", 200, response.getResponseCode() );
68         request = new GetMethodWebRequest( httpReqPath + '/' + resourceName4 );
69         response = wc.getResponse( request );
70         assertEquals( "Response code", 200, response.getResponseCode() );
71         request = new GetMethodWebRequest( httpReqPath + '/' + resourceName5 );
72         response = wc.getResponse( request );
73         // Without params this gives a 404 (not found)
74
assertEquals( "Response code", 404, response.getResponseCode() );
75     }
76
77
78 }
79
Popular Tags