diff --git a/documentation/docs/steps/toolValidate.md b/documentation/docs/steps/toolValidate.md deleted file mode 100644 index ae32a1eb4..000000000 --- a/documentation/docs/steps/toolValidate.md +++ /dev/null @@ -1,41 +0,0 @@ -# toolValidate - -## Description - -Checks the existence and compatibility of a tool, necessary for a successful pipeline execution. -In case a violation is found, an exception is raised. - -## Prerequisites - -none - -## Parameters - -| parameter | mandatory | default | possible values | -| -----------------|-----------|-----------------------------------|----------------------------| -| `tool` | yes | | 'java', 'mta', 'neo' | -| `home` | yes | | | - -* `tool` The tool that is checked for existence and compatible version. -* `home` The location in the file system where Jenkins can access the tool. - -## Step configuration - -none - -## Side effects - -none - -## Exceptions - -* `IllegalArgumentException`: - * If at least one of the parameters `tool`, `home` is not provided. -* `AbortException`: - * If `tool` is not supported. - -## Example - -```groovy -toolValidate tool: 'neo', home:'/path/to/neo-java-web-sdk' -``` diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index 493868652..44cd4b87f 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -34,7 +34,6 @@ nav: - slackSendNotification: steps/slackSendNotification.md - snykExecute: steps/snykExecute.md - testsPublishResults: steps/testsPublishResults.md - - toolValidate: steps/toolValidate.md - transportRequestCreate: steps/transportRequestCreate.md - transportRequestRelease: steps/transportRequestRelease.md - transportRequestUploadFile: steps/transportRequestUploadFile.md diff --git a/src/com/sap/piper/EnvironmentUtils.groovy b/src/com/sap/piper/EnvironmentUtils.groovy deleted file mode 100644 index 14259be18..000000000 --- a/src/com/sap/piper/EnvironmentUtils.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package com.sap.piper - -import hudson.AbortException - - -class EnvironmentUtils implements Serializable { - - static boolean isEnvironmentVariable(script, variable) { - return !getEnvironmentVariable(script, variable).isEmpty() - } - - static String getEnvironmentVariable(script, variable) { - try { - def envVar = script.sh returnStdout: true, script: """#!/bin/bash --login - echo \$$variable""" - return envVar.trim() - } catch(AbortException e) { - throw new AbortException("There was an error requesting the environment variable '$variable'. Reason: $e.message.") - } - } -} diff --git a/src/com/sap/piper/FileUtils.groovy b/src/com/sap/piper/FileUtils.groovy deleted file mode 100644 index f8f934ad5..000000000 --- a/src/com/sap/piper/FileUtils.groovy +++ /dev/null @@ -1,91 +0,0 @@ -package com.sap.piper - -import hudson.AbortException - -class FileUtils implements Serializable { - - static boolean directoryOrFileExists(script, dirOrFile) { - if (!dirOrFile) throw new IllegalArgumentException("The parameter 'dirOrFile' can not be null or empty.") - def returnStatus = script.sh returnStatus: true, script: """ - set +x - if [ -d $dirOrFile ]; then - echo \"$dirOrFile exists.\" - exit 0 - elif [ -f $dirOrFile ]; then - echo \"$dirOrFile exists.\" - exit 0 - else - echo \"$dirOrFile does not exist.\" - exit 1 - fi - """ - return returnStatus == 0 - } - - static boolean isDirectory(script, dir) { - if (!dir) throw new IllegalArgumentException("The parameter 'dir' can not be null or empty.") - def returnStatus = script.sh returnStatus: true, script: """ - set +x - if [ -d $dir ]; then - echo \"$dir is a directory.\" - exit 0 - else - echo \"$dir is not a directory.\" - exit 1 - fi - """ - return returnStatus == 0 - } - - static boolean isDirectoryEmpty(script, dir) { - if (!dir) throw new IllegalArgumentException("The parameter 'dir' can not be null or empty.") - def returnStatus = script.sh returnStatus: true, script: """ - set +x - if [ -z "\$(ls -A $dir)" ]; then - echo "$dir is empty." - exit 1 - else - echo "$dir is not empty." - exit 0 - fi - """ - return returnStatus == 1 - } - - static boolean isFile(script, filePath) { - if (!filePath) throw new IllegalArgumentException("The parameter 'filePath' can not be null or empty.") - def returnStatus = script.sh returnStatus: true, script: """ - set +x - if [ -f $filePath ]; then - echo \"$filePath is a file.\" - exit 0 - else - echo \"$filePath is not a file.\" - exit 1 - fi - """ - return returnStatus == 0 - } - - static validateDirectoryOrFileExists(script, dirOrFile) { - if (!dirOrFile) throw new IllegalArgumentException("The parameter 'dirOrFile' can not be null or empty.") - if (!directoryOrFileExists(script, dirOrFile)) throw new AbortException("Validation failed. '$dirOrFile' does not exist.") - } - - static validateDirectory(script, dir) { - if (!dir) throw new IllegalArgumentException("The parameter 'dir' can not be null or empty.") - validateDirectoryOrFileExists(script, dir) - if (!isDirectory(script, dir)) throw new AbortException("Validation failed. '$dir' is not a directory.") - } - - static validateDirectoryIsNotEmpty(script, dir) { - validateDirectory(script, dir) - if (isDirectoryEmpty(script, dir)) throw new AbortException("Validation failed. '$dir' is empty.") - } - - static validateFile(script, filePath) { - if (!filePath) throw new IllegalArgumentException("The parameter 'filePath' can not be null or empty.") - validateDirectoryOrFileExists(script, filePath) - if (!isFile(script, filePath)) throw new AbortException("Validation failed. '$filePath' is not a file.") - } -} diff --git a/src/com/sap/piper/Version.groovy b/src/com/sap/piper/Version.groovy deleted file mode 100644 index d09d92a7f..000000000 --- a/src/com/sap/piper/Version.groovy +++ /dev/null @@ -1,52 +0,0 @@ -package com.sap.piper - -import hudson.AbortException - - -class Version implements Serializable { - - final def major - final def minor - final def patch - - Version(major, minor, patch = -1) { - if (major < 0) throw new IllegalArgumentException("The parameter 'major' can not have a value less than 0.") - if (minor < 0) throw new IllegalArgumentException("The parameter 'minor' can not have a value less than 0.") - this.major = major - this.minor = minor - this.patch = patch - } - - Version(text) { - if (!text) throw new IllegalArgumentException("The parameter 'text' can not be null or empty.") - def group = text =~ /(\d+[.]\d+[.]\d+)/ - if (!group) throw new AbortException("The version '$text' has an unexpected format. The expected format is .") - def i = group[0].size()-1 - def versionNumbers = group[0][i].split("\\.") - major = versionNumbers[0].toInteger() - minor = versionNumbers[1].toInteger() - patch = versionNumbers[2].toInteger() - } - - @Override - boolean equals(version) { - if (!version) throw new IllegalArgumentException("The parameter 'version' can not be null.") - return major == version.major && minor == version.minor && patch == version.patch - } - - boolean isHigher(version) { - if (!version) throw new IllegalArgumentException("The parameter 'version' can not be null.") - return major > version.major || major == version.major && ( minor > version.minor || minor == version.minor && patch > version.patch) - } - - boolean isCompatibleVersion(version) { - if (!version) throw new IllegalArgumentException("The parameter 'version' can not be null.") - return this == version || isHigher(version) && major == version.major - } - - @Override - String toString() { - return patch != -1 ? "$major.$minor.$patch".toString() : "$major.$minor".toString() - } -} - diff --git a/src/com/sap/piper/VersionUtils.groovy b/src/com/sap/piper/VersionUtils.groovy deleted file mode 100644 index 9e1087e26..000000000 --- a/src/com/sap/piper/VersionUtils.groovy +++ /dev/null @@ -1,73 +0,0 @@ -package com.sap.piper - -import hudson.AbortException - - -class VersionUtils implements Serializable { - - def static getVersion(script, name, executable, versionOption) { - - return new Version(getVersionDesc(script, name, executable, versionOption)) - } - - def static getVersionDesc(script, name, executable, versionOption) { - - def toolVersion - try { - toolVersion = script.sh returnStdout: true, script: """#!/bin/bash - $executable $versionOption""" - } catch(AbortException e) { - throw new AbortException("The verification of $name failed. Please check '$executable'. $e.message.") - } - - return toolVersion - } - - def static verifyVersion(script, name, executable, String version, versionOption) { - - script.echo "Verifying $name version $version or compatible version." - - Version installedVersion = getVersion(script, name, executable, versionOption) - - if (!installedVersion.isCompatibleVersion(new Version(version))) { - throw new AbortException("The installed version of $name is ${installedVersion.toString()}. Please install version $version or a compatible version.") - } - script.echo "Verification success. $name version ${installedVersion.toString()} is installed." - } - - def static verifyVersion(script, name, String versionDesc, String versionExpected) { - - script.echo "Verifying $name version $versionExpected or compatible version." - - Version versionAvailable = new Version(versionDesc) - - if (!versionAvailable.isCompatibleVersion(new Version(versionExpected))) { - throw new AbortException("The installed version of $name is ${versionAvailable.toString()}. Please install version $versionExpected or a compatible version.") - } - script.echo "Verification success. $name version ${versionAvailable.toString()} is installed." - } - - - def static verifyVersion(script, name, executable, Map versions, versionOption) { - - def versionDesc = getVersionDesc(script, name, executable, versionOption) - - verifyVersion(script, name, versionDesc, versions) - } - - def static verifyVersion(script, name, String versionDesc, Map versions) { - - for (def entry : versions) { - if (versionDesc.contains(entry.getKey())) { - def installedVersion = new Version(versionDesc) - def expectedVersion = entry.getValue() - script.echo "Verifying $name version $expectedVersion or compatible version." - if (!installedVersion.isCompatibleVersion(new Version(expectedVersion))) { - throw new AbortException("The installed version of $name is ${installedVersion.toString()}. Please install version $expectedVersion or a compatible version.") - } - script.echo "Verification success. $name version ${installedVersion.toString()} is installed." - } - } - script.echo "Verification success." - } -} diff --git a/src/com/sap/piper/tools/JavaArchiveDescriptor.groovy b/src/com/sap/piper/tools/JavaArchiveDescriptor.groovy deleted file mode 100644 index 4a164d6ef..000000000 --- a/src/com/sap/piper/tools/JavaArchiveDescriptor.groovy +++ /dev/null @@ -1,98 +0,0 @@ -package com.sap.piper.tools - -import com.sap.piper.VersionUtils -import com.sap.piper.EnvironmentUtils -import com.sap.piper.FileUtils - -import hudson.AbortException - - -class JavaArchiveDescriptor implements Serializable { - - final name - final environmentKey - final stepConfigurationKey - final version - final versionOption - final javaTool - final javaOptions - - JavaArchiveDescriptor(name, environmentKey, stepConfigurationKey, version, versionOption, javaTool, javaOptions = '') { - this.name = name - this.environmentKey = environmentKey - this.stepConfigurationKey = stepConfigurationKey - this.version = version - this.versionOption = versionOption - this.javaTool = javaTool - this.javaOptions = javaOptions - } - - def getFile(script, configuration, log = true) { - - def javaArchiveFile - if (EnvironmentUtils.isEnvironmentVariable(script, environmentKey)) { - javaArchiveFile = EnvironmentUtils.getEnvironmentVariable(script, environmentKey) - if (log) script.echo "$name file '$javaArchiveFile' retrieved from environment." - if (!isJavaArchiveFile(javaArchiveFile)) { - //script.error "The value '$javaArchiveFile' of the environment variable '$environmentKey' has an unexpected format." - javaArchiveFile += '/mta.jar' // Compatibility code - } - } - else if (configuration.containsKey(stepConfigurationKey)) { - javaArchiveFile = configuration.get(stepConfigurationKey) - if (log) script.echo "$name file '$javaArchiveFile' retrieved from configuration." - if (!isJavaArchiveFile(javaArchiveFile)) { - //script.error "The value '$javaArchiveFile' of the configuration key '$stepConfigurationKey' has an unexpected format." - javaArchiveFile += '/mta.jar' // Compatibility code - } - } else { - throw new AbortException(getMessage()) - } - return javaArchiveFile - } - - def isJavaArchiveFile(String javaArchiveFile) { - def group = javaArchiveFile =~ /(.+[\/\\])(.+[.]jar)/ - if (!group.matches() || group[0].size() == 0) group = javaArchiveFile =~ /(.+[.]jar)/ - if (!group.matches() || group[0].size() == 0) return false - return true - } - - def getCall(script, configuration, log = true) { - - def javaArchiveFile = getFile(script, configuration, log) - if (log) script.echo "Using $name '$javaArchiveFile'." - def javaExecutable = javaTool.getToolExecutable(script, configuration, false) - def javaCall = "$javaExecutable -jar" - if (javaOptions) javaCall += " $javaOptions" - return "$javaCall $javaArchiveFile" - } - - def verify(script, configuration) { - - verifyFile(script, configuration) - verifyVersion(script, configuration) - } - - def verifyFile(script, configuration) { - - def javaArchiveFile = getFile(script, configuration, false) - script.echo "Verifying $name '$javaArchiveFile'." - FileUtils.validateFile(script, javaArchiveFile) - script.echo "Verification success. $name '$javaArchiveFile' exists." - } - - def verifyVersion(script, configuration) { - - def javaArchiveCall = getCall(script, configuration, false) - VersionUtils.verifyVersion(script, name, javaArchiveCall, version, versionOption) - } - - def getMessage() { - def configOptions = "Please, configure $name. $name can be set " - if (environmentKey) configOptions += "using the environment variable '$environmentKey'" - if (environmentKey && stepConfigurationKey) configOptions += ", or " - if (stepConfigurationKey) configOptions += "using the configuration key '$stepConfigurationKey'." - return configOptions - } -} diff --git a/src/com/sap/piper/tools/ToolDescriptor.groovy b/src/com/sap/piper/tools/ToolDescriptor.groovy deleted file mode 100644 index 7886d5c9b..000000000 --- a/src/com/sap/piper/tools/ToolDescriptor.groovy +++ /dev/null @@ -1,135 +0,0 @@ -package com.sap.piper.tools - -import com.sap.piper.VersionUtils -import com.sap.piper.EnvironmentUtils -import com.sap.piper.FileUtils -import com.sap.piper.Version - -import hudson.AbortException - - -class ToolDescriptor implements Serializable { - - final name - final environmentKey - final stepConfigurationKey - final executablePath - final executableName - final singleVersion - final multipleVersions - final versionOption - - ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, String singleVersion, versionOption) { - this.name = name - this.environmentKey = environmentKey - this.stepConfigurationKey = stepConfigurationKey - this.executablePath = executablePath - this.executableName = executableName - this.singleVersion = singleVersion - this.multipleVersions = [:] - this.versionOption = versionOption - } - - ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, Map multipleVersions, versionOption) { - this.name = name - this.environmentKey = environmentKey - this.stepConfigurationKey = stepConfigurationKey - this.executablePath = executablePath - this.executableName = executableName - this.singleVersion = '' - this.multipleVersions = multipleVersions - this.versionOption = versionOption - } - - def getToolLocation(script, configuration, log = true) { - - def toolLocation - if (EnvironmentUtils.isEnvironmentVariable(script, environmentKey)) { - toolLocation = EnvironmentUtils.getEnvironmentVariable(script, environmentKey) - if (log) script.echo "$name home '$toolLocation' retrieved from environment." - } - else if (configuration.containsKey(stepConfigurationKey)) { - toolLocation = configuration.get(stepConfigurationKey) - if (log) script.echo "$name home '$toolLocation' retrieved from configuration." - } else if (isOnPath(script, configuration)){ - toolLocation = '' - if (log) script.echo "$name is on PATH." - } else { - throw new AbortException(getMessage()) - } - return toolLocation - } - - def getTool(script, configuration, log = true) { - - def toolLocation = getToolLocation(script, configuration, log) - - if (toolLocation) { - return "$toolLocation$executablePath$executableName" - } else { - return executableName - } - } - - def getToolExecutable(script, configuration, log = true) { - def executable = getTool(script, configuration, log) - if (log) script.echo "Using $name '$executable'." - return executable - } - - def verify(script, configuration) { - - verifyToolLocation(script, configuration) - verifyToolExecutable(script, configuration) - verifyVersion(script, configuration) - } - - def verifyToolLocation(script, configuration) { - - def toolLocation = getToolLocation(script, configuration) - if (toolLocation) { - script.echo "Verifying $name location '$toolLocation'." - FileUtils.validateDirectoryIsNotEmpty(script, toolLocation) - script.echo "Verification success. $name location '$toolLocation' exists." - } - } - - def verifyToolExecutable(script, configuration) { - - def home = getToolLocation(script, configuration, false) - def tool = getTool(script, configuration, false) - if (home) { - script.echo "Verifying $name '$tool'." - FileUtils.validateFile(script, tool) - script.echo "Verification success. $name '$tool' exists." - } - } - - def verifyVersion(script, configuration) { - - def executable = getToolExecutable(script, configuration, false) - def versionDesc = VersionUtils.getVersionDesc(script, name, executable, versionOption) - if (singleVersion) VersionUtils.verifyVersion(script, name, versionDesc, singleVersion) - if (multipleVersions) VersionUtils.verifyVersion(script, name, versionDesc, multipleVersions) - } - - def getMessage() { - def configOptions = "Please, configure $name home. $name home can be set " - if (environmentKey) configOptions += "using the environment variable '$environmentKey', or " - if (stepConfigurationKey) configOptions += "using the configuration key '$stepConfigurationKey', or " - configOptions += "on PATH." - return configOptions - } - - def isOnPath(script, configuration) { - - def exitStatus - try { - exitStatus = script.sh returnStatus: true, script: """set +x - which $executableName""" - } catch(AbortException e) { - throw new AbortException("The verification of $name failed, while checking if it was on PATH. Reason: $e.message.") - } - return exitStatus == 0 - } -} diff --git a/test/groovy/CommonStepsTest.groovy b/test/groovy/CommonStepsTest.groovy index aca11b1fb..f8dde2060 100644 --- a/test/groovy/CommonStepsTest.groovy +++ b/test/groovy/CommonStepsTest.groovy @@ -51,8 +51,7 @@ public class CommonStepsTest extends BasePiperTest{ 'pipelineExecute', 'piperPipeline', 'prepareDefaultValues', - 'setupCommonPipelineEnvironment', - 'toolValidate', + 'setupCommonPipelineEnvironment' ] List steps = getSteps().stream() @@ -103,7 +102,6 @@ public class CommonStepsTest extends BasePiperTest{ } private static fieldRelatedWhitelist = [ - 'toolValidate', // step is intended to be configured by other steps 'durationMeasure', // only expects parameters via signature 'prepareDefaultValues', // special step (infrastructure) 'piperPipeline', // special step (infrastructure) diff --git a/test/groovy/FioriOnCloudPlatformPipelineTest.groovy b/test/groovy/FioriOnCloudPlatformPipelineTest.groovy index 46eeb95b3..db8094544 100644 --- a/test/groovy/FioriOnCloudPlatformPipelineTest.groovy +++ b/test/groovy/FioriOnCloudPlatformPipelineTest.groovy @@ -72,14 +72,6 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest { // needed since we have dockerExecute inside mtaBuild JenkinsUtils.metaClass.static.isPluginActive = {def s -> false} - // - // Things we validate: - shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*echo \\$JAVA_HOME.*', '/opt/sap/java') - shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*echo \\$MTA_JAR_LOCATION.*', '/opt/sap') - shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*echo \\$NEO_HOME.*', '/opt/sap/neo') - shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, ".*bin/java -version.*", '1.8.0') // the java version - shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, ".*bin/java -jar .*mta.jar", '1.36.0') // the mta version - // // there is a check for the mta.yaml file and for the deployable test.mtar file helper.registerAllowedMethod('fileExists', [String],{ @@ -132,7 +124,7 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest { // // the mta build call: assertThat(shellRule.shell, hasItem( - allOf( containsString('java -jar /opt/sap/mta.jar'), + allOf( containsString('java -jar /opt/sap/mta/lib/mta.jar'), // default mtaJarLocation containsString('--mtar test.mtar'), containsString('--build-target=NEO'), containsString('build')))) diff --git a/test/groovy/MtaBuildTest.groovy b/test/groovy/MtaBuildTest.groovy index d5de756cc..b15f6698a 100644 --- a/test/groovy/MtaBuildTest.groovy +++ b/test/groovy/MtaBuildTest.groovy @@ -17,9 +17,6 @@ import util.Rules public class MtaBuildTest extends BasePiperTest { - def toolMtaValidateCalled = false - def toolJavaValidateCalled = false - private ExpectedException thrown = new ExpectedException() private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this) @@ -89,9 +86,6 @@ public class MtaBuildTest extends BasePiperTest { stepRule.step.mtaBuild(script: nullScript, mtaJarLocation: '/mylocation/mta/mta.jar', buildTarget: 'NEO') assert shellRule.shell.find { c -> c.contains('-jar /mylocation/mta/mta.jar --mtar')} - - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/mylocation/mta/mta.jar' retrieved from configuration.") - assert loggingRule.log.contains("Using SAP Multitarget Application Archive Builder '/mylocation/mta/mta.jar'.") } @@ -130,19 +124,6 @@ public class MtaBuildTest extends BasePiperTest { } - @Test - void mtaJarLocationFromEnvironmentTest() { - - shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*\\$MTA_JAR_LOCATION.*', '/env/mta/mta.jar') - - stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO') - - assert shellRule.shell.find { c -> c.contains("-jar /env/mta/mta.jar --mtar")} - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/env/mta/mta.jar' retrieved from environment.") - assert loggingRule.log.contains("Using SAP Multitarget Application Archive Builder '/env/mta/mta.jar'.") - } - - @Test void mtaJarLocationFromCustomStepConfigurationTest() { @@ -151,9 +132,7 @@ public class MtaBuildTest extends BasePiperTest { stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO') - assert shellRule.shell.find(){ c -> c.contains("-jar /config/mta/mta.jar --mtar")} - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/config/mta/mta.jar' retrieved from configuration.") - assert loggingRule.log.contains("Using SAP Multitarget Application Archive Builder '/config/mta/mta.jar'.") + assert shellRule.shell.find(){ c -> c.contains('java -jar /config/mta/mta.jar --mtar')} } @@ -163,9 +142,7 @@ public class MtaBuildTest extends BasePiperTest { stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO') - assert shellRule.shell.find(){ c -> c.contains("-jar /opt/sap/mta/lib/mta.jar --mtar")} - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/opt/sap/mta/lib/mta.jar' retrieved from configuration.") - assert loggingRule.log.contains("Using SAP Multitarget Application Archive Builder '/opt/sap/mta/lib/mta.jar'.") + assert shellRule.shell.find(){ c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar')} } diff --git a/test/groovy/NeoDeployTest.groovy b/test/groovy/NeoDeployTest.groovy index 704b266eb..e25279735 100644 --- a/test/groovy/NeoDeployTest.groovy +++ b/test/groovy/NeoDeployTest.groovy @@ -29,8 +29,6 @@ import util.Rules class NeoDeployTest extends BasePiperTest { - def toolJavaValidateCalled = false - private ExpectedException thrown = new ExpectedException().none() private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this) diff --git a/test/groovy/ToolValidateTest.groovy b/test/groovy/ToolValidateTest.groovy deleted file mode 100644 index a016053a0..000000000 --- a/test/groovy/ToolValidateTest.groovy +++ /dev/null @@ -1,270 +0,0 @@ -import org.apache.commons.exec.* -import hudson.AbortException - -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException -import org.junit.rules.RuleChain - -import util.BasePiperTest -import util.JenkinsLoggingRule -import util.JenkinsReadYamlRule -import util.JenkinsStepRule -import util.Rules - -class ToolValidateTest extends BasePiperTest { - - private ExpectedException thrown = new ExpectedException().none() - private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) - private JenkinsStepRule stepRule = new JenkinsStepRule(this) - - @Rule - public RuleChain ruleChain = Rules - .getCommonRules(this) - .around(new JenkinsReadYamlRule(this)) - .around(thrown) - .around(loggingRule) - .around(stepRule) - - def home = 'home' - - @Test - void nullHomeTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'home' can not be null or empty.") - - stepRule.step.toolValidate(tool: 'java') - } - - @Test - void emptyHomeTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'home' can not be null or empty.") - - stepRule.step.toolValidate(tool: 'java', home: '') - } - - @Test - void nullToolTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> return 0 }) - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'tool' can not be null or empty.") - - stepRule.step.toolValidate(tool: null, home: home) - } - - @Test - void emptyToolTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> return 0 }) - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'tool' can not be null or empty.") - - stepRule.step.toolValidate(tool: '', home: home) - } - - @Test - void invalidToolTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> return 0 }) - - thrown.expect(AbortException) - thrown.expectMessage("The tool 'test' is not supported.") - - stepRule.step.toolValidate(tool: 'test', home: home) - } - - @Test - void unableToValidateJavaTest() { - - thrown.expect(AbortException) - thrown.expectMessage('The verification of Java failed.') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - - stepRule.step.toolValidate(tool: 'java', home: home) - } - - @Test - void unableToValidateMtaTest() { - - thrown.expect(AbortException) - thrown.expectMessage('The verification of SAP Multitarget Application Archive Builder failed.') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - - stepRule.step.toolValidate(tool: 'mta', home: home) - } - - @Test - void unableToValidateNeoTest() { - - thrown.expect(AbortException) - thrown.expectMessage('The verification of SAP Cloud Platform Console Client failed.') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - - stepRule.step.toolValidate(tool: 'neo', home: home) - } - - @Test - void unableToValidateCmTest() { - - thrown.expect(AbortException) - thrown.expectMessage('The verification of Change Management Command Line Interface failed.') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) }) - - stepRule.step.toolValidate(tool: 'cm', home: home) - } - - @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) }) - - stepRule.step.toolValidate(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) }) - - stepRule.step.toolValidate(tool: 'mta', 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') - - stepRule.step.toolValidate(tool: 'cm', home: home) - } - - @Test - void validateJavaTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - stepRule.step.toolValidate(tool: 'java', home: home) - - assert loggingRule.log.contains('Verifying Java version 1.8.0 or compatible version.') - assert loggingRule.log.contains('Java version 1.8.0 is installed.') - } - - @Test - void validateMtaTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - stepRule.step.toolValidate(tool: 'mta', home: home) - - assert loggingRule.log.contains('Verifying SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.') - assert loggingRule.log.contains('SAP Multitarget Application Archive Builder version 1.0.6 is installed.') - } - - @Test - void validateNeoTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - stepRule.step.toolValidate(tool: 'neo', home: home) - } - - @Test - void validateCmTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - stepRule.step.toolValidate(tool: 'cm', home: home) - - assert loggingRule.log.contains('Verifying Change Management Command Line Interface version 0.0.1 or compatible version.') - assert loggingRule.log.contains('Change Management Command Line Interface version 0.0.1 is installed.') - } - - - private getToolHome(Map m) { - - if(m.script.contains('JAVA_HOME')) { - return '/env/java' - } else if(m.script.contains('MTA_JAR_LOCATION')) { - return '/env/mta/mta.jar' - } else if(m.script.contains('NEO_HOME')) { - return '/env/neo' - } else if(m.script.contains('CM_CLI_HOME')) { - return '/env/cmclient' - } else { - return 0 - } - } - - private getNoVersion(Map m) { - - if(m.script.contains('java -version')) { - throw new AbortException('script returned exit code 127') - } else if(m.script.contains('mta.jar -v')) { - throw new AbortException('script returned exit code 127') - } else if(m.script.contains('neo.sh version')) { - throw new AbortException('script returned exit code 127') - } else if(m.script.contains('cmclient -v')) { - throw new AbortException('script returned exit code 127') - } else { - return getToolHome(m) - } - } - - 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) - OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)''' - } else if(m.script.contains('mta.jar -v')) { - return '1.0.6' - } else if(m.script.contains('neo.sh version')) { - return '''SAP Cloud Platform Console Client - SDK version : 3.39.10 - Runtime : neo-java-web''' - } else if(m.script.contains('cmclient -v')) { - return '0.0.1-beta-2 : fc9729964a6acf5c1cad9c6f9cd6469727625a8e' - } else { - return getToolHome(m) - } - } - - 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) - OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)''' - } else if(m.script.contains('mta.jar -v')) { - return '1.0.5' - } else if(m.script.contains('neo.sh version')) { - return '''SAP Cloud Platform Console Client - SDK version : 1.126.51 - Runtime : neo-java-web''' - } else if(m.script.contains('cmclient -v')) { - return '0.0.0-beta-1 : fc9729964a6acf5c1cad9c6f9cd6469727625a8e' - } else { - return getToolHome(m) - } - } -} diff --git a/test/groovy/com/sap/piper/EnvironmentUtilsTest.groovy b/test/groovy/com/sap/piper/EnvironmentUtilsTest.groovy deleted file mode 100644 index 5adcb4757..000000000 --- a/test/groovy/com/sap/piper/EnvironmentUtilsTest.groovy +++ /dev/null @@ -1,75 +0,0 @@ -package com.sap.piper - -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException -import org.junit.rules.RuleChain -import util.BasePiperTest -import util.JenkinsStepRule -import util.Rules - -import hudson.AbortException - - -class EnvironmentUtilsTest extends BasePiperTest { - - private ExpectedException thrown = new ExpectedException() - - @Rule - public RuleChain rules = Rules - .getCommonRules(this) - .around(thrown) - - @Test - void isEnvironmentVariableFailedTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> throw new AbortException('') }) - - thrown.expect(AbortException) - thrown.expectMessage("There was an error requesting the environment variable 'JAVA_HOME'.") - - EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME') - } - - @Test - void isNotEnvironmentVariableTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> return '' }) - - def isEnvVar = EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME') - - assert isEnvVar == false - } - - @Test - void isEnvironmentVariableTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> return '/env/java' }) - - def isEnvVar = EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME') - - assert isEnvVar == true - } - - @Test - void getEnvironmentVariableFailedTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> throw new AbortException('') }) - - thrown.expect(AbortException) - thrown.expectMessage("There was an error requesting the environment variable 'JAVA_HOME'.") - - EnvironmentUtils.getEnvironmentVariable(nullScript, 'JAVA_HOME') - } - - @Test - void getEnvironmentVariableTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> return '/env/java' }) - - def envVar = EnvironmentUtils.getEnvironmentVariable(nullScript, 'JAVA_HOME') - - assert envVar == '/env/java' - } -} diff --git a/test/groovy/com/sap/piper/FileUtilsTest.groovy b/test/groovy/com/sap/piper/FileUtilsTest.groovy deleted file mode 100644 index 45465ef26..000000000 --- a/test/groovy/com/sap/piper/FileUtilsTest.groovy +++ /dev/null @@ -1,179 +0,0 @@ -package com.sap.piper - -import org.junit.BeforeClass -import org.junit.ClassRule -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException -import org.junit.rules.TemporaryFolder -import org.junit.rules.RuleChain -import util.BasePiperTest -import util.Rules - -import hudson.AbortException - - -class FileUtilsTest extends BasePiperTest { - - @ClassRule - public static TemporaryFolder tmp = new TemporaryFolder() - - private ExpectedException thrown = new ExpectedException() - - @Rule - public RuleChain rules = Rules.getCommonRules(this) - .around(thrown) - - private static emptyDir - private static notEmptyDir - private static file - - @BeforeClass - static void createTestFiles() { - - emptyDir = tmp.newFolder('emptyDir').getAbsolutePath() - notEmptyDir = tmp.newFolder('notEmptyDir').getAbsolutePath() - file = tmp.newFile('notEmptyDir/file.txt').getAbsolutePath() - } - - @Test - void validateDirectory_nullParameterTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'dir' can not be null or empty.") - - FileUtils.validateDirectory(nullScript, null) - } - - @Test - void validateDirectory_emptyParameterTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'dir' can not be null or empty.") - - FileUtils.validateDirectory(nullScript, '') - } - - @Test - void validateDirectory_directoryDoestNotExistTest() { - - def dir = new File("$emptyDir", 'test').getAbsolutePath() - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, dir) }) - - thrown.expect(AbortException) - thrown.expectMessage("Validation failed. '$dir' does not exist.") - - FileUtils.validateDirectory(nullScript, dir) - } - - @Test - void validateDirectory_isNotDirectoryTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, file) }) - - thrown.expect(AbortException) - thrown.expectMessage("Validation failed. '$file' is not a directory.") - - FileUtils.validateDirectory(nullScript, file) - } - - @Test - void validateDirectoryTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, notEmptyDir) }) - - FileUtils.validateDirectory(nullScript, notEmptyDir) - } - - @Test - void validateDirectoryIsNotEmpty_directoryIsEmptyTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, emptyDir) }) - - thrown.expect(AbortException) - thrown.expectMessage("Validation failed. '$emptyDir' is empty.") - - FileUtils.validateDirectoryIsNotEmpty(nullScript, emptyDir) - } - - @Test - void validateDirectoryIsNotEmptyTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, notEmptyDir) }) - - FileUtils.validateDirectoryIsNotEmpty(nullScript, notEmptyDir) - } - - @Test - void validateFile_NoFilePathTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'filePath' can not be null or empty.") - - FileUtils.validateFile(nullScript, null) - } - - @Test - void validateFile_emptyParameterTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'filePath' can not be null or empty.") - - FileUtils.validateFile(nullScript, '') - } - - @Test - void validateFile_fileDoesNotExistTest() { - - def path = new File("$emptyDir", 'test').getAbsolutePath() - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, path) }) - - thrown.expect(AbortException) - thrown.expectMessage("Validation failed. '$path' does not exist.") - - FileUtils.validateFile(nullScript, path) - } - - @Test - void validateFileTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, file) }) - - FileUtils.validateFile(nullScript, file) - } - - - private script(parameters, path) { - if(parameters.script.contains('exists')) return directoryOrFileExists(path) - else if(parameters.script.contains('directory')) return isDirectory(path) - else if(parameters.script.contains('empty')) return isDirectoryEmpty(path) - else if(parameters.script.contains('file')) return isFile(path) - } - - private directoryOrFileExists(dirOrFile) { - def file = new File(dirOrFile) - if (file.exists()) return 0 - else return 1 - } - - private isDirectory(dir) { - def file = new File(dir) - if (file.isDirectory()) return 0 - else return 1 - } - - private isDirectoryEmpty(dir) { - def file = new File(dir) - if (file.list().size() == 0) return 1 - return 0 - } - - private isFile(filePath) { - def file = new File(filePath) - if (file.isFile()) return 0 - return 1 - } -} diff --git a/test/groovy/com/sap/piper/VersionTest.groovy b/test/groovy/com/sap/piper/VersionTest.groovy deleted file mode 100644 index dc03f9042..000000000 --- a/test/groovy/com/sap/piper/VersionTest.groovy +++ /dev/null @@ -1,194 +0,0 @@ -package com.sap.piper - -import org.junit.Rule -import org.junit.Before -import org.junit.Test -import org.junit.rules.ExpectedException - -import hudson.AbortException - -import com.sap.piper.Version - - -class VersionTest { - - - @Rule - public ExpectedException thrown = new ExpectedException().none() - - - @Test - void illegalMajorVersionTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'major' can not have a value less than 0.") - - Version version = new Version(-1,0) - } - - @Test - void illegalMinorVersionTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'minor' can not have a value less than 0.") - - Version version = new Version(0,-1) - } - - @Test - void nullMajorVersionTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'major' can not have a value less than 0.") - - Version version = new Version(null,0) - } - - @Test - void nullMinorVersionTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'minor' can not have a value less than 0.") - - Version version = new Version(0, null) - } - - @Test - void nullVersionTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'text' can not be null or empty.") - - Version version = new Version(null) - } - - @Test - void emptyVersionTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'text' can not be null or empty.") - - Version version = new Version('') - } - - @Test - void unexpectedFormatTest() { - - thrown.expect(AbortException) - thrown.expectMessage("The version '0-0.1' has an unexpected format. The expected format is .") - - Version version = new Version('0-0.1') - } - - @Test - void isEqualNullTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'version' can not be null.") - - Version version = new Version(0,0,1) - version.equals(null) - } - - @Test - void isEqualPatchTest() { - - Version version1 = new Version(0,0,1) - Version version2 = new Version('0.0.1') - - assert version1.equals(version2) - } - - @Test - void isEqualMinorTest() { - - Version version1 = new Version(0,1,0) - Version version2 = new Version('0.1.0') - - assert version1.equals(version2) - } - - @Test - void isEqualMajorTest() { - - Version version1 = new Version(1,0,0) - Version version2 = new Version('1.0.0') - - assert version1.equals(version2) - } - - @Test - void isHigherNullTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'version' can not be null.") - - Version version = new Version(0,0,1) - version.isHigher(null) - } - - @Test - void isHigherPatchTest() { - - Version version1 = new Version(0,0,1) - Version version2 = new Version('0.0.2') - - assert version2.isHigher(version1) - } - - @Test - void isHigherMinorTest() { - - Version version1 = new Version(0,1,0) - Version version2 = new Version('0.2.0') - - assert version2.isHigher(version1) - } - - @Test - void isHigherMajorTest() { - - Version version1 = new Version(1,0,0) - Version version2 = new Version('2.0.0') - - assert version2.isHigher(version1) - } - - @Test - void isCompatibleVersionNullTest() { - - thrown.expect(IllegalArgumentException) - thrown.expectMessage("The parameter 'version' can not be null.") - - Version version = new Version(0,0,1) - version.isCompatibleVersion(null) - } - - @Test - void isCompatibleVersionPatchTest() { - - Version version1 = new Version(0,0,1) - Version version2 = new Version('0.0.2') - - assert version2.isCompatibleVersion(version1) - } - - @Test - void isCompatibleVersionMinorTest() { - - Version version1 = new Version(0,1,0) - Version version2 = new Version('0.2.0') - - assert version2.isCompatibleVersion(version1) - } - - @Test - void isIncompatibleVersionTest() { - - Version version1 = new Version(1,0,0) - Version version2 = new Version('2.0.0') - - assert !version2.isCompatibleVersion(version1) - } -} - diff --git a/test/groovy/com/sap/piper/VersionUtilsTest.groovy b/test/groovy/com/sap/piper/VersionUtilsTest.groovy deleted file mode 100644 index 118b7d8d2..000000000 --- a/test/groovy/com/sap/piper/VersionUtilsTest.groovy +++ /dev/null @@ -1,83 +0,0 @@ -package com.sap.piper - -import hudson.AbortException -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException -import org.junit.rules.RuleChain -import util.BasePiperTest -import util.JenkinsShellCallRule -import util.Rules - -import static org.junit.Assert.assertEquals -import static org.hamcrest.Matchers.equalTo -import static org.junit.Assert.assertTrue -import static org.junit.Assert.assertFalse -import static org.hamcrest.Matchers.is -import static org.hamcrest.Matchers.notNullValue -import static org.junit.Assert.assertNotNull -import static org.junit.Assert.assertNull -import static org.junit.Assert.assertThat - -class VersionUtilsTest extends BasePiperTest { - - ExpectedException thrown = ExpectedException.none() - - @Rule - public RuleChain ruleChain = Rules.getCommonRules(this).around(thrown) - - @Before - void init() throws Exception { - } - - @Test - void test_if_getVersionDesc_returns_desc() { - helper.registerAllowedMethod('sh', [Map], { Map m -> return 'SAP Cloud Platform Console Client\n\n\nSDK version : 2.129.5.1\nRuntime : neo-javaee6-wp\n'}) - - assertEquals('SAP Cloud Platform Console Client\n\n\nSDK version : 2.129.5.1\nRuntime : neo-javaee6-wp\n',VersionUtils.getVersionDesc(nullScript, "test", "test.sh", "version")) - } - - @Test - void test_if_getVersion_returns_version() { - helper.registerAllowedMethod('sh', [Map], { Map m -> return 'SAP Cloud Platform Console Client\n\n\nSDK version : 2.129.5.1\nRuntime : neo-javaee6-wp\n'}) - - assertEquals(new Version('2.129.5.1'),VersionUtils.getVersion(nullScript, "test", "test.sh", "version")) - } - - @Test - void test_if_verifyVersion_succeeds_compatible() { - helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key' }) - VersionUtils.verifyVersion(nullScript, "test", "test.sh", '1.0.0', "version") - } - - @Test - void test_if_verifyVersion_fails_incompatible() { - helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key' }) - - thrown.expect(AbortException) - thrown.expectMessage("The installed version of test is 1.0.0. Please install version 1.0.1 or a compatible version.") - - VersionUtils.verifyVersion(nullScript, "test", "test.sh", '1.0.1', "version") - } - - @Test - void test_if_verifyVersion_map_succeeds_compatible() { - Map versionMap = ['key1': '1.0.0', 'key2': '2.0.0', 'key3': '3.0.0'] - helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key1' }) - VersionUtils.verifyVersion(nullScript, "test", "test.sh", versionMap, "version") - } - - @Test - void test_if_verifyVersion_map_fails_incompatible() { - Map versionMap = ['key1': '1.0.1', 'key2': '2.0.1', 'key3': '3.0.1'] - helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key1' }) - - thrown.expect(AbortException) - thrown.expectMessage("The installed version of test is 1.0.0. Please install version 1.0.1 or a compatible version.") - - VersionUtils.verifyVersion(nullScript, "test", "test.sh", versionMap, "version") - } - - -} diff --git a/test/groovy/com/sap/piper/tools/JavaArchiveDescriptorTest.groovy b/test/groovy/com/sap/piper/tools/JavaArchiveDescriptorTest.groovy deleted file mode 100644 index 7dc8dd4f8..000000000 --- a/test/groovy/com/sap/piper/tools/JavaArchiveDescriptorTest.groovy +++ /dev/null @@ -1,268 +0,0 @@ -package com.sap.piper.tools - -import org.junit.Ignore -import org.junit.BeforeClass -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException -import org.junit.rules.RuleChain -import util.BasePiperTest -import util.JenkinsLoggingRule -import util.Rules - -import hudson.AbortException - -class JavaArchiveDescriptorTest extends BasePiperTest { - - private ExpectedException thrown = new ExpectedException() - private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) - - @Rule - public RuleChain rules = Rules.getCommonRules(this) - .around(thrown) - .around(loggingRule) - - private static javaArchive - private static configuration - - private script - - - @BeforeClass - static void init() { - - def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1') - javaArchive = new JavaArchiveDescriptor('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '1.0.6', '-v', java) - } - - @Before - void setup() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getNoEnvVars(m) }) - helper.registerAllowedMethod('error', [String], { s -> throw new hudson.AbortException(s) }) - - script = loadScript('mtaBuild.groovy').mtaBuild - - configuration = [:] //no default configuration - } - - @Test - void getJavaArchiveFileFromEnvironmentTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getEnvVars(m) }) - - def javaArchiveFile = javaArchive.getFile(script, configuration) - - assert javaArchiveFile == '/env/mta/mta_archive_builder-1.1.0.jar' - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/env/mta/mta_archive_builder-1.1.0.jar' retrieved from environment.") - } - - @Test - void getJavaArchiveFileFromConfigurationTest() { - - configuration = [mtaJarLocation: '/config/mta/mta_archive_builder-1.1.0.jar'] - - def javaArchiveFile = javaArchive.getFile(script, configuration) - - assert javaArchiveFile == '/config/mta/mta_archive_builder-1.1.0.jar' - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/config/mta/mta_archive_builder-1.1.0.jar' retrieved from configuration.") - } - - // Compatibility tests - @Test - void getJavaArchiveFileFromEnvironment_CompatibilityTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getEnvVarsWithCompatibility(m) }) - - def javaArchiveFile = javaArchive.getFile(script, configuration) - - assert javaArchiveFile == '/env/mta/mta.jar' - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/env/mta' retrieved from environment.") - } - - @Test - void getJavaArchiveFileFromConfiguration_CompatibilityTest() { - - configuration = [mtaJarLocation: '/config/mta'] - - def javaArchiveFile = javaArchive.getFile(script, configuration) - - assert javaArchiveFile == '/config/mta/mta.jar' - assert loggingRule.log.contains("SAP Multitarget Application Archive Builder file '/config/mta' retrieved from configuration.") - } - // - - @Test - void getJavaArchiveFileFailedTest() { - - thrown.expect(AbortException) - thrown.expectMessage("Please, configure SAP Multitarget Application Archive Builder. SAP Multitarget Application Archive Builder can be set using the environment variable 'MTA_JAR_LOCATION', or " + - "using the configuration key 'mtaJarLocation'.") - - javaArchive.getFile(script, configuration) - } - - @Ignore('while compatibility code is not removed') - void getJavaArchiveFileFromEnvironment_UnexpectedFormatTest() { - - thrown.expect(AbortException) - thrown.expectMessage("The value '/env/mta/mta_archive_builder-1.1.0.jarr' of the environment variable 'MTA_JAR_LOCATION' has an unexpected format.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getUnexpectedFormatEnvVars(m) }) - - javaArchive.getFile(script, configuration) - } - - @Ignore('while compatibility code is not removed') - void getJavaArchiveFileFromConfiguration_UnexpectedFormatTest() { - - thrown.expect(AbortException) - thrown.expectMessage("The value '/config/mta/mta_archive_builder-1.1.0.jarr' of the configuration key 'mtaJarLocation' has an unexpected format.") - - configuration = [mtaJarLocation: '/config/mta/mta_archive_builder-1.1.0.jarr'] - - javaArchive.getFile(script, configuration) - } - - @Test - void getJavaArchiveCallTest() { - - configuration = [mtaJarLocation: '/config/mta/mta_archive_builder-1.1.0.jar'] - - def javaArchiveCall = javaArchive.getCall(script, configuration) - - assert javaArchiveCall == 'java -jar /config/mta/mta_archive_builder-1.1.0.jar' - assert loggingRule.log.contains("Using SAP Multitarget Application Archive Builder '/config/mta/mta_archive_builder-1.1.0.jar'.") - } - - @Test - void verifyJavaArchiveFileTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getEnvVars(m) }) - - javaArchive.verifyFile(script, configuration) - - assert loggingRule.log.contains("Verifying SAP Multitarget Application Archive Builder '/env/mta/mta_archive_builder-1.1.0.jar'.") - assert loggingRule.log.contains("Verification success. SAP Multitarget Application Archive Builder '/env/mta/mta_archive_builder-1.1.0.jar' exists.") - } - - @Test - void verifyJavaArchiveVersionTest() { - - configuration = [mtaJarLocation: 'mta_archive_builder-1.1.0.jar'] - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - javaArchive.verifyVersion(script, configuration) - - assert loggingRule.log.contains("Verifying SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.") - assert loggingRule.log.contains("Verification success. SAP Multitarget Application Archive Builder version 1.0.6 is installed.") - } - - @Test - void verifyJavaArchiveVersion_FailedTest() { - - configuration = [mtaJarLocation: 'mta_archive_builder-1.1.0.jar'] - - thrown.expect(AbortException) - thrown.expectMessage("The verification of SAP Multitarget Application Archive Builder failed. Please check 'java -jar mta_archive_builder-1.1.0.jar'. script returned exit code 127.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionFailed(m) }) - - javaArchive.verifyVersion(script, configuration) - } - - @Test - void verifyJavaArchiveVersion_IncompatibleVersionTest() { - - configuration = [mtaJarLocation: '/config/mta/mta_archive_builder-1.1.0.jar'] - - thrown.expect(AbortException) - thrown.expectMessage("The installed version of SAP Multitarget Application Archive Builder is 1.0.5. Please install version 1.0.6 or a compatible version.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - - javaArchive.verifyVersion(script, configuration) - } - - - private getEnvVars(Map m) { - - if(m.script.contains('JAVA_HOME')) { - return '/env/java' - } else if(m.script.contains('MTA_JAR_LOCATION')) { - return '/env/mta/mta_archive_builder-1.1.0.jar' - } else { - return 0 - } - } - - private getEnvVarsWithCompatibility(Map m) { - - if(m.script.contains('JAVA_HOME')) { - return '/env/java' - } else if(m.script.contains('MTA_JAR_LOCATION')) { - return '/env/mta' - } else { - return 0 - } - } - - /* - private getUnexpectedFormatEnvVars(Map m) { - - if(m.script.contains('JAVA_HOME')) { - return '/env/java' - } else if(m.script.contains('MTA_JAR_LOCATION')) { - return '/env/mta/mta_archive_builder-1.1.0.jarr' - } else { - return 0 - } - } - */ - - private getNoEnvVars(Map m) { - - if(m.script.contains('JAVA_HOME')) { - return '' - } else if(m.script.contains('MTA_JAR_LOCATION')) { - return '' - } else if(m.script.contains('which java')) { - return 0 - } else { - return 0 - } - } - - 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) - OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)''' - } else if(m.script.contains('mta_archive_builder-1.1.0.jar -v')) { - return '1.0.6' - } else { - return getNoEnvVars(m) - } - } - - private getVersionFailed(Map m) { - - if(m.script.contains('java -version') || m.script.contains('mta_archive_builder-1.1.0.jar -v')) { - throw new AbortException('script returned exit code 127') - } else { - return getNoEnvVars(m) - } - } - - private getIncompatibleVersion(Map m) { - - if(m.script.contains('java -version') || m.script.contains('mta_archive_builder-1.1.0.jar -v')) { - return '1.0.5' - } else { - return getNoEnvVars(m) - } - } -} diff --git a/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy b/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy deleted file mode 100644 index 9e5632984..000000000 --- a/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy +++ /dev/null @@ -1,258 +0,0 @@ -package com.sap.piper.tools - -import org.junit.BeforeClass -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.rules.ExpectedException -import org.junit.rules.RuleChain -import util.BasePiperTest -import util.JenkinsLoggingRule -import util.Rules - -import hudson.AbortException - -class ToolDescriptorTest extends BasePiperTest { - - private ExpectedException thrown = new ExpectedException() - private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) - - @Rule - public RuleChain rules = Rules.getCommonRules(this) - .around(thrown) - .around(loggingRule) - - private static tool - private static configuration - - private script - - - @BeforeClass - static void init() { - - tool = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', '3.39.10', 'version') - } - - @Before - void setup() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getNoEnvVars(m) }) - - script = loadScript('neoDeploy.groovy').neoDeploy - - configuration = [:] - } - - @Test - void getToolHomeFromEnvironmentTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getEnvVars(m) }) - - def toolHome = tool.getToolLocation(script, configuration) - - assert toolHome == '/env/neo' - assert loggingRule.log.contains("SAP Cloud Platform Console Client home '/env/neo' retrieved from environment.") - } - - @Test - void getToolHomeFromConfigurationTest() { - - configuration = [neoHome: '/config/neo'] - - def toolHome = tool.getToolLocation(script, configuration) - - assert toolHome == '/config/neo' - assert loggingRule.log.contains("SAP Cloud Platform Console Client home '/config/neo' retrieved from configuration.") - } - - @Test - void getToolHomeFromCurrentWorkingDirectoryTest() { - - def toolHome = tool.getToolLocation(script, configuration) - - assert toolHome == '' - assert loggingRule.log.contains("SAP Cloud Platform Console Client is on PATH.") - } - - @Test - void getToolTest() { - - configuration = [neoHome: '/config/neo'] - - def toolExecutable = tool.getTool(script, configuration) - - assert toolExecutable == '/config/neo/tools/neo.sh' - } - - @Test - void getToolExecutableTest() { - - configuration = [neoHome: '/config/neo'] - - def toolExecutable = tool.getToolExecutable(script, configuration) - - assert toolExecutable == '/config/neo/tools/neo.sh' - assert loggingRule.log.contains("Using SAP Cloud Platform Console Client '/config/neo/tools/neo.sh'.") - } - - @Test - void verifyToolHomeTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getEnvVars(m) }) - - tool.verifyToolLocation(script, configuration) - - assert loggingRule.log.contains("Verifying SAP Cloud Platform Console Client location '/env/neo'.") - assert loggingRule.log.contains("Verification success. SAP Cloud Platform Console Client location '/env/neo' exists.") - } - - @Test - void verifyToolExecutableTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getEnvVars(m) }) - - tool.verifyToolExecutable(script, configuration) - - assert loggingRule.log.contains("Verifying SAP Cloud Platform Console Client '/env/neo/tools/neo.sh'.") - assert loggingRule.log.contains("Verification success. SAP Cloud Platform Console Client '/env/neo/tools/neo.sh' exists.") - } - - @Test - void verifyToolVersionTest() { - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - tool.verifyVersion(script, configuration) - - assert loggingRule.log.contains("Verifying SAP Cloud Platform Console Client version 3.39.10 or compatible version.") - assert loggingRule.log.contains("Verification success. SAP Cloud Platform Console Client version 3.39.10 is installed.") - } - - @Test - void verifyToolVersion_FailedTest() { - - thrown.expect(AbortException) - thrown.expectMessage("The verification of SAP Cloud Platform Console Client failed. Please check 'neo.sh'. script returned exit code 127.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionFailed(m) }) - - tool.verifyVersion(script, configuration) - } - - @Test - void verifyToolVersion_IncompatibleVersionTest() { - - thrown.expect(AbortException) - thrown.expectMessage("The installed version of SAP Cloud Platform Console Client is 1.0.5. Please install version 3.39.10 or a compatible version.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - - tool.verifyVersion(script, configuration) - } - - @Test - void verifyToolVersion_WithMultipleVersionsTest() { - - def neoVersions = ['neo-java-web': '3.39.10', 'neo-javaee6-wp': '2.132.6', 'neo-javaee7-wp': '1.21.13'] - def tool = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', neoVersions, 'version') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - tool.verifyVersion(script, configuration) - - assert loggingRule.log.contains("Verifying SAP Cloud Platform Console Client version 3.39.10 or compatible version.") - assert loggingRule.log.contains("Verification success. SAP Cloud Platform Console Client version 3.39.10 is installed.") - } - - @Test - void verifyToolVersion_WithMultipleVersions_FailedTest() { - - def neoVersions = ['neo-java-web': '3.39.10', 'neo-javaee6-wp': '2.132.6', 'neo-javaee7-wp': '1.21.13'] - def tool = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', neoVersions, 'version') - - thrown.expect(AbortException) - thrown.expectMessage("The verification of SAP Cloud Platform Console Client failed. Please check 'neo.sh'. script returned exit code 127.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionFailed(m) }) - - tool.verifyVersion(script, configuration) - } - - @Test - void verifyToolVersion_WithMultipleVersions_IncompatibleVersionTest() { - - def neoVersions = ['neo-java-web': '3.39.10', 'neo-javaee6-wp': '2.132.6', 'neo-javaee7-wp': '1.21.13'] - def tool = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', neoVersions, 'version') - - thrown.expect(AbortException) - thrown.expectMessage("The installed version of SAP Cloud Platform Console Client is 1.0.5. Please install version 3.39.10 or a compatible version.") - - helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - - tool.verifyVersion(script, configuration) - } - - @Test - void verifyToolVersion_without_version_check() { - - def tool = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) - - tool.verifyVersion(script, configuration) - } - - - - private getEnvVars(Map m) { - - if(m.script.contains('NEO_HOME')) { - return '/env/neo' - } else { - return 0 - } - } - - private getNoEnvVars(Map m) { - - if(m.script.contains('NEO_HOME')) { - return '' - } else if(m.script.contains('which neo')) { - return 0 - } else { - return 0 - } - } - - private getVersion(Map m) { - - if(m.script.contains('neo.sh version')) { - return '''SAP Cloud Platform Console Client - SDK version : 3.39.10 - Runtime : neo-java-web''' - } else { - return getNoEnvVars(m) - } - } - - private getVersionFailed(Map m) { - - if(m.script.contains('neo.sh version')) { - throw new AbortException('script returned exit code 127') - } else { - return getNoEnvVars(m) - } - } - - private getIncompatibleVersion(Map m) { - - if(m.script.contains('neo.sh version')) { - return '''SAP Cloud Platform Console Client - SDK version : 1.0.5 - Runtime : neo-java-web''' - } else { - return getNoEnvVars(m) - } - } -} diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index 89497de06..fd4a4d86c 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -3,8 +3,6 @@ import static com.sap.piper.Prerequisites.checkScript import com.sap.piper.ConfigurationHelper import com.sap.piper.MtaUtils import com.sap.piper.Utils -import com.sap.piper.tools.JavaArchiveDescriptor -import com.sap.piper.tools.ToolDescriptor import groovy.transform.Field @@ -43,8 +41,6 @@ void call(Map parameters = [:]) { ], configuration) dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) { - def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1') - def mta = new JavaArchiveDescriptor('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '1.0.6', '-v', java) def mtaYamlName = "mta.yaml" def applicationName = configuration.applicationName @@ -72,7 +68,9 @@ void call(Map parameters = [:]) { } def mtarFileName = "${id}.mtar" - def mtaJar = mta.getCall(this, configuration) + // If it is not configured, it is expected on the PATH + def mtaJar = 'java -jar ' + mtaJar += configuration.mtaJarLocation ?: 'mta.jar' def buildTarget = configuration.buildTarget def mtaCall = "${mtaJar} --mtar ${mtarFileName} --build-target=${buildTarget}" diff --git a/vars/toolValidate.groovy b/vars/toolValidate.groovy deleted file mode 100644 index 339c6bb9c..000000000 --- a/vars/toolValidate.groovy +++ /dev/null @@ -1,49 +0,0 @@ -import com.sap.piper.FileUtils -import com.sap.piper.Version -import com.sap.piper.tools.JavaArchiveDescriptor -import com.sap.piper.tools.ToolDescriptor -import groovy.transform.Field - -import groovy.transform.Field - -import hudson.AbortException - -@Field STEP_NAME = getClass().getName() - -void call(Map parameters = [:]) { - - handlePipelineStepErrors (stepName: 'toolValidate', stepParameters: parameters) { - - echo '[WARNING][toolValidate] This step is deprecated, and it will be removed in future versions.' - - def tool = parameters.tool - def home = parameters.home - - if (!tool) throw new IllegalArgumentException("The parameter 'tool' can not be null or empty.") - if (!home) throw new IllegalArgumentException("The parameter 'home' can not be null or empty.") - - FileUtils.validateDirectoryIsNotEmpty(this, home) - - switch(tool) { - case 'java': - def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1') - java.verifyVersion(this, [:]) - return - case 'mta': - def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1') - def mta = new JavaArchiveDescriptor('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '1.0.6', '-v', java) - mta.verifyVersion(this, [mtaJarLocation: home]) - return - case 'neo': - def neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version') - neo.verifyVersion(this, [neoHome: home]) - return - case 'cm': - def cmCli = new ToolDescriptor('Change Management Command Line Interface', 'CM_CLI_HOME', 'cmCliHome', '/bin/', 'cmclient', '0.0.1', '-v') - cmCli.verifyVersion(this, [cmCliHome: home]) - return - default: - throw new AbortException("The tool \'$tool\' is not supported. The following tools are supported: java, mta, neo and cm.") - } - } -}