github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/AbapEnvironmentPipelineStageAUnitTest.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 AbapEnvironmentPipelineStageAUnitTest 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 = 'AUnit'
    30  
    31          helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
    32              assertThat(m.stageName, is('AUnit'))
    33              return body()
    34          })
    35          helper.registerAllowedMethod('abapEnvironmentRunAUnitTest', [Map.class], {m -> stepsCalled.add('abapEnvironmentRunAUnitTest')})
    36          helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')})
    37      }
    38      
    39      @Test
    40      void testAbapEnvironmentRunTestsWithoutHost() {
    41          nullScript.commonPipelineEnvironment.configuration.runStage = [
    42              'AUnit': true
    43          ]
    44          jsr.step.abapEnvironmentPipelineStageAUnit(script: nullScript)
    45  
    46          assertThat(stepsCalled, hasItems('abapEnvironmentRunAUnitTest','cloudFoundryCreateServiceKey'))
    47      }
    48  
    49      @Test
    50      void testAbapEnvironmentRunTestsWithHost() {
    51          nullScript.commonPipelineEnvironment.configuration.runStage = [
    52              'AUnit': true
    53          ]
    54          jsr.step.abapEnvironmentPipelineStageAUnit(script: nullScript,  host: 'abc.com')
    55  
    56          assertThat(stepsCalled, hasItems('abapEnvironmentRunAUnitTest'))
    57          assertThat(stepsCalled, not(hasItems('cloudFoundryCreateServiceKey')))
    58      }
    59  
    60  }