introduce JenkinsConfigRule

This commit is contained in:
Thorsten Duda
2018-01-23 15:02:25 +01:00
committed by Marcus Holl
parent 106a8b4693
commit e8363e9637
8 changed files with 54 additions and 10 deletions
+4 -2
View File
@@ -4,6 +4,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
@@ -19,6 +20,7 @@ class DockerExecuteTest extends PiperTestBase {
@Rule
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
.around(jlr)
.around(new JenkinsConfigRule(this))
int whichDockerReturnValue = 0
@@ -53,8 +55,8 @@ class DockerExecuteTest extends PiperTestBase {
assertTrue(docker.getParameters().contains(' --volume my_vol:/my_vol'))
}
@Test
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
@Test
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
whichDockerReturnValue = 1
def script = loadScript("test/resources/pipelines/dockerExecuteTest/executeInsideDockerWithParameters.groovy")
+2 -1
View File
@@ -7,7 +7,7 @@ import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import org.junit.rules.TemporaryFolder
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
@@ -26,6 +26,7 @@ public class MTABuildTest extends PiperTestBase {
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jscr)
.around(new JenkinsConfigRule(this))
def currentDir
def otherDir
+2
View File
@@ -7,6 +7,7 @@ import org.junit.rules.RuleChain
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import util.JenkinsConfigRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
@@ -19,6 +20,7 @@ class MavenExecuteTest extends PiperTestBase {
@Rule
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this))
.around(jscr)
.around(new JenkinsConfigRule(this))
@Before
void init() {
+2
View File
@@ -6,6 +6,7 @@ import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule
@@ -23,6 +24,7 @@ class NeoDeploymentTest extends PiperTestBase {
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jscr)
.around(new JenkinsConfigRule(this))
def archivePath
def warArchivePath
def propertiesFilePath
+2
View File
@@ -1,4 +1,5 @@
import hudson.AbortException
import util.JenkinsConfigRule
import util.JenkinsSetupRule
import org.junit.rules.TemporaryFolder
@@ -15,6 +16,7 @@ class PipelineExecuteTest extends PiperTestBase {
@Rule
public RuleChain ruleChain = RuleChain.outerRule(thrown)
.around(new JenkinsSetupRule(this))
.around(new JenkinsConfigRule(this))
def pipelinePath
def checkoutParameters = [:]
+1 -7
View File
@@ -1,5 +1,5 @@
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
import org.yaml.snakeyaml.Yaml
import static ProjectSource.projectSource
@@ -19,14 +19,8 @@ public class PiperTestBase extends BasePipelineTest {
super.setUp()
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
Yaml yamlParser = new Yaml()
return yamlParser.load(parameters.text)
})
pipeline = pipelineFolder.newFile()
DefaultValueCache.reset()
}
protected withPipeline(p) {
+3
View File
@@ -7,6 +7,7 @@ import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import org.junit.rules.TemporaryFolder
import util.JenkinsConfigRule
import util.JenkinsLoggingRule
import util.JenkinsSetupRule
@@ -15,6 +16,7 @@ class ToolValidateTest extends PiperTestBase {
private ExpectedException thrown = new ExpectedException().none()
private TemporaryFolder tmp = new TemporaryFolder()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsConfigRule jcr = new JenkinsConfigRule(this)
@Rule
public RuleChain ruleChain =
@@ -22,6 +24,7 @@ class ToolValidateTest extends PiperTestBase {
.around(thrown)
.around(new JenkinsSetupRule(this))
.around(jlr)
.around(jcr)
private notEmptyDir
private script
+38
View File
@@ -0,0 +1,38 @@
package util
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.yaml.snakeyaml.Yaml
class JenkinsConfigRule implements TestRule {
final BasePipelineTest testInstance
JenkinsConfigRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
}
@Override
Statement apply(Statement base, Description description) {
return statement(base)
}
private Statement statement(final Statement base) {
return new Statement() {
@Override
void evaluate() throws Throwable {
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
Yaml yamlParser = new Yaml()
return yamlParser.load(parameters.text)
})
DefaultValueCache.reset()
base.evaluate()
}
}
}
}