From 3cafd0b6d5ba45545270f51d4ab2812a53ea14c9 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Wed, 21 Feb 2018 12:48:14 +0100 Subject: [PATCH] Validating mta jar inside mtaBuild --- test/groovy/MTABuildTest.groovy | 30 ++++++++++++++++++++++++++++++ vars/mtaBuild.groovy | 13 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/test/groovy/MTABuildTest.groovy b/test/groovy/MTABuildTest.groovy index ab37ce21a..662ef3868 100644 --- a/test/groovy/MTABuildTest.groovy +++ b/test/groovy/MTABuildTest.groovy @@ -20,6 +20,9 @@ import util.JenkinsEnvironmentRule import util.Rules public class MtaBuildTest extends BasePipelineTest { + + def toolMtaValidateCalled = false + @ClassRule public static TemporaryFolder tmp = new TemporaryFolder() @@ -59,6 +62,20 @@ public class MtaBuildTest extends BasePipelineTest { helper.registerAllowedMethod('pwd', [], { currentDir } ) binding.setVariable('PATH', '/usr/bin') + + // + // needs to be after loading the scripts. Here we have a different behaviour + // for usual steps and for steps contained in the shared lib itself. + // + // toolValidate mocked here since we are not interested in testing + // toolValidate here. This is expected to be done in a test class for + // toolValidate. + // + helper.registerAllowedMethod('toolValidate', [Map], { m -> + + if(m.tool == 'mta') + toolMtaValidateCalled = true + }) } @@ -217,6 +234,19 @@ public class MtaBuildTest extends BasePipelineTest { assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')} } + @Test + void skipValidationInCaseMtarJarFileIsUsedFromWorkingDir() { + jscr.setReturnValue('ls mta.jar', 0) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) + assert !toolMtaValidateCalled + } + + @Test + void performValidationInCaseMtarJarFileIsNotUsedFromWorkingDir() { + jscr.setReturnValue('ls mta.jar', 1) + jsr.step.call(script: [commonPipelineEnvironment: jer.env]) + assert toolMtaValidateCalled + } private static defaultMtaYaml() { return ''' diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index 1d3b85aea..3dfc4eba0 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -1,6 +1,9 @@ import com.sap.piper.ConfigurationLoader import com.sap.piper.ConfigurationMerger +import groovy.transform.Field + +@Field def DEFAULT_MTA_JAR_NAME = 'mta.jar' def call(Map parameters = [:]) { @@ -28,6 +31,16 @@ def call(Map parameters = [:]) { null, stepConfigurationKeys) + + MTA_JAR_FILE_VALIDATE: { + // same order like inside getMtaJar, + def mtaJarLocation = configuration?.mtaJarLocation ?: env?.MTA_JAR_LOCATION + def returnCodeLsMtaJar = sh script: 'ls mta.jar', returnStatus:true + if(mtaJarLocation || ( !mtaJarLocation && returnCodeLsMtaJar != 0)) { + toolValidate tool: 'mta', home: mtaJarLocation + } + } + def mtaYaml = readYaml file: "${pwd()}/mta.yaml" //[Q]: Why not yaml.dump()? [A]: This reformats the whole file.