mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
Merge pull request #53 from marcusholl/pr/testCleanup
Beautify the tests
This commit is contained in:
commit
c9d7cc8856
@ -1,61 +1,97 @@
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.JenkinsConfigRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsSetupRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.junit.Assert.assertFalse
|
||||
|
||||
class DockerExecuteTest extends PiperTestBase {
|
||||
class DockerExecuteTest extends BasePipelineTest {
|
||||
private DockerMock docker
|
||||
|
||||
String echos
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
|
||||
.around(jlr)
|
||||
.around(new JenkinsConfigRule(this))
|
||||
|
||||
int whichDockerReturnValue = 0
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
super.setUp()
|
||||
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()]]]])
|
||||
|
||||
echos = ''
|
||||
helper.registerAllowedMethod("echo", [String.class], { String s -> echos += " $s" })
|
||||
helper.registerAllowedMethod('sh', [Map.class], {return whichDockerReturnValue})
|
||||
|
||||
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
||||
dockerExecuteScript = loadScript('dockerExecute.groovy').dockerExecute
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteInsideDocker() throws Exception {
|
||||
def script = loadScript("test/resources/pipelines/dockerExecuteTest/executeInsideDocker.groovy")
|
||||
script.execute()
|
||||
|
||||
dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine') {
|
||||
bodyExecuted = true
|
||||
}
|
||||
|
||||
assertEquals('maven:3.5-jdk-8-alpine', docker.getImageName())
|
||||
assertTrue(docker.isImagePulled())
|
||||
assertEquals(' --env http_proxy --env https_proxy --env no_proxy --env HTTP_PROXY --env HTTPS_PROXY --env NO_PROXY', docker.getParameters())
|
||||
assertTrue(echos.contains('Inside Docker'))
|
||||
assertTrue(bodyExecuted)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteInsideDockerWithParameters() throws Exception {
|
||||
def script = loadScript("test/resources/pipelines/dockerExecuteTest/executeInsideDockerWithParameters.groovy")
|
||||
|
||||
script.execute()
|
||||
dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
dockerOptions: '-it',
|
||||
dockerVolumeBind: ['my_vol': '/my_vol'],
|
||||
dockerEnvVars: ['http_proxy': 'http://proxy:8000']) {
|
||||
bodyExecuted = true
|
||||
}
|
||||
assertTrue(docker.getParameters().contains(' --env https_proxy '))
|
||||
assertTrue(docker.getParameters().contains(' --env http_proxy=http://proxy:8000'))
|
||||
assertTrue(docker.getParameters().contains(' -it'))
|
||||
assertTrue(docker.getParameters().contains(' --volume my_vol:/my_vol'))
|
||||
assertTrue(bodyExecuted)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
|
||||
@Test
|
||||
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
|
||||
|
||||
whichDockerReturnValue = 1
|
||||
def script = loadScript("test/resources/pipelines/dockerExecuteTest/executeInsideDockerWithParameters.groovy")
|
||||
|
||||
script.execute()
|
||||
assertTrue(echos.contains('No docker environment found'))
|
||||
assertTrue(echos.contains('Running on local environment'))
|
||||
dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
dockerOptions: '-it',
|
||||
dockerVolumeBind: ['my_vol': '/my_vol'],
|
||||
dockerEnvVars: ['http_proxy': 'http://proxy:8000']) {
|
||||
bodyExecuted = true
|
||||
}
|
||||
|
||||
assertTrue(jlr.log.contains('No docker environment found'))
|
||||
assertTrue(jlr.log.contains('Running on local environment'))
|
||||
assertTrue(bodyExecuted)
|
||||
assertFalse(docker.isImagePulled())
|
||||
}
|
||||
|
||||
@ -99,5 +135,4 @@ class DockerExecuteTest extends PiperTestBase {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,27 +4,43 @@ import org.jenkinsci.plugins.pipeline.utility.steps.shaded.org.yaml.snakeyaml.pa
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
public class MTABuildTest extends PiperTestBase {
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.JenkinsConfigRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsSetupRule
|
||||
import util.JenkinsShellCallRule
|
||||
|
||||
public class MTABuildTest extends BasePipelineTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
private TemporaryFolder tmp = new TemporaryFolder()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = new ExpectedException()
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder()
|
||||
public RuleChain ruleChain =
|
||||
RuleChain.outerRule(thrown)
|
||||
.around(tmp)
|
||||
.around(new JenkinsSetupRule(this))
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
.around(new JenkinsConfigRule(this))
|
||||
|
||||
def currentDir
|
||||
def otherDir
|
||||
def mtaBuildShEnv
|
||||
|
||||
def mtaBuildScript
|
||||
def cpe
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
void init() {
|
||||
|
||||
super.setUp()
|
||||
currentDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
||||
otherDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
||||
|
||||
@ -49,6 +65,8 @@ public class MTABuildTest extends PiperTestBase {
|
||||
binding.setVariable('JAVA_HOME', '/opt/java')
|
||||
binding.setVariable('env', [:])
|
||||
|
||||
mtaBuildScript = loadScript("mtaBuild.groovy").mtaBuild
|
||||
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
||||
}
|
||||
|
||||
|
||||
@ -59,17 +77,18 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||
|
||||
def mtarFilePath = withPipeline(defaultPipeline()).execute()
|
||||
def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
buildTarget: 'NEO')
|
||||
|
||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
|
||||
assert shellCalls[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
assert jscr.shell[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
|
||||
assert shellCalls[1].contains(' -jar /opt/mta/mta.jar --mtar ')
|
||||
assert jscr.shell[1].contains(' -jar /opt/mta/mta.jar --mtar ')
|
||||
|
||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||
|
||||
assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
||||
assert jlr.log.contains( "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment.")
|
||||
}
|
||||
|
||||
|
||||
@ -80,17 +99,20 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||
|
||||
def mtarFilePath = withPipeline(returnMtarFilePathFromCommonPipelineEnvironmentPipeline()).execute()
|
||||
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
buildTarget: 'NEO')
|
||||
|
||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
def mtarFilePath = cpe.getMtarFilePath()
|
||||
|
||||
assert shellCalls[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
|
||||
assert shellCalls[1].contains(' -jar /opt/mta/mta.jar --mtar ')
|
||||
assert jscr.shell[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
|
||||
assert jscr.shell[1].contains(' -jar /opt/mta/mta.jar --mtar ')
|
||||
|
||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||
|
||||
assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
||||
assert jlr.log.contains("[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment.")
|
||||
}
|
||||
|
||||
|
||||
@ -100,20 +122,24 @@ public class MTABuildTest extends PiperTestBase {
|
||||
binding.getVariable('env')['MTA_JAR_LOCATION'] = '/opt/mta'
|
||||
|
||||
def newDirName = 'newDir'
|
||||
new File("${currentDir}/${newDirName}").mkdirs()
|
||||
new File("${currentDir}/${newDirName}/mta.yaml") << defaultMtaYaml()
|
||||
def newDir = new File("${currentDir}/${newDirName}")
|
||||
|
||||
def mtarFilePath = withPipeline(withSurroundingDirPipeline()).execute(newDirName)
|
||||
newDir.mkdirs()
|
||||
new File(newDir, 'mta.yaml') << defaultMtaYaml()
|
||||
|
||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
|
||||
helper.registerAllowedMethod('pwd', [], { newDir } )
|
||||
|
||||
assert shellCalls[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], buildTarget: 'NEO')
|
||||
|
||||
assert shellCalls[1].contains(' -jar /opt/mta/mta.jar --mtar ')
|
||||
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
|
||||
|
||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||
assert jscr.shell[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
|
||||
assert messages[1] == "[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment."
|
||||
assert jscr.shell[1].contains(' -jar /opt/mta/mta.jar --mtar ')
|
||||
|
||||
assert mtarFilePath == "${currentDir}/${newDirName}/com.mycompany.northwind.mtar"
|
||||
|
||||
assert jlr.log.contains("[mtaBuild] MTA JAR \"/opt/mta/mta.jar\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -121,17 +147,17 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||
|
||||
def mtarFilePath = withPipeline(defaultPipeline()).execute()
|
||||
def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], buildTarget: 'NEO')
|
||||
|
||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
|
||||
assert shellCalls[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
assert jscr.shell[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
|
||||
assert shellCalls[1].contains(' -jar mta.jar --mtar ')
|
||||
assert jscr.shell[1].contains(' -jar mta.jar --mtar ')
|
||||
|
||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||
|
||||
assert messages[1] == "[mtaBuild] Using MTA JAR from current working directory."
|
||||
assert jlr.log.contains( "[mtaBuild] Using MTA JAR from current working directory." )
|
||||
}
|
||||
|
||||
|
||||
@ -140,17 +166,17 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||
|
||||
def mtarFilePath = withPipeline(mtaJarLocationAsParameterPipeline()).execute()
|
||||
def mtarFilePath = mtaBuildScript.call(mtaJarLocation: '/mylocation/mta', buildTarget: 'NEO')
|
||||
|
||||
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
|
||||
|
||||
assert shellCalls[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
assert jscr.shell[1].contains("PATH=./node_modules/.bin:/usr/bin")
|
||||
|
||||
assert shellCalls[1].contains(' -jar /etc/mta/mta.jar --mtar ')
|
||||
assert jscr.shell[1].contains(' -jar /mylocation/mta/mta.jar --mtar ')
|
||||
|
||||
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
|
||||
|
||||
assert messages[1] == "[mtaBuild] MTA JAR \"/etc/mta/mta.jar\" retrieved from parameters."
|
||||
assert jlr.log.contains("[mtaBuild] MTA JAR \"/mylocation/mta/mta.jar\" retrieved from parameters.".toString())
|
||||
}
|
||||
|
||||
|
||||
@ -158,7 +184,8 @@ public class MTABuildTest extends PiperTestBase {
|
||||
public void noMtaPresentTest(){
|
||||
thrown.expect(FileNotFoundException)
|
||||
|
||||
withPipeline(defaultPipeline()).execute()
|
||||
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
buildTarget: 'NEO')
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +196,8 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << badMtaYaml()
|
||||
|
||||
withPipeline(defaultPipeline()).execute()
|
||||
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
buildTarget: 'NEO')
|
||||
}
|
||||
|
||||
|
||||
@ -180,7 +208,8 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << noIdMtaYaml()
|
||||
|
||||
withPipeline(defaultPipeline()).execute()
|
||||
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
buildTarget: 'NEO')
|
||||
}
|
||||
|
||||
|
||||
@ -191,74 +220,9 @@ public class MTABuildTest extends PiperTestBase {
|
||||
|
||||
new File("${currentDir}/mta.yaml") << defaultMtaYaml()
|
||||
|
||||
withPipeline(noBuildTargetPipeline()).execute()
|
||||
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe])
|
||||
}
|
||||
|
||||
|
||||
private defaultPipeline(){
|
||||
return '''
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(){
|
||||
mtaBuild buildTarget: 'NEO'
|
||||
}
|
||||
|
||||
return this
|
||||
'''
|
||||
}
|
||||
|
||||
private returnMtarFilePathFromCommonPipelineEnvironmentPipeline(){
|
||||
return '''
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(){
|
||||
mtaBuild buildTarget: 'NEO'
|
||||
return commonPipelineEnvironment.getMtarFilePath()
|
||||
}
|
||||
|
||||
return this
|
||||
'''
|
||||
}
|
||||
|
||||
private mtaJarLocationAsParameterPipeline(){
|
||||
return '''
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(){
|
||||
mtaBuild mtaJarLocation: '/etc/mta', buildTarget: 'NEO'
|
||||
}
|
||||
|
||||
return this
|
||||
'''
|
||||
}
|
||||
|
||||
private withSurroundingDirPipeline(){
|
||||
return '''
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(dirPath){
|
||||
dir("${dirPath}"){
|
||||
mtaBuild buildTarget: 'NEO'
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
'''
|
||||
}
|
||||
|
||||
private noBuildTargetPipeline(){
|
||||
return '''
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(){
|
||||
mtaBuild()
|
||||
}
|
||||
|
||||
return this
|
||||
'''
|
||||
}
|
||||
|
||||
|
||||
private defaultMtaYaml(){
|
||||
return '''
|
||||
_schema-version: "2.0.0"
|
||||
|
@ -1,20 +1,35 @@
|
||||
import junit.framework.TestCase
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
class MavenExecuteTest extends PiperTestBase {
|
||||
import util.JenkinsConfigRule
|
||||
import util.JenkinsSetupRule
|
||||
import util.JenkinsShellCallRule
|
||||
|
||||
class MavenExecuteTest extends BasePipelineTest {
|
||||
|
||||
Map dockerParameters
|
||||
List shellCalls
|
||||
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
|
||||
.around(jscr)
|
||||
.around(new JenkinsConfigRule(this))
|
||||
|
||||
def mavenExecuteScript
|
||||
def cpe
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
super.setUp()
|
||||
void init() {
|
||||
|
||||
shellCalls = []
|
||||
dockerParameters = [:]
|
||||
|
||||
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
|
||||
@ -22,23 +37,35 @@ class MavenExecuteTest extends PiperTestBase {
|
||||
dockerParameters = parameters
|
||||
closure()
|
||||
})
|
||||
helper.registerAllowedMethod('sh', [String], { s -> shellCalls.add(s) })
|
||||
|
||||
mavenExecuteScript = loadScript("mavenExecute.groovy").mavenExecute
|
||||
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteBasicMavenCommand() throws Exception {
|
||||
def script = loadScript("test/resources/pipelines/mavenExecuteTest/executeBasicMavenCommand.groovy")
|
||||
script.execute()
|
||||
|
||||
mavenExecuteScript.call(script: [commonPipelineEnvironment: cpe], goals: 'clean install')
|
||||
assertEquals('maven:3.5-jdk-7', dockerParameters.dockerImage)
|
||||
assertTrue(shellCalls.contains('mvn clean install'))
|
||||
|
||||
assert jscr.shell[0] == 'mvn clean install'
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteMavenCommandWithParameter() throws Exception {
|
||||
def script = loadScript("test/resources/pipelines/mavenExecuteTest/executeMavenCommandWithParameters.groovy")
|
||||
script.execute()
|
||||
|
||||
mavenExecuteScript.call(
|
||||
script: [commonPipelineEnvironment: cpe],
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
goals: 'clean install',
|
||||
globalSettingsFile: 'globalSettingsFile.xml',
|
||||
projectSettingsFile: 'projectSettingsFile.xml',
|
||||
pomPath: 'pom.xml',
|
||||
flags: '-o',
|
||||
m2Path: 'm2Path',
|
||||
defines: '-Dmaven.tests.skip=true')
|
||||
assertEquals('maven:3.5-jdk-8-alpine', dockerParameters.dockerImage)
|
||||
String mvnCommand = "mvn --global-settings 'globalSettingsFile.xml' -Dmaven.repo.local='m2Path' --settings 'projectSettingsFile.xml' --file 'pom.xml' -o clean install -Dmaven.tests.skip=true"
|
||||
assertTrue(shellCalls.contains(mvnCommand))
|
||||
assertTrue(jscr.shell.contains(mvnCommand))
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,42 @@
|
||||
import hudson.AbortException
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
|
||||
|
||||
import static ProjectSource.projectSource
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
class NeoDeploymentTest extends PiperTestBase {
|
||||
import util.JenkinsConfigRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsSetupRule
|
||||
import util.JenkinsShellCallRule
|
||||
|
||||
class NeoDeploymentTest extends BasePipelineTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException().none()
|
||||
private TemporaryFolder tmp = new TemporaryFolder()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = new ExpectedException().none()
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder()
|
||||
|
||||
public RuleChain ruleChain = RuleChain.outerRule(thrown)
|
||||
.around(tmp)
|
||||
.around(new JenkinsSetupRule(this))
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
.around(new JenkinsConfigRule(this))
|
||||
def archivePath
|
||||
def warArchivePath
|
||||
def propertiesFilePath
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
def neoDeployScript
|
||||
def cpe
|
||||
|
||||
super.setUp()
|
||||
@Before
|
||||
void init() {
|
||||
|
||||
archivePath = "${tmp.newFolder("workspace").toURI().getPath()}archiveName.mtar"
|
||||
warArchivePath = "${tmp.getRoot().toURI().getPath()}workspace/warArchive.war"
|
||||
@ -52,6 +63,10 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
|
||||
binding.setVariable('env', [:])
|
||||
|
||||
neoDeployScript = loadScript("neoDeploy.groovy").neoDeploy
|
||||
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -62,11 +77,17 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
|
||||
new File(archivePath) << "dummy archive"
|
||||
|
||||
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archivePath,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
|
||||
}
|
||||
|
||||
@ -80,8 +101,13 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
|
||||
thrown.expect(MissingPropertyException)
|
||||
|
||||
withPipeline(defaultPipeline()).execute(archivePath, 'badCredentialsId')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archivePath,
|
||||
neoCredentialsId: 'badCredentialsId'
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -92,11 +118,16 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
|
||||
new File(archivePath) << "dummy archive"
|
||||
|
||||
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archivePath
|
||||
)
|
||||
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
|
||||
@ -105,11 +136,16 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
|
||||
new File(archivePath) << "dummy archive"
|
||||
|
||||
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "neo" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archivePath
|
||||
)
|
||||
|
||||
assert messages[1] == "Using Neo executable from PATH."
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "neo" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
|
||||
assert jlr.log.contains("Using Neo executable from PATH.")
|
||||
}
|
||||
|
||||
|
||||
@ -118,11 +154,18 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
|
||||
new File(archivePath) << "dummy archive"
|
||||
|
||||
withPipeline(neoHomeParameterPipeline()).execute(archivePath, 'myCredentialsId')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archivePath,
|
||||
neoCredentialsId: 'myCredentialsId',
|
||||
neoHome: '/etc/neo'
|
||||
)
|
||||
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters."
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters.")
|
||||
|
||||
}
|
||||
|
||||
@ -133,8 +176,10 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR archivePath')
|
||||
|
||||
withPipeline(noArchivePathPipeline()).execute()
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe])
|
||||
}
|
||||
|
||||
|
||||
@ -144,8 +189,11 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Archive cannot be found with parameter archivePath: '")
|
||||
|
||||
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archivePath)
|
||||
}
|
||||
|
||||
|
||||
@ -157,8 +205,7 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR deployHost')
|
||||
|
||||
withPipeline(noScriptPipeline()).execute(archivePath)
|
||||
|
||||
neoDeployScript.call(archivePath: archivePath)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -166,10 +213,14 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
new File(archivePath) << "dummy archive"
|
||||
|
||||
withPipeline(mtaDeployModePipeline()).execute(archivePath, 'mta')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe], archivePath: archivePath, deployMode: 'mta')
|
||||
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -177,10 +228,24 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
new File(warArchivePath) << "dummy war archive"
|
||||
|
||||
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'warParams', 'lite', 'deploy')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite'/
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
def appName = 'testApp'
|
||||
def runtime = 'neo-javaee6-wp'
|
||||
def runtimeVersion = '2.125'
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
deployMode: 'warParams',
|
||||
vmSize: 'lite',
|
||||
warAction: 'deploy',
|
||||
archivePath: warArchivePath)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite'/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -188,10 +253,20 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
new File(warArchivePath) << "dummy war archive"
|
||||
|
||||
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'warParams', 'lite', 'rolling-update')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite'/
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'rolling-update',
|
||||
vmSize: 'lite')
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite'/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -200,10 +275,18 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
new File(warArchivePath) << "dummy war archive"
|
||||
new File(propertiesFilePath) << "dummy properties file"
|
||||
|
||||
withPipeline(warPropertiesFileDeployModePipeline()).execute(warArchivePath, propertiesFilePath, 'warPropertiesFile', 'deploy')
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'warPropertiesFile',
|
||||
propertiesFile: propertiesFilePath,
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'deploy',
|
||||
vmSize: 'lite')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" .*\.properties/
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" .*\.properties/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -212,10 +295,18 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
new File(warArchivePath) << "dummy war archive"
|
||||
new File(propertiesFilePath) << "dummy properties file"
|
||||
|
||||
withPipeline(warPropertiesFileDeployModePipeline()).execute(warArchivePath, propertiesFilePath, 'warPropertiesFile', 'rolling-update')
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'warPropertiesFile',
|
||||
propertiesFile: propertiesFilePath,
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'rolling-update',
|
||||
vmSize: 'lite')
|
||||
|
||||
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" .*\.properties/
|
||||
assert messages[1] == "[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment."
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" .*\.properties/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -225,7 +316,15 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR applicationName')
|
||||
|
||||
withPipeline(noApplicationNamePipeline()).execute(warArchivePath, 'warParams')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'warParams',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125'
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -235,7 +334,14 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime')
|
||||
|
||||
withPipeline(noRuntimePipeline()).execute(warArchivePath, 'warParams')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
applicationName: 'testApp',
|
||||
deployMode: 'warParams',
|
||||
runtimeVersion: '2.125')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -245,7 +351,14 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion')
|
||||
|
||||
withPipeline(noRuntimeVersionPipeline()).execute(warArchivePath, 'warParams')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
applicationName: 'testApp',
|
||||
deployMode: 'warParams',
|
||||
runtime: 'neo-javaee6-wp')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -255,7 +368,17 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'")
|
||||
|
||||
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'illegalMode', 'lite', 'deploy')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'illegalMode',
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'deploy',
|
||||
vmSize: 'lite')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -265,7 +388,17 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.")
|
||||
|
||||
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'warParams', 'illegalVM', 'deploy')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'deploy',
|
||||
vmSize: 'illegalVM')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -275,221 +408,16 @@ class NeoDeploymentTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
|
||||
|
||||
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'warParams', 'lite', 'illegalWARAction')
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: warArchivePath,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'illegalWARAction',
|
||||
vmSize: 'lite')
|
||||
}
|
||||
|
||||
private defaultPipeline(){
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(archivePath, neoCredentialsId) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noCredentialsIdPipeline(){
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(archivePath) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: archivePath
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private neoHomeParameterPipeline(){
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(archivePath, neoCredentialsId) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: archivePath, neoCredentialsId: neoCredentialsId, neoHome: '/etc/neo'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noArchivePathPipeline(){
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
node() {
|
||||
neoDeploy script: this
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noScriptPipeline(){
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(archivePath) {
|
||||
|
||||
node() {
|
||||
neoDeploy archivePath: archivePath
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noApplicationNamePipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(warArchivePath, deployMode) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
def runtime = 'neo-javaee6-wp'
|
||||
def runtimeVersion = '2.125'
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: warArchivePath, deployMode: deployMode, runtime: runtime, runtimeVersion: runtimeVersion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noRuntimePipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(warArchivePath, deployMode) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
def appName = 'testApp'
|
||||
def runtime = 'neo-javaee6-wp'
|
||||
def runtimeVersion = '2.125'
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: warArchivePath, deployMode: deployMode, applicationName: appName, runtimeVersion: runtimeVersion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noRuntimeVersionPipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(warArchivePath, deployMode) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
def appName = 'testApp'
|
||||
def runtime = 'neo-javaee6-wp'
|
||||
def runtimeVersion = '2.125'
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: warArchivePath, deployMode: deployMode, applicationName: appName, runtime: runtime
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private warPropertiesFileDeployModePipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(warArchivePath, propertiesFilePath, deployMode, warAction) {
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, deployMode: deployMode, archivePath: warArchivePath, propertiesFile: propertiesFilePath, warAction: warAction
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private warParamsDeployModePipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(warArchivePath, deployMode, vmSize, warAction) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
def appName = 'testApp'
|
||||
def runtime = 'neo-javaee6-wp'
|
||||
def runtimeVersion = '2.125'
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: warArchivePath, deployMode: deployMode, applicationName: appName, runtime: runtime, runtimeVersion: runtimeVersion, warAction: warAction, vmSize: vmSize
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private mtaDeployModePipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute(archivePath, deployMode) {
|
||||
|
||||
commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
node() {
|
||||
neoDeploy script: this, archivePath: archivePath, deployMode: deployMode
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,34 @@
|
||||
import hudson.AbortException
|
||||
import util.JenkinsConfigRule
|
||||
import util.JenkinsSetupRule
|
||||
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
class PipelineExecuteTest extends PiperTestBase {
|
||||
class PipelineExecuteTest extends BasePipelineTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException().none()
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = new ExpectedException().none()
|
||||
public RuleChain ruleChain = RuleChain.outerRule(thrown)
|
||||
.around(new JenkinsSetupRule(this))
|
||||
.around(new JenkinsConfigRule(this))
|
||||
|
||||
def pipelinePath
|
||||
def checkoutParameters = [:]
|
||||
def load
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
def pipelineExecuteScript
|
||||
|
||||
super.setUp()
|
||||
@Before
|
||||
void init() {
|
||||
|
||||
pipelinePath = null
|
||||
checkoutParameters.clear()
|
||||
@ -32,13 +43,14 @@ class PipelineExecuteTest extends PiperTestBase {
|
||||
})
|
||||
helper.registerAllowedMethod('load', [String], { s -> load = s })
|
||||
|
||||
pipelineExecuteScript = loadScript("pipelineExecute.groovy").pipelineExecute
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void straightForwardTest() {
|
||||
|
||||
withPipeline(defaultPipeline()).execute()
|
||||
pipelineExecuteScript.call(repoUrl: "https://test.com/myRepo.git")
|
||||
assert load == "Jenkinsfile"
|
||||
assert checkoutParameters.branch == 'master'
|
||||
assert checkoutParameters.repoUrl == "https://test.com/myRepo.git"
|
||||
@ -50,7 +62,11 @@ class PipelineExecuteTest extends PiperTestBase {
|
||||
@Test
|
||||
void parameterizeTest() {
|
||||
|
||||
withPipeline(parameterizePipeline()).execute()
|
||||
pipelineExecuteScript.call(repoUrl: "https://test.com/anotherRepo.git",
|
||||
branch: 'feature',
|
||||
path: 'path/to/Jenkinsfile',
|
||||
credentialsId: 'abcd1234')
|
||||
|
||||
assert load == "path/to/Jenkinsfile"
|
||||
assert checkoutParameters.branch == 'feature'
|
||||
assert checkoutParameters.repoUrl == "https://test.com/anotherRepo.git"
|
||||
@ -65,50 +81,6 @@ class PipelineExecuteTest extends PiperTestBase {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR repoUrl")
|
||||
|
||||
withPipeline(noRepoUrlPipeline()).execute()
|
||||
|
||||
}
|
||||
|
||||
|
||||
private defaultPipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
|
||||
pipelineExecute repoUrl: "https://test.com/myRepo.git"
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private parameterizePipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
|
||||
pipelineExecute repoUrl: "https://test.com/anotherRepo.git", branch: 'feature', path: 'path/to/Jenkinsfile', credentialsId: 'abcd1234'
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
}
|
||||
|
||||
private noRepoUrlPipeline() {
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
|
||||
pipelineExecute()
|
||||
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
pipelineExecuteScript.call()
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import com.sap.piper.DefaultValueCache
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import static ProjectSource.projectSource
|
||||
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
public class PiperTestBase extends BasePipelineTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder pipelineFolder = new TemporaryFolder()
|
||||
|
||||
private File pipeline
|
||||
|
||||
protected messages = [], shellCalls = []
|
||||
|
||||
void setUp() {
|
||||
|
||||
super.setUp()
|
||||
|
||||
messages.clear()
|
||||
shellCalls.clear()
|
||||
|
||||
preparePiperLib()
|
||||
|
||||
helper.registerAllowedMethod('echo', [String], {s -> messages.add(s)} )
|
||||
helper.registerAllowedMethod('sh', [String], { s ->
|
||||
shellCalls.add(s.replaceAll(/\s+/, " ").trim())
|
||||
})
|
||||
|
||||
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
||||
Yaml yamlParser = new Yaml()
|
||||
return yamlParser.load(parameters.text)
|
||||
})
|
||||
|
||||
pipeline = pipelineFolder.newFile()
|
||||
|
||||
DefaultValueCache.reset()
|
||||
}
|
||||
|
||||
protected withPipeline(p) {
|
||||
pipeline << p
|
||||
loadScript(pipeline.toURI().getPath())
|
||||
}
|
||||
|
||||
private preparePiperLib() {
|
||||
def piperLib = library()
|
||||
.name('piper-library-os')
|
||||
.retriever(projectSource())
|
||||
.targetPath('clonePath/is/not/necessary')
|
||||
.defaultVersion('<irrelevant>')
|
||||
.allowOverride(true)
|
||||
.implicit(false)
|
||||
.build()
|
||||
helper.registerSharedLibrary(piperLib)
|
||||
}
|
||||
}
|
@ -1,17 +1,28 @@
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.JenkinsSetupRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertNotNull
|
||||
|
||||
class SetupCommonPipelineEnvironmentTest extends PiperTestBase {
|
||||
class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
|
||||
|
||||
def usedConfigFile
|
||||
|
||||
def setupCommonPipelineEnvironmentScript
|
||||
|
||||
def commonPipelineEnvironment
|
||||
|
||||
@Rule
|
||||
public JenkinsSetupRule jsr = new JenkinsSetupRule(this)
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
super.setUp()
|
||||
void init() {
|
||||
|
||||
def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text
|
||||
|
||||
@ -28,16 +39,18 @@ class SetupCommonPipelineEnvironmentTest extends PiperTestBase {
|
||||
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 {
|
||||
def script = loadScript("test/resources/pipelines/setupCommonPipelineEnvironmentTest/loadConfiguration.groovy")
|
||||
script.execute()
|
||||
setupCommonPipelineEnvironmentScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment])
|
||||
|
||||
assertEquals('.pipeline/config.yml', usedConfigFile)
|
||||
assertNotNull(script.commonPipelineEnvironment.configuration)
|
||||
assertEquals('develop', script.commonPipelineEnvironment.configuration.general.productiveBranch)
|
||||
assertEquals('my-maven-docker', script.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
|
||||
assertNotNull(commonPipelineEnvironment.configuration)
|
||||
assertEquals('develop', commonPipelineEnvironment.configuration.general.productiveBranch)
|
||||
assertEquals('my-maven-docker', commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
|
||||
}
|
||||
}
|
||||
|
@ -4,27 +4,36 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class ToolValidateTest extends PiperTestBase {
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.JenkinsConfigRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsSetupRule
|
||||
|
||||
class ToolValidateTest extends BasePipelineTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException().none()
|
||||
private TemporaryFolder tmp = new TemporaryFolder()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsConfigRule jcr = new JenkinsConfigRule(this)
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = new ExpectedException().none()
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder()
|
||||
public RuleChain ruleChain =
|
||||
RuleChain.outerRule(tmp)
|
||||
.around(thrown)
|
||||
.around(new JenkinsSetupRule(this))
|
||||
.around(jlr)
|
||||
.around(jcr)
|
||||
|
||||
private notEmptyDir
|
||||
private script
|
||||
|
||||
def toolValidateScript
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
|
||||
super.setUp()
|
||||
|
||||
script = withPipeline(defaultPipeline())
|
||||
void init() {
|
||||
|
||||
notEmptyDir = tmp.newFolder('notEmptyDir')
|
||||
def path = "${notEmptyDir.getAbsolutePath()}${File.separator}test.txt"
|
||||
@ -33,8 +42,7 @@ class ToolValidateTest extends PiperTestBase {
|
||||
|
||||
binding.setVariable('JAVA_HOME', notEmptyDir.getAbsolutePath())
|
||||
|
||||
binding.setVariable('home', notEmptyDir.getAbsolutePath())
|
||||
|
||||
toolValidateScript = loadScript("toolValidate.groovy").toolValidate
|
||||
}
|
||||
|
||||
|
||||
@ -44,10 +52,7 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'home' can not be null or empty.")
|
||||
|
||||
binding.setVariable('tool', 'java')
|
||||
binding.setVariable('home', null)
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'java', home: null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -56,10 +61,7 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'home' can not be null or empty.")
|
||||
|
||||
binding.setVariable('tool', 'java')
|
||||
binding.setVariable('home', '')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'java', home: '')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,9 +70,7 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'tool' can not be null or empty.")
|
||||
|
||||
binding.setVariable('tool', null)
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -79,9 +79,7 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'tool' can not be null or empty.")
|
||||
|
||||
binding.setVariable('tool', '')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: '')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -90,9 +88,7 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("The tool 'test' is not supported.")
|
||||
|
||||
binding.setVariable('tool', 'test')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'test', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -102,9 +98,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The validation of Java failed.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
|
||||
binding.setVariable('tool', 'java')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'java', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -114,9 +109,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The validation of SAP Multitarget Application Archive Builder failed.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
|
||||
binding.setVariable('tool', 'mta')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'mta', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -126,9 +120,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The validation of SAP Cloud Platform Console Client failed.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
|
||||
binding.setVariable('tool', 'neo')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'neo', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -138,7 +131,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The validation of Change Management Command Line Interface failed.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
|
||||
binding.setVariable('tool', 'cm')
|
||||
|
||||
toolValidateScript.call(tool: 'cm', home: notEmptyDir.getAbsolutePath())
|
||||
|
||||
script.execute()
|
||||
}
|
||||
@ -150,9 +144,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The installed version of Java is 1.7.0.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
|
||||
binding.setVariable('tool', 'java')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'java', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -162,9 +155,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The installed version of SAP Multitarget Application Archive Builder is 1.0.5.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
|
||||
binding.setVariable('tool', 'mta')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'mta', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -174,9 +166,8 @@ class ToolValidateTest extends PiperTestBase {
|
||||
thrown.expectMessage('The installed version of SAP Cloud Platform Console Client is 1.126.51.')
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
|
||||
binding.setVariable('tool', 'neo')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'neo', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -188,80 +179,59 @@ class ToolValidateTest extends PiperTestBase {
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
|
||||
binding.setVariable('tool', 'cm')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'cm', home: notEmptyDir.getAbsolutePath())
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateJavaTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
|
||||
binding.setVariable('tool', 'java')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'java', home: notEmptyDir.getAbsolutePath())
|
||||
|
||||
assert messages[0].contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
|
||||
assert messages[1].contains('[INFO] Validating Java version 1.8.0 or compatible version.')
|
||||
assert messages[2].contains('[INFO] Java version 1.8.0 is installed.')
|
||||
assert messages[3].contains('--- END LIBRARY STEP: toolValidate.groovy ---')
|
||||
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 ---')
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateMtaTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
|
||||
binding.setVariable('tool', 'mta')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'mta', home: notEmptyDir.getAbsolutePath())
|
||||
|
||||
assert messages[0].contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
|
||||
assert messages[1].contains('[INFO] Validating SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.')
|
||||
assert messages[2].contains('[INFO] SAP Multitarget Application Archive Builder version 1.0.6 is installed.')
|
||||
assert messages[3].contains('--- END LIBRARY STEP: toolValidate.groovy ---')
|
||||
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 ---')
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateNeoTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
|
||||
binding.setVariable('tool', 'neo')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'neo', home: notEmptyDir.getAbsolutePath())
|
||||
|
||||
assert messages[0].contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
|
||||
assert messages[1].contains('[INFO] Validating SAP Cloud Platform Console Client version 3.39.10 or compatible version.')
|
||||
assert messages[2].contains('[INFO] SAP Cloud Platform Console Client version 3.39.10 is installed.')
|
||||
assert messages[3].contains('--- END LIBRARY STEP: toolValidate.groovy ---')
|
||||
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 ---')
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateCmTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
|
||||
binding.setVariable('tool', 'cm')
|
||||
|
||||
script.execute()
|
||||
toolValidateScript.call(tool: 'cm', home: notEmptyDir.getAbsolutePath())
|
||||
|
||||
assert messages[0].contains('--- BEGIN LIBRARY STEP: toolValidate.groovy ---')
|
||||
assert messages[1].contains('[INFO] Validating Change Management Command Line Interface version 0.0.1 or compatible version.')
|
||||
assert messages[2].contains('[INFO] Change Management Command Line Interface version 0.0.1 is installed.')
|
||||
assert messages[3].contains('--- END LIBRARY STEP: toolValidate.groovy ---')
|
||||
}
|
||||
|
||||
|
||||
private defaultPipeline(){
|
||||
return """
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
|
||||
node() {
|
||||
|
||||
toolValidate tool: tool, home: home
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
"""
|
||||
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 ---')
|
||||
}
|
||||
|
||||
private getNoVersion(Map m) {
|
||||
|
38
test/groovy/util/JenkinsConfigRule.groovy
Normal file
38
test/groovy/util/JenkinsConfigRule.groovy
Normal file
@ -0,0 +1,38 @@
|
||||
package util
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import com.sap.piper.DefaultValueCache
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
class JenkinsConfigRule implements TestRule {
|
||||
|
||||
final BasePipelineTest testInstance
|
||||
|
||||
|
||||
JenkinsConfigRule(BasePipelineTest testInstance) {
|
||||
this.testInstance = testInstance
|
||||
}
|
||||
|
||||
@Override
|
||||
Statement apply(Statement base, Description description) {
|
||||
return statement(base)
|
||||
}
|
||||
|
||||
private Statement statement(final Statement base) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
void evaluate() throws Throwable {
|
||||
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
||||
Yaml yamlParser = new Yaml()
|
||||
return yamlParser.load(parameters.text)
|
||||
})
|
||||
DefaultValueCache.reset()
|
||||
|
||||
base.evaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
37
test/groovy/util/JenkinsShellCallRule.groovy
Normal file
37
test/groovy/util/JenkinsShellCallRule.groovy
Normal file
@ -0,0 +1,37 @@
|
||||
package util
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
|
||||
class JenkinsShellCallRule implements TestRule {
|
||||
|
||||
final BasePipelineTest testInstance
|
||||
|
||||
List shell = []
|
||||
|
||||
JenkinsShellCallRule(BasePipelineTest testInstance) {
|
||||
this.testInstance = testInstance
|
||||
}
|
||||
|
||||
@Override
|
||||
Statement apply(Statement base, Description description) {
|
||||
return statement(base)
|
||||
}
|
||||
|
||||
private Statement statement(final Statement base) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
void evaluate() throws Throwable {
|
||||
|
||||
testInstance.helper.registerAllowedMethod("sh", [String.class], {
|
||||
command ->
|
||||
shell.add(command.replaceAll(/\s+/," ").trim())
|
||||
})
|
||||
|
||||
base.evaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
node() {
|
||||
dockerExecute(script: this, dockerImage: 'maven:3.5-jdk-8-alpine') {
|
||||
echo 'Inside Docker'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
@ -1,11 +0,0 @@
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
node() {
|
||||
dockerExecute(script: this, dockerImage: 'maven:3.5-jdk-8-alpine', dockerOptions: '-it', dockerVolumeBind: ['my_vol': '/my_vol'], dockerEnvVars: ['http_proxy': 'http://proxy:8000']) {
|
||||
echo 'Inside Docker'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
@ -1,9 +0,0 @@
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
node() {
|
||||
mavenExecute script: this, goals: 'clean install'
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
@ -1,21 +0,0 @@
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
node() {
|
||||
mavenExecute(
|
||||
script: this,
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
goals: 'clean install',
|
||||
globalSettingsFile: 'globalSettingsFile.xml',
|
||||
projectSettingsFile: 'projectSettingsFile.xml',
|
||||
pomPath: 'pom.xml',
|
||||
flags: '-o',
|
||||
m2Path: 'm2Path',
|
||||
defines: '-Dmaven.tests.skip=true'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
@Library('piper-library-os')
|
||||
|
||||
execute() {
|
||||
node() {
|
||||
setupCommonPipelineEnvironment script:this
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user