diff --git a/test/groovy/DockerExecuteTest.groovy b/test/groovy/DockerExecuteTest.groovy index 9c6c425c6..6ab08a64c 100644 --- a/test/groovy/DockerExecuteTest.groovy +++ b/test/groovy/DockerExecuteTest.groovy @@ -6,9 +6,8 @@ import org.junit.rules.RuleChain import com.lesfurets.jenkins.unit.BasePipelineTest -import util.JenkinsConfigRule import util.JenkinsLoggingRule -import util.JenkinsSetupRule +import util.Rules import static org.junit.Assert.assertEquals import static org.junit.Assert.assertTrue @@ -20,9 +19,8 @@ class DockerExecuteTest extends BasePipelineTest { private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) @Rule - public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this)) - .around(jlr) - .around(new JenkinsConfigRule(this)) + public RuleChain ruleChain = RuleChain.outerRule(Rules.getCommonRules(this)) + .around(jlr) int whichDockerReturnValue = 0 diff --git a/test/groovy/DurationMeasureTest.groovy b/test/groovy/DurationMeasureTest.groovy index 2b01720c2..9ba66dec8 100644 --- a/test/groovy/DurationMeasureTest.groovy +++ b/test/groovy/DurationMeasureTest.groovy @@ -1,14 +1,17 @@ #!groovy import com.lesfurets.jenkins.unit.BasePipelineTest + import org.junit.Rule import org.junit.Test -import util.JenkinsSetupRule import static org.junit.Assert.assertTrue +import org.junit.rules.RuleChain + +import util.Rules class DurationMeasureTest extends BasePipelineTest { @Rule - public JenkinsSetupRule setupRule = new JenkinsSetupRule(this) + public RuleChain rules = Rules.getCommonRules(this) @Test void testDurationMeasurement() throws Exception { diff --git a/test/groovy/InfluxWriteDataTest.groovy b/test/groovy/InfluxWriteDataTest.groovy index fd430ba04..02e39529d 100644 --- a/test/groovy/InfluxWriteDataTest.groovy +++ b/test/groovy/InfluxWriteDataTest.groovy @@ -6,7 +6,7 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain import util.JenkinsLoggingRule -import util.JenkinsSetupRule +import util.Rules import static org.junit.Assert.assertTrue import static org.junit.Assert.assertEquals @@ -21,13 +21,11 @@ class InfluxWriteDataTest extends BasePipelineTest { def cpe - public JenkinsSetupRule setupRule = new JenkinsSetupRule(this) public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) @Rule - public RuleChain ruleChain = - RuleChain.outerRule(setupRule) - .around(loggingRule) + public RuleChain ruleChain = Rules.getCommonRules(this) + .around(loggingRule) @Before void init() throws Exception { diff --git a/test/groovy/MTABuildTest.groovy b/test/groovy/MTABuildTest.groovy index 999b3b220..100aa8969 100644 --- a/test/groovy/MTABuildTest.groovy +++ b/test/groovy/MTABuildTest.groovy @@ -10,10 +10,9 @@ import org.junit.rules.TemporaryFolder import com.lesfurets.jenkins.unit.BasePipelineTest -import util.JenkinsConfigRule import util.JenkinsLoggingRule -import util.JenkinsSetupRule import util.JenkinsShellCallRule +import util.Rules public class MTABuildTest extends BasePipelineTest { @@ -23,13 +22,12 @@ public class MTABuildTest extends BasePipelineTest { private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) @Rule - public RuleChain ruleChain = - RuleChain.outerRule(thrown) + public RuleChain ruleChain = Rules.getCommonRules(this) + .around(thrown) .around(tmp) - .around(new JenkinsSetupRule(this)) .around(jlr) .around(jscr) - .around(new JenkinsConfigRule(this)) + def currentDir def otherDir @@ -122,12 +120,13 @@ public class MTABuildTest extends BasePipelineTest { binding.getVariable('env')['MTA_JAR_LOCATION'] = '/opt/mta' def newDirName = 'newDir' - def newDir = new File("${currentDir}/${newDirName}") + def newDirPath = "${currentDir}/${newDirName}" + def newDir = new File(newDirPath) newDir.mkdirs() new File(newDir, 'mta.yaml') << defaultMtaYaml() - helper.registerAllowedMethod('pwd', [], { newDir } ) + helper.registerAllowedMethod('pwd', [], { newDirPath } ) def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], buildTarget: 'NEO') diff --git a/test/groovy/MavenExecuteTest.groovy b/test/groovy/MavenExecuteTest.groovy index 2f62af7d7..4eabaaa6a 100644 --- a/test/groovy/MavenExecuteTest.groovy +++ b/test/groovy/MavenExecuteTest.groovy @@ -9,9 +9,8 @@ import com.lesfurets.jenkins.unit.BasePipelineTest import static org.junit.Assert.assertEquals import static org.junit.Assert.assertTrue -import util.JenkinsConfigRule -import util.JenkinsSetupRule import util.JenkinsShellCallRule +import util.Rules class MavenExecuteTest extends BasePipelineTest { @@ -20,9 +19,8 @@ class MavenExecuteTest extends BasePipelineTest { private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) @Rule - public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this)) - .around(jscr) - .around(new JenkinsConfigRule(this)) + public RuleChain ruleChain = Rules.getCommonRules(this) + .around(jscr) def mavenExecuteScript def cpe diff --git a/test/groovy/NeoDeploymentTest.groovy b/test/groovy/NeoDeploymentTest.groovy index 101f4bb84..bb9dccd25 100644 --- a/test/groovy/NeoDeploymentTest.groovy +++ b/test/groovy/NeoDeploymentTest.groovy @@ -10,10 +10,10 @@ import org.junit.Test import org.junit.rules.ExpectedException import org.junit.rules.RuleChain -import util.JenkinsConfigRule + import util.JenkinsLoggingRule -import util.JenkinsSetupRule import util.JenkinsShellCallRule +import util.Rules class NeoDeploymentTest extends BasePipelineTest { @@ -23,12 +23,11 @@ class NeoDeploymentTest extends BasePipelineTest { private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) @Rule - public RuleChain ruleChain = RuleChain.outerRule(thrown) - .around(tmp) - .around(new JenkinsSetupRule(this)) - .around(jlr) - .around(jscr) - .around(new JenkinsConfigRule(this)) + public RuleChain ruleChain = Rules.getCommonRules(this) + .around(thrown) + .around(tmp) + .around(jlr) + .around(jscr) def workspacePath def warArchiveName @@ -468,4 +467,31 @@ class NeoDeploymentTest extends BasePipelineTest { warAction: 'illegalWARAction', vmSize: 'lite') } + + @Test + void deployHostProvidedAsDeprecatedParameterTest() { + new File(workspacePath, archiveName) << "dummy archive" + cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') + + neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + archivePath: archiveName, + deployHost: "my.deploy.host.com" + ) + + assert jlr.log.contains("[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead.") + } + + @Test + void deployAccountProvidedAsDeprecatedParameterTest() { + new File(workspacePath, archiveName) << "dummy archive" + cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') + + neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + archivePath: archiveName, + host: "my.deploy.host.com", + deployAccount: "myAccount" + ) + + assert jlr.log.contains("Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead.") + } } diff --git a/test/groovy/PipelineExecuteTest.groovy b/test/groovy/PipelineExecuteTest.groovy index 782f33679..1a08022cf 100644 --- a/test/groovy/PipelineExecuteTest.groovy +++ b/test/groovy/PipelineExecuteTest.groovy @@ -1,8 +1,4 @@ -import hudson.AbortException -import util.JenkinsConfigRule -import util.JenkinsSetupRule - -import org.junit.rules.TemporaryFolder +import util.Rules import com.lesfurets.jenkins.unit.BasePipelineTest @@ -12,14 +8,15 @@ import org.junit.Test import org.junit.rules.ExpectedException import org.junit.rules.RuleChain +import util.JenkinsReadYamlRule + class PipelineExecuteTest extends BasePipelineTest { private ExpectedException thrown = new ExpectedException().none() @Rule - public RuleChain ruleChain = RuleChain.outerRule(thrown) - .around(new JenkinsSetupRule(this)) - .around(new JenkinsConfigRule(this)) + public RuleChain ruleChain = Rules.getCommonRules(this) + .around(thrown) def pipelinePath def checkoutParameters = [:] diff --git a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy index 0f4b9498d..b95589b94 100644 --- a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy +++ b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy @@ -1,11 +1,12 @@ import org.junit.Before import org.junit.Rule import org.junit.Test +import org.junit.rules.RuleChain import org.yaml.snakeyaml.Yaml import com.lesfurets.jenkins.unit.BasePipelineTest -import util.JenkinsSetupRule +import util.Rules import static org.junit.Assert.assertEquals import static org.junit.Assert.assertNotNull @@ -19,7 +20,7 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest { def commonPipelineEnvironment @Rule - public JenkinsSetupRule jsr = new JenkinsSetupRule(this) + public RuleChain rules = Rules.getCommonRules(this) @Before void init() { diff --git a/test/groovy/ToolValidateTest.groovy b/test/groovy/ToolValidateTest.groovy index 973f2dc59..06800a9f4 100644 --- a/test/groovy/ToolValidateTest.groovy +++ b/test/groovy/ToolValidateTest.groovy @@ -9,24 +9,21 @@ import org.junit.rules.TemporaryFolder import com.lesfurets.jenkins.unit.BasePipelineTest -import util.JenkinsConfigRule import util.JenkinsLoggingRule -import util.JenkinsSetupRule +import util.Rules class ToolValidateTest extends BasePipelineTest { private ExpectedException thrown = new ExpectedException().none() private TemporaryFolder tmp = new TemporaryFolder() private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) - private JenkinsConfigRule jcr = new JenkinsConfigRule(this) @Rule - public RuleChain ruleChain = - RuleChain.outerRule(tmp) - .around(thrown) - .around(new JenkinsSetupRule(this)) - .around(jlr) - .around(jcr) + public RuleChain ruleChain = Rules.getCommonRules(this) + .around(tmp) + .around(thrown) + .around(jlr) + private notEmptyDir diff --git a/test/groovy/com/sap/piper/UtilsTest.groovy b/test/groovy/com/sap/piper/UtilsTest.groovy index 211c20717..99f9127bb 100644 --- a/test/groovy/com/sap/piper/UtilsTest.groovy +++ b/test/groovy/com/sap/piper/UtilsTest.groovy @@ -6,8 +6,7 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.ExpectedException import org.junit.rules.RuleChain -import util.JenkinsLoggingRule -import util.JenkinsSetupRule +import util.Rules import util.SharedLibraryCreator import static org.hamcrest.Matchers.containsString @@ -21,7 +20,7 @@ class UtilsTest extends BasePipelineTest { public ExpectedException exception = ExpectedException.none() @Rule - public JenkinsSetupRule setUpRule = new JenkinsSetupRule(this, SharedLibraryCreator.lazyLoadedLibrary) + public RuleChain rules = Rules.getCommonRules(this, SharedLibraryCreator.lazyLoadedLibrary) Utils utils diff --git a/test/groovy/util/JenkinsConfigRule.groovy b/test/groovy/util/JenkinsReadYamlRule.groovy similarity index 61% rename from test/groovy/util/JenkinsConfigRule.groovy rename to test/groovy/util/JenkinsReadYamlRule.groovy index 2779501e5..187bb8d32 100644 --- a/test/groovy/util/JenkinsConfigRule.groovy +++ b/test/groovy/util/JenkinsReadYamlRule.groovy @@ -7,12 +7,12 @@ import org.junit.runner.Description import org.junit.runners.model.Statement import org.yaml.snakeyaml.Yaml -class JenkinsConfigRule implements TestRule { +class JenkinsReadYamlRule implements TestRule { final BasePipelineTest testInstance - JenkinsConfigRule(BasePipelineTest testInstance) { + JenkinsReadYamlRule(BasePipelineTest testInstance) { this.testInstance = testInstance } @@ -25,11 +25,15 @@ class JenkinsConfigRule implements TestRule { return new Statement() { @Override void evaluate() throws Throwable { - testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map parameters -> - Yaml yamlParser = new Yaml() - return yamlParser.load(parameters.text) + testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map m -> + if(m.text) { + return new Yaml().load(m.text) + } else if(m.file) { + throw new UnsupportedOperationException() + } else { + throw new IllegalArgumentException("Key 'text' is missing in map ${m}.") + } }) - DefaultValueCache.reset() base.evaluate() } diff --git a/test/groovy/util/JenkinsResetDefaultCacheRule.groovy b/test/groovy/util/JenkinsResetDefaultCacheRule.groovy new file mode 100644 index 000000000..680e2fc93 --- /dev/null +++ b/test/groovy/util/JenkinsResetDefaultCacheRule.groovy @@ -0,0 +1,34 @@ +package util + +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement + +import com.lesfurets.jenkins.unit.BasePipelineTest +import com.sap.piper.DefaultValueCache + +class JenkinsResetDefaultCacheRule implements TestRule { + + + JenkinsResetDefaultCacheRule() { + this(null) + } + + // + // Actually not needed. Only provided for the sake of consistency + // with our other rules which comes with an constructor having the + // test case contained in the signature. + JenkinsResetDefaultCacheRule(BasePipelineTest testInstance) { + } + + @Override + Statement apply(Statement base, Description description) { + return new Statement() { + @Override + void evaluate() throws Throwable { + DefaultValueCache.reset() + base.evaluate() + } + } + } +} diff --git a/test/groovy/util/JenkinsSetupRule.groovy b/test/groovy/util/JenkinsSetupRule.groovy index 57bcd21ca..a2b3996b4 100644 --- a/test/groovy/util/JenkinsSetupRule.groovy +++ b/test/groovy/util/JenkinsSetupRule.groovy @@ -13,12 +13,13 @@ class JenkinsSetupRule implements TestRule { final BasePipelineTest testInstance JenkinsSetupRule(BasePipelineTest testInstance) { - this.testInstance = testInstance + this(testInstance, null) } JenkinsSetupRule(BasePipelineTest testInstance, LibraryConfiguration configuration) { this.testInstance = testInstance - this.library = configuration + if(configuration) + this.library = configuration } @Override diff --git a/test/groovy/util/Rules.groovy b/test/groovy/util/Rules.groovy new file mode 100644 index 000000000..d009d2576 --- /dev/null +++ b/test/groovy/util/Rules.groovy @@ -0,0 +1,19 @@ +package util; + +import org.junit.rules.RuleChain; + +import com.lesfurets.jenkins.unit.BasePipelineTest; +import com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration + +public class Rules { + + public static RuleChain getCommonRules(BasePipelineTest testCase) { + return getCommonRules(testCase, null) + } + + public static RuleChain getCommonRules(BasePipelineTest testCase, LibraryConfiguration libConfig) { + return RuleChain.outerRule(new JenkinsSetupRule(testCase, libConfig)) + .around(new JenkinsReadYamlRule(testCase)) + .around(new JenkinsResetDefaultCacheRule()) + } +} diff --git a/vars/neoDeploy.groovy b/vars/neoDeploy.groovy index e072ee2af..4e53463e3 100644 --- a/vars/neoDeploy.groovy +++ b/vars/neoDeploy.groovy @@ -11,6 +11,8 @@ def call(parameters = [:]) { 'applicationName', 'archivePath', 'account', + 'deployAccount', //deprecated, replaced by parameter 'account' + 'deployHost', //deprecated, replaced by parameter 'host' 'deployMode', 'dockerEnvVars', 'dockerImage', @@ -60,14 +62,21 @@ def call(parameters = [:]) { stepConfiguration.put('account', defaultDeployAccount) } - if(parameters.DEPLOY_HOST && !parameters.host) { - echo "[WARNING][${stepName}] Deprecated parameter 'DEPLOY_HOST' is used. This will not work anymore in future versions. Use parameter 'host' instead." - parameters.put('host', parameters.DEPLOY_HOST) + if(parameters.deployHost && !parameters.host) { + echo "[WARNING][${stepName}] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead." + parameters.put('host', parameters.deployHost) } - if(parameters.CI_DEPLOY_ACCOUNT && !parameters.account) { - echo "[WARNING][${stepName}] Deprecated parameter 'CI_DEPLOY_ACCOUNT' is used. This will not work anymore in future versions. Use parameter 'account' instead." - parameters.put('account', parameters.CI_DEPLOY_ACCOUNT) + if(parameters.deployAccount && !parameters.account) { + echo "[WARNING][${stepName}] Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead." + parameters.put('account', parameters.deployAccount) + } + + def credId = script.commonPipelineEnvironment.getConfigProperty('neoCredentialsId') + + if(credId && !parameters.neoCredentialsId) { + echo "[WARNING][${stepName}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions." + parameters.put('neoCredentialsId', credId) } // Backward compatibility end