github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/NeoDeployTest.groovy (about) 1 import com.sap.piper.StepAssertions 2 import com.sap.piper.Utils 3 4 import hudson.AbortException 5 6 import util.JenkinsReadFileRule 7 import util.JenkinsReadJsonRule 8 9 import static org.hamcrest.Matchers.allOf 10 import static org.hamcrest.Matchers.containsString 11 import static org.hamcrest.Matchers.hasItem 12 import static org.hamcrest.Matchers.not 13 import static org.junit.Assert.assertThat 14 15 import org.hamcrest.BaseMatcher 16 import org.hamcrest.Description 17 import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException 18 import org.junit.After 19 import org.junit.Assert 20 import org.junit.Before 21 import org.junit.Rule 22 import org.junit.Test 23 import org.junit.rules.ExpectedException 24 import org.junit.rules.RuleChain 25 import util.BasePiperTest 26 import util.CommandLineMatcher 27 import util.JenkinsCredentialsRule 28 import util.JenkinsLockRule 29 import util.JenkinsLoggingRule 30 import util.JenkinsPropertiesRule 31 import util.JenkinsReadYamlRule 32 import util.JenkinsShellCallRule 33 import util.JenkinsShellCallRule.Type 34 import util.JenkinsStepRule 35 import util.JenkinsWithEnvRule 36 import util.JenkinsFileExistsRule 37 import util.Rules 38 39 class NeoDeployTest extends BasePiperTest { 40 41 private ExpectedException thrown = new ExpectedException().none() 42 private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) 43 private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this) 44 private JenkinsStepRule stepRule = new JenkinsStepRule(this) 45 private JenkinsReadFileRule readFileRule = new JenkinsReadFileRule(this, 'test/resources') 46 private JenkinsFileExistsRule fileExistsRule = new JenkinsFileExistsRule(this, ['warArchive.war', 'archive.mtar', 'war.properties']) 47 48 @Rule 49 public RuleChain ruleChain = Rules 50 .getCommonRules(this) 51 .around(new JenkinsReadYamlRule(this)) 52 .around(new JenkinsPropertiesRule(this, warPropertiesFileName, warProperties)) 53 .around(thrown) 54 .around(loggingRule) 55 .around(shellRule) 56 .around(new JenkinsCredentialsRule(this) 57 .withCredentials('myCredentialsId', 'anonymous', '********') 58 .withCredentials('CI_CREDENTIALS_ID', 'defaultUser', '********') 59 .withCredentials('testOauthId', 'clientId', '********') 60 .withCredentials("OauthDataFileId","oauth.json")) 61 .around(new JenkinsReadJsonRule(this)) 62 .around(readFileRule) 63 .around(stepRule) 64 .around(new JenkinsLockRule(this)) 65 .around(new JenkinsWithEnvRule(this)) 66 .around(fileExistsRule) 67 68 69 private static warArchiveName = 'warArchive.war' 70 private static warPropertiesFileName = 'war.properties' 71 private static archiveName = 'archive.mtar' 72 private static warProperties 73 74 75 @Before 76 void init() { 77 78 warProperties = new Properties() 79 warProperties.put('account', 'trialuser123') 80 warProperties.put('host', 'test.deploy.host.com') 81 warProperties.put('application', 'testApp') 82 83 helper.registerAllowedMethod('dockerExecute', [Map, Closure], null) 84 helper.registerAllowedMethod('pwd', [], { return './' }) 85 86 nullScript.commonPipelineEnvironment.configuration = [steps: [neoDeploy: [neo: [host: 'test.deploy.host.com', account: 'trialuser123']]]] 87 88 Utils.metaClass.echo = { def m -> } 89 } 90 91 @After 92 void tearDown() { 93 GroovySystem.metaClassRegistry.removeMetaClass(StepAssertions) 94 GroovySystem.metaClassRegistry.removeMetaClass(Utils) 95 } 96 97 @Test 98 void straightForwardTestConfigViaParameters() { 99 100 stepRule.step.neoDeploy(script: nullScript, 101 source: archiveName, 102 neo:[credentialsId: 'myCredentialsId'], 103 utils: utils, 104 ) 105 106 Assert.assertThat(shellRule.shell, 107 new CommandLineMatcher().hasProlog("neo.sh deploy-mta") 108 .hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com') 109 .hasSingleQuotedOption('account', 'trialuser123') 110 .hasOption('synchronous', '') 111 .hasSingleQuotedOption('user', 'anonymous') 112 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 113 .hasSingleQuotedOption('source', '.*')) 114 } 115 116 @Test 117 void straightForwardTestConfigViaConfiguration() { 118 119 nullScript.commonPipelineEnvironment.configuration = [steps: [ 120 neoDeploy: [ 121 neo: [ 122 host: 'configuration-frwk.deploy.host.com', 123 account: 'configurationFrwkUser123' 124 ], 125 source: archiveName 126 ] 127 ]] 128 129 stepRule.step.neoDeploy(script: nullScript, 130 neo:[credentialsId: 'myCredentialsId'] 131 ) 132 133 Assert.assertThat(shellRule.shell, 134 new CommandLineMatcher().hasProlog("neo.sh deploy-mta") 135 .hasSingleQuotedOption('host', 'configuration-frwk\\.deploy\\.host\\.com') 136 .hasSingleQuotedOption('account', 'configurationFrwkUser123') 137 .hasOption('synchronous', '') 138 .hasSingleQuotedOption('user', 'anonymous') 139 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 140 .hasSingleQuotedOption('source', archiveName)) 141 } 142 143 @Test 144 void extensionsAsStringTest() { 145 146 def checkedExtensionFiles = [] 147 148 StepAssertions.metaClass.static.assertFileExists = 149 getFileExistsCheck(checkedExtensionFiles, [archiveName, 'myExtension.yml']) 150 151 stepRule.step.neoDeploy( 152 script: nullScript, 153 source: archiveName, 154 extensions: 'myExtension.yml' 155 ) 156 157 assert checkedExtensionFiles.contains('myExtension.yml') 158 159 assertThat(shellRule.shell, 160 new CommandLineMatcher() 161 .hasProlog('neo.sh deploy-mta') 162 .hasSingleQuotedOption('extensions', 'myExtension.yml')) 163 } 164 165 @Test 166 void extensionsAsEmptyString() { 167 168 thrown.expect(AbortException) 169 thrown.expectMessage('extension file name was null or empty') 170 171 stepRule.step.neoDeploy( 172 script: nullScript, 173 source: archiveName, 174 extensions: '' 175 ) 176 } 177 178 @Test 179 void extensionsAsSetTest() { 180 Set extensions= ['myExtension1.yml' ,'myExtension2.yml'] 181 extensionsAsCollectionTest(extensions) 182 } 183 184 @Test 185 void extensionsAsCollectionWithEmptyStringTest() { 186 187 thrown.expect(AbortException) 188 thrown.expectMessage('extension file name was null or empty') 189 190 stepRule.step.neoDeploy( 191 script: nullScript, 192 source: archiveName, 193 extensions: ['myExtension1.yml' ,'']) 194 } 195 196 @Test 197 void extensionsNullTest() { 198 199 stepRule.step.neoDeploy( 200 script: nullScript, 201 source: archiveName, 202 extensions: null) 203 204 assert shellRule.shell.find { c -> c.startsWith('neo.sh deploy-mta') && ! c.contains('--extensions') } 205 } 206 207 @Test 208 void extensionsAsEmptyCollectionTest() { 209 210 stepRule.step.neoDeploy( 211 script: nullScript, 212 source: archiveName, 213 extensions: []) 214 215 assert shellRule.shell.find { c -> c.startsWith('neo.sh deploy-mta') && ! c.contains('--extensions') } 216 } 217 218 @Test 219 void extensionsAsCollectionsWithNullEntrySetTest() { 220 221 thrown.expect(AbortException) 222 thrown.expectMessage('extension file name was null or empty') 223 224 stepRule.step.neoDeploy( 225 script: nullScript, 226 source: archiveName, 227 extensions: [null]) 228 } 229 230 @Test 231 void extensionsAsListTest() { 232 List extensions= ['myExtension1.yml' ,'myExtension2.yml'] 233 extensionsAsCollectionTest(extensions) 234 } 235 236 @Test 237 void sameExtensionProvidedTwiceTest() { 238 List extensions= ['myExtension1.yml' ,'myExtension2.yml', 'myExtension1.yml'] 239 extensionsAsCollectionTest(extensions) 240 } 241 242 void extensionsAsCollectionTest(def extensions) { 243 244 def checkedExtensionFiles = [] 245 246 StepAssertions.metaClass.static.assertFileExists = 247 getFileExistsCheck(checkedExtensionFiles, [archiveName, 'myExtension1.yml', 'myExtension2.yml']) 248 249 stepRule.step.neoDeploy( 250 script: nullScript, 251 source: archiveName, 252 extensions: extensions 253 ) 254 255 assert checkedExtensionFiles.contains('myExtension1.yml') 256 assert checkedExtensionFiles.contains('myExtension2.yml') 257 258 assertThat(shellRule.shell, 259 new CommandLineMatcher() 260 .hasProlog('neo.sh deploy-mta') 261 // some kind of creative usage for the single quotation check (... single quotes inside) 262 .hasSingleQuotedOption('extensions', 'myExtension1.yml\',\'myExtension2.yml')) 263 264 } 265 266 private static getFileExistsCheck(def checkedExtensionFiles, def fileNames) { 267 268 { Script step, String filePath -> 269 checkedExtensionFiles << filePath 270 if( ! fileNames.contains(filePath) ) 271 step.error("File ${filePath} cannot be found.") 272 } 273 } 274 275 @Test 276 void extensionsForWrongDeployModeTest() { 277 278 thrown.expect(AbortException) 279 thrown.expectMessage('Extensions are only supported for deploy mode \'MTA\'') 280 281 stepRule.step.neoDeploy( 282 script: nullScript, 283 source: archiveName, 284 deployMode: 'warParams', 285 extensions: 'myExtension.yml', 286 neo: 287 [ 288 application: 'does', 289 runtime: 'not', 290 runtimeVersion: 'matter' 291 ] 292 ) 293 } 294 295 @Test 296 void deployWithBearerTokenCredentials_success(){ 297 298 nullScript.commonPipelineEnvironment.setMtarFilePath('archive.mtar') 299 300 301 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, "https:\\/\\/api\\.test\\.com\\/oauth2\\/apitoken\\/v1", "{\"access_token\":\"xxx\"}") 302 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, "https:\\/\\/slservice\\.test\\.host\\.com\\/slservice\\/v1\\/oauth\\/accounts\\/testUser123\\/mtars", "{\"id\":123}") 303 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, "https:\\/\\/slservice\\.test\\.host\\.com\\/slservice\\/v1\\/oauth\\/accounts\\/testUser123\\/mtars", "{\"state\":\"DONE\"}") 304 305 306 stepRule.step.neoDeploy( 307 script: nullScript, 308 source: archiveName, 309 deployMode: 'mta', 310 neo: [ 311 host: 'test.host.com', 312 account: 'testUser123', 313 credentialsId: 'OauthDataFileId', 314 credentialType: 'SecretFile' 315 ], 316 ) 317 318 Assert.assertThat(shellRule.shell[0], containsString("#!/bin/bash curl --fail --silent --show-error --retry 12 -XPOST -u \"abc123:testclientsecret123\" \"https://api.test.com/oauth2/apitoken/v1?grant_type=client_credentials\"")) 319 Assert.assertThat(shellRule.shell[1], containsString("#!/bin/bash curl --fail --silent --show-error --retry 12 -XPOST -H \"Authorization: Bearer xxx\" -F file=@\"archive.mtar\" \"https://slservice.test.host.com/slservice/v1/oauth/accounts/testUser123/mtars\"")) 320 } 321 322 @Test 323 void archivePathFromCPETest() { 324 325 nullScript.commonPipelineEnvironment.setMtarFilePath('archive.mtar') 326 327 stepRule.step.neoDeploy(script: nullScript) 328 329 Assert.assertThat(shellRule.shell, 330 new CommandLineMatcher().hasProlog("neo.sh deploy-mta") 331 .hasSingleQuotedOption('source', 'archive.mtar')) 332 } 333 334 @Test 335 void archivePathFromParamsHasHigherPrecedenceThanCPETest() { 336 337 nullScript.commonPipelineEnvironment.setMtarFilePath('archive2.mtar') 338 339 stepRule.step.neoDeploy(script: nullScript, 340 source: "archive.mtar") 341 342 Assert.assertThat(shellRule.shell, 343 new CommandLineMatcher().hasProlog("neo.sh deploy-mta") 344 .hasSingleQuotedOption('source', 'archive.mtar')) 345 } 346 347 348 @Test 349 void badCredentialsIdTest() { 350 351 thrown.expect(CredentialNotFoundException) 352 353 stepRule.step.neoDeploy(script: nullScript, 354 source: archiveName, 355 neo:[credentialsId: 'badCredentialsId'] 356 ) 357 } 358 359 360 @Test 361 void credentialsIdNotProvidedTest() { 362 363 stepRule.step.neoDeploy(script: nullScript, 364 source: archiveName 365 ) 366 367 Assert.assertThat(shellRule.shell, 368 new CommandLineMatcher().hasProlog("neo.sh deploy-mta") 369 .hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com') 370 .hasSingleQuotedOption('account', 'trialuser123') 371 .hasOption('synchronous', '') 372 .hasSingleQuotedOption('user', 'defaultUser') 373 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 374 .hasSingleQuotedOption('source', '.*') 375 ) 376 } 377 378 @Test 379 void wrongArchivePathProvidedTest() { 380 381 thrown.expect(AbortException) 382 thrown.expectMessage('File wrongArchiveName cannot be found') 383 stepRule.step.neoDeploy(script: nullScript, 384 source: 'wrongArchiveName') 385 } 386 387 388 @Test 389 void sanityChecksDeployModeMTATest() { 390 391 thrown.expect(Exception) 392 thrown.expectMessage( 393 allOf( 394 containsString('ERROR - NO VALUE AVAILABLE FOR:'), 395 containsString('neo/host'), 396 containsString('neo/account'), 397 containsString('source'))) 398 399 nullScript.commonPipelineEnvironment.configuration = [:] 400 401 // deployMode mta is the default, but for the sake of transparency it is better to repeat it. 402 stepRule.step.neoDeploy(script: nullScript, deployMode: 'mta') 403 } 404 405 @Test 406 public void sanityChecksDeployModeWarPropertiesFileTest() { 407 408 thrown.expect(IllegalArgumentException) 409 // using this deploy mode 'account' and 'host' are provided by the properties file 410 thrown.expectMessage( 411 allOf( 412 not(containsString('neo/host')), 413 not(containsString('neo/account')))) 414 415 nullScript.commonPipelineEnvironment.configuration = [:] 416 417 stepRule.step.neoDeploy(script: nullScript, deployMode: 'warPropertiesFile', source: warArchiveName) 418 } 419 420 @Test 421 public void sanityChecksDeployModeWarParamsTest() { 422 423 thrown.expect(IllegalArgumentException) 424 thrown.expectMessage( 425 allOf( 426 containsString('ERROR - NO VALUE AVAILABLE FOR:'), 427 containsString('neo/application'), 428 containsString('neo/runtime'), 429 containsString('neo/runtimeVersion'), 430 containsString('neo/host'), 431 containsString('neo/account'))) 432 433 nullScript.commonPipelineEnvironment.configuration = [:] 434 435 stepRule.step.neoDeploy(script: nullScript, deployMode: 'warParams', source: warArchiveName) 436 } 437 438 @Test 439 void mtaDeployModeTest() { 440 441 stepRule.step.neoDeploy(script: nullScript, source: archiveName, deployMode: 'mta') 442 443 Assert.assertThat(shellRule.shell, 444 new CommandLineMatcher().hasProlog("neo.sh deploy-mta") 445 .hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com') 446 .hasSingleQuotedOption('account', 'trialuser123') 447 .hasOption('synchronous', '') 448 .hasSingleQuotedOption('user', 'defaultUser') 449 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 450 .hasSingleQuotedOption('source', '.*')) 451 452 } 453 454 @Test 455 void invalidateCache_Success_Test() { 456 457 nullScript.commonPipelineEnvironment.configuration = [steps: [neoDeploy: [neo: [host: 'test.deploy.host.com', account: 'trialuser123', invalidateCache: true, oauthCredentialId: 'testOauthId', siteId: "12346"]]]] 458 fileExistsRule.registerExistingFile('./target/artifact.war') 459 460 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, "https:\\/\\/oauthasservices-trialuser123\\.test\\.deploy\\.host\\.com\\/oauth2\\/api\\/v1\\/token", "{\"access_token\":\"xxx\"}") 461 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, "fiori\\/api\\/v1\\/csrf", "X-CSRF-Token=xxx") 462 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, "fiori\\/v1\\/operations\\/invalidateCache", "{\"statusCode\":\"200\"}") 463 464 stepRule.step.neoDeploy(script: nullScript, 465 source: archiveName, 466 deployMode: 'mta') 467 468 Assert.assertThat(shellRule.shell, hasItem(containsString("curl -X POST -u \"clientId:********\" --fail \"https://oauthasservices-trialuser123.test.deploy.host.com/oauth2/api/v1/token?grant_type=client_credentials&scope=write,read"))) 469 Assert.assertThat(shellRule.shell[3], containsString("#!/bin/bash curl -i -L -c 'cookies.jar' -H 'X-CSRF-Token: Fetch' -H \"Authorization: Bearer xxx\" --fail \"https://cloudnwcportal-trialuser123.test.deploy.host.com/fiori/api/v1/csrf\"")) 470 } 471 472 @Test 473 void invalidateCache_notPerformed_warFiles() { 474 475 nullScript.commonPipelineEnvironment.configuration = [steps: [neoDeploy: [neo: [host: 'test.deploy.host.com', account: 'trialuser123', invalidateCache: true]]]] 476 477 stepRule.step.neoDeploy(script: nullScript, 478 neo: [ 479 application: 'testApp', 480 runtime: 'neo-javaee6-wp', 481 runtimeVersion: '2.125', 482 size: 'lite', 483 ], 484 deployMode: 'warParams', 485 warAction: 'deploy', 486 source: warArchiveName) 487 488 assertThat(loggingRule.log, containsString("Invalidation of cache is ignored. It is performed only for html5 applications.")) 489 } 490 491 @Test 492 void warFileParamsDeployModeTest() { 493 494 stepRule.step.neoDeploy(script: nullScript, 495 neo: [ 496 application: 'testApp', 497 runtime: 'neo-javaee6-wp', 498 runtimeVersion: '2.125', 499 size: 'lite', 500 ], 501 deployMode: 'warParams', 502 warAction: 'deploy', 503 source: warArchiveName) 504 505 Assert.assertThat(shellRule.shell, 506 new CommandLineMatcher().hasProlog("neo.sh deploy") 507 .hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com') 508 .hasSingleQuotedOption('account', 'trialuser123') 509 .hasSingleQuotedOption('application', 'testApp') 510 .hasSingleQuotedOption('runtime', 'neo-javaee6-wp') 511 .hasSingleQuotedOption('runtime-version', '2\\.125') 512 .hasSingleQuotedOption('size', 'lite') 513 .hasSingleQuotedOption('user', 'defaultUser') 514 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 515 .hasSingleQuotedOption('source', '.*\\.war')) 516 517 } 518 519 @Test 520 void warFileParamsDeployModeRollingUpdateTest() { 521 522 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.* status .*', 'Status: STARTED') 523 524 stepRule.step.neoDeploy(script: nullScript, 525 source: warArchiveName, 526 deployMode: 'warParams', 527 warAction: 'rolling-update', 528 neo: [ 529 application: 'testApp', 530 runtime: 'neo-javaee6-wp', 531 runtimeVersion: '2.125', 532 size: 'lite' 533 ] 534 ) 535 536 Assert.assertThat(shellRule.shell, 537 new CommandLineMatcher().hasProlog("neo.sh rolling-update") 538 .hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com') 539 .hasSingleQuotedOption('account', 'trialuser123') 540 .hasSingleQuotedOption('application', 'testApp') 541 .hasSingleQuotedOption('runtime', 'neo-javaee6-wp') 542 .hasSingleQuotedOption('runtime-version', '2\\.125') 543 .hasSingleQuotedOption('size', 'lite') 544 .hasSingleQuotedOption('user', 'defaultUser') 545 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 546 .hasSingleQuotedOption('source', '.*\\.war')) 547 } 548 549 @Test 550 void warFirstTimeRollingUpdateTest() { 551 552 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.* status .*', 'ERROR: Application [testApp] not found') 553 554 stepRule.step.neoDeploy(script: nullScript, 555 source: warArchiveName, 556 deployMode: 'warParams', 557 warAction: 'rolling-update', 558 neo: [ 559 application: 'testApp', 560 runtime: 'neo-javaee6-wp', 561 runtimeVersion: '2.125' 562 ] 563 ) 564 565 Assert.assertThat(shellRule.shell, 566 new CommandLineMatcher() 567 .hasProlog("neo.sh deploy") 568 .hasSingleQuotedOption('application', 'testApp')) 569 } 570 571 void warNotStartedRollingUpdateTest() { 572 573 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.* status .*', 'Status: STOPPED') 574 575 stepRule.step.neoDeploy(script: nullScript, 576 source: warArchiveName, 577 deployMode: 'warParams', 578 warAction: 'rolling-update', 579 neo: [ 580 application: 'testApp', 581 runtime: 'neo-javaee6-wp', 582 runtimeVersion: '2.125' 583 ] 584 ) 585 586 Assert.assertThat(shellRule.shell, 587 new CommandLineMatcher() 588 .hasProlog("\"/opt/neo/tools/neo.sh\" deploy") 589 .hasSingleQuotedOption('application', 'testApp')) 590 } 591 592 @Test 593 void showLogsOnFailingDeployment() { 594 595 thrown.expect(AbortException) 596 shellRule.setReturnValue(Type.REGEX, '.* deploy .*', {throw new AbortException()}) 597 598 stepRule.step.neoDeploy(script: nullScript, 599 source: warArchiveName, 600 deployMode: 'warParams', 601 warAction: 'deploy', 602 neo: [ 603 application: 'testApp', 604 runtime: 'neo-javaee6-wp', 605 runtimeVersion: '2.125' 606 ] 607 ) 608 609 Assert.assertThat(shellRule.shell, 610 new CommandLineMatcher().hasProlog("cat /var/log/neo/*")) 611 } 612 613 @Test 614 void warPropertiesFileDeployModeTest() { 615 616 stepRule.step.neoDeploy(script: nullScript, 617 source: warArchiveName, 618 deployMode: 'warPropertiesFile', 619 warAction: 'deploy', 620 neo: [ 621 propertiesFile: warPropertiesFileName 622 ] 623 ) 624 625 Assert.assertThat(shellRule.shell, 626 new CommandLineMatcher().hasProlog("neo.sh deploy") 627 .hasArgument('war.properties') 628 .hasSingleQuotedOption('user', 'defaultUser') 629 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 630 .hasSingleQuotedOption('source', '.*\\.war')) 631 } 632 633 @Test 634 void warPropertiesFileDeployModeRollingUpdateTest() { 635 636 shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.* status .*', 'Status: STARTED') 637 638 stepRule.step.neoDeploy(script: nullScript, 639 source: warArchiveName, 640 deployMode: 'warPropertiesFile', 641 warAction: 'rolling-update', 642 neo: [ 643 propertiesFile: warPropertiesFileName 644 ]) 645 646 Assert.assertThat(shellRule.shell, 647 new CommandLineMatcher().hasProlog("neo.sh rolling-update") 648 .hasArgument('war.properties') 649 .hasSingleQuotedOption('user', 'defaultUser') 650 .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') 651 .hasSingleQuotedOption('source', '.*\\.war')) 652 } 653 654 @Test 655 void illegalDeployModeTest() { 656 657 thrown.expect(Exception) 658 thrown.expectMessage("Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: [mta, warParams, warPropertiesFile].") 659 660 stepRule.step.neoDeploy(script: nullScript, 661 source: warArchiveName, 662 deployMode: 'illegalMode', 663 warAction: 'deploy', 664 neo: [ 665 application: 'testApp', 666 runtime: 'neo-javaee6-wp', 667 runtimeVersion: '2.125', 668 size: 'lite' 669 ]) 670 } 671 672 @Test 673 void illegalWARActionTest() { 674 675 thrown.expect(Exception) 676 thrown.expectMessage("Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: [deploy, rolling-update].") 677 678 stepRule.step.neoDeploy(script: nullScript, 679 source: warArchiveName, 680 deployMode: 'warParams', 681 warAction: 'illegalWARAction', 682 neo: [ 683 application: 'testApp', 684 runtime: 'neo-javaee6-wp', 685 runtimeVersion: '2.125', 686 size: 'lite' 687 ]) 688 } 689 690 @Test 691 void dontSwallowExceptionWhenUnableToProvideLogsTest() { 692 693 thrown.expect(AbortException) 694 thrown.expectMessage('The execution of the deploy command failed, see the log for details.') 695 thrown.expect(new BaseMatcher() { 696 697 def expectedException = AbortException 698 def expectedText = 'Cannot provide logs.' 699 700 boolean matches(def ex) { 701 def suppressed = ex.getSuppressed() 702 return (suppressed.size() == 1 && 703 suppressed[0] in expectedException && 704 suppressed[0].message == expectedText) 705 706 } 707 708 void describeTo(Description d) { 709 d.appendText(" a suppressed ${expectedException} with message ${expectedText}.") 710 } 711 }) 712 713 loggingRule.expect('Unable to provide the logs.') 714 715 helper.registerAllowedMethod('fileExists', [String], 716 { f -> 717 f == 'archive.mtar' 718 } 719 ) 720 721 helper.registerAllowedMethod("sh", [String], 722 { cmd -> 723 if (cmd.toString().contains('cat logs/neo/')) 724 throw new AbortException('Cannot provide logs.') 725 if (cmd.toString().contains('neo.sh deploy-mta')) 726 throw new AbortException('Something went wrong during neo deployment.') 727 } 728 ) 729 730 stepRule.step.neoDeploy(script: nullScript, 731 source: archiveName, 732 neo:[credentialsId: 'myCredentialsId'], 733 deployMode: 'mta', 734 utils: utils, 735 ) 736 } 737 738 @Test 739 void deployModeAsGStringTest() { 740 741 Map deployProps = [deployMode: 'warPropertiesFile'] 742 743 stepRule.step.neoDeploy(script: nullScript, 744 utils: utils, 745 neo: [credentialsId: 'myCredentialsId', 746 propertiesFile: warPropertiesFileName], 747 deployMode: "$deployProps.deployMode", 748 source: archiveName) 749 } 750 751 @Test 752 public void DefaultMavenDeploymentModuleNoPomTest() { 753 754 thrown.expect(AbortException) 755 thrown.expectMessage(containsString('does not contain a pom file')) 756 757 nullScript.commonPipelineEnvironment.configuration = [:] 758 stepRule.step.neoDeploy(script: nullScript, deployMode: 'warPropertiesFile') 759 } 760 761 @Test 762 public void DefaultMavenDeploymentModuleTest() { 763 764 helper.registerAllowedMethod('readMavenPom', [Map], { return [artifactId:'artifact', packaging: 'war'] }) 765 766 fileExistsRule.registerExistingFile('./pom.xml') 767 fileExistsRule.registerExistingFile('./target/artifact.war') 768 769 nullScript.commonPipelineEnvironment.configuration = [:] 770 stepRule.step.neoDeploy([ 771 script: nullScript, 772 deployMode: 'warParams', 773 neo: [ 774 application: 'testApp', 775 runtime: 'neo-javaee6-wp', 776 runtimeVersion: '2.125', 777 host: 'host', 778 account: 'account' 779 ] 780 ]) 781 782 Assert.assertThat(shellRule.shell, 783 new CommandLineMatcher().hasProlog("neo.sh deploy") 784 .hasSingleQuotedOption('source', './target/artifact.war')) 785 } 786 }