github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/PiperPipelineStageAcceptanceTest.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.* 8 9 import static org.hamcrest.Matchers.anyOf 10 import static org.hamcrest.Matchers.containsString 11 import static org.hamcrest.Matchers.hasItem 12 import static org.hamcrest.Matchers.hasItems 13 import static org.hamcrest.Matchers.is 14 import static org.hamcrest.Matchers.not 15 import static org.junit.Assert.assertThat 16 17 class PiperPipelineStageAcceptanceTest extends BasePiperTest { 18 private JenkinsStepRule jsr = new JenkinsStepRule(this) 19 private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) 20 21 @Rule 22 public RuleChain rules = Rules 23 .getCommonRules(this) 24 .around(new JenkinsReadYamlRule(this)) 25 .around(jlr) 26 .around(jsr) 27 28 private List stepsCalled = [] 29 private Map stepParameters = [:] 30 31 @Before 32 void init() { 33 nullScript.env.STAGE_NAME = 'Acceptance' 34 helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body -> 35 assertThat(m.stageName, is('Acceptance')) 36 return body() 37 }) 38 39 helper.registerAllowedMethod('healthExecuteCheck', [Map.class], {m -> 40 stepsCalled.add('healthExecuteCheck') 41 stepParameters.healthExecuteCheck = m 42 }) 43 44 helper.registerAllowedMethod('multicloudDeploy', [Map.class], {m -> 45 stepsCalled.add('multicloudDeploy') 46 stepParameters.multicloudDeploy = m 47 }) 48 49 helper.registerAllowedMethod('cloudFoundryDeploy', [Map.class], {m -> 50 stepsCalled.add('cloudFoundryDeploy') 51 stepParameters.cloudFoundryDeploy = m 52 }) 53 54 helper.registerAllowedMethod('neoDeploy', [Map.class], {m -> 55 stepsCalled.add('neoDeploy') 56 stepParameters.neoDeploy = m 57 }) 58 59 helper.registerAllowedMethod('kubernetesDeploy', [Map.class], {m -> 60 stepsCalled.add('kubernetesDeploy') 61 stepParameters.kubernetesDeploy = m 62 }) 63 64 helper.registerAllowedMethod('gaugeExecuteTests', [Map.class], {m -> 65 stepsCalled.add('gaugeExecuteTests') 66 stepParameters.gaugeExecuteTests = m 67 }) 68 69 helper.registerAllowedMethod('newmanExecute', [Map.class], {m -> 70 stepsCalled.add('newmanExecute') 71 stepParameters.newmanExecute = m 72 }) 73 74 helper.registerAllowedMethod('uiVeri5ExecuteTests', [Map.class], {m -> 75 stepsCalled.add('uiVeri5ExecuteTests') 76 stepParameters.uiVeri5ExecuteTests = m 77 }) 78 79 helper.registerAllowedMethod('npmExecuteEndToEndTests', [Map.class], {m -> 80 stepsCalled.add('npmExecuteEndToEndTests') 81 stepParameters.npmExecuteEndToEndTests = m 82 }) 83 84 helper.registerAllowedMethod('testsPublishResults', [Map.class], {m -> 85 stepsCalled.add('testsPublishResults') 86 stepParameters.testsPublishResults = m 87 }) 88 } 89 90 @Test 91 void testAcceptanceStageDefault() { 92 93 jsr.step.piperPipelineStageAcceptance( 94 script: nullScript, 95 juStabUtils: utils 96 ) 97 assertThat(stepsCalled, not(anyOf(hasItem('cloudFoundryDeploy'), hasItem('neoDeploy'), hasItem('kubernetesDeploy'), hasItem('healthExecuteCheck'), hasItem('newmanExecute'), hasItem('uiVeri5ExecuteTests'), hasItem('gaugeExecuteTests')))) 98 99 } 100 101 @Test 102 void testReleaseStageMultiCloud() { 103 104 jsr.step.piperPipelineStageAcceptance( 105 script: nullScript, 106 juStabUtils: utils, 107 multicloudDeploy: true, 108 healthExecuteCheck: true 109 ) 110 111 assertThat(stepsCalled, hasItems('multicloudDeploy', 'healthExecuteCheck')) 112 } 113 114 @Test 115 void testAcceptanceStageCF() { 116 117 jsr.step.piperPipelineStageAcceptance( 118 script: nullScript, 119 juStabUtils: utils, 120 cloudFoundryDeploy: true, 121 healthExecuteCheck: true 122 ) 123 124 assertThat(stepsCalled, hasItems('cloudFoundryDeploy', 'healthExecuteCheck')) 125 assertThat(stepsCalled, not(hasItem('testsPublishResults'))) 126 } 127 128 @Test 129 void testAcceptanceStageNeo() { 130 131 jsr.step.piperPipelineStageAcceptance( 132 script: nullScript, 133 juStabUtils: utils, 134 neoDeploy: true 135 ) 136 assertThat(stepsCalled, hasItem('neoDeploy')) 137 assertThat(stepsCalled, not(hasItem('testsPublishResults'))) 138 } 139 140 @Test 141 void testReleaseStageKubernetes() { 142 143 jsr.step.piperPipelineStageRelease( 144 script: nullScript, 145 juStabUtils: utils, 146 kubernetesDeploy: true 147 ) 148 149 assertThat(stepsCalled, hasItem('kubernetesDeploy')) 150 assertThat(stepsCalled, not(hasItem('testsPublishResults'))) 151 } 152 153 @Test 154 void testAcceptanceStageGauge() { 155 156 jsr.step.piperPipelineStageAcceptance( 157 script: nullScript, 158 juStabUtils: utils, 159 gaugeExecuteTests: true 160 ) 161 assertThat(stepsCalled, hasItems('gaugeExecuteTests', 'testsPublishResults')) 162 assertThat(stepParameters.testsPublishResults.gauge.archive, is(true)) 163 } 164 165 @Test 166 void testAcceptanceStageNewman() { 167 168 jsr.step.piperPipelineStageAcceptance( 169 script: nullScript, 170 juStabUtils: utils, 171 newmanExecute: true 172 ) 173 assertThat(stepsCalled, hasItems('newmanExecute', 'testsPublishResults')) 174 } 175 176 @Test 177 void testAcceptanceStageUiVeri5() { 178 179 jsr.step.piperPipelineStageAcceptance( 180 script: nullScript, 181 juStabUtils: utils, 182 uiVeri5ExecuteTests: true 183 ) 184 assertThat(stepsCalled, hasItems('uiVeri5ExecuteTests', 'testsPublishResults')) 185 } 186 187 @Test 188 void testAcceptanceNpmExecuteEndToEndTests() { 189 190 jsr.step.piperPipelineStageAcceptance( 191 script: nullScript, 192 juStabUtils: utils, 193 npmExecuteEndToEndTests: true 194 ) 195 196 assertThat(stepsCalled, hasItem('npmExecuteEndToEndTests')) 197 } 198 }