KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > HttpUnitAdminTest


1
2 /*
3  *
4  * Project : JasperSoft
5  * File Name : HttpUnitAdminTest.java
6  * Package : com.jaspersoft.jasperserver.war
7  *
8  * Copyright (c) JasperSoft, Inc.
9  * All rights reserved.
10  */

11
12 package com.jaspersoft.jasperserver.war;
13
14 import com.meterware.httpunit.*;
15
16 import junit.framework.*;
17
18 /**
19  * This Class is used for writing Testcases for testing a Jasper site. The test cases are for: -
20  * Connecting the Jasper Server Startup Page - checking the Jasper Server Home Page - checking the
21  * Jasper Server Admin Reports Page
22  **/

23 public class HttpUnitAdminTest
24     extends HttpUnitBaseTestCase {
25     //private static String homePageUrl = JasperServerConstants.HOME_PAGE_URL;
26
private static String JavaDoc admHomePageUrl = JasperServerConstants.BASE_URL +
27                                            "/jasperserver/admhompage.html";
28     private static String JavaDoc adminPgText1 = "ADMIN HOME PAGE";
29     private static String JavaDoc adminPgText2 = "NOTIFICATIONS";
30
31     /**
32      * Constructor
33      *
34      * @param s
35      **/

36     public HttpUnitAdminTest(String JavaDoc s) {
37         super(s);
38     }
39
40     /**
41      * Checks through commonLoginFunction for logging in in at first time
42      *
43      * @throws Exception if fails
44      **/

45     public void setUp()
46       throws Exception JavaDoc {
47             wResponse = commonLoginFunction(admHomePageUrl);
48         }
49     
50     
51     //****--------------------------------------------------------------------------*****/
52
//* HttpUnit test cases */
53
//****--------------------------------------------------------------------------*****/
54

55     
56     
57     /**
58      * This test case method is for Admin Home Page of JS application This Page checks if the
59      * wResponse for this page is Null, and also checks for the text contents. On a proper
60      * response - test is success else - failure
61      *
62      * @throws Exception if fails
63      **/

64     public void testAdmHomePage()
65       throws Exception JavaDoc {
66         WebResponse adminPage = this.getWebConversation().getCurrentPage();
67         assertNotNull("Admin Page Response is Null", adminPage);
68
69         String JavaDoc opt = adminPage.getText();
70
71         if ((opt == null) || (opt.trim().length() == 0)) {
72             fail("Text not found in response");
73         }
74
75         assertTrue((opt.indexOf(adminPgText1) != -1) && (opt.indexOf(adminPgText2) != -1));
76     }
77     
78     
79     //****--------------------------------------------------------------------------*****/
80
//* Base class method implementaion */
81
//****--------------------------------------------------------------------------*****/
82

83     
84     
85     /* (non-Javadoc)
86      * @see com.jaspersoft.jasperserver.war.HttpUnitBaseTestCase#getloginCredentials()
87      */

88     protected String JavaDoc[] getloginCredentials() {
89         return new String JavaDoc[] { USERNAME, PASSWORD };
90     }
91     
92     //****--------------------------------------------------------------------------*****/
93
//* HttpUnit framework methods */
94
//****--------------------------------------------------------------------------*****/
95

96     
97     /**
98      * the main method for calling all the test cases whichever is being added into the suite.
99      *
100      * @param args
101      **/

102     public static void main(String JavaDoc[] args) {
103         try {
104             junit.textui.TestRunner.run(suite());
105         } catch (Exception JavaDoc _ex) {
106             _ex.printStackTrace();
107         }
108     }
109     
110     /**
111      * this method is for adding which all test case/s method/s need to be tested
112      *
113      * @return Test
114      *
115      * @throws Exception if fails
116      **/

117     public static Test suite()
118       throws Exception JavaDoc {
119         TestSuite suite = new TestSuite();
120
121         TestCase test1 = new HttpUnitAdminTest("testAdmHomePage");
122         suite.addTest(test1);
123
124         return suite;
125     }
126
127 }
128
Popular Tags