github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/AbapEnvironmentPipelineStagePublishTest.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 abapEnvironmentPipelineStagePublishTest 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 = 'Publish' 30 31 helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body -> 32 assertThat(m.stageName, is('Publish')) 33 return body() 34 }) 35 helper.registerAllowedMethod('input', [Map], {m -> 36 stepsCalled.add('input') 37 return null 38 }) 39 helper.registerAllowedMethod('abapAddonAssemblyKitPublishTargetVector', [Map.class], {m -> stepsCalled.add('abapAddonAssemblyKitPublishTargetVector')}) 40 } 41 42 @Test 43 void testPublishExecuted() { 44 45 nullScript.commonPipelineEnvironment.configuration.runStage = [] 46 47 jsr.step.abapEnvironmentPipelineStagePublish(script: nullScript) 48 49 assertThat(stepsCalled, hasItem('abapAddonAssemblyKitPublishTargetVector')) 50 } 51 52 @Test 53 void testPublishSkipped4testBuild() { 54 nullScript.commonPipelineEnvironment.configuration.runStage = [] 55 jsr.step.abapEnvironmentPipelineStagePublish(script: nullScript, testBuild: true) 56 assertThat(stepsCalled, not(hasItem('abapAddonAssemblyKitPublishTargetVector'))) 57 } 58 }