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

use new rules

This commit is contained in:
Christopher Fenner 2018-02-28 13:11:09 +01:00
parent 4fcc911e6c
commit 158a60aecc
No known key found for this signature in database
GPG Key ID: 749881F766EA636F
8 changed files with 153 additions and 188 deletions

View File

@ -18,15 +18,12 @@ import util.Rules
import static org.junit.Assert.assertEquals
class ArtifactSetVersionTest extends BasePipelineTest {
def gitUtils
def sshAgentList = []
ExpectedException thrown = ExpectedException.none()
JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this)
JenkinsStepRule jsr = new JenkinsStepRule(this)
JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
private ExpectedException thrown = ExpectedException.none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
private JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain ruleChain = Rules
@ -39,6 +36,9 @@ class ArtifactSetVersionTest extends BasePipelineTest {
.around(jsr)
.around(jer)
def gitUtils
def sshAgentList = []
@Before
void init() throws Throwable {
helper.registerAllowedMethod("sshagent", [List.class, Closure.class], { list, closure ->
@ -108,6 +108,4 @@ class ArtifactSetVersionTest extends BasePipelineTest {
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
}
}

View File

@ -10,22 +10,23 @@ import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import util.Rules
import util.JenkinsStepRule
class ChecksPublishResultsTest extends BasePipelineTest {
Map publisherStepOptions
List archiveStepPatterns
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(jsr)
def checksPublishResultsScript
Map publisherStepOptions
List archiveStepPatterns
@Before
void init() {
publisherStepOptions = [:]
archiveStepPatterns = []
// prepare checkResultsPublish step
checksPublishResultsScript = loadScript("checksPublishResults.groovy").checksPublishResults
// add handler for generic step call
helper.registerAllowedMethod("step", [Map.class], {
parameters -> publisherStepOptions[parameters.$class] = parameters
@ -37,7 +38,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithDefaultSettings() throws Exception {
checksPublishResultsScript.call()
jsr.step.call()
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
// ensure nothing else is published
@ -50,7 +51,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishForJavaWithDefaultSettings() throws Exception {
checksPublishResultsScript.call(pmd: true, cpd: true, findbugs: true, checkstyle: true)
jsr.step.call(pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -68,7 +69,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishForJavaScriptWithDefaultSettings() throws Exception {
checksPublishResultsScript.call(eslint: true)
jsr.step.call(eslint: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
@ -86,7 +87,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishForPythonWithDefaultSettings() throws Exception {
checksPublishResultsScript.call(pylint: true)
jsr.step.call(pylint: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
@ -105,7 +106,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothing() throws Exception {
checksPublishResultsScript.call(aggregation: false)
jsr.step.call(aggregation: false)
// ensure nothing is published
assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null)
@ -118,7 +119,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothingExplicitFalse() throws Exception {
checksPublishResultsScript.call(pmd: false)
jsr.step.call(pmd: false)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
// ensure nothing else is published
@ -131,7 +132,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothingImplicitTrue() throws Exception {
checksPublishResultsScript.call(pmd: [:])
jsr.step.call(pmd: [:])
// ensure pmd is not published
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -139,7 +140,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothingExplicitActiveFalse() throws Exception {
checksPublishResultsScript.call(pmd: [active: false])
jsr.step.call(pmd: [active: false])
// ensure pmd is not published
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
@ -148,7 +149,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithChangedStepDefaultSettings() throws Exception {
// pmd has been set to active: true in step configuration
checksPublishResultsScript.call(script: [commonPipelineEnvironment: [
jsr.step.call(script: [commonPipelineEnvironment: [
configuration: [steps: [checksPublishResults: [pmd: [active: true]]]]
]])
@ -163,7 +164,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithCustomPattern() throws Exception {
checksPublishResultsScript.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml'])
jsr.step.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml'])
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -180,7 +181,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithArchive() throws Exception {
checksPublishResultsScript.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true)
jsr.step.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 5)
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
@ -192,7 +193,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithPartialArchive() throws Exception {
checksPublishResultsScript.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true)
jsr.step.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 4)
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
@ -205,7 +206,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithDefaultThresholds() throws Exception {
checksPublishResultsScript.call(pmd: true)
jsr.step.call(pmd: true)
assertTrue("AnalysisPublisher options not set",
publisherStepOptions['AnalysisPublisher'] != null)
@ -239,7 +240,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithThresholds() throws Exception {
checksPublishResultsScript.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true)
jsr.step.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)

View File

@ -7,21 +7,26 @@ import static org.junit.Assert.assertTrue
import org.junit.rules.RuleChain
import util.Rules
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
class DurationMeasureTest extends BasePipelineTest {
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain rules = Rules.getCommonRules(this)
public RuleChain rules = Rules
.getCommonRules(this)
.around(jsr)
.around(jer)
@Test
void testDurationMeasurement() throws Exception {
def cpe = loadScript("commonPipelineEnvironment.groovy").commonPipelineEnvironment
def script = loadScript("durationMeasure.groovy")
def bodyExecuted = false
script.call(script: [commonPipelineEnvironment: cpe], measurementName: 'test') {
jsr.step.call(script: [commonPipelineEnvironment: jer.env], measurementName: 'test') {
bodyExecuted = true
}
assertTrue(cpe.getPipelineMeasurement('test') != null)
assertTrue(jer.env.getPipelineMeasurement('test') != null)
assertTrue(bodyExecuted)
assertJobStatusSuccess()
}

View File

@ -6,37 +6,36 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import util.Rules
import static org.junit.Assert.assertTrue
import static org.junit.Assert.assertEquals
class InfluxWriteDataTest extends BasePipelineTest {
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
Script influxWriteDataScript
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(loggingRule)
.around(jsr)
.around(jer)
Map fileMap = [:]
Map stepMap = [:]
String echoLog = ''
def cpe
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(loggingRule)
@Before
void init() throws Exception {
//
// Currently we have dependencies between the tests since
// DefaultValueCache is a singleton which keeps its status
// for all the tests. Depending on the test order we fail.
// As long as this status remains we need:
DefaultValueCache.reset()
//reset stepMap
stepMap = [:]
//reset fileMap
@ -48,20 +47,16 @@ class InfluxWriteDataTest extends BasePipelineTest {
steps : [influxWriteData: [influxServer: 'testInflux']]
]
})
helper.registerAllowedMethod('writeFile', [Map.class],{m -> fileMap[m.file] = m.text})
helper.registerAllowedMethod('step', [Map.class],{m -> stepMap = m})
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
influxWriteDataScript = loadScript("influxWriteData.groovy")
}
@Test
void testInfluxWriteDataWithDefault() throws Exception {
cpe.setArtifactVersion('1.2.3')
influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe])
jer.env.setArtifactVersion('1.2.3')
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assertTrue(loggingRule.log.contains('Artifact version: 1.2.3'))
@ -79,8 +74,8 @@ class InfluxWriteDataTest extends BasePipelineTest {
@Test
void testInfluxWriteDataNoInflux() throws Exception {
cpe.setArtifactVersion('1.2.3')
influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe], influxServer: '')
jer.env.setArtifactVersion('1.2.3')
jsr.step.call(script: [commonPipelineEnvironment: jer.env], influxServer: '')
assertEquals(0, stepMap.size())
@ -93,7 +88,7 @@ class InfluxWriteDataTest extends BasePipelineTest {
@Test
void testInfluxWriteDataNoArtifactVersion() throws Exception {
influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assertEquals(0, stepMap.size())
assertEquals(0, fileMap.size())

View File

@ -15,31 +15,34 @@ import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsShellCallRule
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import util.Rules
class NeoDeploymentTest extends BasePipelineTest {
class NeoDeployTest extends BasePipelineTest {
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
private ExpectedException thrown = new ExpectedException().none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(jlr)
.around(jscr)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jlr)
.around(jscr)
.around(jsr)
.around(jer)
private static workspacePath
private static warArchiveName
private static propertiesFileName
private static archiveName
def neoDeployScript
def cpe
@BeforeClass
static void createTestFiles() {
@ -78,22 +81,18 @@ class NeoDeploymentTest extends BasePipelineTest {
binding.setVariable('env', ['NEO_HOME':'/opt/neo'])
neoDeployScript = loadScript('neoDeploy.groovy').neoDeploy
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
cpe.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]]
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]]
}
@Test
void straightForwardTestConfigViaConfigProperties() {
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
jer.env.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
jer.env.configuration = [:]
cpe.configuration = [:]
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
@ -104,10 +103,10 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void straightForwardTestConfigViaConfiguration() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
}
@ -115,13 +114,13 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void straightForwardTestConfigViaConfigurationAndViaConfigProperties() {
cpe.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
jer.env.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
cpe.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com',
jer.env.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com',
account: 'configurationFrwkUser123']]]
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
@ -136,7 +135,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(MissingPropertyException)
thrown.expectMessage('No such property: username')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'badCredentialsId'
)
@ -146,7 +145,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void credentialsIdNotProvidedTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
@ -159,7 +158,7 @@ class NeoDeploymentTest extends BasePipelineTest {
binding.setVariable('env', [:])
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
@ -171,7 +170,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void neoHomeAsParameterTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId',
neoHome: '/etc/neo'
@ -185,7 +184,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void neoHomeFromEnvironmentTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
@ -197,9 +196,9 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void neoHomeFromCustomStepConfigurationTest() {
cpe.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/step/neo']]]
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/step/neo']]]
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
@ -214,7 +213,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage('Archive path not configured (parameter "archivePath").')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
}
@ -224,7 +223,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(AbortException)
thrown.expectMessage('Archive cannot be found')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: 'wrongArchiveName')
}
@ -235,15 +234,15 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
cpe.configuration = [:]
jer.env.configuration = [:]
neoDeployScript.call(archivePath: archiveName)
jsr.step.call(archivePath: archiveName)
}
@Test
void mtaDeployModeTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe], archivePath: archiveName, deployMode: 'mta')
jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, deployMode: 'mta')
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
}
@ -251,7 +250,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void warFileParamsDeployModeTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
@ -266,7 +265,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void warFileParamsDeployModeRollingUpdateTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
@ -281,7 +280,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void warPropertiesFileDeployModeTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warPropertiesFile',
propertiesFile: propertiesFileName,
@ -297,7 +296,7 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void warPropertiesFileDeployModeRollingUpdateTest() {
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warPropertiesFile',
propertiesFile: propertiesFileName,
@ -316,7 +315,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR applicationName')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
runtime: 'neo-javaee6-wp',
@ -330,7 +329,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
applicationName: 'testApp',
deployMode: 'warParams',
@ -343,7 +342,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
applicationName: 'testApp',
deployMode: 'warParams',
@ -356,7 +355,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'")
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'illegalMode',
applicationName: 'testApp',
@ -372,7 +371,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.")
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
@ -388,7 +387,7 @@ class NeoDeploymentTest extends BasePipelineTest {
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
@ -401,9 +400,9 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void deployHostProvidedAsDeprecatedParameterTest() {
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
deployHost: "my.deploy.host.com"
)
@ -414,9 +413,9 @@ class NeoDeploymentTest extends BasePipelineTest {
@Test
void deployAccountProvidedAsDeprecatedParameterTest() {
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
host: "my.deploy.host.com",
deployAccount: "myAccount"

View File

@ -9,24 +9,24 @@ import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsReadYamlRule
import util.JenkinsStepRule
class PipelineExecuteTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none()
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jsr)
def pipelinePath
def checkoutParameters = [:]
def load
def pipelineExecuteScript
@Before
void init() {
pipelinePath = null
checkoutParameters.clear()
load = null
@ -39,15 +39,12 @@ class PipelineExecuteTest extends BasePipelineTest {
checkoutParameters.path = m.extensions[0].sparseCheckoutPaths[0].path
})
helper.registerAllowedMethod('load', [String], { s -> load = s })
pipelineExecuteScript = loadScript("pipelineExecute.groovy").pipelineExecute
}
@Test
void straightForwardTest() {
pipelineExecuteScript.call(repoUrl: "https://test.com/myRepo.git")
jsr.step.call(repoUrl: "https://test.com/myRepo.git")
assert load == "Jenkinsfile"
assert checkoutParameters.branch == 'master'
assert checkoutParameters.repoUrl == "https://test.com/myRepo.git"
@ -58,8 +55,7 @@ class PipelineExecuteTest extends BasePipelineTest {
@Test
void parameterizeTest() {
pipelineExecuteScript.call(repoUrl: "https://test.com/anotherRepo.git",
jsr.step.call(repoUrl: "https://test.com/anotherRepo.git",
branch: 'feature',
path: 'path/to/Jenkinsfile',
credentialsId: 'abcd1234')
@ -74,10 +70,9 @@ class PipelineExecuteTest extends BasePipelineTest {
@Test
void noRepoUrlTest() {
thrown.expect(Exception)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR repoUrl")
pipelineExecuteScript.call()
jsr.step.call()
}
}

View File

@ -7,24 +7,26 @@ import org.yaml.snakeyaml.Yaml
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.Rules
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull
class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(jsr)
.around(jer)
def usedConfigFile
def setupCommonPipelineEnvironmentScript
def commonPipelineEnvironment
@Rule
public RuleChain rules = Rules.getCommonRules(this)
@Before
void init() {
def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
@ -32,26 +34,21 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
if(parameters.text) {
return yamlParser.load(parameters.text)
}
usedConfigFile = parameters.file
return yamlParser.load(examplePipelineConfig)
})
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 {
setupCommonPipelineEnvironmentScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assertEquals('.pipeline/config.yml', usedConfigFile)
assertNotNull(commonPipelineEnvironment.configuration)
assertEquals('develop', commonPipelineEnvironment.configuration.general.productiveBranch)
assertEquals('my-maven-docker', commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
assertNotNull(jer.env.configuration)
assertEquals('develop', jer.env.configuration.general.productiveBranch)
assertEquals('my-maven-docker', jer.env.configuration.steps.mavenExecute.dockerImage)
}
}

View File

@ -13,185 +13,166 @@ import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsLoggingRule
import util.JenkinsStepRule
import util.Rules
class ToolValidateTest extends BasePipelineTest {
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
private ExpectedException thrown = new ExpectedException().none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(jlr)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jlr)
.around(jsr)
private static home
private toolValidateScript
@BeforeClass
static void createTestFiles() {
home = "${tmp.getRoot()}"
tmp.newFile('mta.jar')
}
@Before
void init() {
binding.setVariable('JAVA_HOME', home)
toolValidateScript = loadScript('toolValidate.groovy').toolValidate
}
@Test
void nullHomeTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'home' can not be null or empty.")
toolValidateScript.call(tool: 'java', home: null)
jsr.step.call(tool: 'java', home: null)
}
@Test
void emptyHomeTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'home' can not be null or empty.")
toolValidateScript.call(tool: 'java', home: '')
jsr.step.call(tool: 'java', home: '')
}
@Test
void nullToolTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'tool' can not be null or empty.")
toolValidateScript.call(tool: null)
jsr.step.call(tool: null)
}
@Test
void emptyToolTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'tool' can not be null or empty.")
toolValidateScript.call(tool: '')
jsr.step.call(tool: '')
}
@Test
void invalidToolTest() {
thrown.expect(AbortException)
thrown.expectMessage("The tool 'test' is not supported.")
toolValidateScript.call(tool: 'test', home: home)
jsr.step.call(tool: 'test', home: home)
}
@Test
void unableToValidateJavaTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of Java failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'java', home: home)
jsr.step.call(tool: 'java', home: home)
}
@Test
void unableToValidateMtaTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of SAP Multitarget Application Archive Builder failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'mta', home: home)
jsr.step.call(tool: 'mta', home: home)
}
@Test
void unableToValidateNeoTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of SAP Cloud Platform Console Client failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'neo', home: home)
jsr.step.call(tool: 'neo', home: home)
}
@Test
void unableToValidateCmTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of Change Management Command Line Interface failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'cm', home: home)
jsr.step.call(tool: 'cm', home: home)
script.execute()
}
@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) })
toolValidateScript.call(tool: 'java', home: home)
jsr.step.call(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) })
toolValidateScript.call(tool: 'mta', home: home)
jsr.step.call(tool: 'mta', home: home)
}
@Test
void validateNeoIncompatibleVersionTest() {
thrown.expect(AbortException)
thrown.expectMessage('The installed version of SAP Cloud Platform Console Client is 1.126.51.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
toolValidateScript.call(tool: 'neo', home: home)
jsr.step.call(tool: 'neo', 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')
toolValidateScript.call(tool: 'cm', home: home)
jsr.step.call(tool: 'cm', home: home)
}
@Test
void validateJavaTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'java', home: home)
jsr.step.call(tool: 'java', home: home)
assert jlr.log.contains('[toolValidate] Validating Java version 1.8.0 or compatible version.')
assert jlr.log.contains('[toolValidate] Java version 1.8.0 is installed.')
@ -199,10 +180,9 @@ class ToolValidateTest extends BasePipelineTest {
@Test
void validateMtaTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'mta', home: home)
jsr.step.call(tool: 'mta', home: home)
assert jlr.log.contains('[toolValidate] Validating SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.')
assert jlr.log.contains('[toolValidate] SAP Multitarget Application Archive Builder version 1.0.6 is installed.')
@ -210,10 +190,9 @@ class ToolValidateTest extends BasePipelineTest {
@Test
void validateNeoTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'neo', home: home)
jsr.step.call(tool: 'neo', home: home)
assert jlr.log.contains('[toolValidate] Validating SAP Cloud Platform Console Client version 3.39.10 or compatible version.')
assert jlr.log.contains('[toolValidate] SAP Cloud Platform Console Client version 3.39.10 is installed.')
@ -221,21 +200,19 @@ class ToolValidateTest extends BasePipelineTest {
@Test
void validateCmTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'cm', home: home)
jsr.step.call(tool: 'cm', home: home)
assert jlr.log.contains('[toolValidate] Validating Change Management Command Line Interface version 0.0.1 or compatible version.')
assert jlr.log.contains('[toolValidate] Change Management Command Line Interface version 0.0.1 is installed.')
}
private getNoVersion(Map m) {
private getNoVersion(Map m) {
throw new AbortException('script returned exit code 127')
}
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)
@ -252,7 +229,6 @@ class ToolValidateTest extends BasePipelineTest {
}
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)
@ -268,4 +244,3 @@ class ToolValidateTest extends BasePipelineTest {
}
}
}