github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/AbapEnvironmentPipelineStagePrepareSystemTest.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 AbapEnvironmentPipelineStagePrepareSystemTest 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 = 'Prepare System' 30 31 helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body -> 32 assertThat(m.stageName, is('Prepare System')) 33 return body() 34 }) 35 helper.registerAllowedMethod('input', [Map], {m -> 36 stepsCalled.add('input') 37 return null 38 }) 39 helper.registerAllowedMethod('abapEnvironmentCreateSystem', [Map.class], {m -> stepsCalled.add('abapEnvironmentCreateSystem')}) 40 } 41 42 @Test 43 void testAbapEnvironmentPipelineStagePrepareSystemExecuted() { 44 45 nullScript.commonPipelineEnvironment.configuration.runStage = [ 46 'Prepare System': true 47 ] 48 jsr.step.abapEnvironmentPipelineStagePrepareSystem(script: nullScript) 49 50 assertThat(stepsCalled, hasItem('abapEnvironmentCreateSystem')) 51 } 52 }