mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
speed up tests
* use new base class for testing * initialize jenkins unit test framework only once for all test classes * minor test cleanups
This commit is contained in:
parent
4ae3998458
commit
f8e5733486
@ -1,11 +1,11 @@
|
||||
#!groovy
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import com.sap.piper.GitUtils
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsDockerExecuteRule
|
||||
import util.JenkinsEnvironmentRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadMavenPomRule
|
||||
@ -14,16 +14,17 @@ import util.JenkinsStepRule
|
||||
import util.JenkinsWriteFileRule
|
||||
import util.Rules
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem
|
||||
import static org.junit.Assert.assertThat
|
||||
import static org.junit.Assert.assertEquals
|
||||
|
||||
class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
class ArtifactSetVersionTest extends BasePiperTest {
|
||||
Map dockerParameters
|
||||
def mavenExecuteScript
|
||||
|
||||
def gitUtils
|
||||
def sshAgentList = []
|
||||
|
||||
private ExpectedException thrown = ExpectedException.none()
|
||||
private JenkinsDockerExecuteRule jder = new JenkinsDockerExecuteRule(this)
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
private JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this)
|
||||
@ -38,6 +39,7 @@ class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
.around(jscr)
|
||||
.around(new JenkinsReadMavenPomRule(this, 'test/resources/MavenArtifactVersioning'))
|
||||
.around(jwfr)
|
||||
.around(jder)
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
@ -45,14 +47,6 @@ class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
void init() throws Throwable {
|
||||
dockerParameters = [:]
|
||||
|
||||
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
|
||||
{ parameters, closure ->
|
||||
dockerParameters = parameters
|
||||
closure()
|
||||
})
|
||||
|
||||
mavenExecuteScript = loadScript("mavenExecute.groovy").mavenExecute
|
||||
|
||||
helper.registerAllowedMethod("sshagent", [List.class, Closure.class], { list, closure ->
|
||||
sshAgentList = list
|
||||
return closure()
|
||||
@ -65,11 +59,7 @@ class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
|
||||
binding.setVariable('Jenkins', [instance: [pluginManager: [plugins: [new DockerExecuteTest.PluginMock()]]]])
|
||||
|
||||
|
||||
gitUtils = new GitUtils()
|
||||
prepareObjectInterceptors(gitUtils)
|
||||
|
||||
this.helper.registerAllowedMethod('fileExists', [String.class], {true})
|
||||
helper.registerAllowedMethod('fileExists', [String.class], {true})
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -79,12 +69,12 @@ class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
assertEquals('1.2.3-20180101010203_testCommitId', jer.env.getArtifactVersion())
|
||||
assertEquals('testCommitId', jer.env.getGitCommitId())
|
||||
|
||||
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId', jscr.shell[6])
|
||||
assertEquals('git add .', jscr.shell[7])
|
||||
assertEquals ("git commit -m 'update version 1.2.3-20180101010203_testCommitId'", jscr.shell[8])
|
||||
assertEquals ("git remote set-url origin myGitSshUrl", jscr.shell[9])
|
||||
assertEquals ("git tag build_1.2.3-20180101010203_testCommitId", jscr.shell[10])
|
||||
assertEquals ("git push origin build_1.2.3-20180101010203_testCommitId", jscr.shell[11])
|
||||
assertThat(jscr.shell, hasItem("mvn --file 'pom.xml' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId"))
|
||||
assertThat(jscr.shell, hasItem('git add .'))
|
||||
assertThat(jscr.shell, hasItem("git commit -m 'update version 1.2.3-20180101010203_testCommitId'"))
|
||||
assertThat(jscr.shell, hasItem("git remote set-url origin myGitSshUrl"))
|
||||
assertThat(jscr.shell, hasItem("git tag build_1.2.3-20180101010203_testCommitId"))
|
||||
assertThat(jscr.shell, hasItem("git push origin build_1.2.3-20180101010203_testCommitId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -92,7 +82,7 @@ class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
jsr.step.call(script: jsr.step, juStabGitUtils: gitUtils, buildTool: 'maven', commitVersion: false)
|
||||
|
||||
assertEquals('1.2.3-20180101010203_testCommitId', jer.env.getArtifactVersion())
|
||||
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId', jscr.shell[6])
|
||||
assertThat(jscr.shell, hasItem("mvn --file 'pom.xml' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -100,14 +90,14 @@ class ArtifactSetVersionTest extends BasePipelineTest {
|
||||
jsr.step.call(juStabGitUtils: gitUtils, buildTool: 'maven', commitVersion: false)
|
||||
|
||||
assertEquals('1.2.3-20180101010203_testCommitId', jer.env.getArtifactVersion())
|
||||
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId', jscr.shell[6])
|
||||
assertThat(jscr.shell, hasItem("mvn --file 'pom.xml' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVersioningCustomGitUserAndEMail() {
|
||||
jsr.step.call(script: jsr.step, juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test')
|
||||
|
||||
assertEquals ('git -c user.email="test@test.com" -c user.name="test" commit -m \'update version 1.2.3-20180101010203_testCommitId\'', jscr.shell[8])
|
||||
assertThat(jscr.shell, hasItem("git -c user.email=\"test@test.com\" -c user.name=\"test\" commit -m 'update version 1.2.3-20180101010203_testCommitId'"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4,7 +4,7 @@ import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
import org.junit.Ignore
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import util.BasePiperTest
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
@ -12,7 +12,7 @@ import static org.junit.Assert.assertTrue
|
||||
import util.Rules
|
||||
import util.JenkinsStepRule
|
||||
|
||||
class ChecksPublishResultsTest extends BasePipelineTest {
|
||||
class ChecksPublishResultsTest extends BasePiperTest {
|
||||
Map publisherStepOptions
|
||||
List archiveStepPatterns
|
||||
|
||||
|
@ -4,23 +4,20 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.Rules
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsEnvironmentRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.junit.Assert.assertFalse
|
||||
|
||||
class DockerExecuteTest extends BasePipelineTest {
|
||||
class DockerExecuteTest extends BasePiperTest {
|
||||
private DockerMock docker
|
||||
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
@ -44,7 +41,7 @@ class DockerExecuteTest extends BasePipelineTest {
|
||||
@Test
|
||||
void testExecuteInsideDocker() throws Exception {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine') {
|
||||
bodyExecuted = true
|
||||
}
|
||||
@ -58,7 +55,7 @@ class DockerExecuteTest extends BasePipelineTest {
|
||||
@Test
|
||||
void testExecuteInsideDockerWithParameters() throws Exception {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
dockerOptions: '-it',
|
||||
dockerVolumeBind: ['my_vol': '/my_vol'],
|
||||
@ -74,7 +71,7 @@ class DockerExecuteTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testExecuteDockerWithDockerOptionsList() throws Exception {
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
dockerOptions: ['-it', '--network=my-network'],
|
||||
dockerEnvVars: ['http_proxy': 'http://proxy:8000']) {
|
||||
@ -91,7 +88,7 @@ class DockerExecuteTest extends BasePipelineTest {
|
||||
|
||||
whichDockerReturnValue = 1
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
dockerOptions: '-it',
|
||||
dockerVolumeBind: ['my_vol': '/my_vol'],
|
||||
|
@ -1,32 +1,29 @@
|
||||
#!groovy
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import util.BasePiperTest
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.Rules
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsEnvironmentRule
|
||||
|
||||
class DurationMeasureTest extends BasePipelineTest {
|
||||
class DurationMeasureTest extends BasePiperTest {
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
@Test
|
||||
void testDurationMeasurement() throws Exception {
|
||||
def bodyExecuted = false
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env], measurementName: 'test') {
|
||||
jsr.step.call(script: nullScript, measurementName: 'test') {
|
||||
bodyExecuted = true
|
||||
}
|
||||
assertTrue(jer.env.getPipelineMeasurement('test') != null)
|
||||
assertTrue(nullScript.commonPipelineEnvironment.getPipelineMeasurement('test') != null)
|
||||
assertTrue(bodyExecuted)
|
||||
assertJobStatusSuccess()
|
||||
}
|
||||
|
@ -1,29 +1,26 @@
|
||||
#!groovy
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import com.sap.piper.DefaultValueCache
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
import util.BasePiperTest
|
||||
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 {
|
||||
class InfluxWriteDataTest extends BasePiperTest {
|
||||
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(loggingRule)
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
Map fileMap = [:]
|
||||
Map stepMap = [:]
|
||||
@ -55,8 +52,8 @@ class InfluxWriteDataTest extends BasePipelineTest {
|
||||
@Test
|
||||
void testInfluxWriteDataWithDefault() throws Exception {
|
||||
|
||||
jer.env.setArtifactVersion('1.2.3')
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3')
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assertTrue(loggingRule.log.contains('Artifact version: 1.2.3'))
|
||||
|
||||
@ -74,8 +71,8 @@ class InfluxWriteDataTest extends BasePipelineTest {
|
||||
@Test
|
||||
void testInfluxWriteDataNoInflux() throws Exception {
|
||||
|
||||
jer.env.setArtifactVersion('1.2.3')
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env], influxServer: '')
|
||||
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3')
|
||||
jsr.step.call(script: nullScript, influxServer: '')
|
||||
|
||||
assertEquals(0, stepMap.size())
|
||||
|
||||
@ -88,7 +85,7 @@ class InfluxWriteDataTest extends BasePipelineTest {
|
||||
@Test
|
||||
void testInfluxWriteDataNoArtifactVersion() throws Exception {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assertEquals(0, stepMap.size())
|
||||
assertEquals(0, fileMap.size())
|
||||
|
@ -9,16 +9,14 @@ import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.yaml.snakeyaml.parser.ParserException
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import hudson.AbortException
|
||||
import util.JenkinsEnvironmentRule
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
public class MtaBuildTest extends BasePipelineTest {
|
||||
public class MtaBuildTest extends BasePiperTest {
|
||||
|
||||
def toolMtaValidateCalled = false
|
||||
def toolJavaValidateCalled = false
|
||||
@ -30,7 +28,6 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
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
|
||||
@ -39,7 +36,6 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
private static currentDir
|
||||
private static newDir
|
||||
@ -88,10 +84,10 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
@Test
|
||||
void mtarFilePathFromCommonPipelineEnviromentTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
buildTarget: 'NEO')
|
||||
|
||||
def mtarFilePath = jer.env.getMtarFilePath()
|
||||
def mtarFilePath = nullScript.commonPipelineEnvironment.getMtarFilePath()
|
||||
|
||||
assert mtarFilePath == "$currentDir/com.mycompany.northwind.mtar"
|
||||
}
|
||||
@ -172,9 +168,9 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
@Test
|
||||
void mtaJarLocationFromCustomStepConfigurationTest() {
|
||||
|
||||
jer.env.configuration = [steps:[mtaBuild:[mtaJarLocation: '/config/mta/mta.jar']]]
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[mtaJarLocation: '/config/mta/mta.jar']]]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
buildTarget: 'NEO')
|
||||
|
||||
assert jscr.shell.find(){ c -> c.contains("-jar /config/mta/mta.jar --mtar")}
|
||||
@ -186,7 +182,7 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
@Test
|
||||
void mtaJarLocationFromDefaultStepConfigurationTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
buildTarget: 'NEO')
|
||||
|
||||
assert jscr.shell.find(){ c -> c.contains("-jar mta.jar --mtar")}
|
||||
@ -207,9 +203,9 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
@Test
|
||||
void buildTargetFromCustomStepConfigurationTest() {
|
||||
|
||||
jer.env.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assert jscr.shell.find(){ c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
|
||||
}
|
||||
@ -218,9 +214,9 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
@Test
|
||||
void buildTargetFromDefaultStepConfigurationTest() {
|
||||
|
||||
jer.env.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
|
||||
nullScript.commonPipelineEnvironment.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
|
||||
}
|
||||
@ -238,9 +234,9 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
@Test
|
||||
void extensionFromCustomStepConfigurationTest() {
|
||||
|
||||
jer.env.configuration = [steps:[mtaBuild:[buildTarget: 'NEO', extension: 'config_extension']]]
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[buildTarget: 'NEO', extension: 'config_extension']]]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assert jscr.shell.find(){ c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO --extension=config_extension build')}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import util.JenkinsDockerExecuteRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
@ -18,32 +19,21 @@ class MavenExecuteTest extends BasePiperTest {
|
||||
Map dockerParameters
|
||||
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
private JenkinsDockerExecuteRule jder = new JenkinsDockerExecuteRule(this)
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
.around(jscr)
|
||||
|
||||
def mavenExecuteScript
|
||||
|
||||
@Before
|
||||
void init() {
|
||||
|
||||
dockerParameters = [:]
|
||||
|
||||
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
|
||||
{ parameters, closure ->
|
||||
dockerParameters = parameters
|
||||
closure()
|
||||
})
|
||||
|
||||
mavenExecuteScript = loadScript("mavenExecute.groovy").mavenExecute
|
||||
}
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jder)
|
||||
.around(jscr)
|
||||
.around(jsr)
|
||||
|
||||
@Test
|
||||
void testExecuteBasicMavenCommand() throws Exception {
|
||||
|
||||
mavenExecuteScript.call(script: nullScript, goals: 'clean install')
|
||||
assertEquals('maven:3.5-jdk-7', dockerParameters.dockerImage)
|
||||
jsr.step.mavenExecute(script: nullScript, goals: 'clean install')
|
||||
assertEquals('maven:3.5-jdk-7', jder.dockerParams.dockerImage)
|
||||
|
||||
assert jscr.shell[0] == 'mvn clean install'
|
||||
}
|
||||
@ -51,7 +41,7 @@ class MavenExecuteTest extends BasePiperTest {
|
||||
@Test
|
||||
void testExecuteMavenCommandWithParameter() throws Exception {
|
||||
|
||||
mavenExecuteScript.call(
|
||||
jsr.step.mavenExecute(
|
||||
script: nullScript,
|
||||
dockerImage: 'maven:3.5-jdk-8-alpine',
|
||||
goals: 'clean install',
|
||||
@ -61,7 +51,7 @@ class MavenExecuteTest extends BasePiperTest {
|
||||
flags: '-o',
|
||||
m2Path: 'm2Path',
|
||||
defines: '-Dmaven.tests.skip=true')
|
||||
assertEquals('maven:3.5-jdk-8-alpine', dockerParameters.dockerImage)
|
||||
assertEquals('maven:3.5-jdk-8-alpine', jder.dockerParams.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(jscr.shell.contains(mvnCommand))
|
||||
}
|
||||
@ -69,8 +59,8 @@ class MavenExecuteTest extends BasePiperTest {
|
||||
@Test
|
||||
void testMavenCommandForwardsDockerOptions() throws Exception {
|
||||
|
||||
mavenExecuteScript.call(script: nullScript, goals: 'clean install')
|
||||
assertEquals('maven:3.5-jdk-7', dockerParameters.dockerImage)
|
||||
jsr.step.mavenExecute(script: nullScript, goals: 'clean install')
|
||||
assertEquals('maven:3.5-jdk-7', jder.dockerParams.dockerImage)
|
||||
|
||||
assert jscr.shell[0] == 'mvn clean install'
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ import hudson.AbortException
|
||||
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Ignore
|
||||
@ -12,15 +10,13 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsEnvironmentRule
|
||||
import util.Rules
|
||||
|
||||
class NeoDeployTest extends BasePipelineTest {
|
||||
class NeoDeployTest extends BasePiperTest {
|
||||
|
||||
def toolJavaValidateCalled = false
|
||||
|
||||
@ -31,7 +27,6 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
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
|
||||
@ -40,7 +35,6 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
private static workspacePath
|
||||
private static warArchiveName
|
||||
@ -86,18 +80,18 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithEnvVars(m) })
|
||||
|
||||
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]]
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]]
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfigProperties() {
|
||||
|
||||
jer.env.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
jer.env.configuration = [:]
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
@ -108,7 +102,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfiguration() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
@ -119,13 +113,13 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfigurationAndViaConfigProperties() {
|
||||
|
||||
jer.env.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
|
||||
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
jer.env.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com',
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com',
|
||||
account: 'configurationFrwkUser123']]]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
@ -140,7 +134,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(MissingPropertyException)
|
||||
thrown.expectMessage('No such property: username')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'badCredentialsId'
|
||||
)
|
||||
@ -150,7 +144,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void credentialsIdNotProvidedTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName
|
||||
)
|
||||
|
||||
@ -163,7 +157,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithPath(m) })
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName
|
||||
)
|
||||
|
||||
@ -178,7 +172,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithPath(m) })
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId',
|
||||
neoHome: '/param/neo'
|
||||
@ -193,7 +187,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void neoHomeFromEnvironmentTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName
|
||||
)
|
||||
|
||||
@ -208,9 +202,9 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithPath(m) })
|
||||
|
||||
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/config/neo']]]
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/config/neo']]]
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName
|
||||
)
|
||||
|
||||
@ -226,7 +220,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('Archive path not configured (parameter "archivePath").')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
jsr.step.call(script: nullScript)
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +230,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage('Archive cannot be found')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: 'wrongArchiveName')
|
||||
}
|
||||
|
||||
@ -247,7 +241,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
|
||||
|
||||
jer.env.configuration = [:]
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
jsr.step.call(archivePath: archiveName)
|
||||
}
|
||||
@ -255,7 +249,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void mtaDeployModeTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, deployMode: 'mta')
|
||||
jsr.step.call(script: nullScript, archivePath: archiveName, deployMode: 'mta')
|
||||
|
||||
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/}
|
||||
}
|
||||
@ -263,7 +257,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void warFileParamsDeployModeTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
@ -278,7 +272,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void warFileParamsDeployModeRollingUpdateTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
@ -293,7 +287,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void warPropertiesFileDeployModeTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warPropertiesFile',
|
||||
propertiesFile: propertiesFileName,
|
||||
@ -309,7 +303,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void warPropertiesFileDeployModeRollingUpdateTest() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warPropertiesFile',
|
||||
propertiesFile: propertiesFileName,
|
||||
@ -328,7 +322,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR applicationName')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warParams',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
@ -342,7 +336,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
applicationName: 'testApp',
|
||||
deployMode: 'warParams',
|
||||
@ -355,7 +349,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
applicationName: 'testApp',
|
||||
deployMode: 'warParams',
|
||||
@ -368,7 +362,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: [mta, warParams, warPropertiesFile]")
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'illegalMode',
|
||||
applicationName: 'testApp',
|
||||
@ -384,7 +378,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: [lite, pro, prem, prem-plus].")
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
@ -400,7 +394,7 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: [deploy, rolling-update].")
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
@ -413,9 +407,9 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void deployHostProvidedAsDeprecatedParameterTest() {
|
||||
|
||||
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
deployHost: "my.deploy.host.com"
|
||||
)
|
||||
@ -426,9 +420,9 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
@Test
|
||||
void deployAccountProvidedAsDeprecatedParameterTest() {
|
||||
|
||||
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
jsr.step.call(script: nullScript,
|
||||
archivePath: archiveName,
|
||||
host: "my.deploy.host.com",
|
||||
deployAccount: "myAccount"
|
||||
|
@ -1,17 +1,15 @@
|
||||
import util.BasePiperTest
|
||||
import util.Rules
|
||||
|
||||
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
|
||||
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
class PipelineExecuteTest extends BasePipelineTest {
|
||||
class PipelineExecuteTest extends BasePiperTest {
|
||||
private ExpectedException thrown = new ExpectedException().none()
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
|
||||
|
@ -4,26 +4,22 @@ import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.BasePiperTest
|
||||
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 {
|
||||
class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
||||
def usedConfigFile
|
||||
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
@Before
|
||||
void init() {
|
||||
@ -44,11 +40,11 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testIsConfigurationAvailable() throws Exception {
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
|
||||
jsr.step.call(script: nullScript)
|
||||
|
||||
assertEquals('.pipeline/config.yml', usedConfigFile)
|
||||
assertNotNull(jer.env.configuration)
|
||||
assertEquals('develop', jer.env.configuration.general.productiveBranch)
|
||||
assertEquals('my-maven-docker', jer.env.configuration.steps.mavenExecute.dockerImage)
|
||||
assertNotNull(nullScript.commonPipelineEnvironment.configuration)
|
||||
assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch)
|
||||
assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
|
||||
}
|
||||
}
|
||||
|
@ -4,28 +4,30 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsStepRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
import util.Rules
|
||||
|
||||
class TestsPublishResultsTest extends BasePipelineTest {
|
||||
class TestsPublishResultsTest extends BasePiperTest {
|
||||
Map publisherStepOptions
|
||||
List archiveStepPatterns
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = RuleChain.outerRule(Rules.getCommonRules(this))
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
|
||||
def testsPublishResultsScript
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jsr)
|
||||
|
||||
@Before
|
||||
void init() {
|
||||
publisherStepOptions = [:]
|
||||
archiveStepPatterns = []
|
||||
// prepare checkResultsPublish step
|
||||
testsPublishResultsScript = loadScript('testsPublishResults.groovy').testsPublishResults
|
||||
helper.registerAllowedMethod('junit', [Map.class], {
|
||||
parameters -> publisherStepOptions['junit'] = parameters
|
||||
})
|
||||
@ -45,7 +47,7 @@ class TestsPublishResultsTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingWithDefaultSettings() throws Exception {
|
||||
testsPublishResultsScript.call()
|
||||
jsr.step.testsPublishResults()
|
||||
|
||||
// ensure nothing is published
|
||||
assertTrue('WarningsPublisher options not empty', publisherStepOptions.junit == null)
|
||||
@ -56,7 +58,7 @@ class TestsPublishResultsTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testPublishNothingWithAllDisabled() throws Exception {
|
||||
testsPublishResultsScript.call(junit: false, jacoco: false, cobertura: false, jmeter: false)
|
||||
jsr.step.testsPublishResults(junit: false, jacoco: false, cobertura: false, jmeter: false)
|
||||
|
||||
// ensure nothing is published
|
||||
assertTrue('WarningsPublisher options not empty', publisherStepOptions.junit == null)
|
||||
@ -67,7 +69,7 @@ class TestsPublishResultsTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testPublishUnitTestsWithDefaultSettings() throws Exception {
|
||||
testsPublishResultsScript.call(junit: true)
|
||||
jsr.step.testsPublishResults(junit: true)
|
||||
|
||||
assertTrue('JUnit options are empty', publisherStepOptions.junit != null)
|
||||
// ensure default patterns are set
|
||||
@ -81,7 +83,7 @@ class TestsPublishResultsTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testPublishCoverageWithDefaultSettings() throws Exception {
|
||||
testsPublishResultsScript.call(jacoco: true, cobertura: true)
|
||||
jsr.step.testsPublishResults(jacoco: true, cobertura: true)
|
||||
|
||||
assertTrue('JaCoCo options are empty', publisherStepOptions.jacoco != null)
|
||||
assertTrue('Cobertura options are empty', publisherStepOptions.cobertura != null)
|
||||
@ -96,7 +98,7 @@ class TestsPublishResultsTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testPublishJMeterWithDefaultSettings() throws Exception {
|
||||
testsPublishResultsScript.call(jmeter: true)
|
||||
jsr.step.testsPublishResults(jmeter: true)
|
||||
|
||||
assertTrue('JMeter options are empty', publisherStepOptions.jmeter != null)
|
||||
assertEquals('JMeter default pattern not set',
|
||||
@ -110,7 +112,7 @@ class TestsPublishResultsTest extends BasePipelineTest {
|
||||
|
||||
@Test
|
||||
void testPublishUnitTestsWithCustomSettings() throws Exception {
|
||||
testsPublishResultsScript.call(junit: [pattern: 'fancy/file/path', archive: true, active: true])
|
||||
jsr.step.testsPublishResults(junit: [pattern: 'fancy/file/path', archive: true, active: true])
|
||||
|
||||
assertTrue('JUnit options are empty', publisherStepOptions.junit != null)
|
||||
// ensure default patterns are set
|
||||
|
@ -6,15 +6,13 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
class ToolValidateTest extends BasePipelineTest {
|
||||
class ToolValidateTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException().none()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
@ -122,8 +120,6 @@ class ToolValidateTest extends BasePipelineTest {
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
|
||||
|
||||
jsr.step.call(tool: 'cm', home: home)
|
||||
|
||||
script.execute()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -5,32 +5,21 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import com.sap.piper.EnvironmentUtils
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
class EnvironmentUtilsTest extends BasePipelineTest {
|
||||
class EnvironmentUtilsTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
|
||||
@Rule
|
||||
public RuleChain rules = Rules.getCommonRules(this)
|
||||
.around(thrown)
|
||||
|
||||
private script
|
||||
|
||||
|
||||
@Before
|
||||
void setup() {
|
||||
|
||||
script = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
||||
}
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(thrown)
|
||||
|
||||
@Test
|
||||
void isEnvironmentVariableFailedTest() {
|
||||
@ -40,7 +29,7 @@ class EnvironmentUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("There was an error requesting the environment variable 'JAVA_HOME'.")
|
||||
|
||||
EnvironmentUtils.isEnvironmentVariable(script, 'JAVA_HOME')
|
||||
EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -48,7 +37,7 @@ class EnvironmentUtilsTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> return '' })
|
||||
|
||||
def isEnvVar = EnvironmentUtils.isEnvironmentVariable(script, 'JAVA_HOME')
|
||||
def isEnvVar = EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME')
|
||||
|
||||
assert isEnvVar == false
|
||||
}
|
||||
@ -58,7 +47,7 @@ class EnvironmentUtilsTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> return '/env/java' })
|
||||
|
||||
def isEnvVar = EnvironmentUtils.isEnvironmentVariable(script, 'JAVA_HOME')
|
||||
def isEnvVar = EnvironmentUtils.isEnvironmentVariable(nullScript, 'JAVA_HOME')
|
||||
|
||||
assert isEnvVar == true
|
||||
}
|
||||
@ -71,7 +60,7 @@ class EnvironmentUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("There was an error requesting the environment variable 'JAVA_HOME'.")
|
||||
|
||||
EnvironmentUtils.getEnvironmentVariable(script, 'JAVA_HOME')
|
||||
EnvironmentUtils.getEnvironmentVariable(nullScript, 'JAVA_HOME')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -79,7 +68,7 @@ class EnvironmentUtilsTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> return '/env/java' })
|
||||
|
||||
def envVar = EnvironmentUtils.getEnvironmentVariable(script, 'JAVA_HOME')
|
||||
def envVar = EnvironmentUtils.getEnvironmentVariable(nullScript, 'JAVA_HOME')
|
||||
|
||||
assert envVar == '/env/java'
|
||||
}
|
||||
|
@ -8,17 +8,13 @@ import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.Rules
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import com.sap.piper.FileUtils
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
class FileUtilsTest extends BasePipelineTest {
|
||||
class FileUtilsTest extends BasePiperTest {
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder tmp = new TemporaryFolder()
|
||||
@ -33,8 +29,6 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
private static notEmptyDir
|
||||
private static file
|
||||
|
||||
private static script
|
||||
|
||||
@BeforeClass
|
||||
static void createTestFiles() {
|
||||
|
||||
@ -43,20 +37,13 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
file = tmp.newFile('notEmptyDir/file.txt').getAbsolutePath()
|
||||
}
|
||||
|
||||
@Before
|
||||
void setup() {
|
||||
|
||||
script = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void validateDirectory_nullParameterTest() {
|
||||
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'dir' can not be null or empty.")
|
||||
|
||||
FileUtils.validateDirectory(script, null)
|
||||
FileUtils.validateDirectory(nullScript, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -65,7 +52,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'dir' can not be null or empty.")
|
||||
|
||||
FileUtils.validateDirectory(script, '')
|
||||
FileUtils.validateDirectory(nullScript, '')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,7 +65,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Validation failed. '$dir' does not exist.")
|
||||
|
||||
FileUtils.validateDirectory(script, dir)
|
||||
FileUtils.validateDirectory(nullScript, dir)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -89,7 +76,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Validation failed. '$file' is not a directory.")
|
||||
|
||||
FileUtils.validateDirectory(script, file)
|
||||
FileUtils.validateDirectory(nullScript, file)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,7 +84,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, notEmptyDir) })
|
||||
|
||||
FileUtils.validateDirectory(script, notEmptyDir)
|
||||
FileUtils.validateDirectory(nullScript, notEmptyDir)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -108,7 +95,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Validation failed. '$emptyDir' is empty.")
|
||||
|
||||
FileUtils.validateDirectoryIsNotEmpty(script, emptyDir)
|
||||
FileUtils.validateDirectoryIsNotEmpty(nullScript, emptyDir)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -116,7 +103,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, notEmptyDir) })
|
||||
|
||||
FileUtils.validateDirectoryIsNotEmpty(script, notEmptyDir)
|
||||
FileUtils.validateDirectoryIsNotEmpty(nullScript, notEmptyDir)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -125,7 +112,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'filePath' can not be null or empty.")
|
||||
|
||||
FileUtils.validateFile(script, null)
|
||||
FileUtils.validateFile(nullScript, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -134,7 +121,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("The parameter 'filePath' can not be null or empty.")
|
||||
|
||||
FileUtils.validateFile(script, '')
|
||||
FileUtils.validateFile(nullScript, '')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -147,7 +134,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Validation failed. '$path' does not exist.")
|
||||
|
||||
FileUtils.validateFile(script, path)
|
||||
FileUtils.validateFile(nullScript, path)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -155,7 +142,7 @@ class FileUtilsTest extends BasePipelineTest {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> script(m, file) })
|
||||
|
||||
FileUtils.validateFile(script, file)
|
||||
FileUtils.validateFile(nullScript, file)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,19 +1,18 @@
|
||||
package com.sap.piper
|
||||
|
||||
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
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsShellCallRule
|
||||
import util.MockHelper
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertNull
|
||||
|
||||
class GitUtilsTest extends BasePipelineTest {
|
||||
class GitUtilsTest extends BasePiperTest {
|
||||
|
||||
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
ExpectedException thrown = ExpectedException.none()
|
||||
@ -21,22 +20,11 @@ class GitUtilsTest extends BasePipelineTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this).around(jscr).around(thrown)
|
||||
|
||||
GitUtils gitUtils
|
||||
|
||||
@Before
|
||||
void init() throws Exception {
|
||||
gitUtils = new GitUtils()
|
||||
prepareObjectInterceptors(gitUtils)
|
||||
|
||||
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
|
||||
}
|
||||
|
||||
void prepareObjectInterceptors(object) {
|
||||
object.metaClass.invokeMethod = helper.getMethodInterceptor()
|
||||
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
|
||||
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGitCommitId() {
|
||||
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 0)
|
||||
|
@ -9,15 +9,13 @@ import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import hudson.AbortException
|
||||
import util.JenkinsEnvironmentRule
|
||||
import util.BasePiperTest
|
||||
import util.Rules
|
||||
|
||||
|
||||
class MtaUtilsTest extends BasePipelineTest {
|
||||
class MtaUtilsTest extends BasePiperTest {
|
||||
private static srcPackageJson = 'test/resources/MtaUtils/package.json'
|
||||
private static mtaTemplate = 'resources/template_mta.yml'
|
||||
private static data
|
||||
@ -26,26 +24,15 @@ class MtaUtilsTest extends BasePipelineTest {
|
||||
private File badJson
|
||||
private mtaUtils
|
||||
|
||||
@Rule
|
||||
public JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
|
||||
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown= ExpectedException.none();
|
||||
private ExpectedException thrown= ExpectedException.none();
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder tmp = new TemporaryFolder()
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jer)
|
||||
|
||||
void prepareObjectInterceptors(object) {
|
||||
object.metaClass.invokeMethod = helper.getMethodInterceptor()
|
||||
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
|
||||
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
|
||||
}
|
||||
.getCommonRules(this)
|
||||
.around(thrown)
|
||||
|
||||
@Before
|
||||
void init() {
|
||||
|
@ -7,20 +7,13 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsErrorRule
|
||||
import util.Rules
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import com.sap.piper.tools.ToolDescriptor
|
||||
import com.sap.piper.tools.JavaArchiveDescriptor
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
class JavaArchiveDescriptorTest extends BasePipelineTest {
|
||||
class JavaArchiveDescriptorTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
|
@ -6,18 +6,13 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.Rules
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
import com.sap.piper.tools.ToolDescriptor
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
class ToolDescriptorTest extends BasePipelineTest {
|
||||
class ToolDescriptorTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
|
@ -1,22 +1,20 @@
|
||||
package com.sap.piper.versioning
|
||||
|
||||
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
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadFileRule
|
||||
import util.JenkinsReadMavenPomRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsWriteFileRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
class DockerArtifactVersioningTest extends BasePipelineTest{
|
||||
class DockerArtifactVersioningTest extends BasePiperTest{
|
||||
|
||||
DockerArtifactVersioning av
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.sap.piper.versioning
|
||||
|
||||
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
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsReadMavenPomRule
|
||||
@ -16,7 +14,6 @@ import static org.junit.Assert.assertEquals
|
||||
class MavenArtifactVersioningTest extends BasePiperTest{
|
||||
|
||||
Map dockerParameters
|
||||
def mavenExecuteScript
|
||||
def commonPipelineEnvironment
|
||||
|
||||
MavenArtifactVersioning av
|
||||
|
@ -3,6 +3,7 @@
|
||||
package util
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
import org.junit.Before
|
||||
import org.junit.runner.RunWith
|
||||
@ -22,6 +23,9 @@ abstract class BasePiperTest extends BasePipelineTest {
|
||||
@Autowired
|
||||
Script nullScript
|
||||
|
||||
@Autowired
|
||||
GitUtils gitUtils
|
||||
|
||||
@Autowired
|
||||
Utils utils
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
package util
|
||||
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
import org.codehaus.groovy.runtime.InvokerHelper
|
||||
import org.springframework.context.annotation.Bean
|
||||
@ -18,6 +19,13 @@ class BasePiperTestContext {
|
||||
return nullScript
|
||||
}
|
||||
|
||||
@Bean
|
||||
GitUtils mockGitUtils() {
|
||||
def mockGitUtils = new GitUtils()
|
||||
LibraryLoadingTestExecutionListener.prepareObjectInterceptors(mockGitUtils)
|
||||
return mockGitUtils
|
||||
}
|
||||
|
||||
@Bean
|
||||
Utils mockUtils() {
|
||||
def mockUtils = new Utils()
|
||||
|
37
test/groovy/util/JenkinsDockerExecuteRule.groovy
Normal file
37
test/groovy/util/JenkinsDockerExecuteRule.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 JenkinsDockerExecuteRule implements TestRule {
|
||||
|
||||
final BasePipelineTest testInstance
|
||||
|
||||
def dockerParams = [:]
|
||||
|
||||
JenkinsDockerExecuteRule(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("dockerExecute", [Map.class, Closure.class], {map, closure ->
|
||||
dockerParams = map
|
||||
return closure()
|
||||
})
|
||||
|
||||
base.evaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user