1 21 22 package com.jaspersoft.jasperserver.war.repository; 23 24 import java.io.File ; 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 48 public AbstractHttpRepositeryBaseFlow(String 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 67 public void setUp() 68 throws Exception { 69 wResponse = commonLoginFunction(homePageUrl); 70 } 71 72 73 74 78 79 public void repositoryFlow(TestAttribute attrib) throws Exception { 80 81 82 checkRepositoryPage(); 84 checkAddNamePage(attrib); 86 addForDataSource(attrib); 88 addForDataType(attrib); 90 addFile(attrib); 92 addInputControlFile(attrib); 94 95 } 96 97 98 private void checkRepositoryPage() throws Exception { 100 assertNotNull(" Home Page Response is Null ", wResponse); 102 103 WebLink link = wResponse.getLinkWith(repositoryLink); 105 assertNotNull(repositoryLink+" Link is Null ", link); 106 107 wResponse = link.click(); 108 109 assertNotNull("Link element is not on the page",wResponse.getElementsWithName(rootLink)); 111 112 String 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 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 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 private void checkAddNamePage(TestAttribute attrib) throws Exception { 143 144 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 wResponse = addNewForm.submit(saveButton); 155 156 String 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 addNewForm.setParameter("actualFolder.name",attrib.getDataSourceReportName()); 166 addNewForm.setParameter("actualFolder.label",attrib.getLabel()); 167 168 wResponse = addNewForm.submit(saveButton); 169 170 } 171 172 173 private void addForDataSource(TestAttribute attrib) throws Exception { 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 private void dataSourcePage(TestAttribute attrib)throws Exception { 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 private void dataDescriptionPage(TestAttribute attrib) throws Exception { 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 wResponse = form.submit(saveButton); 224 225 String 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 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 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 private void addForDataType(TestAttribute attrib)throws Exception { 253 254 assertNotNull(" repository browser sellection page is Null ", wResponse); 255 256 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 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 { 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 private void addFile(TestAttribute attrib)throws Exception { 296 297 assertNotNull(" repository browser sellection page is Null ", wResponse); 298 299 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 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 { 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 file = new File (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 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 { 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 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 private void addInputControlFile(TestAttribute attrib)throws Exception { 377 378 assertNotNull(" repository browser sellection page is Null ", wResponse); 379 380 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 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 { 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 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 { 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 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 { 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 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 getJrxmlFileResourceURL(String jrxml) { 480 return getClass().getClassLoader().getResource(jrxml).getPath(); 482 } 483 484 485 489 public class Description { 490 private String fileName; 491 private String fileLabel; 492 private String fileDescription; 493 private String fileType; 494 495 public Description() { 496 super(); 497 } 498 499 public Description(String name, 500 String label, 501 String description, 502 String type) { 503 super(); 504 this.fileName = name; 505 this.fileLabel = label; 506 this.fileDescription = description; 507 this.fileType = type; 508 } 509 510 public String getFileDescription() { 511 return fileDescription; 512 } 513 514 public void setFileDescription(String fileDescription) { 515 this.fileDescription = fileDescription; 516 } 517 518 public String getFileLabel() { 519 return fileLabel; 520 } 521 522 public void setFileLabel(String fileLabel) { 523 this.fileLabel = fileLabel; 524 } 525 526 public String getFileName() { 527 return fileName; 528 } 529 530 public void setFileName(String fileName) { 531 this.fileName = fileName; 532 } 533 534 public String getFileType() { 535 return fileType; 536 } 537 538 public void setFileType(String fileType) { 539 this.fileType = fileType; 540 } 541 } 542 } | Popular Tags |