1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

Validating mta jar inside mtaBuild

This commit is contained in:
Marcus Holl 2018-02-21 12:48:14 +01:00
parent 3bc53b906f
commit 3cafd0b6d5
2 changed files with 43 additions and 0 deletions

View File

@ -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 '''

View File

@ -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.