github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/AbapEnvironmentPipelineStagePostTest.groovy (about) 1 package templates 2 3 import org.junit.Before 4 import org.junit.Rule 5 import org.junit.Test 6 import org.junit.rules.RuleChain 7 import util.BasePiperTest 8 import util.JenkinsReadYamlRule 9 import util.JenkinsStepRule 10 import util.PipelineWhenException 11 import util.Rules 12 13 import static org.hamcrest.Matchers.* 14 import static org.junit.Assert.assertThat 15 16 class abapEnvironmentPipelineStagePostTest extends BasePiperTest { 17 private JenkinsStepRule jsr = new JenkinsStepRule(this) 18 19 @Rule 20 public RuleChain rules = Rules 21 .getCommonRules(this) 22 .around(new JenkinsReadYamlRule(this)) 23 .around(jsr) 24 25 private stepsCalled = [] 26 27 @Before 28 void init() { 29 binding.variables.env.STAGE_NAME = 'Declarative: Post Actions' 30 31 helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body -> 32 assertThat(m.stageName, is('Post')) 33 return body() 34 }) 35 helper.registerAllowedMethod('input', [Map], {m -> 36 stepsCalled.add('input') 37 return null 38 }) 39 helper.registerAllowedMethod('cloudFoundryDeleteService', [Map.class], {m -> stepsCalled.add('cloudFoundryDeleteService')}) 40 } 41 42 @Test 43 void testCloudFoundryDeleteServiceExecutedConfirm() { 44 45 nullScript.commonPipelineEnvironment.configuration.runStage = [ 46 'Prepare System': true 47 ] 48 jsr.step.abapEnvironmentPipelineStagePost(script: nullScript, confirmDeletion: true) 49 50 assertThat(stepsCalled, hasItems('input')) 51 assertThat(stepsCalled, hasItems('cloudFoundryDeleteService')) 52 } 53 54 @Test 55 void testCloudFoundryDeleteServiceExecutedNoConfirm() { 56 57 nullScript.commonPipelineEnvironment.configuration.runStage = [ 58 'Prepare System': true 59 ] 60 jsr.step.abapEnvironmentPipelineStagePost(script: nullScript, confirmDeletion: false) 61 62 assertThat(stepsCalled, not(hasItem('input'))) 63 assertThat(stepsCalled, hasItems('cloudFoundryDeleteService')) 64 } 65 66 @Test 67 void testCloudFoundryDeleteServiceNotExecuted() { 68 69 nullScript.commonPipelineEnvironment.configuration.runStage = [ 70 'Prepare System': false 71 ] 72 jsr.step.abapEnvironmentPipelineStagePost(script: nullScript) 73 74 assertThat(stepsCalled, not(hasItem('cloudFoundryDeleteService'))) 75 } 76 77 @Test 78 void testCloudFoundryDeleteServiceDebugTrue() { 79 80 nullScript.commonPipelineEnvironment.configuration.runStage = [ 81 'Prepare System': true 82 ] 83 jsr.step.abapEnvironmentPipelineStagePost(script: nullScript, debug: true) 84 85 assertThat(stepsCalled, not(hasItem('cloudFoundryDeleteService'))) 86 } 87 88 @Test 89 void testCloudFoundryDeleteServiceDebugFalse() { 90 91 nullScript.commonPipelineEnvironment.configuration.runStage = [ 92 'Prepare System': true 93 ] 94 jsr.step.abapEnvironmentPipelineStagePost(script: nullScript, debug: false) 95 96 assertThat(stepsCalled, hasItem('cloudFoundryDeleteService')) 97 } 98 }