Make use of JenkinsShellCallRule

This commit is contained in:
Marcus Holl
2018-01-23 15:02:25 +01:00
parent 1089e192f3
commit 106a8b4693
5 changed files with 46 additions and 46 deletions
+18 -15
View File
@@ -10,12 +10,14 @@ import org.junit.rules.TemporaryFolder
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
public class MTABuildTest extends PiperTestBase {
private ExpectedException thrown = new ExpectedException()
private TemporaryFolder tmp = new TemporaryFolder()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule
public RuleChain ruleChain =
@@ -23,6 +25,7 @@ public class MTABuildTest extends PiperTestBase {
.around(tmp)
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jscr)
def currentDir
def otherDir
@@ -68,11 +71,11 @@ public class MTABuildTest extends PiperTestBase {
def mtarFilePath = withPipeline(defaultPipeline()).execute()
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"
@@ -89,11 +92,11 @@ public class MTABuildTest extends PiperTestBase {
def mtarFilePath = withPipeline(returnMtarFilePathFromCommonPipelineEnvironmentPipeline()).execute()
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"
@@ -112,11 +115,11 @@ public class MTABuildTest extends PiperTestBase {
def mtarFilePath = withPipeline(withSurroundingDirPipeline()).execute(newDirName)
assert shellCalls[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/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"
@@ -130,11 +133,11 @@ public class MTABuildTest extends PiperTestBase {
def mtarFilePath = withPipeline(defaultPipeline()).execute()
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"
@@ -149,11 +152,11 @@ public class MTABuildTest extends PiperTestBase {
def mtarFilePath = withPipeline(mtaJarLocationAsParameterPipeline()).execute()
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 /etc/mta/mta.jar --mtar ')
assert mtarFilePath == "${currentDir}/com.mycompany.northwind.mtar"
+9 -6
View File
@@ -2,24 +2,27 @@
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
class MavenExecuteTest extends PiperTestBase {
Map dockerParameters
List shellCalls
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule
public JenkinsSetupRule jsr = new JenkinsSetupRule(this)
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
.around(jscr)
@Before
void init() {
shellCalls = []
dockerParameters = [:]
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
@@ -27,7 +30,6 @@ class MavenExecuteTest extends PiperTestBase {
dockerParameters = parameters
closure()
})
helper.registerAllowedMethod('sh', [String], { s -> shellCalls.add(s) })
}
@Test
@@ -35,7 +37,8 @@ class MavenExecuteTest extends PiperTestBase {
def script = loadScript("test/resources/pipelines/mavenExecuteTest/executeBasicMavenCommand.groovy")
script.execute()
assertEquals('maven:3.5-jdk-7', dockerParameters.dockerImage)
assertTrue(shellCalls.contains('mvn clean install'))
assert jscr.shell[0] == 'mvn clean install'
}
@Test
@@ -44,6 +47,6 @@ class MavenExecuteTest extends PiperTestBase {
script.execute()
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))
}
}
+17 -14
View File
@@ -8,18 +8,21 @@ import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
class NeoDeploymentTest extends PiperTestBase {
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 RuleChain ruleChain = RuleChain.outerRule(thrown)
.around(tmp)
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jscr)
def archivePath
def warArchivePath
def propertiesFilePath
@@ -64,7 +67,7 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(defaultPipeline()).execute(archivePath, 'myCredentialsId')
assert shellCalls[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
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.")
@@ -94,7 +97,7 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
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 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.")
}
@@ -107,7 +110,7 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(noCredentialsIdPipeline()).execute(archivePath)
assert shellCalls[0] =~ /#!\/bin\/bash "neo" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
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.")
}
@@ -120,7 +123,7 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(neoHomeParameterPipeline()).execute(archivePath, 'myCredentialsId')
assert shellCalls[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
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.")
@@ -168,8 +171,8 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(mtaDeployModePipeline()).execute(archivePath, 'mta')
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."
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
@@ -179,8 +182,8 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'warParams', 'lite', 'deploy')
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."
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
@@ -190,8 +193,8 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(warParamsDeployModePipeline()).execute(warArchivePath, 'warParams', 'lite', 'rolling-update')
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."
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
@@ -202,8 +205,8 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(warPropertiesFileDeployModePipeline()).execute(warArchivePath, propertiesFilePath, 'warPropertiesFile', 'deploy')
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
@@ -214,8 +217,8 @@ class NeoDeploymentTest extends PiperTestBase {
withPipeline(warPropertiesFileDeployModePipeline()).execute(warArchivePath, propertiesFilePath, 'warPropertiesFile', 'rolling-update')
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
-8
View File
@@ -15,18 +15,10 @@ public class PiperTestBase extends BasePipelineTest {
private File pipeline
protected shellCalls = []
void setUp() {
super.setUp()
shellCalls.clear()
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)
+2 -3
View File
@@ -9,7 +9,7 @@ class JenkinsShellCallRule implements TestRule {
final BasePipelineTest testInstance
String shell = ""
List shell = []
JenkinsShellCallRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
@@ -27,8 +27,7 @@ class JenkinsShellCallRule implements TestRule {
testInstance.helper.registerAllowedMethod("sh", [String.class], {
command ->
command = command.replaceAll(/\s+/," ").trim()
shell += "$command \n"
shell.add(command.replaceAll(/\s+/," ").trim())
})
base.evaluate()