KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > wizard > AbstractHttpWizardBaseFlow


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 package com.jaspersoft.jasperserver.war.wizard;
22
23 import java.io.File JavaDoc;
24
25 import com.jaspersoft.jasperserver.war.HttpUnitBaseTestCase;
26 import com.meterware.httpunit.SubmitButton;
27 import com.meterware.httpunit.UploadFileSpec;
28 import com.meterware.httpunit.WebForm;
29 import com.meterware.httpunit.WebLink;
30 import com.meterware.httpunit.WebResponse;
31
32
33 /**
34  * The test cases are for: -
35  * Connecting the Jasper Server Startup Page - checking the Jasper Server Wizard
36  **/

37 public abstract class AbstractHttpWizardBaseFlow
38     extends HttpUnitBaseTestCase
39     implements WizardScreenConstants {
40     private static WebForm repNamingForm;
41     private static WebForm loadPageForm;
42     private static SubmitButton nextButton;
43     private static SubmitButton backButton;
44     private static WebForm loadJRXMLForm;
45     private static String JavaDoc resourcePath;
46     private static WebForm repositoryForm;
47     private static SubmitButton addNewButton;
48     private static WebForm pageForm;
49     
50     /**
51      * Constructor
52      *
53      * @param s
54      **/

55     public AbstractHttpWizardBaseFlow(String JavaDoc s) {
56         super(s);
57         resourceMap.put("Jrxml1", "AllAccounts.jrxml");
58         resourceMap.put("Jrxml2", "SalesByMonth.jrxml");
59         resourceMap.put("Jrxml3", "SalesByMonthDetail.jrxml");
60         resourceMap.put("Img1", "logo.jpg");
61         resourceMap.put("Img2", "report.jpg");
62         resourceMap.put("text", "test.txt");
63         resourcePath = getClass().getClassLoader().getResource("SalesByMonth.jrxml").getPath();
64     }
65
66     /**
67      * Checks through commonLoginFunction for loggin in at first time
68      *
69      * @throws Exception if fails
70      **/

71     public void setUp()
72       throws Exception JavaDoc {
73         wResponse = commonLoginFunction(homePageUrl);
74         
75     }
76     
77     
78
79     //****--------------------------------------------------------------------------*****/
80
//* HttpUnit test Common Workflow */
81
//****--------------------------------------------------------------------------*****/
82

83     
84     
85     
86     protected void runWizardFlow(TestAttribute attrb)
87       throws Exception JavaDoc {
88         
89         // step 1:Getting the repository browser page
90
checkRepositoryPage();
91         // Step 2:Get report naming page
92
checkRepNamingPage(attrb);
93         // step 3:Get Load JRXML page
94
checkLoadFilePage(attrb);
95         // step 4:Get Select Source page
96
checkSelectSourcePage();
97         // step 5:Get Data Source page
98
checkDataSourcepage(attrb);
99         // step 6:Get Service Property page
100
checkDataDescriptionPage(attrb);
101         // step 7:Get External Resource page
102
checkPublishPage();
103     }
104
105     
106     //step 1:Getting the repository browser page
107
private void checkRepositoryPage() throws Exception JavaDoc {
108         //this is response for home page
109
assertNotNull(" Home Page Response is Null ", wResponse);
110         
111         //checks for the Repository link on the home page
112
WebLink link = wResponse.getLinkWith(repositoryLink);
113         assertNotNull(repositoryLink +"Link is Null ", link);
114
115         wResponse = link.click();
116         
117         //checking if the link exist on the page
118
assertNotNull("Link element is not on the page",wResponse.getElementsWithName(rootLink));
119         
120         //checking for the text on the Repositery Browser page
121
String JavaDoc opt = wResponse.getText();
122         assertNotNull("page text is Null ", opt);
123         
124         if ((opt == null) || (opt.trim().length() == 0)) {
125             fail("Text not found in response");
126         }
127
128         assertTrue((opt.indexOf(repositoryPageText1) != -1) && (opt.indexOf(repositoryPageText2) != -1));
129         
130         //createing new report
131
repositoryForm = wResponse.getFormWithName(repFormText);
132         assertNotNull("Form text is Null ", repositoryForm);
133         
134         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
135         assertNotNull("Button text is Null ", addNewButton);
136         
137         repositoryForm.setParameter("cmbResourceType",repositoryUnitValueText);
138         
139         wResponse = repositoryForm.submit(addNewButton);
140
141         String JavaDoc str = wResponse.getText();
142         assertNotNull("page text is Null ", str);
143         
144         if ((str == null) || (str.trim().length() == 0)) {
145             fail("Text not found in response");
146         }
147
148         assertTrue((str.indexOf(createReportPageText) != -1));
149     }
150     
151     
152     //step 2:Checks for the Report name & Report Label
153
protected void checkRepNamingPage(TestAttribute attrb)
154       throws Exception JavaDoc {
155         assertNotNull(" Home Page Response is Null ", wResponse);
156
157         //checking if the textField exists
158
assertNotNull("No text field on the page", wResponse.getElementsWithName(nameText));
159
160         //checking for the text on the page
161
String JavaDoc string = wResponse.getText();
162         assertNotNull("page text is Null ", string);
163         
164         if ((string == null) || (string.trim().length() == 0)) {
165             fail("There is no text in response");
166         }
167
168         assertTrue((string.indexOf(pageText) != -1));
169
170         //checking for "cancel" button functionality
171
repNamingForm = wResponse.getFormWithName(repNameFormText);
172         assertNotNull("Form text is Null ", repNamingForm);
173         
174         SubmitButton cancelButton = repNamingForm.getSubmitButton(cancelBtnText);
175         assertNotNull("Button text is Null ", cancelButton);
176         
177         wResponse = repNamingForm.submit(cancelButton);
178
179         String JavaDoc report = wResponse.getText();
180         assertNotNull("page text is Null ", report);
181         
182         if ((report == null) || (report.trim().length() == 0)) {
183             fail("There is no text in response");
184         }
185         
186         assertTrue(report.indexOf(ViewReportPageText) != -1);
187
188         repositoryForm = wResponse.getFormWithName(repFormText);
189         assertNotNull("Form text is Null ", repositoryForm);
190         
191         addNewButton = repositoryForm.getSubmitButton(addNewBtnText);
192         assertNotNull("Button text is Null ", addNewButton);
193         
194         repositoryForm.setParameter("cmbResourceType",repositoryUnitValueText);
195         
196         wResponse = repositoryForm.submit(addNewButton);
197
198         String JavaDoc wizard = wResponse.getText();
199         assertNotNull("page text is Null ", wizard);
200         
201         if ((wizard == null) || (wizard.trim().length() == 0)) {
202             fail("there is no text on response");
203         }
204
205         assertTrue(wizard.indexOf(pageText) != -1);
206         
207         checkNxtBtnForRepNamingPage(attrb);
208     }
209
210     
211     // Next button functionality for report naming page
212
private void checkNxtBtnForRepNamingPage(TestAttribute attrb)
213       throws Exception JavaDoc {
214         assertNotNull(" Report Naming Page Response is Null ", wResponse);
215         
216         repNamingForm = wResponse.getFormWithName(repNameFormText);
217         assertNotNull("Form text is Null ", repNamingForm);
218         
219         nextButton = repNamingForm.getSubmitButton(nextBtnText);
220         assertNotNull("Button text is Null ", nextButton);
221         
222         //checking for the "next" button functionality with error message
223
assertNotNull(" Report Naming Page Response is Null ", wResponse);
224                 
225         assertNotNull(" FORM object is null ", repNamingForm);
226
227         nextButton = repNamingForm.getSubmitButton(nextBtnText);
228         assertNotNull(" Next button is null ", nextButton);
229
230         wResponse = repNamingForm.submit(nextButton);
231
232         String JavaDoc str = wResponse.getText();
233         assertNotNull("page text is Null ", str);
234         
235         if ((str == null) || (str.trim().length() == 0)) {
236             fail(" there is no text on response ");
237         }
238
239         assertTrue((str.indexOf(errorMsgRepPageText1) != -1) &&
240                    (str.indexOf(errorMsgRepPageText2) != -1));
241
242         //checking for the "next" button functionality with proper response
243

244         repNamingForm.setParameter("reportUnit.name", attrb.getReportName());
245         repNamingForm.setParameter("reportUnit.label", attrb.getLabel());
246
247         wResponse = repNamingForm.submit(nextButton);
248
249         String JavaDoc nextPage = wResponse.getText();
250         assertNotNull("page text is Null ", nextPage);
251         
252         if ((nextPage == null) || (nextPage.trim().length() == 0)) {
253             fail(" there is no text on response ");
254         }
255         assertTrue(nextPage.indexOf(loadPageText1) != -1);
256     }
257     
258
259     //step 3: Get Load JRXML page
260
protected void checkLoadFilePage(TestAttribute attrb)
261       throws Exception JavaDoc {
262         assertNotNull(" Report Naming Page Response is Null ", wResponse);
263
264         //checking if the textField exists
265
assertNotNull("No text field on the page", wResponse.getElementsWithName(fileFieldText));
266
267         //checking for text
268
String JavaDoc string = wResponse.getText();
269         assertNotNull("page text is Null ", string);
270         
271         if ((string == null) || (string.trim().length() == 0)) {
272             fail(" There is no text on response ");
273         }
274
275         assertTrue((string.indexOf(loadPageText1) != -1));
276
277         //checking for the back button
278
loadJRXMLForm = wResponse.getFormWithName(formText);
279         backButton = loadJRXMLForm.getSubmitButton(backBtnText);
280
281         wResponse = loadJRXMLForm.submit(backButton);
282
283         String JavaDoc str = wResponse.getText();
284         assertNotNull("page text is Null ", str);
285         
286         if ((str == null) || (str.trim().length() == 0)) {
287             fail("There is no text in response");
288         }
289
290         assertTrue(str.indexOf("Description") != -1);
291
292         repNamingForm = wResponse.getFormWithName(repNameFormText);
293         assertNotNull("Form text is Null ", repNamingForm);
294         
295         nextButton = repNamingForm.getSubmitButton(nextBtnText);
296         assertNotNull("Button text is Null ", nextButton);
297         
298         wResponse = repNamingForm.submit(nextButton);
299
300         String JavaDoc str1 = wResponse.getText();
301         assertNotNull("page text is Null ", str1);
302         
303         if ((str1 == null) || (str1.trim().length() == 0)) {
304             fail("There is no text in response");
305         }
306
307         assertTrue(str1.indexOf(loadPageText1) != -1);
308
309         checkNxtBtnForLoadFilePage(attrb);
310     }
311     
312
313     //next button functionality for Load JRXML page
314
private void checkNxtBtnForLoadFilePage(TestAttribute attrb)
315       throws Exception JavaDoc {
316             
317         assertNotNull(" Load File Page Response is Null ", wResponse);
318         
319         loadPageForm = wResponse.getFormWithName(formText);
320         assertNotNull("Form text is Null ", loadPageForm);
321         
322         //next button with no uploaded file
323
loadPageForm = wResponse.getFormWithName(formText);
324         assertNotNull("Form text is Null ", loadPageForm);
325         
326         nextButton = loadPageForm.getSubmitButton(nextBtnText);
327         assertNotNull("Button text is Null ", nextButton);
328         
329         wResponse = loadPageForm.submit(nextButton);
330
331         String JavaDoc error = wResponse.getText();
332         assertNotNull("page text is Null ", error);
333         
334         if ((error == null) || (error.trim().length() == 0)) {
335             fail("There is no text in response");
336         }
337
338         assertTrue(error.indexOf(errorMsgLoadPageText) != -1);
339
340         //next button with proper response
341
SubmitButton nextButton2 = loadPageForm.getSubmitButton(nextBtnText);
342         File JavaDoc jrxml = new File JavaDoc(getJrxmlFileResourceURL(attrb.getJrxml()));
343         UploadFileSpec[] uploadFile = new UploadFileSpec[] { new UploadFileSpec(jrxml) };
344         loadPageForm.setParameter("jrxmlData", uploadFile);
345
346         wResponse = loadPageForm.submit(nextButton2);
347
348         String JavaDoc page = wResponse.getText();
349         assertNotNull("page text is Null ", page);
350         
351         if ((page == null) || (page.trim().length() == 0)) {
352             fail("There is no text in response");
353         }
354
355         assertTrue(page.indexOf(reportListPageText) != -1);
356
357         
358         //For adding new Control through Add Control button
359

360         //description for file through Add Control
361
Description description = new Description();
362         description.setFileName("newFile"+String.valueOf((int)(Math.random()*1000)));
363         description.setFileLabel("newLink");
364         description.setFileDescription("This is new file");
365         
366         wResponse = addControl(wResponse, description);
367         
368         String JavaDoc text1 = wResponse.getText();
369         assertNotNull("page text is Null ", text1);
370         
371         if ((text1 == null) || (text1.trim().length() == 0)) {
372             fail("There is no text in response");
373         }
374
375         assertTrue(text1.indexOf(addControlPageText) != -1);
376         
377         
378         //For adding new resources
379

380         //description for file through Add Resources
381
Description description2 = new Description();
382         description2.setFileName("ResourceFile"+String.valueOf((int)(Math.random()*1000)));
383         description2.setFileLabel("ResourceLink");
384         description2.setFileDescription("This is new Resource File");
385         
386         wResponse = addResource(wResponse,description2, getFileResourceURLByType("Img2"));
387         
388         String JavaDoc text2 = wResponse.getText();
389         assertNotNull("page text is Null ", text2);
390         
391         if ((text2 == null) || (text2.trim().length() == 0)) {
392             fail("There is no text in response");
393         }
394
395         assertTrue(text2.indexOf(resourceFileText) != -1);
396         
397         String JavaDoc str = wResponse.getText();
398         assertNotNull("page text is Null ", str);
399         
400         //adding file details through Add Now link
401
if(str.indexOf("LogoLink") != -1){
402         
403         wResponse = addNowDetails(wResponse, getFileResourceURLByType("Img2"));
404         
405         String JavaDoc text3 = wResponse.getText();
406         assertNotNull("page text is Null ", text3);
407         
408         if ((text3 == null) || (text3.trim().length() == 0)) {
409             fail("There is no text in response");
410         }
411
412         assertTrue(text3.indexOf(fileAddedText) != -1);
413         
414         
415         wResponse = addNowDetails(wResponse, getFileResourceURLByType("Img1"));
416         
417         String JavaDoc text4 = wResponse.getText();
418         assertNotNull("page text is Null ", text4);
419         
420         if ((text4 == null) || (text4.trim().length() == 0)) {
421             fail("There is no text in response");
422         }
423
424         assertTrue(text4.indexOf(fileAddedText) != -1);
425         }else{
426             wResponse = addNowDetails(wResponse, getFileResourceURLByType("Jrxml3"));
427             
428             String JavaDoc text5 = wResponse.getText();
429             
430             if ((text5 == null) || (text5.trim().length() == 0)) {
431                 fail("There is no text in response");
432             }
433
434             assertTrue(text5.indexOf(fileAddedText) != -1);
435             
436             
437             wResponse = addNowDetails(wResponse, getFileResourceURLByType("Img1"));
438             
439             String JavaDoc text6 = wResponse.getText();
440             
441             if ((text6 == null) || (text6.trim().length() == 0)) {
442                 fail("There is no text in response");
443             }
444
445             assertTrue(text6.indexOf(fileAddedText) != -1);
446         }
447         
448         //Going to next page through Next button
449
pageForm = wResponse.getFormWithName(listPageFormText);
450         assertNotNull("Form is Null ", pageForm);
451         
452         nextButton = pageForm.getSubmitButton(nextBtnText);
453         assertNotNull("button is Null ", nextButton);
454         
455         wResponse = pageForm.submit(nextButton);
456         
457         String JavaDoc string = wResponse.getText();
458         assertNotNull("page text is Null ", string);
459         
460         if ((string == null) || (string.trim().length() == 0)) {
461             fail("There is no text on response");
462         }
463
464         assertTrue(string.indexOf(sourceSelectionPageText) != -1);
465     }
466
467     
468     //step 4:Get Select Source page
469
public void checkSelectSourcePage()
470       throws Exception JavaDoc {
471         assertNotNull("Upload Success Page Response is Null ", wResponse);
472
473         WebForm sourceSellectionForm = wResponse.getFormWithName(sourceSellFormText);
474         assertNotNull("Form is Null ", sourceSellectionForm);
475         
476         //checking for back button
477
SubmitButton backButton = sourceSellectionForm.getSubmitButton(backBtnText);
478         assertNotNull("Form is Null ", backButton);
479         
480         wResponse = sourceSellectionForm.submit(backButton);
481
482         loadPageForm = wResponse.getFormWithName(listPageFormText);
483         nextButton = loadPageForm.getSubmitButton(nextBtnText);
484
485         wResponse = loadPageForm.submit(nextButton);
486
487         String JavaDoc next = wResponse.getText();
488         assertNotNull("page text is Null ", next);
489         
490         if ((next == null) || (next.trim().length() == 0)) {
491             fail("There is no text in response");
492         }
493
494         assertTrue(next.indexOf(sourceSelectionPageText) != -1);
495
496         //checking for next button
497
WebForm sourceSelectionForm2 = wResponse.getFormWithName(sourceSellFormText);
498         nextButton = sourceSelectionForm2.getSubmitButton(nextBtnText);
499
500         sourceSelectionForm2.setParameter("source", "LOCAL");
501         sourceSelectionForm2.setParameter("selectedUri", "/datasources/JServerJNDIDS");
502
503         wResponse = sourceSelectionForm2.submit(nextButton);
504
505         String JavaDoc str = wResponse.getText();
506         assertNotNull("page text is Null ", str);
507         
508         if ((str == null) || (str.trim().length() == 0)) {
509             fail("There is no text in response");
510         }
511
512         assertTrue(str.indexOf(dataSrcPageText1) != -1);
513     }
514
515     
516     //step 5:Get Data Source page
517
public void checkDataSourcepage(TestAttribute attrb)
518       throws Exception JavaDoc {
519         assertNotNull(" Load File Page Response is Null ", wResponse);
520
521         //checking for text on the page
522
String JavaDoc str = wResponse.getText();
523         assertNotNull("page text is Null ", str);
524         
525         if ((str == null) || (str.trim().length() == 0)) {
526             fail("There is no text on response");
527         }
528
529         assertTrue((str.indexOf(dataSrcPageText1) != -1));
530
531         WebForm dataSrcForm = wResponse.getFormWithName(dataSrcPageFormText);
532         assertNotNull("Form is Null ", dataSrcForm);
533         
534         nextButton = dataSrcForm.getSubmitButton(nextBtnText);
535         assertNotNull("Form is Null ", nextButton);
536         
537         dataSrcForm.setParameter("type", attrb.getDataSourceAttrb().getDataSourceType());
538         wResponse = dataSrcForm.submit(nextButton);
539     }
540
541     
542     //step 6:Get Data Description page
543
public void checkDataDescriptionPage(TestAttribute attrb)
544       throws Exception JavaDoc {
545         assertNotNull(" Data Source Page Response is Null ", wResponse);
546
547         String JavaDoc string = wResponse.getText();
548         assertNotNull("page text is Null ", string);
549         
550         if (string.indexOf("JDBC") != -1) {
551             assertNotNull(" Data Source Page Response is Null ", wResponse);
552
553             //next buttoon with error message
554
WebForm propertyForm1 = wResponse.getFormWithName("fmCRValidConf");
555             nextButton = propertyForm1.getSubmitButton(nextBtnText);
556
557             wResponse = propertyForm1.submit(nextButton);
558
559             String JavaDoc opt = wResponse.getText();
560
561             if ((opt == null) || (opt.trim().length() == 0)) {
562                 fail("There is no text on the page");
563             }
564
565             assertTrue((opt.indexOf(errMsgText2) != -1) &&
566                        (opt.indexOf(errorMsgText3) != -1));
567
568             //now the next button with proper response
569
propertyForm1.setParameter("reportDataSource.name", attrb.getDataSourceAttrb().getName());
570             propertyForm1.setParameter("reportDataSource.label", attrb.getDataSourceAttrb().getLabel());
571
572             propertyForm1.setParameter("reportDataSource.driverClass", attrb.getDataSourceAttrb().getDriver());
573             propertyForm1.setParameter("reportDataSource.connectionUrl", attrb.getDataSourceAttrb().getUrl());
574             propertyForm1.setParameter("reportDataSource.username", attrb.getDataSourceAttrb().getUsername());
575             propertyForm1.setParameter("reportDataSource.password", attrb.getDataSourceAttrb().getPassword());
576
577             wResponse = propertyForm1.submit(nextButton);
578         } else {
579             assertNotNull(" Data Source Page Response is Null ", wResponse);
580
581             //next buttoon with error message
582
WebForm propertyForm2 = wResponse.getFormWithName(propertyPageFormText);
583             nextButton = propertyForm2.getSubmitButton(nextBtnText);
584
585             wResponse = propertyForm2.submit(nextButton);
586
587             String JavaDoc str = wResponse.getText();
588
589             if ((str == null) || (str.trim().length() == 0)) {
590                 fail("There is no text on the page");
591             }
592
593             assertTrue((str.indexOf(errMsgServiceNameText1) != -1) &&
594                        (str.indexOf(errMsgText2) != -1));
595
596             //now the next button with proper response
597
propertyForm2.setParameter("reportDataSource.name", attrb.getDataSourceAttrb().getName());
598             propertyForm2.setParameter("reportDataSource.label", attrb.getDataSourceAttrb().getLabel());
599             propertyForm2.setParameter("reportDataSource.jndiName", attrb.getDataSourceAttrb().getServiceName());
600
601             wResponse = propertyForm2.submit(nextButton);
602         }
603
604         String JavaDoc page = wResponse.getText();
605         assertNotNull("page text is Null ", page);
606         if ((page == null) || (page.trim().length() == 0)) {
607             fail("There is no text on the page");
608         }
609
610         assertTrue(page.indexOf(validationPageText) != -1);
611     }
612
613     
614     //step 7:Get Report Velidation page
615
public void checkPublishPage()
616       throws Exception JavaDoc {
617         assertNotNull(" Data Source Description Page Response is Null ", wResponse);
618
619         WebForm extResourceForm = wResponse.getFormWithName(testFormText);
620         assertNotNull("Form is Null ", extResourceForm);
621         
622         SubmitButton saveButton = extResourceForm.getSubmitButton(saveSelectedBtnText);
623         assertNotNull("Form is Null ", saveButton);
624         
625         wResponse = extResourceForm.submit(saveButton);
626
627         String JavaDoc string = wResponse.getText();
628         assertNotNull("page text is Null ", string);
629         
630         if ((string == null) || (string.trim().length() == 0)) {
631             fail("There is no text on the page");
632         }
633
634         assertTrue(string.indexOf(ViewReportPageText) != -1);
635     }
636     
637
638
639     //****--------------------------------------------------------------------------*****/
640
//* HttpUnit private framework methods */
641
//****--------------------------------------------------------------------------*****/
642

643     
644     
645     /**
646      * @param type of file
647      *
648      * @return resourceMap
649      **/

650     protected String JavaDoc getFileResourceByType(String JavaDoc type) {
651         return (String JavaDoc)resourceMap.get(type);
652         
653     }
654
655     /**
656      * Shows which jrxml to be taken from resource
657      *
658      * @return file path
659      **/

660     private String JavaDoc getJrxmlFileResourceURL(String JavaDoc jrxml) {
661         //return resourcePath+File.separator+jrxml;
662
return getClass().getClassLoader().getResource(jrxml).getPath();
663     }
664
665     /**
666      * Shows the type of file to be uploaded and gives the URL for the path
667      *
668      * @param type of file
669      *
670      * @return URL from where file to be uploaded
671      **/

672     private String JavaDoc getFileResourceURLByType(String JavaDoc type) {
673         //return resourcePath+File.separator+resourceMap.get(type);
674
return getClass().getClassLoader().getResource((String JavaDoc)resourceMap.get(type)).getPath();
675     }
676
677     
678
679     //****--------------------------------------------------------------------------*****/
680
//* Abstract method defination */
681
//****--------------------------------------------------------------------------*****/
682

683     
684     
685     /**
686      * Add controls for File
687      *
688      * @param webResponse page refrence
689      * @param description of parameters
690      *
691      * @return webResponse
692      *
693      * @throws Exception if fails
694      */

695     public WebResponse addControl(WebResponse webResponse,
696                                     Description description)
697     throws Exception JavaDoc {
698         
699         assertNotNull("List Report Detail page response is Null",webResponse);
700         
701         String JavaDoc str = webResponse.getText();
702         
703         if ((str == null) || (str.trim().length() == 0)) {
704             fail("There is no text on response");
705         }
706
707         assertTrue(str.indexOf(reportListPageText) != -1);
708         
709         pageForm = webResponse.getFormWithName(listPageFormText);
710         assertNotNull("Form is Null ", pageForm);
711         
712         SubmitButton addControlBtn = pageForm.getSubmitButton(addCtrlBtnText);
713         assertNotNull("Button is Null ", addControlBtn);
714         
715         webResponse = pageForm.submit(addControlBtn);
716         
717         String JavaDoc text = webResponse.getText();
718         assertNotNull("page text is Null ", text);
719         
720         if(text == null || text.trim().length()==0)
721             fail("There is no text on page");
722         
723         assertTrue(text.indexOf(locateInputControlText)!= -1);
724         
725         WebForm locateInputForm = webResponse.getFormWithName(datadescFormText);
726         assertNotNull("Form is Null ", locateInputForm);
727         
728         nextButton = locateInputForm.getSubmitButton(nextBtnText);
729         assertNotNull("button is Null ", nextButton);
730         
731         locateInputForm.setParameter("inputControlSource","LOCAL");
732         
733         webResponse = locateInputForm.submit(nextButton);
734         
735         String JavaDoc string = webResponse.getText();
736         assertNotNull("page text is Null ", string);
737         
738         if(string == null || string.trim().length()==0)
739             fail("There is no text on page");
740         
741         assertTrue(string.indexOf(reportInputControlText)!= -1);
742         
743         
744         WebForm descriptionForm = webResponse.getFormWithName(descriptionFormText);
745         assertNotNull("Form is Null ", descriptionForm);
746         
747         nextButton = descriptionForm.getSubmitButton(nextBtnText);
748         assertNotNull("button is Null ", nextButton);
749         
750         descriptionForm.setParameter("inputControl.name",description.getFileName());
751         descriptionForm.setParameter("inputControl.label",description.getFileLabel());
752         
753         webResponse = descriptionForm.submit(nextButton);
754         
755         WebForm dataTypeForm = webResponse.getFormWithName(datadescFormText);
756         assertNotNull("Form is Null ", dataTypeForm);
757         
758         nextButton = dataTypeForm.getSubmitButton(nextBtnText);
759         assertNotNull("button is Null ", nextButton);
760         
761         dataTypeForm.setParameter("source","LOCAL");
762                 
763         webResponse = dataTypeForm.submit(nextButton);
764         
765         String JavaDoc page = webResponse.getText();
766         assertNotNull("page text is Null ", page);
767         
768         if(page == null || page.trim().length()==0)
769             fail("There is no text on page");
770         
771         assertTrue(page.indexOf(dataTypePageText)!= -1);
772         
773         WebForm dataDescForm = webResponse.getFormWithName(dataTypeFormText);
774         assertNotNull("Form is Null ", dataDescForm);
775         
776         SubmitButton saveButton = dataDescForm.getSubmitButton(savetBtnText);
777         assertNotNull("button is Null ", saveButton);
778         
779         dataDescForm.setParameter("dataType.name",description.getFileName());
780         dataDescForm.setParameter("dataType.label",description.getFileLabel());
781         
782         webResponse = dataDescForm.submit(saveButton);
783         
784         return webResponse;
785     }
786     
787     
788     
789     /**
790      * Add resource for File
791      *
792      * @param webResponse page refrence
793      * @param description of parameters
794      * @param fileLocation locates the file location
795      *
796      * @return webResponse
797      *
798      * @throws Exception if fails
799      */

800     public WebResponse addResource(WebResponse webResponse,
801                                     Description description,
802                                     String JavaDoc fileLocation)
803     throws Exception JavaDoc {
804         
805         assertNotNull("List Report Detail page response is Null",webResponse);
806         
807         pageForm = webResponse.getFormWithName(listPageFormText);
808         
809         SubmitButton addResourceBtn = pageForm.getSubmitButton(addResourceBtnText);
810         
811         webResponse = pageForm.submit(addResourceBtn);
812         
813         String JavaDoc string = webResponse.getText();
814         
815         if(string == null || string.trim().length()==0)
816             fail("There is no text on page");
817         
818         assertTrue(string.indexOf(reportFileResPageText)!= -1);
819         
820         WebForm loadPageForm = webResponse.getFormWithName(formText);
821         
822         SubmitButton nextButton = loadPageForm.getSubmitButton(nextBtnText);
823         
824         File JavaDoc file1 = new File JavaDoc(fileLocation);
825         UploadFileSpec[] uploadFile = new UploadFileSpec[] { new UploadFileSpec(file1) };
826
827         loadPageForm.setParameter("source", "FILE_SYSTEM");
828         loadPageForm.setParameter("newData", uploadFile);
829         
830         webResponse = loadPageForm.submit(nextButton);
831         
832         String JavaDoc str = webResponse.getText();
833         if(str==null || str.trim().length()==0)
834             fail("There is no text on the page");
835         
836         assertTrue(str.indexOf(fileResourcePageText)!= -1);
837         
838         WebForm rescDescForm = webResponse.getFormWithName(resDescriptiomFormText);
839         
840         nextButton = rescDescForm.getSubmitButton(nextBtnText);
841         
842         rescDescForm.setParameter("fileResource.name",description.getFileName());
843         rescDescForm.setParameter("fileResource.label",description.getFileLabel());
844         rescDescForm.setParameter("fileResource.description",description.getFileDescription());
845         
846         webResponse = rescDescForm.submit(nextButton);
847         
848         return webResponse;
849         
850     }
851     
852     
853     /**
854      * Add Details for File
855      *
856      * @param wResponse page refrence
857      * @param fileLocation where file is located
858      * @param description of parameters
859      *
860      * @return wResponse
861      *
862      * @throws Exception if fails
863      **/

864     public WebResponse addNowDetails(WebResponse wResponse,
865                                      String JavaDoc fileLocation)
866       throws Exception JavaDoc {
867         assertNotNull(" Load File Page Response is Null ", wResponse);
868
869         String JavaDoc str = wResponse.getText();
870         
871         if ((str == null) || (str.trim().length() == 0)) {
872             fail("There is no text on response");
873         }
874
875         assertTrue(str.indexOf(reportListPageText) != -1);
876
877         pageForm = wResponse.getFormWithName(listPageFormText);
878         
879         WebLink addNowLink = wResponse.getLinkWith("Add Now");
880                 
881         wResponse = addNowLink.click();
882         
883         String JavaDoc string = wResponse.getText();
884         if ((string == null) || (string.trim().length() == 0)) {
885             fail("There is no text on response");
886         }
887
888         assertTrue(string.indexOf(reportFileResPageText) != -1);
889         
890                 
891         WebForm form1 = wResponse.getFormWithName(formText);
892         
893         nextButton = form1.getSubmitButton(nextBtnText);
894
895         File JavaDoc file = new File JavaDoc(fileLocation);
896         UploadFileSpec[] uploadFile1 = new UploadFileSpec[] { new UploadFileSpec(file) };
897
898         form1.setParameter("source", "FILE_SYSTEM");
899         form1.setParameter("newData", uploadFile1);
900
901         wResponse = form1.submit(nextButton);
902
903         String JavaDoc string2 = wResponse.getText();
904
905         if ((string2 == null) || (string2.trim().length() == 0)) {
906             fail("There is no text on response");
907         }
908
909         assertTrue(string2.indexOf(fileResourcePageText) != -1);
910
911         WebForm descriptionForm = wResponse.getFormWithName(resDescriptiomFormText);
912         nextButton = descriptionForm.getSubmitButton(nextBtnText);
913         wResponse = descriptionForm.submit(nextButton);
914
915         return wResponse;
916     }
917
918     /**
919      * Form bean for Resource nameing
920      *
921      **/

922     public class Description {
923         private String JavaDoc fileName;
924         private String JavaDoc fileLabel;
925         private String JavaDoc fileDescription;
926         private String JavaDoc fileType;
927
928         public Description() {
929             super();
930         }
931
932         public Description(String JavaDoc name,
933                            String JavaDoc label,
934                            String JavaDoc description,
935                            String JavaDoc type) {
936             super();
937             this.fileName = name;
938             this.fileLabel = label;
939             this.fileDescription = description;
940             this.fileType = type;
941         }
942
943         public String JavaDoc getFileDescription() {
944             return fileDescription;
945         }
946
947         public void setFileDescription(String JavaDoc fileDescription) {
948             this.fileDescription = fileDescription;
949         }
950
951         public String JavaDoc getFileLabel() {
952             return fileLabel;
953         }
954
955         public void setFileLabel(String JavaDoc fileLabel) {
956             this.fileLabel = fileLabel;
957         }
958
959         public String JavaDoc getFileName() {
960             return fileName;
961         }
962
963         public void setFileName(String JavaDoc fileName) {
964             this.fileName = fileName;
965         }
966
967         public String JavaDoc getFileType() {
968             return fileType;
969         }
970
971         public void setFileType(String JavaDoc fileType) {
972             this.fileType = fileType;
973         }
974     }
975     
976 }
977
Popular Tags