Skip to content

Commit

Permalink
Merge bb5e38a into 157c9ca
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandraferreirovidal committed Feb 9, 2018
2 parents 157c9ca + bb5e38a commit 763dc62
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 220 deletions.
6 changes: 6 additions & 0 deletions src/com/sap/piper/FileUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ class FileUtils implements Serializable {
def file = new File(dir)
if (file.list().size() == 0) throw new AbortException("'${file.getAbsolutePath()}' is empty.")
}

static validateFile(filePath) {
if (!filePath) throw new IllegalArgumentException("The parameter 'filePath' can not be null or empty.")
def file = new File(filePath)
if (!file.exists()) throw new AbortException("'${file.getAbsolutePath()}' does not exist.")
}
}
60 changes: 60 additions & 0 deletions src/com/sap/piper/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,63 @@ def getMandatoryParameter(Map map, paramName, defaultValue = null) {
return paramValue

}

def getMtaJar(script, stepName, configuration, environment) {
def mtaJarLocation = 'mta.jar' //default, maybe it is in current working directory

if(configuration?.mtaJarLocation){
mtaJarLocation = "${configuration.mtaJarLocation}/mta.jar"
script.echo "[$stepName] MTA JAR \"${mtaJarLocation}\" retrieved from configuration."
return mtaJarLocation
}

if(environment?.MTA_JAR_LOCATION){
mtaJarLocation = "${environment.MTA_JAR_LOCATION}/mta.jar"
script.echo "[$stepName] MTA JAR \"${mtaJarLocation}\" retrieved from environment."
return mtaJarLocation
}

script.echo "[$stepName] Using MTA JAR from current working directory."
return mtaJarLocation
}

def getNeoExecutable(script, stepName, configuration, environment) {

def neoExecutable = 'neo.sh' // default, if nothing below applies maybe it is the path.

if (configuration?.neoHome) {
neoExecutable = "${configuration.neoHome}/tools/neo.sh"
script.echo "[$stepName] Neo executable \"${neoExecutable}\" retrieved from configuration."
return neoExecutable
}

if (environment?.NEO_HOME) {
neoExecutable = "${environment.NEO_HOME}/tools/neo.sh"
script.echo "[$stepName] Neo executable \"${neoExecutable}\" retrieved from environment."
return neoExecutable
}

script.echo "[$stepName] Using Neo executable from PATH."
return neoExecutable
}

def getCmCliExecutable(script, stepName, configuration, environment) {

def cmCliExecutable = 'cmclient' // default, if nothing below applies maybe it is the path.

if (configuration?.cmCliHome) {
cmCliExecutable = "${configuration.cmCliHome}/bin/cmclient"
script.echo "[$stepName] Change Management Command Line Interface \"${cmCliExecutable}\" retrieved from configuration."
return cmCliExecutable
}

if (environment?.CM_CLI_HOME) {
cmCliExecutable = "${environment.CM_CLI_HOME}/bin/cmclient"
script.echo "[$stepName] Change Management Command Line Interface \"${cmCliExecutable}\" retrieved from environment."
return cmCliExecutable
}

script.echo "[$stepName] Change Management Command Line Interface retrieved from current working directory."
return cmCliExecutable
}

2 changes: 1 addition & 1 deletion test/groovy/MTABuildTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class MTABuildTest extends BasePipelineTest {

assert jscr.shell[1].contains(' -jar /mylocation/mta/mta.jar --mtar ')

assert jlr.log.contains('[mtaBuild] MTA JAR "/mylocation/mta/mta.jar" retrieved from parameters.')
assert jlr.log.contains('[mtaBuild] MTA JAR "/mylocation/mta/mta.jar" retrieved from configuration.')
}


Expand Down
164 changes: 93 additions & 71 deletions test/groovy/ToolValidateTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,37 @@ class ToolValidateTest extends BasePipelineTest {
.around(thrown)
.around(jlr)

private toolValidateScript
private commonPipelineEnvironment

private notEmptyDir
private home

private mtaJar
private neoExecutable
private cmCliExecutable

def toolValidateScript

@Before
void init() {

notEmptyDir = tmp.newFolder('notEmptyDir')
def path = "${notEmptyDir.getAbsolutePath()}${File.separator}test.txt"
File file = new File(path)
file.createNewFile()

binding.setVariable('JAVA_HOME', notEmptyDir.getAbsolutePath())
home = "${tmp.getRoot()}"

toolValidateScript = loadScript("toolValidate.groovy").toolValidate
}
tmp.newFile('mta.jar')
tmp.newFolder('tools')
tmp.newFolder('bin')
tmp.newFile('tools/neo.sh')
tmp.newFile('bin/cmclient')

mtaJar = "$home/mta.jar"
neoExecutable = "$home/tools/neo.sh"
cmCliExecutable = "$home/bin/cmclient"

@Test
void nullHomeTest() {
helper.registerAllowedMethod('fileExists', [String], { s -> return true })

thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'home' can not be null or empty.")
binding.setVariable('JAVA_HOME', home)

toolValidateScript.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: '')
}

@Test
void nullToolTest() {

thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'tool' can not be null or empty.")

toolValidateScript.call(tool: null)
}

@Test
void emptyToolTest() {

thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'tool' can not be null or empty.")

toolValidateScript.call(tool: '')
toolValidateScript = loadScript('toolValidate.groovy').toolValidate
commonPipelineEnvironment = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
}

@Test
Expand All @@ -85,7 +63,7 @@ class ToolValidateTest extends BasePipelineTest {
thrown.expect(AbortException)
thrown.expectMessage("The tool 'test' is not supported.")

toolValidateScript.call(tool: 'test', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'test', home: home)
}

@Test
Expand All @@ -96,7 +74,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })

toolValidateScript.call(tool: 'java', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'java', home: home)
}

@Test
Expand All @@ -107,7 +85,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })

toolValidateScript.call(tool: 'mta', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'mta', home: home)
}

@Test
Expand All @@ -118,7 +96,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })

toolValidateScript.call(tool: 'neo', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'neo', home: home)
}

@Test
Expand All @@ -129,7 +107,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })

toolValidateScript.call(tool: 'cm', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'cm', home: home)

script.execute()
}
Expand All @@ -142,7 +120,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })

toolValidateScript.call(tool: 'java', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'java', home: home)
}

@Test
Expand All @@ -153,7 +131,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })

toolValidateScript.call(tool: 'mta', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'mta', home: home)
}

@Test
Expand All @@ -164,7 +142,7 @@ class ToolValidateTest extends BasePipelineTest {

helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })

toolValidateScript.call(tool: 'neo', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'neo', home: home)
}

@Test
Expand All @@ -176,61 +154,105 @@ class ToolValidateTest extends BasePipelineTest {
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
binding.setVariable('tool', 'cm')

toolValidateScript.call(tool: 'cm', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'cm', home: home)
}

@Test
void validateJavaTest() {

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(tool: 'java', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'java', home: home)

assert jlr.log.contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
assert jlr.log.contains('[INFO] Validating Java version 1.8.0 or compatible version.')
assert jlr.log.contains('[INFO] Java version 1.8.0 is installed.')
assert jlr.log.contains('--- END LIBRARY STEP: toolValidate.groovy ---')
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.')
}

@Test
void validateMtaTest() {

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(tool: 'mta', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'mta', home: home)

assert jlr.log.contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
assert jlr.log.contains('[INFO] Validating SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.')
assert jlr.log.contains('[INFO] SAP Multitarget Application Archive Builder version 1.0.6 is installed.')
assert jlr.log.contains('--- END LIBRARY STEP: toolValidate.groovy ---')
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.')
}

@Test
void validateNeoTest() {

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(tool: 'neo', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'neo', home: home)

assert jlr.log.contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
assert jlr.log.contains('[INFO] Validating SAP Cloud Platform Console Client version 3.39.10 or compatible version.')
assert jlr.log.contains('[INFO] SAP Cloud Platform Console Client version 3.39.10 is installed.')
assert jlr.log.contains('--- END LIBRARY STEP: toolValidate.groovy ---')
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.')
}

@Test
void validateCmTest() {

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(tool: 'cm', home: notEmptyDir.getAbsolutePath())
toolValidateScript.call(tool: 'cm', home: home)

assert jlr.log.contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
assert jlr.log.contains('[INFO] Validating Change Management Command Line Interface version 0.0.1 or compatible version.')
assert jlr.log.contains('[INFO] Change Management Command Line Interface version 0.0.1 is installed.')
assert jlr.log.contains('--- END LIBRARY STEP: toolValidate.groovy ---')
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.')
}

@Test
void toolNotSetTest() {

thrown.expect(Exception)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR tool")

toolValidateScript.call()
}

@Test
void mtaJarLocationFromCustomStepConfigurationTest() {

commonPipelineEnvironment.configuration = [general:[mtaJarLocation: "$home"]]

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment], tool: 'mta')

assert jlr.log.contains("[toolValidate] MTA JAR \"$mtaJar\" retrieved from configuration.")
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.')
}

@Test
void neoHomeFromCustomStepConfigurationTest() {

commonPipelineEnvironment.configuration = [general:[neoHome: "$home"]]

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment], tool: 'neo')

assert jlr.log.contains("[toolValidate] Neo executable \"$neoExecutable\" retrieved from configuration.")
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.')
}

@Test
void cmCliHomeFromCustomStepConfigurationTest() {

commonPipelineEnvironment.configuration = [general:[cmCliHome: "$home"]]

helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })

toolValidateScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment], tool: 'cm')

assert jlr.log.contains("[toolValidate] Change Management Command Line Interface \"$cmCliExecutable\" retrieved from configuration.")
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) {
throw new AbortException('script returned exit code 127')
}
Expand Down
Loading

0 comments on commit 763dc62

Please sign in to comment.