github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/PipelineStashFilesAfterBuildTest.groovy (about) 1 import org.junit.After 2 import org.junit.Before 3 import org.junit.Rule 4 import org.junit.Test 5 import org.junit.rules.RuleChain 6 import util.* 7 import com.sap.piper.Utils 8 9 import static org.hamcrest.Matchers.containsString 10 import static org.junit.Assert.assertFalse 11 import static org.junit.Assert.assertThat 12 13 14 class PipelineStashFilesAfterBuildTest extends BasePiperTest { 15 JenkinsStepRule stepRule = new JenkinsStepRule(this) 16 JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) 17 JenkinsReadJsonRule readJsonRule = new JenkinsReadJsonRule(this) 18 19 @Rule 20 public RuleChain rules = Rules 21 .getCommonRules(this) 22 .around(new JenkinsReadYamlRule(this)) 23 .around(readJsonRule) 24 .around(loggingRule) 25 .around(stepRule) 26 27 @Before 28 public void setup() { 29 Utils.metaClass.echo = { def m -> } 30 } 31 32 @After 33 public void tearDown() { 34 Utils.metaClass = null 35 } 36 37 @Test 38 void testStashAfterBuild() { 39 helper.registerAllowedMethod("fileExists", [String.class], { 40 searchTerm -> 41 return true 42 }) 43 stepRule.step.pipelineStashFilesAfterBuild( 44 script: nullScript, 45 juStabUtils: utils, 46 runCheckmarx: true 47 ) 48 // asserts 49 assertThat(loggingRule.log, containsString('Stash content: checkmarx')) 50 assertThat(loggingRule.log, containsString('Stash content: classFiles')) 51 assertThat(loggingRule.log, containsString('Stash content: sonar')) 52 } 53 }