KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 /*
3  *
4  * Project : JasperSoft
5  * File Name : HttpUnitReportMgmtTest.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 Reports Management Page - checking the Jasper Server Report Details Page
22  **/

23 public class HttpUnitReportMgmtTest
24     extends HttpUnitBaseTestCase {
25     private static String JavaDoc reptMgmtPageUrl = JasperServerConstants.BASE_URL +
26                                                    "/jasperserver/reportmgmt.html";
27     private static String JavaDoc repMgmtLink = "AllAccounts";
28     private static String JavaDoc repNameText = "txRepName";
29     private static String JavaDoc repPageText = "SEARCH";
30     private static String JavaDoc repDetFormName = "fmRptDtls";
31     private static String JavaDoc repDetText1 = "AllAccounts";
32     private static String JavaDoc repDetText2 = "sub-JRXML-01 in Repository";
33     private static String JavaDoc crRepImgText = "/jasperserver/images/create_button.gif";
34     
35     protected static WebResponse retResponse;
36
37     /**
38      * Constructor
39      *
40      * @param s
41      **/

42     public HttpUnitReportMgmtTest(String JavaDoc s) {
43         super(s);
44     }
45
46     /**
47      * Checks through commonLoginFunction for loggin in at first time
48      *
49      * @throws Exception if fails
50      **/

51     public void setUp()
52       throws Exception JavaDoc {
53             wResponse = commonLoginFunction(reptMgmtPageUrl);
54         }
55
56     
57     //****--------------------------------------------------------------------------*****/
58
//* HttpUnit test cases */
59
//****--------------------------------------------------------------------------*****/
60

61     
62     /**
63      * This test case method is for Report Management Page of JS application This checks if the
64      * wResponse for the page is Null, checks for the textField. and also checks for the
65      * "AllAccounts" link. On a proper wResponse - test is success else - failure
66      *
67      * @throws Exception if fails
68      **/

69     public void testReptMgmtPage()
70       throws Exception JavaDoc {
71         WebResponse reportMgmt = this.getWebConversation().getCurrentPage();
72         
73         assertNotNull("Report Management response is Null", reportMgmt);
74         
75         //checking for text field on the page
76
assertNotNull("Report Management element is Null",
77                 reportMgmt.getElementsWithName(repNameText));
78
79         //checking for the link on the page
80
// WebLink link = reportMgmt.getLinkWith(repMgmtLink);
81
// assertNotNull("All Account report is Null", link);
82

83         String JavaDoc page = reportMgmt.getText();
84
85         if ((page == null) || (page.trim().length() == 0)) {
86             fail("No text fond in response");
87         }
88
89         assertTrue(page.indexOf("Name:") != -1);
90
91         WebImage image = reportMgmt.getImageWithSource(crRepImgText);
92         assertNotNull("Image is present", image);
93
94     }
95
96     /**
97      * This test case method is for Report Detail Page of JS application This checks if the
98      * response for the previous link is Null, and checks for the "AllAccounts" link, than on
99      * click goes to next page and checks for the text contents.
100      * Again click on the return button it comes back to report management page.
101      * On a proper response test-success, else - failure
102      *
103      * @throws Exception if fails
104      **/

105     public void testReptDetlPage()
106       throws Exception JavaDoc {
107         //this is the report management page
108
WebResponse reportMgmt = this.getWebConversation().getCurrentPage();
109         assertNotNull("Report Detail response is Null", reportMgmt);
110
111         WebLink link = reportMgmt.getLinkWith(repMgmtLink);
112         link.click();
113         
114         //checking for the next page after clicking on the link
115
WebResponse reportDetail = this.getWebConversation().getCurrentPage();
116         
117         String JavaDoc string = reportDetail.getText();
118
119         if ((string == null) || (string.trim().length() == 0)) {
120             fail("No text found in response");
121         }
122
123         assertTrue((string.indexOf(repDetText1) != -1) &&
124                    (string.indexOf(repDetText2) != -1));
125
126         WebForm repDetForm = reportDetail.getFormWithName(repDetFormName);
127         repDetForm.getScriptableObject().setParameterValue("repdtlsaction", "torepmgmt");
128         repDetForm.submit();
129
130         
131         WebResponse bkRepMgmt = this.getWebConversation().getCurrentPage();
132         
133         String JavaDoc str = bkRepMgmt.getText();
134
135         if ((str == null) || (str.trim().length() == 0)) {
136             fail("No text found in response");
137         }
138
139         assertTrue(str.indexOf(repPageText) != -1);
140     }
141     
142
143     //****--------------------------------------------------------------------------*****/
144
//* Base class method implementaion */
145
//****--------------------------------------------------------------------------*****/
146

147     
148     
149     /* (non-Javadoc)
150      * @see com.jaspersoft.jasperserver.war.HttpUnitBaseTestCase#getloginCredentials()
151      */

152     protected String JavaDoc[] getloginCredentials() {
153         return new String JavaDoc[] { USERNAME, PASSWORD };
154     }
155     
156     
157     //****--------------------------------------------------------------------------*****/
158
//* HttpUnit framework methods */
159
//****--------------------------------------------------------------------------*****/
160

161     
162     /**
163      * the main method for calling all the test cases whichever is being added into the suite.
164      *
165      * @param args
166      **/

167     public static void main(String JavaDoc[] args) {
168         try {
169             junit.textui.TestRunner.run(suite());
170         } catch (Exception JavaDoc _ex) {
171             _ex.printStackTrace();
172         }
173     }
174     
175     /**
176      * this method is for adding which all test case/s method/s need to be
177      *
178      * @return Test
179      *
180      * @throws Exception if fails
181      **/

182     public static Test suite()
183       throws Exception JavaDoc {
184         TestSuite suite = new TestSuite();
185         
186         TestCase test1 = new HttpUnitReportMgmtTest("testReptMgmtPage");
187         TestCase test2 = new HttpUnitReportMgmtTest("testReptDetlPage");
188
189         suite.addTest(test1);
190     // suite.addTest(test2);
191
return suite;
192     }
193 }
194
Popular Tags