From 158a60aecc7113fa85f7c713812e6090ae52ce8a Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Wed, 28 Feb 2018 13:11:09 +0100 Subject: [PATCH 1/7] use new rules --- test/groovy/ArtifactSetVersionTest.groovy | 20 ++-- test/groovy/ChecksPublishResultsTest.groovy | 41 ++++---- test/groovy/DurationMeasureTest.groovy | 15 ++- test/groovy/InfluxWriteDataTest.groovy | 37 +++---- ...oymentTest.groovy => NeoDeployTest.groovy} | 99 +++++++++---------- test/groovy/PipelineExecuteTest.groovy | 23 ++--- .../SetupCommonPipelineEnvironmentTest.groovy | 31 +++--- test/groovy/ToolValidateTest.groovy | 75 +++++--------- 8 files changed, 153 insertions(+), 188 deletions(-) rename test/groovy/{NeoDeploymentTest.groovy => NeoDeployTest.groovy} (80%) diff --git a/test/groovy/ArtifactSetVersionTest.groovy b/test/groovy/ArtifactSetVersionTest.groovy index 6db4e4ceb..9a6460f4d 100644 --- a/test/groovy/ArtifactSetVersionTest.groovy +++ b/test/groovy/ArtifactSetVersionTest.groovy @@ -18,15 +18,12 @@ import util.Rules import static org.junit.Assert.assertEquals class ArtifactSetVersionTest extends BasePipelineTest { - def gitUtils - def sshAgentList = [] - - ExpectedException thrown = ExpectedException.none() - JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) - JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) - JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this) - JenkinsStepRule jsr = new JenkinsStepRule(this) - JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) + private ExpectedException thrown = ExpectedException.none() + private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) + private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) + private JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this) + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @Rule public RuleChain ruleChain = Rules @@ -39,6 +36,9 @@ class ArtifactSetVersionTest extends BasePipelineTest { .around(jsr) .around(jer) + def gitUtils + def sshAgentList = [] + @Before void init() throws Throwable { helper.registerAllowedMethod("sshagent", [List.class, Closure.class], { list, closure -> @@ -108,6 +108,4 @@ class ArtifactSetVersionTest extends BasePipelineTest { object.metaClass.static.invokeMethod = helper.getMethodInterceptor() object.metaClass.methodMissing = helper.getMethodMissingInterceptor() } - - } diff --git a/test/groovy/ChecksPublishResultsTest.groovy b/test/groovy/ChecksPublishResultsTest.groovy index 7914fe11a..4b9a83103 100644 --- a/test/groovy/ChecksPublishResultsTest.groovy +++ b/test/groovy/ChecksPublishResultsTest.groovy @@ -10,22 +10,23 @@ import static org.junit.Assert.assertEquals import static org.junit.Assert.assertTrue import util.Rules +import util.JenkinsStepRule class ChecksPublishResultsTest extends BasePipelineTest { - Map publisherStepOptions - List archiveStepPatterns + private JenkinsStepRule jsr = new JenkinsStepRule(this) @Rule - public RuleChain ruleChain = Rules.getCommonRules(this) + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(jsr) - def checksPublishResultsScript + Map publisherStepOptions + List archiveStepPatterns @Before void init() { publisherStepOptions = [:] archiveStepPatterns = [] - // prepare checkResultsPublish step - checksPublishResultsScript = loadScript("checksPublishResults.groovy").checksPublishResults // add handler for generic step call helper.registerAllowedMethod("step", [Map.class], { parameters -> publisherStepOptions[parameters.$class] = parameters @@ -37,7 +38,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithDefaultSettings() throws Exception { - checksPublishResultsScript.call() + jsr.step.call() assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) // ensure nothing else is published @@ -50,7 +51,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishForJavaWithDefaultSettings() throws Exception { - checksPublishResultsScript.call(pmd: true, cpd: true, findbugs: true, checkstyle: true) + jsr.step.call(pmd: true, cpd: true, findbugs: true, checkstyle: true) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) @@ -68,7 +69,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishForJavaScriptWithDefaultSettings() throws Exception { - checksPublishResultsScript.call(eslint: true) + jsr.step.call(eslint: true) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null) @@ -86,7 +87,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishForPythonWithDefaultSettings() throws Exception { - checksPublishResultsScript.call(pylint: true) + jsr.step.call(pylint: true) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null) @@ -105,7 +106,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishNothing() throws Exception { - checksPublishResultsScript.call(aggregation: false) + jsr.step.call(aggregation: false) // ensure nothing is published assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null) @@ -118,7 +119,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishNothingExplicitFalse() throws Exception { - checksPublishResultsScript.call(pmd: false) + jsr.step.call(pmd: false) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) // ensure nothing else is published @@ -131,7 +132,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishNothingImplicitTrue() throws Exception { - checksPublishResultsScript.call(pmd: [:]) + jsr.step.call(pmd: [:]) // ensure pmd is not published assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) @@ -139,7 +140,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishNothingExplicitActiveFalse() throws Exception { - checksPublishResultsScript.call(pmd: [active: false]) + jsr.step.call(pmd: [active: false]) // ensure pmd is not published assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null) @@ -148,7 +149,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithChangedStepDefaultSettings() throws Exception { // pmd has been set to active: true in step configuration - checksPublishResultsScript.call(script: [commonPipelineEnvironment: [ + jsr.step.call(script: [commonPipelineEnvironment: [ configuration: [steps: [checksPublishResults: [pmd: [active: true]]]] ]]) @@ -163,7 +164,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithCustomPattern() throws Exception { - checksPublishResultsScript.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml']) + jsr.step.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml']) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) @@ -180,7 +181,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithArchive() throws Exception { - checksPublishResultsScript.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true) + jsr.step.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true) assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 5) assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml')) @@ -192,7 +193,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithPartialArchive() throws Exception { - checksPublishResultsScript.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true) + jsr.step.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true) assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 4) assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml')) @@ -205,7 +206,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithDefaultThresholds() throws Exception { - checksPublishResultsScript.call(pmd: true) + jsr.step.call(pmd: true) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) @@ -239,7 +240,7 @@ class ChecksPublishResultsTest extends BasePipelineTest { @Test void testPublishWithThresholds() throws Exception { - checksPublishResultsScript.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true) + jsr.step.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true) assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null) assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null) diff --git a/test/groovy/DurationMeasureTest.groovy b/test/groovy/DurationMeasureTest.groovy index 9ba66dec8..5cb536e81 100644 --- a/test/groovy/DurationMeasureTest.groovy +++ b/test/groovy/DurationMeasureTest.groovy @@ -7,21 +7,26 @@ import static org.junit.Assert.assertTrue import org.junit.rules.RuleChain import util.Rules +import util.JenkinsStepRule +import util.JenkinsEnvironmentRule class DurationMeasureTest extends BasePipelineTest { + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @Rule - public RuleChain rules = Rules.getCommonRules(this) + public RuleChain rules = Rules + .getCommonRules(this) + .around(jsr) + .around(jer) @Test void testDurationMeasurement() throws Exception { - def cpe = loadScript("commonPipelineEnvironment.groovy").commonPipelineEnvironment - def script = loadScript("durationMeasure.groovy") def bodyExecuted = false - script.call(script: [commonPipelineEnvironment: cpe], measurementName: 'test') { + jsr.step.call(script: [commonPipelineEnvironment: jer.env], measurementName: 'test') { bodyExecuted = true } - assertTrue(cpe.getPipelineMeasurement('test') != null) + assertTrue(jer.env.getPipelineMeasurement('test') != null) assertTrue(bodyExecuted) assertJobStatusSuccess() } diff --git a/test/groovy/InfluxWriteDataTest.groovy b/test/groovy/InfluxWriteDataTest.groovy index 02e39529d..23d693895 100644 --- a/test/groovy/InfluxWriteDataTest.groovy +++ b/test/groovy/InfluxWriteDataTest.groovy @@ -6,37 +6,36 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain import util.JenkinsLoggingRule +import util.JenkinsStepRule +import util.JenkinsEnvironmentRule import util.Rules import static org.junit.Assert.assertTrue import static org.junit.Assert.assertEquals class InfluxWriteDataTest extends BasePipelineTest { + public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) - Script influxWriteDataScript + @Rule + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(loggingRule) + .around(jsr) + .around(jer) Map fileMap = [:] Map stepMap = [:] String echoLog = '' - def cpe - - public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) - - @Rule - public RuleChain ruleChain = Rules.getCommonRules(this) - .around(loggingRule) - @Before void init() throws Exception { - - // // Currently we have dependencies between the tests since // DefaultValueCache is a singleton which keeps its status // for all the tests. Depending on the test order we fail. // As long as this status remains we need: DefaultValueCache.reset() - //reset stepMap stepMap = [:] //reset fileMap @@ -48,20 +47,16 @@ class InfluxWriteDataTest extends BasePipelineTest { steps : [influxWriteData: [influxServer: 'testInflux']] ] }) - helper.registerAllowedMethod('writeFile', [Map.class],{m -> fileMap[m.file] = m.text}) helper.registerAllowedMethod('step', [Map.class],{m -> stepMap = m}) - - cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment - influxWriteDataScript = loadScript("influxWriteData.groovy") } @Test void testInfluxWriteDataWithDefault() throws Exception { - cpe.setArtifactVersion('1.2.3') - influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe]) + jer.env.setArtifactVersion('1.2.3') + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) assertTrue(loggingRule.log.contains('Artifact version: 1.2.3')) @@ -79,8 +74,8 @@ class InfluxWriteDataTest extends BasePipelineTest { @Test void testInfluxWriteDataNoInflux() throws Exception { - cpe.setArtifactVersion('1.2.3') - influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe], influxServer: '') + jer.env.setArtifactVersion('1.2.3') + jsr.step.call(script: [commonPipelineEnvironment: jer.env], influxServer: '') assertEquals(0, stepMap.size()) @@ -93,7 +88,7 @@ class InfluxWriteDataTest extends BasePipelineTest { @Test void testInfluxWriteDataNoArtifactVersion() throws Exception { - influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe]) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) assertEquals(0, stepMap.size()) assertEquals(0, fileMap.size()) diff --git a/test/groovy/NeoDeploymentTest.groovy b/test/groovy/NeoDeployTest.groovy similarity index 80% rename from test/groovy/NeoDeploymentTest.groovy rename to test/groovy/NeoDeployTest.groovy index d36fe3334..67dd1c650 100644 --- a/test/groovy/NeoDeploymentTest.groovy +++ b/test/groovy/NeoDeployTest.groovy @@ -15,31 +15,34 @@ import org.junit.rules.RuleChain import util.JenkinsLoggingRule import util.JenkinsShellCallRule +import util.JenkinsStepRule +import util.JenkinsEnvironmentRule import util.Rules -class NeoDeploymentTest extends BasePipelineTest { - +class NeoDeployTest extends BasePipelineTest { @ClassRule public static TemporaryFolder tmp = new TemporaryFolder() private ExpectedException thrown = new ExpectedException().none() private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @Rule - public RuleChain ruleChain = Rules.getCommonRules(this) - .around(thrown) - .around(jlr) - .around(jscr) + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(thrown) + .around(jlr) + .around(jscr) + .around(jsr) + .around(jer) private static workspacePath private static warArchiveName private static propertiesFileName private static archiveName - def neoDeployScript - def cpe - @BeforeClass static void createTestFiles() { @@ -78,22 +81,18 @@ class NeoDeploymentTest extends BasePipelineTest { binding.setVariable('env', ['NEO_HOME':'/opt/neo']) - neoDeployScript = loadScript('neoDeploy.groovy').neoDeploy - cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment - - cpe.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]] + jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]] } @Test void straightForwardTestConfigViaConfigProperties() { - cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') - cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') + jer.env.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') + jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') + jer.env.configuration = [:] - cpe.configuration = [:] - - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, neoCredentialsId: 'myCredentialsId' ) @@ -104,10 +103,10 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void straightForwardTestConfigViaConfiguration() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, neoCredentialsId: 'myCredentialsId' -) + ) assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/ } @@ -115,13 +114,13 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void straightForwardTestConfigViaConfigurationAndViaConfigProperties() { - cpe.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com') - cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') + jer.env.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com') + jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') - cpe.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com', + jer.env.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com', account: 'configurationFrwkUser123']]] - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, neoCredentialsId: 'myCredentialsId' ) @@ -136,7 +135,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(MissingPropertyException) thrown.expectMessage('No such property: username') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, neoCredentialsId: 'badCredentialsId' ) @@ -146,7 +145,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void credentialsIdNotProvidedTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName ) @@ -159,7 +158,7 @@ class NeoDeploymentTest extends BasePipelineTest { binding.setVariable('env', [:]) - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName ) @@ -171,7 +170,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void neoHomeAsParameterTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, neoCredentialsId: 'myCredentialsId', neoHome: '/etc/neo' @@ -185,7 +184,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void neoHomeFromEnvironmentTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName ) @@ -197,9 +196,9 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void neoHomeFromCustomStepConfigurationTest() { - cpe.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/step/neo']]] + jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/step/neo']]] - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName ) @@ -214,7 +213,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage('Archive path not configured (parameter "archivePath").') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe]) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) } @@ -224,7 +223,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(AbortException) thrown.expectMessage('Archive cannot be found') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: 'wrongArchiveName') } @@ -235,15 +234,15 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host') - cpe.configuration = [:] + jer.env.configuration = [:] - neoDeployScript.call(archivePath: archiveName) + jsr.step.call(archivePath: archiveName) } @Test void mtaDeployModeTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], archivePath: archiveName, deployMode: 'mta') + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, deployMode: 'mta') assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/ } @@ -251,7 +250,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void warFileParamsDeployModeTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], applicationName: 'testApp', runtime: 'neo-javaee6-wp', runtimeVersion: '2.125', @@ -266,7 +265,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void warFileParamsDeployModeRollingUpdateTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'warParams', applicationName: 'testApp', @@ -281,7 +280,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void warPropertiesFileDeployModeTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'warPropertiesFile', propertiesFile: propertiesFileName, @@ -297,7 +296,7 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void warPropertiesFileDeployModeRollingUpdateTest() { - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'warPropertiesFile', propertiesFile: propertiesFileName, @@ -316,7 +315,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR applicationName') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'warParams', runtime: 'neo-javaee6-wp', @@ -330,7 +329,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, applicationName: 'testApp', deployMode: 'warParams', @@ -343,7 +342,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, applicationName: 'testApp', deployMode: 'warParams', @@ -356,7 +355,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage("[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'") - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'illegalMode', applicationName: 'testApp', @@ -372,7 +371,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage("[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.") - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'warParams', applicationName: 'testApp', @@ -388,7 +387,7 @@ class NeoDeploymentTest extends BasePipelineTest { thrown.expect(Exception) thrown.expectMessage("[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.") - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: warArchiveName, deployMode: 'warParams', applicationName: 'testApp', @@ -401,9 +400,9 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void deployHostProvidedAsDeprecatedParameterTest() { - cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') + jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, deployHost: "my.deploy.host.com" ) @@ -414,9 +413,9 @@ class NeoDeploymentTest extends BasePipelineTest { @Test void deployAccountProvidedAsDeprecatedParameterTest() { - cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') + jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123') - neoDeployScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, host: "my.deploy.host.com", deployAccount: "myAccount" diff --git a/test/groovy/PipelineExecuteTest.groovy b/test/groovy/PipelineExecuteTest.groovy index 1a08022cf..de9c75b03 100644 --- a/test/groovy/PipelineExecuteTest.groovy +++ b/test/groovy/PipelineExecuteTest.groovy @@ -9,24 +9,24 @@ import org.junit.rules.ExpectedException import org.junit.rules.RuleChain import util.JenkinsReadYamlRule +import util.JenkinsStepRule class PipelineExecuteTest extends BasePipelineTest { - private ExpectedException thrown = new ExpectedException().none() + private JenkinsStepRule jsr = new JenkinsStepRule(this) @Rule - public RuleChain ruleChain = Rules.getCommonRules(this) - .around(thrown) + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(thrown) + .around(jsr) def pipelinePath def checkoutParameters = [:] def load - def pipelineExecuteScript - @Before void init() { - pipelinePath = null checkoutParameters.clear() load = null @@ -39,15 +39,12 @@ class PipelineExecuteTest extends BasePipelineTest { checkoutParameters.path = m.extensions[0].sparseCheckoutPaths[0].path }) helper.registerAllowedMethod('load', [String], { s -> load = s }) - - pipelineExecuteScript = loadScript("pipelineExecute.groovy").pipelineExecute } @Test void straightForwardTest() { - - pipelineExecuteScript.call(repoUrl: "https://test.com/myRepo.git") + jsr.step.call(repoUrl: "https://test.com/myRepo.git") assert load == "Jenkinsfile" assert checkoutParameters.branch == 'master' assert checkoutParameters.repoUrl == "https://test.com/myRepo.git" @@ -58,8 +55,7 @@ class PipelineExecuteTest extends BasePipelineTest { @Test void parameterizeTest() { - - pipelineExecuteScript.call(repoUrl: "https://test.com/anotherRepo.git", + jsr.step.call(repoUrl: "https://test.com/anotherRepo.git", branch: 'feature', path: 'path/to/Jenkinsfile', credentialsId: 'abcd1234') @@ -74,10 +70,9 @@ class PipelineExecuteTest extends BasePipelineTest { @Test void noRepoUrlTest() { - thrown.expect(Exception) thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR repoUrl") - pipelineExecuteScript.call() + jsr.step.call() } } diff --git a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy index b95589b94..ea69bc80a 100644 --- a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy +++ b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy @@ -7,24 +7,26 @@ import org.yaml.snakeyaml.Yaml import com.lesfurets.jenkins.unit.BasePipelineTest import util.Rules +import util.JenkinsStepRule +import util.JenkinsEnvironmentRule import static org.junit.Assert.assertEquals import static org.junit.Assert.assertNotNull class SetupCommonPipelineEnvironmentTest extends BasePipelineTest { + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) + + @Rule + public RuleChain rules = Rules + .getCommonRules(this) + .around(jsr) + .around(jer) def usedConfigFile - def setupCommonPipelineEnvironmentScript - - def commonPipelineEnvironment - - @Rule - public RuleChain rules = Rules.getCommonRules(this) - @Before void init() { - def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text helper.registerAllowedMethod("readYaml", [Map], { Map parameters -> @@ -32,26 +34,21 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest { if(parameters.text) { return yamlParser.load(parameters.text) } - usedConfigFile = parameters.file return yamlParser.load(examplePipelineConfig) }) - helper.registerAllowedMethod("fileExists", [String], { String path -> return path.endsWith('.pipeline/config.yml') }) - - setupCommonPipelineEnvironmentScript = loadScript("setupCommonPipelineEnvironment.groovy").setupCommonPipelineEnvironment - commonPipelineEnvironment = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment } @Test void testIsConfigurationAvailable() throws Exception { - setupCommonPipelineEnvironmentScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment]) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) assertEquals('.pipeline/config.yml', usedConfigFile) - assertNotNull(commonPipelineEnvironment.configuration) - assertEquals('develop', commonPipelineEnvironment.configuration.general.productiveBranch) - assertEquals('my-maven-docker', commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage) + assertNotNull(jer.env.configuration) + assertEquals('develop', jer.env.configuration.general.productiveBranch) + assertEquals('my-maven-docker', jer.env.configuration.steps.mavenExecute.dockerImage) } } diff --git a/test/groovy/ToolValidateTest.groovy b/test/groovy/ToolValidateTest.groovy index 03e897139..63f728705 100644 --- a/test/groovy/ToolValidateTest.groovy +++ b/test/groovy/ToolValidateTest.groovy @@ -13,185 +13,166 @@ import org.junit.rules.TemporaryFolder import com.lesfurets.jenkins.unit.BasePipelineTest import util.JenkinsLoggingRule +import util.JenkinsStepRule import util.Rules class ToolValidateTest extends BasePipelineTest { - @ClassRule public static TemporaryFolder tmp = new TemporaryFolder() private ExpectedException thrown = new ExpectedException().none() private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) + private JenkinsStepRule jsr = new JenkinsStepRule(this) @Rule - public RuleChain ruleChain = Rules.getCommonRules(this) - .around(thrown) - .around(jlr) - + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(thrown) + .around(jlr) + .around(jsr) private static home - private toolValidateScript - - @BeforeClass static void createTestFiles() { - home = "${tmp.getRoot()}" tmp.newFile('mta.jar') } @Before void init() { - binding.setVariable('JAVA_HOME', home) - - toolValidateScript = loadScript('toolValidate.groovy').toolValidate } @Test void nullHomeTest() { - thrown.expect(IllegalArgumentException) thrown.expectMessage("The parameter 'home' can not be null or empty.") - toolValidateScript.call(tool: 'java', home: null) + jsr.step.call(tool: 'java', home: null) } @Test void emptyHomeTest() { - thrown.expect(IllegalArgumentException) thrown.expectMessage("The parameter 'home' can not be null or empty.") - toolValidateScript.call(tool: 'java', home: '') + jsr.step.call(tool: 'java', home: '') } @Test void nullToolTest() { - thrown.expect(IllegalArgumentException) thrown.expectMessage("The parameter 'tool' can not be null or empty.") - toolValidateScript.call(tool: null) + jsr.step.call(tool: null) } @Test void emptyToolTest() { - thrown.expect(IllegalArgumentException) thrown.expectMessage("The parameter 'tool' can not be null or empty.") - toolValidateScript.call(tool: '') + jsr.step.call(tool: '') } @Test void invalidToolTest() { - thrown.expect(AbortException) thrown.expectMessage("The tool 'test' is not supported.") - toolValidateScript.call(tool: 'test', home: home) + jsr.step.call(tool: 'test', home: home) } @Test void unableToValidateJavaTest() { - thrown.expect(AbortException) thrown.expectMessage('The validation of Java failed.') helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - toolValidateScript.call(tool: 'java', home: home) + jsr.step.call(tool: 'java', home: home) } @Test void unableToValidateMtaTest() { - thrown.expect(AbortException) thrown.expectMessage('The validation of SAP Multitarget Application Archive Builder failed.') helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - toolValidateScript.call(tool: 'mta', home: home) + jsr.step.call(tool: 'mta', home: home) } @Test void unableToValidateNeoTest() { - thrown.expect(AbortException) thrown.expectMessage('The validation of SAP Cloud Platform Console Client failed.') helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - toolValidateScript.call(tool: 'neo', home: home) + jsr.step.call(tool: 'neo', home: home) } @Test void unableToValidateCmTest() { - thrown.expect(AbortException) thrown.expectMessage('The validation of Change Management Command Line Interface failed.') helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - toolValidateScript.call(tool: 'cm', home: home) + jsr.step.call(tool: 'cm', home: home) script.execute() } @Test void validateIncompatibleVersionJavaTest() { - thrown.expect(AbortException) thrown.expectMessage('The installed version of Java is 1.7.0.') helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - toolValidateScript.call(tool: 'java', home: home) + jsr.step.call(tool: 'java', home: home) } @Test void validateIncompatibleVersionMtaTest() { - thrown.expect(AbortException) thrown.expectMessage('The installed version of SAP Multitarget Application Archive Builder is 1.0.5.') helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - toolValidateScript.call(tool: 'mta', home: home) + jsr.step.call(tool: 'mta', home: home) } @Test void validateNeoIncompatibleVersionTest() { - thrown.expect(AbortException) thrown.expectMessage('The installed version of SAP Cloud Platform Console Client is 1.126.51.') helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - toolValidateScript.call(tool: 'neo', home: home) + jsr.step.call(tool: 'neo', home: home) } @Test void validateCmIncompatibleVersionTest() { - thrown.expect(AbortException) thrown.expectMessage('The installed version of Change Management Command Line Interface is 0.0.0.') helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) binding.setVariable('tool', 'cm') - toolValidateScript.call(tool: 'cm', home: home) + jsr.step.call(tool: 'cm', home: home) } @Test void validateJavaTest() { - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - toolValidateScript.call(tool: 'java', home: home) + jsr.step.call(tool: 'java', home: home) assert jlr.log.contains('[toolValidate] Validating Java version 1.8.0 or compatible version.') assert jlr.log.contains('[toolValidate] Java version 1.8.0 is installed.') @@ -199,10 +180,9 @@ class ToolValidateTest extends BasePipelineTest { @Test void validateMtaTest() { - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - toolValidateScript.call(tool: 'mta', home: home) + jsr.step.call(tool: 'mta', home: home) assert jlr.log.contains('[toolValidate] Validating SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.') assert jlr.log.contains('[toolValidate] SAP Multitarget Application Archive Builder version 1.0.6 is installed.') @@ -210,10 +190,9 @@ class ToolValidateTest extends BasePipelineTest { @Test void validateNeoTest() { - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - toolValidateScript.call(tool: 'neo', home: home) + jsr.step.call(tool: 'neo', home: home) assert jlr.log.contains('[toolValidate] Validating SAP Cloud Platform Console Client version 3.39.10 or compatible version.') assert jlr.log.contains('[toolValidate] SAP Cloud Platform Console Client version 3.39.10 is installed.') @@ -221,21 +200,19 @@ class ToolValidateTest extends BasePipelineTest { @Test void validateCmTest() { - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - toolValidateScript.call(tool: 'cm', home: home) + jsr.step.call(tool: 'cm', home: home) assert jlr.log.contains('[toolValidate] Validating Change Management Command Line Interface version 0.0.1 or compatible version.') assert jlr.log.contains('[toolValidate] Change Management Command Line Interface version 0.0.1 is installed.') } - private getNoVersion(Map m) { + private getNoVersion(Map m) { throw new AbortException('script returned exit code 127') } private getVersion(Map m) { - if(m.script.contains('java -version')) { return '''openjdk version \"1.8.0_121\" OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-1~bpo8+1-b13) @@ -252,7 +229,6 @@ class ToolValidateTest extends BasePipelineTest { } private getIncompatibleVersion(Map m) { - if(m.script.contains('java -version')) { return '''openjdk version \"1.7.0_121\" OpenJDK Runtime Environment (build 1.7.0_121-8u121-b13-1~bpo8+1-b13) @@ -268,4 +244,3 @@ class ToolValidateTest extends BasePipelineTest { } } } - From a54e1a7611fe0108225c76b6f3fc1e9bc7a7bf4d Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Wed, 28 Feb 2018 13:12:03 +0100 Subject: [PATCH 2/7] use new rules --- test/groovy/DockerExecuteTest.groovy | 27 ++++++------ test/groovy/MTABuildTest.groovy | 61 ++++++++++++++-------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/test/groovy/DockerExecuteTest.groovy b/test/groovy/DockerExecuteTest.groovy index 6ab08a64c..27b1f20ae 100644 --- a/test/groovy/DockerExecuteTest.groovy +++ b/test/groovy/DockerExecuteTest.groovy @@ -8,45 +8,42 @@ import com.lesfurets.jenkins.unit.BasePipelineTest import util.JenkinsLoggingRule import util.Rules +import util.JenkinsStepRule +import util.JenkinsEnvironmentRule import static org.junit.Assert.assertEquals import static org.junit.Assert.assertTrue import static org.junit.Assert.assertFalse class DockerExecuteTest extends BasePipelineTest { - private DockerMock docker - private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @Rule - public RuleChain ruleChain = RuleChain.outerRule(Rules.getCommonRules(this)) - .around(jlr) + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(jlr) + .around(jsr) + private DockerMock docker int whichDockerReturnValue = 0 - def bodyExecuted - def cpe - def dockerExecuteScript; - @Before void init() { - bodyExecuted = false docker = new DockerMock() binding.setVariable('docker', docker) binding.setVariable('Jenkins', [instance: [pluginManager: [plugins: [new PluginMock()]]]]) helper.registerAllowedMethod('sh', [Map.class], {return whichDockerReturnValue}) - - cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment - dockerExecuteScript = loadScript('dockerExecute.groovy').dockerExecute } @Test void testExecuteInsideDocker() throws Exception { - dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], dockerImage: 'maven:3.5-jdk-8-alpine') { bodyExecuted = true } @@ -60,7 +57,7 @@ class DockerExecuteTest extends BasePipelineTest { @Test void testExecuteInsideDockerWithParameters() throws Exception { - dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], dockerImage: 'maven:3.5-jdk-8-alpine', dockerOptions: '-it', dockerVolumeBind: ['my_vol': '/my_vol'], @@ -79,7 +76,7 @@ class DockerExecuteTest extends BasePipelineTest { whichDockerReturnValue = 1 - dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], dockerImage: 'maven:3.5-jdk-8-alpine', dockerOptions: '-it', dockerVolumeBind: ['my_vol': '/my_vol'], diff --git a/test/groovy/MTABuildTest.groovy b/test/groovy/MTABuildTest.groovy index d3de58d58..42d2c704d 100644 --- a/test/groovy/MTABuildTest.groovy +++ b/test/groovy/MTABuildTest.groovy @@ -15,30 +15,33 @@ import com.lesfurets.jenkins.unit.BasePipelineTest import util.JenkinsLoggingRule import util.JenkinsShellCallRule +import util.JenkinsStepRule +import util.JenkinsEnvironmentRule import util.Rules -public class MTABuildTest extends BasePipelineTest { - +public class MtaBuildTest extends BasePipelineTest { @ClassRule public static TemporaryFolder tmp = new TemporaryFolder() private ExpectedException thrown = new ExpectedException() private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) + private JenkinsStepRule jsr = new JenkinsStepRule(this) + private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @Rule - public RuleChain ruleChain = Rules.getCommonRules(this) - .around(thrown) - .around(jlr) - .around(jscr) + public RuleChain ruleChain = Rules + .getCommonRules(this) + .around(thrown) + .around(jlr) + .around(jscr) + .around(jsr) + .around(jer) private static currentDir private static newDir private static mtaYaml - def mtaBuildScript - def cpe - @BeforeClass static void createTestFiles() { @@ -51,22 +54,18 @@ public class MTABuildTest extends BasePipelineTest { @Before void init() { - mtaYaml.text = defaultMtaYaml() helper.registerAllowedMethod('pwd', [], { currentDir } ) binding.setVariable('PATH', '/usr/bin') - - mtaBuildScript = loadScript('mtaBuild.groovy').mtaBuild - cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment } @Test void environmentPathTest() { - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') assert jscr.shell[1].contains('PATH=./node_modules/.bin:/usr/bin') } @@ -75,7 +74,7 @@ public class MTABuildTest extends BasePipelineTest { @Test void sedTest() { - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/ } @@ -84,10 +83,10 @@ public class MTABuildTest extends BasePipelineTest { @Test void mtarFilePathFromCommonPipelineEnviromentTest() { - mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], buildTarget: 'NEO') - def mtarFilePath = cpe.getMtarFilePath() + def mtarFilePath = jer.env.getMtarFilePath() assert mtarFilePath == "$currentDir/com.mycompany.northwind.mtar" } @@ -98,7 +97,7 @@ public class MTABuildTest extends BasePipelineTest { helper.registerAllowedMethod('pwd', [], { newDir } ) - def mtarFilePath = mtaBuildScript.call(buildTarget: 'NEO') + def mtarFilePath = jsr.step.call(buildTarget: 'NEO') assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/ @@ -109,7 +108,7 @@ public class MTABuildTest extends BasePipelineTest { @Test void mtaJarLocationNotSetTest() { - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') assert jscr.shell[1].contains(' -jar mta.jar --mtar ') @@ -120,7 +119,7 @@ public class MTABuildTest extends BasePipelineTest { @Test void mtaJarLocationAsParameterTest() { - mtaBuildScript.call(mtaJarLocation: '/mylocation/mta', buildTarget: 'NEO') + jsr.step.call(mtaJarLocation: '/mylocation/mta', buildTarget: 'NEO') assert jscr.shell[1].contains(' -jar /mylocation/mta/mta.jar --mtar ') @@ -134,7 +133,7 @@ public class MTABuildTest extends BasePipelineTest { mtaYaml.delete() thrown.expect(FileNotFoundException) - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') } @@ -146,7 +145,7 @@ public class MTABuildTest extends BasePipelineTest { mtaYaml.text = badMtaYaml() - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') } @@ -158,7 +157,7 @@ public class MTABuildTest extends BasePipelineTest { mtaYaml.text = noIdMtaYaml() - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') } @@ -168,7 +167,7 @@ public class MTABuildTest extends BasePipelineTest { binding.setVariable('env', [:]) binding.getVariable('env')['MTA_JAR_LOCATION'] = '/env/mta' - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') assert jscr.shell[1].contains('-jar /env/mta/mta.jar --mtar') assert jlr.log.contains('[mtaBuild] MTA JAR "/env/mta/mta.jar" retrieved from environment.') @@ -178,9 +177,9 @@ public class MTABuildTest extends BasePipelineTest { @Test void mtaJarLocationFromCustomStepConfigurationTest() { - cpe.configuration = [steps:[mtaBuild:[mtaJarLocation: '/step/mta']]] + jer.env.configuration = [steps:[mtaBuild:[mtaJarLocation: '/step/mta']]] - mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], + jsr.step.call(script: [commonPipelineEnvironment: jer.env], buildTarget: 'NEO') assert jscr.shell[1].contains('-jar /step/mta/mta.jar --mtar') @@ -191,7 +190,7 @@ public class MTABuildTest extends BasePipelineTest { @Test void buildTargetFromParametersTest() { - mtaBuildScript.call(buildTarget: 'NEO') + jsr.step.call(buildTarget: 'NEO') assert jscr.shell[1].contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build') } @@ -200,9 +199,9 @@ public class MTABuildTest extends BasePipelineTest { @Test void buildTargetFromCustomStepConfigurationTest() { - cpe.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]] + jer.env.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]] - mtaBuildScript.call(script: [commonPipelineEnvironment: cpe]) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) assert jscr.shell[1].contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build') } @@ -211,9 +210,9 @@ public class MTABuildTest extends BasePipelineTest { @Test void buildTargetFromDefaultStepConfigurationTest() { - cpe.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]] + jer.env.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]] - mtaBuildScript.call(script: [commonPipelineEnvironment: cpe]) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) assert jscr.shell[1].contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build') } From 3ed2d6419594e4cc9267a4436ba85a736eeb6fa2 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 2 Mar 2018 10:53:09 +0100 Subject: [PATCH 3/7] Update ArtifactSetVersionTest.groovy --- test/groovy/ArtifactSetVersionTest.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/groovy/ArtifactSetVersionTest.groovy b/test/groovy/ArtifactSetVersionTest.groovy index 9a6460f4d..34e067cd5 100644 --- a/test/groovy/ArtifactSetVersionTest.groovy +++ b/test/groovy/ArtifactSetVersionTest.groovy @@ -18,6 +18,9 @@ import util.Rules import static org.junit.Assert.assertEquals class ArtifactSetVersionTest extends BasePipelineTest { + def gitUtils + def sshAgentList = [] + private ExpectedException thrown = ExpectedException.none() private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) @@ -36,9 +39,6 @@ class ArtifactSetVersionTest extends BasePipelineTest { .around(jsr) .around(jer) - def gitUtils - def sshAgentList = [] - @Before void init() throws Throwable { helper.registerAllowedMethod("sshagent", [List.class, Closure.class], { list, closure -> From 76fd77f9071345119e7abe46a621397fcae003ef Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 2 Mar 2018 10:53:46 +0100 Subject: [PATCH 4/7] Update ChecksPublishResultsTest.groovy --- test/groovy/ChecksPublishResultsTest.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/groovy/ChecksPublishResultsTest.groovy b/test/groovy/ChecksPublishResultsTest.groovy index 4b9a83103..cdadc1a4f 100644 --- a/test/groovy/ChecksPublishResultsTest.groovy +++ b/test/groovy/ChecksPublishResultsTest.groovy @@ -13,6 +13,9 @@ import util.Rules import util.JenkinsStepRule class ChecksPublishResultsTest extends BasePipelineTest { + Map publisherStepOptions + List archiveStepPatterns + private JenkinsStepRule jsr = new JenkinsStepRule(this) @Rule @@ -20,9 +23,6 @@ class ChecksPublishResultsTest extends BasePipelineTest { .getCommonRules(this) .around(jsr) - Map publisherStepOptions - List archiveStepPatterns - @Before void init() { publisherStepOptions = [:] From 83d75e99b772f8a31276d13b8ecffb6099b7fabf Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 2 Mar 2018 10:54:50 +0100 Subject: [PATCH 5/7] Update DockerExecuteTest.groovy --- test/groovy/DockerExecuteTest.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/groovy/DockerExecuteTest.groovy b/test/groovy/DockerExecuteTest.groovy index 27b1f20ae..1bf71445e 100644 --- a/test/groovy/DockerExecuteTest.groovy +++ b/test/groovy/DockerExecuteTest.groovy @@ -16,6 +16,10 @@ import static org.junit.Assert.assertTrue import static org.junit.Assert.assertFalse class DockerExecuteTest extends BasePipelineTest { + private DockerMock docker + int whichDockerReturnValue = 0 + def bodyExecuted + private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsStepRule jsr = new JenkinsStepRule(this) private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @@ -26,10 +30,6 @@ class DockerExecuteTest extends BasePipelineTest { .around(jlr) .around(jsr) - private DockerMock docker - int whichDockerReturnValue = 0 - def bodyExecuted - @Before void init() { bodyExecuted = false From e38eda33a7cdd37a67fb5c516afd3c027f048046 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 2 Mar 2018 10:55:27 +0100 Subject: [PATCH 6/7] Update DockerExecuteTest.groovy --- test/groovy/DockerExecuteTest.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/groovy/DockerExecuteTest.groovy b/test/groovy/DockerExecuteTest.groovy index 1bf71445e..743a52f9d 100644 --- a/test/groovy/DockerExecuteTest.groovy +++ b/test/groovy/DockerExecuteTest.groovy @@ -17,8 +17,6 @@ import static org.junit.Assert.assertFalse class DockerExecuteTest extends BasePipelineTest { private DockerMock docker - int whichDockerReturnValue = 0 - def bodyExecuted private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsStepRule jsr = new JenkinsStepRule(this) @@ -29,6 +27,9 @@ class DockerExecuteTest extends BasePipelineTest { .getCommonRules(this) .around(jlr) .around(jsr) + + int whichDockerReturnValue = 0 + def bodyExecuted @Before void init() { From d10b94a1664f9c473330eab48e8f0fd1332c2df4 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 2 Mar 2018 10:57:50 +0100 Subject: [PATCH 7/7] Update SetupCommonPipelineEnvironmentTest.groovy --- test/groovy/SetupCommonPipelineEnvironmentTest.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy index ea69bc80a..0be89f59a 100644 --- a/test/groovy/SetupCommonPipelineEnvironmentTest.groovy +++ b/test/groovy/SetupCommonPipelineEnvironmentTest.groovy @@ -14,6 +14,8 @@ import static org.junit.Assert.assertEquals import static org.junit.Assert.assertNotNull class SetupCommonPipelineEnvironmentTest extends BasePipelineTest { + def usedConfigFile + private JenkinsStepRule jsr = new JenkinsStepRule(this) private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this) @@ -23,8 +25,6 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest { .around(jsr) .around(jer) - def usedConfigFile - @Before void init() { def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text