github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/AbapEnvironmentPipelineStageATCTest.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 AbapEnvironmentPipelineStageATCTest 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 = 'ATC'
    30  
    31          helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
    32              assertThat(m.stageName, is('ATC'))
    33              return body()
    34          })
    35          helper.registerAllowedMethod('abapEnvironmentRunATCCheck', [Map.class], {m -> stepsCalled.add('abapEnvironmentRunATCCheck')})
    36          helper.registerAllowedMethod('abapEnvironmentPushATCSystemConfig', [Map.class], {m -> stepsCalled.add('abapEnvironmentPushATCSystemConfig')})
    37          helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')})
    38      }
    39  
    40      @Test
    41      void testAbapEnvironmentRunTests() {
    42  
    43          nullScript.commonPipelineEnvironment.configuration.runStage = []
    44          jsr.step.abapEnvironmentPipelineStageATC(script: nullScript)
    45  
    46          assertThat(stepsCalled, hasItems('abapEnvironmentRunATCCheck','cloudFoundryCreateServiceKey'))
    47          assertThat(stepsCalled, not(hasItems('abapEnvironmentPushATCSystemConfig')))
    48      }
    49  
    50      @Test
    51      void testAbapEnvironmentRunTestsWithATCSystemConfig() {
    52  
    53          nullScript.commonPipelineEnvironment.configuration.runStage = []
    54          jsr.step.abapEnvironmentPipelineStageATC(script: nullScript, atcSystemConfigFilePath: 'atcSystemConfig.json' )
    55  
    56          assertThat(stepsCalled, hasItems('abapEnvironmentRunATCCheck','abapEnvironmentPushATCSystemConfig','cloudFoundryCreateServiceKey'))
    57      }
    58  
    59      @Test
    60      void testAbapEnvironmentRunTestsWithHost() {
    61  
    62          nullScript.commonPipelineEnvironment.configuration.runStage = []
    63          jsr.step.abapEnvironmentPipelineStageATC(script: nullScript,  host: 'abc.com')
    64  
    65          assertThat(stepsCalled, hasItems('abapEnvironmentRunATCCheck'))
    66          assertThat(stepsCalled, not(hasItems('abapEnvironmentPushATCSystemConfig','cloudFoundryCreateServiceKey')))
    67      }
    68  
    69  }