KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > repository > AbstractHttpRepositeryBaseFlow


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21
22 package com.jaspersoft.jasperserver.war.repository;
23
24 import java.io.File JavaDoc;
25
26 import com.jaspersoft.jasperserver.war.HttpUnitBaseTestCase;
27 import com.jaspersoft.jasperserver.war.wizard.TestAttribute;
28 import com.meterware.httpunit.SubmitButton;
29 import com.meterware.httpunit.UploadFileSpec;
30 import com.meterware.httpunit.WebForm;
31 import com.meterware.httpunit.WebLink;
32
33 public abstract class AbstractHttpRepositeryBaseFlow
34     extends HttpUnitBaseTestCase
35     implements RepositroryBrowserConstants{
36     
37     private static WebForm addNewForm;
38     private static WebForm repositoryForm;
39     private static SubmitButton saveButton;
40     private static SubmitButton addNewButton;
41     
42     
43     /**
44      * Constructor
45      *
46      * @param s
47      **/

48     public AbstractHttpRepositeryBaseFlow(String JavaDoc s) {
49         super(s);
50         
51         resourceMap.put("Jrxml1", "AllAccounts.jrxml");
52         resourceMap.put("Jrxml2", "SalesByMonth.jrxml");
53         resourceMap.put("Jrxml3", "SalesByMonthDetail.jrxml");
54         resourceMap.put("Img1", "logo.jpg");
55         resourceMap.put("Img2", "report.jpg");
56         resourceMap.put("text", "test.txt");
57         resourceMap.put("font", "arial.ttf");
58         resourceMap.put("jar","httpunit.jar");
59         resourceMap.put("resourceBundle","jndi.properties");
60     }
61
62     /**
63      * Checks through commonLoginFunction for logging in in at first time
64      *
65      * @throws Exception if fails
66      **/

67     public void setUp()
68       throws Exception JavaDoc {
69             wResponse = commonLoginFunction(homePageUrl);
70         }
71             
72     
73     
74     //****--------------------------------------------------------------------------*****/
75
//* HttpUnit test cases */
76
//****--------------------------------------------------------------------------*****/
77

78         
79     public void repositoryFlow(TestAttribute attrib) throws Exception JavaDoc {
80         
81             
82         // step 1:Getting the repository browser page
83
checkRepositoryPage();
84         // step 2:Adding New report to root folder
85
checkAddNamePage(attrib);
86         // step 3:Adding file to Data Source folder
87
addForDataSource(attrib);
88         // step 4:Adding file to Data Type folder
89
addForDataType(attrib);
90         // step 5: Add different files
91
addFile(attrib);
92         // step 6: Add Input Control files
93
addInputControlFile(attrib);
94         
95     }
96     
97     
98     //step 1:Getting the repository browser page
99
private void checkRepositoryPage() throws Exception JavaDoc {
100         //this is response for home page
101
assertNotNull(" Home Page Response is Null ", wResponse);
102         
103         //checks for the Repository link on the home page
104
WebLink link = wResponse.getLinkWith(repositoryLink);
105         assertNotNull(repositoryLink+" Link is Null ", link);
106
107         wResponse = link.click();
108         
109         //checking if the link exist on the page
110
assertNotNull("Link element is not on the page",wResponse.getElementsWithName(rootLink));
111         
112         //checking for the text on the Repositery Browser page
113
String JavaDoc opt = wResponse.getText();
114         if ((opt == null) || (opt.trim().length() == 0)) {
115             fail("Text not found in response");
116         }
117
118         assertTrue((opt.indexOf(repositoryPageText1) != -1) && (opt.indexOf(repositoryPageText2) != -1));
119         
120         //createing new report
121
repositoryForm = wResponse.getFormWithName(repFormText);
122         assertNotNull(" Form is Null ", repositoryForm);
123         
124         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
125         assertNotNull(" Button is Null ", addNewButton);
126         
127         wResponse = repositoryForm.submit(addNewButton);
128         
129         String JavaDoc string = wResponse.getText();
130         assertNotNull(" page text is Null ", string);
131         
132         if ((string == null) || (string.trim().length() == 0)) {
133             fail("Text not found in response");
134         }
135         
136         assertTrue((string.indexOf(pageText1) != -1) && (string.indexOf(pageText2) != -1));
137     }
138     
139     
140     
141     //step 2:Adding New report
142
private void checkAddNamePage(TestAttribute attrib) throws Exception JavaDoc {
143         
144         //this is response for add new file page
145
assertNotNull(" add new button Response is Null ", wResponse);
146         
147         addNewForm = wResponse.getFormWithName(addNewFormText);
148         assertNotNull(" Form is Null ", addNewForm);
149         
150         saveButton = addNewForm.getSubmitButton(saveBtnText);
151         assertNotNull(" button is Null ", saveButton);
152         
153         //saving file without giving name and label
154
wResponse = addNewForm.submit(saveButton);
155         
156         String JavaDoc string = wResponse.getText();
157         assertNotNull(" page text is Null ", string);
158         
159         if(string == null || string.trim().length()==0)
160             fail("There is no text on the page");
161         
162         assertTrue(string.indexOf(addPageText1)!= -1 && string.indexOf(addPageText2)!= -1);
163         
164         //saving file with proper details
165
addNewForm.setParameter("actualFolder.name",attrib.getDataSourceReportName());
166         addNewForm.setParameter("actualFolder.label",attrib.getLabel());
167         
168         wResponse = addNewForm.submit(saveButton);
169         
170     }
171     
172     
173     //step 3:Adding file to Data Source folder
174
private void addForDataSource(TestAttribute attrib) throws Exception JavaDoc {
175         
176         assertNotNull(" add new button Response is Null ", wResponse);
177         
178         repositoryForm = wResponse.getFormWithName(repFormText);
179         assertNotNull(" Form is Null ", repositoryForm);
180         
181         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
182         assertNotNull(" Button is Null ", addNewButton);
183         
184         repositoryForm.setParameter("cmbResourceType",dataSourceValueText);
185         
186         wResponse = repositoryForm.submit(addNewButton);
187         
188         dataSourcePage(attrib);
189     }
190     
191     
192     // Get Data source Configuration page
193
private void dataSourcePage(TestAttribute attrib)throws Exception JavaDoc {
194         
195         assertNotNull(" data source sellection page is Null ", wResponse);
196         
197         WebForm dataSrcForm = wResponse.getFormWithName(dataSrcFormText);
198         assertNotNull(" Form is Null ", dataSrcForm);
199         
200         SubmitButton nextButton = dataSrcForm.getSubmitButton(nextBtnText);
201         assertNotNull(" button is Null ", nextButton);
202         
203         dataSrcForm.setParameter("type",attrib.getDataSourceAttrb().getDataSourceType());
204         
205         wResponse = dataSrcForm.submit(nextButton);
206         
207         dataDescriptionPage(attrib);
208     }
209     
210     
211     // Data description page
212
private void dataDescriptionPage(TestAttribute attrib) throws Exception JavaDoc {
213         
214         assertNotNull(" data source sellection page is Null ", wResponse);
215         
216         WebForm form = wResponse.getFormWithName(jndiPropFormText);
217         assertNotNull(" Form is Null ", form);
218         
219         SubmitButton saveButton = form.getSubmitButton(dataSaveBtnText);
220         assertNotNull(" button is Null ", saveButton);
221         
222         //checking save button with error message
223
wResponse = form.submit(saveButton);
224         
225         String JavaDoc str = wResponse.getText();
226         assertNotNull(" page text is Null ", str);
227         
228         if(str == null || str.trim().length()==0)
229             fail("There is no text on the page");
230         
231         assertTrue(str.indexOf(dataSrcPageText)!= -1);
232         
233         //checking save button with proper response
234
form.setParameter("reportDataSource.name",attrib.getDataSourceReportName());
235         form.setParameter("reportDataSource.label",attrib.getLabel());
236         form.setParameter("reportDataSource.jndiName",attrib.getServiceName());
237         
238         wResponse = form.submit(saveButton);
239         
240         String JavaDoc text = wResponse.getText();
241         assertNotNull(" page text is Null ", text);
242         
243         if(text == null || text.trim().length()==0)
244             fail("There is no text on the page");
245         
246         assertTrue(text.indexOf("TestJNDI")!= -1);
247         
248     }
249     
250     
251     //step 4: Adding file to Data type folder
252
private void addForDataType(TestAttribute attrib)throws Exception JavaDoc {
253         
254         assertNotNull(" repository browser sellection page is Null ", wResponse);
255         
256         //createing new report
257
repositoryForm = wResponse.getFormWithName(repFormText);
258         assertNotNull(" Form is Null ", repositoryForm);
259         
260         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
261         assertNotNull(" button is Null ", addNewButton);
262         
263         repositoryForm.setParameter("cmbResourceType",dataTypeValueText);
264         
265         wResponse = repositoryForm.submit(addNewButton);
266         
267         String JavaDoc string = wResponse.getText();
268         assertNotNull(" page text is Null ", string);
269         
270         if(string==null || string.trim().length()==0)
271             fail("there is no text on the page");
272         
273         assertTrue(string.indexOf(dataTypepageText)!= -1);
274         
275         editDataTypePage(attrib);
276     }
277     
278     private void editDataTypePage(TestAttribute attrib) throws Exception JavaDoc {
279         
280         assertNotNull(" repository browser sellection page is Null ", wResponse);
281         
282         WebForm dataTypeForm = wResponse.getFormWithName(dataTypeFormText);
283         assertNotNull(" Form is Null ", dataTypeForm);
284         
285         SubmitButton saveButton = dataTypeForm.getSubmitButton(saveBtnText);
286         assertNotNull(" button is Null ", saveButton);
287         
288         dataTypeForm.setParameter("dataType.name",attrib.getDataTypeReportName());
289         dataTypeForm.setParameter("dataType.label",attrib.getLabel());
290         
291         wResponse = dataTypeForm.submit(saveButton);
292     }
293     
294     //step 5: Add file
295
private void addFile(TestAttribute attrib)throws Exception JavaDoc {
296         
297         assertNotNull(" repository browser sellection page is Null ", wResponse);
298         
299         //createing new report
300
repositoryForm = wResponse.getFormWithName(repFormText);
301         assertNotNull(" Form is Null ", repositoryForm);
302         
303         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
304         assertNotNull(" button is Null ", addNewButton);
305         
306         repositoryForm.setParameter("cmbResourceType",fileSrcTypeValueText);
307         
308         wResponse = repositoryForm.submit(addNewButton);
309             
310         String JavaDoc str = wResponse.getText();
311         assertNotNull(" page text is Null ", str);
312         
313         if(str == null || str.trim().length()==0)
314             fail("There is no text on the page");
315         
316         assertTrue(str.indexOf(addFileText)!= -1);
317         
318         uploadResourceFileText(attrib);
319     }
320     
321     private void uploadResourceFileText(TestAttribute attrib) throws Exception JavaDoc{
322         
323         assertNotNull(" repository browser sellection page is Null ", wResponse);
324         
325         WebForm uploadForm = wResponse.getFormWithName(uploadResourceFormText);
326         assertNotNull(" Form is Null ", uploadForm);
327         
328         SubmitButton nextButton = uploadForm.getSubmitButton(nextBtnText);
329         assertNotNull(" button is Null ", nextButton);
330         
331         File JavaDoc file = new File JavaDoc(getJrxmlFileResourceURL(attrib.getJrxml()));
332         UploadFileSpec[] uploadFile = new UploadFileSpec[] { new UploadFileSpec(file) };
333         
334         uploadForm.setParameter("newData", uploadFile);
335         
336         wResponse = uploadForm.submit(nextButton);
337         
338         String JavaDoc str = wResponse.getText();
339         assertNotNull(" page text is Null ", str);
340         
341         if(str == null || str.trim().length()==0)
342             fail("There is no text on the page");
343         
344         assertTrue(str.indexOf(successText)!= -1);
345         
346         
347         resourceDescriptionPage(attrib);
348     }
349     
350     private void resourceDescriptionPage(TestAttribute attrib) throws Exception JavaDoc {
351         
352         assertNotNull(" repository browser sellection page is Null ", wResponse);
353         
354         WebForm descriptionForm = wResponse.getFormWithName(dataDescFormText);
355         assertNotNull(" Form is Null ", descriptionForm);
356         
357         SubmitButton saveButton = descriptionForm.getSubmitButton(dataSaveBtnText);
358         assertNotNull(" button is Null ", saveButton);
359         
360         descriptionForm.setParameter("fileResource.name",attrib.getJRXMLReportName());
361         descriptionForm.setParameter("fileResource.label",attrib.getLabel());
362         
363         wResponse = descriptionForm.submit(saveButton);
364         
365         String JavaDoc str = wResponse.getText();
366         assertNotNull(" page text is Null ", str);
367         
368         if(str == null || str.trim().length()==0)
369             fail("There is no text on the page");
370         
371         assertTrue(str.indexOf(repositoryPageText1)!= -1);
372     }
373
374     
375     // step 6: Add Input Control file
376
private void addInputControlFile(TestAttribute attrib)throws Exception JavaDoc {
377         
378         assertNotNull(" repository browser sellection page is Null ", wResponse);
379     
380         //createing new report
381
repositoryForm = wResponse.getFormWithName(repFormText);
382         assertNotNull(" Form is Null ", repositoryForm);
383         
384         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
385         assertNotNull(" button is Null ", addNewButton);
386         
387         repositoryForm.setParameter("cmbResourceType",fileInputControlText);
388         
389         wResponse = repositoryForm.submit(addNewButton);
390             
391         String JavaDoc str = wResponse.getText();
392         assertNotNull(" page text is Null ", str);
393         
394         if(str == null || str.trim().length()==0)
395             fail("There is no text on the page");
396         
397         assertTrue(str.indexOf("Input Control")!= -1);
398     
399         inputControlDescriptionPage(attrib);
400     }
401     
402     private void inputControlDescriptionPage(TestAttribute attrib) throws Exception JavaDoc{
403         
404         assertNotNull(" Add Input File sellection page is Null ", wResponse);
405         
406         WebForm descriptionForm = wResponse.getFormWithName(inputCtrlDescFormText);
407         assertNotNull(" Form is Null ", descriptionForm);
408         
409         SubmitButton nextButton = descriptionForm.getSubmitButton(nextBtnText);
410         assertNotNull(" button is Null ", nextButton);
411         
412         descriptionForm.setParameter("inputControl.name",attrib.getInputControlReportName());
413         descriptionForm.setParameter("inputControl.label",attrib.getLabel());
414         
415         wResponse = descriptionForm.submit(nextButton);
416         
417         String JavaDoc str = wResponse.getText();
418         assertNotNull(" page text is Null ", str);
419         
420         if(str == null || str.trim().length()==0)
421             fail("There is no text on the page");
422         
423         assertTrue(str.indexOf(dataTypePageText)!= -1);
424         
425         locateDataPage(attrib);
426     }
427     
428     private void locateDataPage(TestAttribute attrib)throws Exception JavaDoc{
429         
430         assertNotNull(" File Description page is Null ", wResponse);
431         
432         WebForm locateDataForm = wResponse.getFormWithName(locateDataPageFormText);
433         assertNotNull(" Form is Null ", locateDataForm);
434         
435         SubmitButton nextButton = locateDataForm.getSubmitButton(nextBtnText);
436         assertNotNull(" button is Null ", nextButton);
437         
438         locateDataForm.setParameter("source","LOCAL");
439         
440         wResponse = locateDataForm.submit(nextButton);
441         
442         String JavaDoc str = wResponse.getText();
443         assertNotNull(" page text is Null ", str);
444         
445         if(str == null || str.trim().length()==0)
446             fail("There is no text on the page");
447         
448         assertTrue(str.indexOf(locateDataPageText)!= -1);
449         
450         dataTypeDescriptionPage(attrib);
451     }
452     
453     
454     private void dataTypeDescriptionPage(TestAttribute attrib) throws Exception JavaDoc{
455         
456         assertNotNull(" Locate Data page is Null ", wResponse);
457                 
458         WebForm dataDescriptionForm = wResponse.getFormWithName(dataTypeFormText);
459         assertNotNull(" Form is Null ", dataDescriptionForm);
460         
461         SubmitButton saveButton = dataDescriptionForm.getSubmitButton(saveBtnText);
462         assertNotNull(" button is Null ", saveButton);
463         
464         dataDescriptionForm.setParameter("dataType.name",attrib.getInputControlReportName());
465         dataDescriptionForm.setParameter("dataType.label",attrib.getLabel());
466         
467         wResponse = dataDescriptionForm.submit(saveButton);
468     
469         String JavaDoc str = wResponse.getText();
470         assertNotNull(" page text is Null ", str);
471         
472         if(str == null || str.trim().length()==0)
473             fail("There is no text on the page");
474         
475         assertTrue(str.indexOf(repositoryPageText1)!= -1);
476     }
477     
478     
479     private String JavaDoc getJrxmlFileResourceURL(String JavaDoc jrxml) {
480         //return resourcePath+File.separator+jrxml;
481
return getClass().getClassLoader().getResource(jrxml).getPath();
482     }
483     
484
485     /**
486      * Form bean for Resource nameing
487      *
488      **/

489     public class Description {
490         private String JavaDoc fileName;
491         private String JavaDoc fileLabel;
492         private String JavaDoc fileDescription;
493         private String JavaDoc fileType;
494
495         public Description() {
496             super();
497         }
498
499         public Description(String JavaDoc name,
500                            String JavaDoc label,
501                            String JavaDoc description,
502                            String JavaDoc type) {
503             super();
504             this.fileName = name;
505             this.fileLabel = label;
506             this.fileDescription = description;
507             this.fileType = type;
508         }
509
510         public String JavaDoc getFileDescription() {
511             return fileDescription;
512         }
513
514         public void setFileDescription(String JavaDoc fileDescription) {
515             this.fileDescription = fileDescription;
516         }
517
518         public String JavaDoc getFileLabel() {
519             return fileLabel;
520         }
521
522         public void setFileLabel(String JavaDoc fileLabel) {
523             this.fileLabel = fileLabel;
524         }
525
526         public String JavaDoc getFileName() {
527             return fileName;
528         }
529
530         public void setFileName(String JavaDoc fileName) {
531             this.fileName = fileName;
532         }
533
534         public String JavaDoc getFileType() {
535             return fileType;
536         }
537
538         public void setFileType(String JavaDoc fileType) {
539             this.fileType = fileType;
540         }
541     }
542 }
Popular Tags