|
19 | 19 | import org.junit.Rule; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.jvnet.hudson.test.JenkinsRule; |
| 22 | +import com.gargoylesoftware.htmlunit.WebAssert; |
| 23 | +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; |
| 24 | +import com.gargoylesoftware.htmlunit.html.HtmlPage; |
22 | 25 | import com.mathworks.ci.MatlabBuilder.RunTestsAutomaticallyOption; |
23 | 26 | import com.mathworks.ci.MatlabBuilder.RunTestsWithCustomCommandOption; |
24 | 27 |
|
@@ -279,4 +282,132 @@ public void verifyCustomCommandInvokedForBatchMode() throws Exception { |
279 | 282 | jenkins.assertLogContains("-batch", build); |
280 | 283 | jenkins.assertLogContains("runtests", build); |
281 | 284 | } |
| 285 | + |
| 286 | + /* |
| 287 | + * Test to verify if Automatic option passes appropriate test atrtifact values. |
| 288 | + */ |
| 289 | + |
| 290 | + @Test |
| 291 | + public void verifyRunTestAutomaticallyIsDefault() throws Exception { |
| 292 | + this.matlabBuilder.setLocalMatlab(getMatlabroot("R2018b")); |
| 293 | + RunTestsAutomaticallyOption runOption = new RunTestsAutomaticallyOption(); |
| 294 | + runOption.setTaCoberturaChkBx(true); |
| 295 | + runOption.setTaJunitChkBx(true); |
| 296 | + runOption.setTatapChkBx(true); |
| 297 | + this.matlabBuilder.setTestRunTypeList(runOption); |
| 298 | + project.getBuildersList().add(this.matlabBuilder); |
| 299 | + FreeStyleBuild build = project.scheduleBuild2(0).get(); |
| 300 | + jenkins.assertLogContains("-batch", build); |
| 301 | + jenkins.assertLogContains("true,true,true", build); |
| 302 | + } |
| 303 | + |
| 304 | + /* |
| 305 | + * Test to verify default value of getStringByName() when Automatic test mode. |
| 306 | + */ |
| 307 | + |
| 308 | + @Test |
| 309 | + public void verifyDefaultValueOfgetStringByName() throws Exception { |
| 310 | + this.matlabBuilder.setLocalMatlab(getMatlabroot("R2018b")); |
| 311 | + RunTestsAutomaticallyOption runOption = new RunTestsAutomaticallyOption(); |
| 312 | + Assert.assertNull(runOption.getStringByName("fakeChkBox")); |
| 313 | + } |
| 314 | + |
| 315 | + /* |
| 316 | + * Test to verify default value of getBooleanByName() when Custom test mode. |
| 317 | + */ |
| 318 | + |
| 319 | + @Test |
| 320 | + public void verifyDefaultValueOfgetBooleanByName() throws Exception { |
| 321 | + this.matlabBuilder.setLocalMatlab(getMatlabroot("R2018b")); |
| 322 | + RunTestsWithCustomCommandOption runOption = new RunTestsWithCustomCommandOption(); |
| 323 | + Assert.assertFalse(runOption.getBooleanByName("fakeCommand")); |
| 324 | + } |
| 325 | + |
| 326 | + /* |
| 327 | + * Test to verify when MATLAB version is older the R2017a |
| 328 | + */ |
| 329 | + |
| 330 | + @Test |
| 331 | + public void verifyMatlabVersionOlderThanR17a() throws Exception { |
| 332 | + this.matlabBuilder.setLocalMatlab(getMatlabroot("R2018b")); |
| 333 | + RunTestsAutomaticallyOption runOption = new RunTestsAutomaticallyOption(); |
| 334 | + runOption.setTaCoberturaChkBx(true); |
| 335 | + runOption.setTaJunitChkBx(true); |
| 336 | + runOption.setTatapChkBx(true); |
| 337 | + this.matlabBuilder.setTestRunTypeList(runOption); |
| 338 | + project.getBuildersList().add(this.matlabBuilder); |
| 339 | + FreeStyleBuild build = project.scheduleBuild2(0).get(); |
| 340 | + jenkins.assertLogContains("-batch", build); |
| 341 | + jenkins.assertLogContains("true,true,true", build); |
| 342 | + } |
| 343 | + |
| 344 | + /* |
| 345 | + * Test To verify if UI throws an error when MATLAB root is empty. |
| 346 | + * |
| 347 | + */ |
| 348 | + |
| 349 | + @Test |
| 350 | + public void verifyEmptyMatlabRootError() throws Exception { |
| 351 | + project.getBuildersList().add(this.matlabBuilder); |
| 352 | + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); |
| 353 | + WebAssert.assertTextPresent(page, TestMessage.getValue("Builder.matlab.root.empty.error")); |
| 354 | + } |
| 355 | + |
| 356 | + /* |
| 357 | + * Test To verify UI does not throw any error when valid MATLAB root entered |
| 358 | + * |
| 359 | + */ |
| 360 | + |
| 361 | + @Test |
| 362 | + public void verifyInvalidValidMatlabRoot() throws Exception { |
| 363 | + project.getBuildersList().add(this.matlabBuilder); |
| 364 | + this.matlabBuilder.setLocalMatlab("/fake/matlab/path"); |
| 365 | + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); |
| 366 | + WebAssert.assertTextPresent(page, TestMessage.getValue("Builder.invalid.matlab.root.error")); |
| 367 | + } |
| 368 | + |
| 369 | + /* |
| 370 | + * Test To verify UI does not throw any error when valid MATLAB root entered |
| 371 | + * |
| 372 | + */ |
| 373 | + |
| 374 | + @Test |
| 375 | + public void verifyValidMatlabRoot() throws Exception { |
| 376 | + project.getBuildersList().add(this.matlabBuilder); |
| 377 | + this.matlabBuilder.setLocalMatlab(getMatlabroot("R2018b")); |
| 378 | + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); |
| 379 | + WebAssert.assertTextNotPresent(page, TestMessage.getValue("Builder.invalid.matlab.root.error")); |
| 380 | + } |
| 381 | + |
| 382 | + /* |
| 383 | + * Test To verify UI displays Cobertura Warning message when unsupported MATLAB version used. |
| 384 | + * |
| 385 | + */ |
| 386 | + |
| 387 | + @Test |
| 388 | + public void verifyCoberturaWarning() throws Exception { |
| 389 | + project.getBuildersList().add(this.matlabBuilder); |
| 390 | + this.matlabBuilder.setLocalMatlab(getMatlabroot("R2017a")); |
| 391 | + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); |
| 392 | + HtmlCheckBoxInput coberturaChkBx = page.getElementByName("taCoberturaChkBx"); |
| 393 | + coberturaChkBx.setChecked(true); |
| 394 | + WebAssert.assertTextPresent(page, TestMessage.getValue("Builder.matlab.cobertura.support.warning")); |
| 395 | + } |
| 396 | + |
| 397 | + /* |
| 398 | + * Test To verify UI displays Cobertura Error message when invalid MATLAB root entered. |
| 399 | + * |
| 400 | + */ |
| 401 | + |
| 402 | + @Test |
| 403 | + public void verifyCoberturaError() throws Exception { |
| 404 | + project.getBuildersList().add(this.matlabBuilder); |
| 405 | + this.matlabBuilder.setLocalMatlab("/fake/matlab/path"); |
| 406 | + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); |
| 407 | + HtmlCheckBoxInput coberturaChkBx = page.getElementByName("taCoberturaChkBx"); |
| 408 | + coberturaChkBx.setChecked(true); |
| 409 | + String pageText = page.asText(); |
| 410 | + String filteredPageText = pageText.replaceFirst(TestMessage.getValue("Builder.invalid.matlab.root.error"), ""); |
| 411 | + Assert.assertTrue(filteredPageText.contains(TestMessage.getValue("Builder.invalid.matlab.root.error"))); |
| 412 | + } |
282 | 413 | } |
0 commit comments