mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Merge pull request #277 from marcusholl/pr/readYaml
Improve JenkinsRule for reading yaml files / mta build without absolute pathes
This commit is contained in:
commit
1e50b26f19
@ -9,6 +9,7 @@ import util.JenkinsDockerExecuteRule
|
||||
import util.JenkinsEnvironmentRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadMavenPomRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsWriteFileRule
|
||||
@ -38,6 +39,7 @@ class ArtifactSetVersionTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
|
@ -20,6 +20,7 @@ class BatsExecuteTestsTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jder)
|
||||
.around(jscr)
|
||||
|
@ -1,5 +1,4 @@
|
||||
import org.junit.After
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
@ -12,6 +11,7 @@ import com.sap.piper.cm.ChangeManagementException
|
||||
import hudson.AbortException
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsCredentialsRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
@ -23,6 +23,7 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jsr)
|
||||
.around(new JenkinsCredentialsRule(this)
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -9,9 +10,12 @@ import util.BasePiperTest
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
|
||||
import util.Rules
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
|
||||
class ChecksPublishResultsTest extends BasePiperTest {
|
||||
Map publisherStepOptions
|
||||
List archiveStepPatterns
|
||||
@ -21,6 +25,7 @@ class ChecksPublishResultsTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jsr)
|
||||
|
||||
@Before
|
||||
|
@ -12,6 +12,7 @@ import util.JenkinsLoggingRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsWriteFileRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertThat
|
||||
@ -29,10 +30,12 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
private JenkinsDockerExecuteRule jedr = new JenkinsDockerExecuteRule(this)
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
|
||||
private JenkinsReadYamlRule jryr = new JenkinsReadYamlRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jryr)
|
||||
.around(thrown)
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
@ -180,17 +183,7 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
@Test
|
||||
void testCfNativeAppNameFromManifest() {
|
||||
helper.registerAllowedMethod('fileExists', [String.class], { s -> return true })
|
||||
helper.registerAllowedMethod("readYaml", [Map], { Map m ->
|
||||
if(m.text) {
|
||||
return new Yaml().load(m.text)
|
||||
} else if(m.file == 'test.yml') {
|
||||
return [applications: [[name: 'manifestAppName']]]
|
||||
} else if(m.file) {
|
||||
return new Yaml().load((m.file as File).text)
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key 'text' is missing in map ${m}.")
|
||||
}
|
||||
})
|
||||
jryr.registerYaml('test.yml', "[applications: [[name: 'manifestAppName']]]")
|
||||
|
||||
jsr.step.cloudFoundryDeploy([
|
||||
script: nullScript,
|
||||
@ -209,18 +202,7 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
@Test
|
||||
void testCfNativeWithoutAppName() {
|
||||
helper.registerAllowedMethod('fileExists', [String.class], { s -> return true })
|
||||
helper.registerAllowedMethod("readYaml", [Map], { Map m ->
|
||||
if(m.text) {
|
||||
return new Yaml().load(m.text)
|
||||
} else if(m.file == 'test.yml') {
|
||||
return [applications: [[]]]
|
||||
} else if(m.file) {
|
||||
return new Yaml().load((m.file as File).text)
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key 'text' is missing in map ${m}.")
|
||||
}
|
||||
})
|
||||
|
||||
jryr.registerYaml('test.yml', "applications: [[]]")
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage('[cloudFoundryDeploy] ERROR: No appName available in manifest test.yml.')
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
import com.sap.piper.JenkinsUtils
|
||||
|
||||
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.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.PluginMock
|
||||
@ -27,6 +30,7 @@ class DockerExecuteOnKubernetesTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(exception)
|
||||
.around(jder)
|
||||
.around(jscr)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import com.sap.piper.k8s.ContainerMap
|
||||
import com.sap.piper.JenkinsUtils
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -7,6 +8,7 @@ import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
import util.PluginMock
|
||||
import util.Rules
|
||||
@ -23,6 +25,7 @@ class DockerExecuteTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jlr)
|
||||
.around(jsr)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!groovy
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import util.BasePiperTest
|
||||
@ -7,14 +8,17 @@ import static org.junit.Assert.assertTrue
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.Rules
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
|
||||
class DurationMeasureTest extends BasePiperTest {
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jsr)
|
||||
|
||||
@Test
|
||||
|
@ -7,6 +7,7 @@ import org.junit.rules.RuleChain
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
@ -19,6 +20,7 @@ class InfluxWriteDataTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(loggingRule)
|
||||
.around(jsr)
|
||||
|
||||
|
@ -12,6 +12,7 @@ import org.yaml.snakeyaml.parser.ParserException
|
||||
import hudson.AbortException
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
@ -28,35 +29,26 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
||||
private JenkinsReadYamlRule jryr = new JenkinsReadYamlRule(this).registerYaml('mta.yaml', defaultMtaYaml() )
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jryr)
|
||||
.around(thrown)
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
.around(jsr)
|
||||
|
||||
private static currentDir
|
||||
private static newDir
|
||||
private static mtaYaml
|
||||
|
||||
@BeforeClass
|
||||
static void createTestFiles() {
|
||||
|
||||
currentDir = "${tmp.getRoot()}"
|
||||
mtaYaml = tmp.newFile('mta.yaml')
|
||||
newDir = "$currentDir/newDir"
|
||||
tmp.newFolder('newDir')
|
||||
tmp.newFile('newDir/mta.yaml') << defaultMtaYaml()
|
||||
}
|
||||
|
||||
@Before
|
||||
void init() {
|
||||
mtaYaml.text = defaultMtaYaml()
|
||||
|
||||
helper.registerAllowedMethod('pwd', [], { currentDir } )
|
||||
helper.registerAllowedMethod('fileExists', [GString.class], { false })
|
||||
helper.registerAllowedMethod('fileExists', [String], { s -> false })
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithoutEnvVars(m) })
|
||||
|
||||
binding.setVariable('PATH', '/usr/bin')
|
||||
@ -77,7 +69,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
|
||||
jsr.step.call(buildTarget: 'NEO')
|
||||
|
||||
assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/}
|
||||
assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" "mta.yaml"$/}
|
||||
}
|
||||
|
||||
|
||||
@ -89,23 +81,9 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
|
||||
def mtarFilePath = nullScript.commonPipelineEnvironment.getMtarFilePath()
|
||||
|
||||
assert mtarFilePath == "$currentDir/com.mycompany.northwind.mtar"
|
||||
assert mtarFilePath == "com.mycompany.northwind.mtar"
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void mtaBuildWithSurroundingDirTest() {
|
||||
|
||||
helper.registerAllowedMethod('pwd', [], { newDir } )
|
||||
|
||||
def mtarFilePath = jsr.step.call(buildTarget: 'NEO')
|
||||
|
||||
assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/}
|
||||
|
||||
assert mtarFilePath == "$newDir/com.mycompany.northwind.mtar"
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void mtaJarLocationAsParameterTest() {
|
||||
|
||||
@ -121,7 +99,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
@Test
|
||||
void noMtaPresentTest() {
|
||||
|
||||
mtaYaml.delete()
|
||||
jryr.registerYaml('mta.yaml', { throw new FileNotFoundException() })
|
||||
thrown.expect(FileNotFoundException)
|
||||
|
||||
jsr.step.call(buildTarget: 'NEO')
|
||||
@ -134,7 +112,7 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
thrown.expect(ParserException)
|
||||
thrown.expectMessage('while parsing a block mapping')
|
||||
|
||||
mtaYaml.text = badMtaYaml()
|
||||
jryr.registerYaml('mta.yaml', badMtaYaml())
|
||||
|
||||
jsr.step.call(buildTarget: 'NEO')
|
||||
}
|
||||
@ -144,9 +122,9 @@ public class MtaBuildTest extends BasePiperTest {
|
||||
void noIdInMtaTest() {
|
||||
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Property 'ID' not found in mta.yaml file at: '")
|
||||
thrown.expectMessage("Property 'ID' not found in mta.yaml file.")
|
||||
|
||||
mtaYaml.text = noIdMtaYaml()
|
||||
jryr.registerYaml('mta.yaml', noIdMtaYaml() )
|
||||
|
||||
jsr.step.call(buildTarget: 'NEO')
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsDockerExecuteRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
@ -15,7 +17,6 @@ import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertThat
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
|
||||
class MavenExecuteTest extends BasePiperTest {
|
||||
|
||||
Map dockerParameters
|
||||
@ -27,6 +28,7 @@ class MavenExecuteTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jder)
|
||||
.around(jscr)
|
||||
.around(jsr)
|
||||
|
@ -13,8 +13,10 @@ 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.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
@ -34,6 +36,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
|
@ -12,6 +12,7 @@ import static org.junit.Assert.assertThat
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsDockerExecuteRule
|
||||
import util.Rules
|
||||
@ -27,6 +28,7 @@ class NewmanExecuteTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jedr)
|
||||
.around(jscr)
|
||||
|
@ -7,6 +7,7 @@ import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
class PipelineExecuteTest extends BasePiperTest {
|
||||
@ -16,6 +17,7 @@ class PipelineExecuteTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jsr)
|
||||
|
||||
|
@ -15,6 +15,7 @@ class PipelineStashFilesAfterBuildTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jrj)
|
||||
.around(jlr)
|
||||
.around(jsr)
|
||||
|
@ -15,6 +15,7 @@ class PipelineStashFilesBeforeBuildTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain rules = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
//.around(jrj)
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
|
@ -3,13 +3,14 @@ import org.junit.Rule;
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain;
|
||||
|
||||
import com.sap.piper.DefaultValueCache
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule;
|
||||
|
||||
import util.Rules
|
||||
|
||||
public class PrepareDefaultValuesTest extends BasePiperTest {
|
||||
@ -21,6 +22,7 @@ public class PrepareDefaultValuesTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jsr)
|
||||
.around(jlr)
|
||||
|
@ -6,11 +6,13 @@ import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.Rules
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertNotNull
|
||||
|
||||
|
||||
class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
||||
def usedConfigFile
|
||||
|
||||
|
@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsDockerExecuteRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
@ -26,6 +27,7 @@ class SnykExecuteTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jder)
|
||||
.around(jscr)
|
||||
|
@ -5,8 +5,8 @@ import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
@ -21,6 +21,7 @@ class TestsPublishResultsTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jsr)
|
||||
|
||||
@Before
|
||||
|
@ -9,6 +9,7 @@ import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
@ -21,6 +22,7 @@ class ToolValidateTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jlr)
|
||||
.around(jsr)
|
||||
|
@ -11,11 +11,11 @@ import util.BasePiperTest
|
||||
import util.JenkinsCredentialsRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.Rules
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
public class TransportRequestCreateTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
@ -24,6 +24,7 @@ public class TransportRequestCreateTest extends BasePiperTest {
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jsr)
|
||||
.around(jlr)
|
||||
|
@ -11,12 +11,12 @@ import util.BasePiperTest
|
||||
import util.JenkinsCredentialsRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.Rules
|
||||
|
||||
import hudson.AbortException
|
||||
import hudson.scm.NullSCM
|
||||
|
||||
|
||||
public class TransportRequestReleaseTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
@ -25,6 +25,7 @@ public class TransportRequestReleaseTest extends BasePiperTest {
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
.around(jsr)
|
||||
.around(jlr)
|
||||
|
@ -13,11 +13,11 @@ import util.BasePiperTest
|
||||
import util.JenkinsCredentialsRule
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.Rules
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
|
||||
public class TransportRequestUploadFileTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = new ExpectedException()
|
||||
@ -27,6 +27,7 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
.around(thrown)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jsr)
|
||||
.around(jlr)
|
||||
.around(new JenkinsCredentialsRule(this)
|
||||
|
@ -12,6 +12,7 @@ import org.yaml.snakeyaml.Yaml
|
||||
import groovy.json.JsonSlurper
|
||||
import hudson.AbortException
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.Rules
|
||||
|
||||
|
||||
@ -32,6 +33,7 @@ class MtaUtilsTest extends BasePiperTest {
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(thrown)
|
||||
|
||||
@Before
|
||||
|
@ -4,8 +4,10 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsReadMavenPomRule
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.Rules
|
||||
|
||||
@ -23,6 +25,7 @@ class MavenArtifactVersioningTest extends BasePiperTest{
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(new JenkinsReadYamlRule(this))
|
||||
.around(jscr)
|
||||
.around(new JenkinsReadMavenPomRule(this, 'test/resources/versioning/MavenArtifactVersioning'))
|
||||
|
||||
|
@ -12,13 +12,12 @@ import static org.junit.Assert.assertEquals
|
||||
|
||||
class MtaArtifactVersioningTest extends BasePiperTest{
|
||||
|
||||
JenkinsReadYamlRule jryr = new JenkinsReadYamlRule(this, 'test/resources/versioning/MtaArtifactVersioning/')
|
||||
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jryr)
|
||||
.around(new JenkinsReadYamlRule(this).registerYaml('mta.yaml', "version: '1.2.3'"))
|
||||
.around(jscr)
|
||||
|
||||
@Test
|
||||
|
@ -1,21 +1,27 @@
|
||||
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
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
|
||||
class JenkinsReadYamlRule implements TestRule {
|
||||
final BasePipelineTest testInstance
|
||||
final String testRoot
|
||||
|
||||
JenkinsReadYamlRule(BasePipelineTest testInstance, testRoot = '') {
|
||||
// Empty project configuration file registered by default
|
||||
// since almost every test needs it.
|
||||
def ymls = ['.pipeline/config.yml': {''}]
|
||||
|
||||
JenkinsReadYamlRule(BasePipelineTest testInstance) {
|
||||
this.testInstance = testInstance
|
||||
this.testRoot = testRoot
|
||||
}
|
||||
|
||||
JenkinsReadYamlRule registerYaml(fileName, yaml) {
|
||||
ymls.put(fileName, yaml)
|
||||
return this
|
||||
}
|
||||
@Override
|
||||
Statement apply(Statement base, Description description) {
|
||||
return statement(base)
|
||||
@ -26,13 +32,17 @@ class JenkinsReadYamlRule implements TestRule {
|
||||
@Override
|
||||
void evaluate() throws Throwable {
|
||||
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map m ->
|
||||
def yml
|
||||
if(m.text) {
|
||||
return new Yaml().load(m.text)
|
||||
yml = m.text
|
||||
} else if(m.file) {
|
||||
return new Yaml().load(("${this.testRoot}${m.file}" as File).text)
|
||||
yml = ymls.get(m.file)
|
||||
if(yml == null) throw new NullPointerException("yaml file '${m.file}' not registered.")
|
||||
if(yml instanceof Closure) yml = yml()
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key 'text' is missing in map ${m}.")
|
||||
throw new IllegalArgumentException("Key 'text' and 'file' are both missing in map ${m}.")
|
||||
}
|
||||
return new Yaml().load(yml)
|
||||
})
|
||||
|
||||
base.evaluate()
|
||||
|
@ -13,7 +13,6 @@ public class Rules {
|
||||
|
||||
public static RuleChain getCommonRules(BasePipelineTest testCase, LibraryConfiguration libConfig) {
|
||||
return RuleChain.outerRule(new JenkinsSetupRule(testCase, libConfig))
|
||||
.around(new JenkinsReadYamlRule(testCase))
|
||||
.around(new JenkinsResetDefaultCacheRule())
|
||||
.around(new JenkinsErrorRule(testCase))
|
||||
.around(new JenkinsEnvironmentRule(testCase))
|
||||
|
@ -1,11 +0,0 @@
|
||||
_schema-version: "2.0"
|
||||
ID: com.sap.samples.anything
|
||||
version: 1.2.3
|
||||
|
||||
modules:
|
||||
- name: any-ui
|
||||
type: html5
|
||||
path: any-ui/
|
||||
|
||||
resources:
|
||||
- name: any-resource
|
@ -38,26 +38,26 @@ def call(Map parameters = [:]) {
|
||||
def mta = new JavaArchiveDescriptor('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '1.0.6', '-v', java)
|
||||
mta.verify(this, configuration)
|
||||
|
||||
def mtaYmlName = "${pwd()}/mta.yaml"
|
||||
def mtaYamlName = "mta.yaml"
|
||||
def applicationName = configuration.applicationName
|
||||
|
||||
if (!fileExists(mtaYmlName)) {
|
||||
if (!fileExists(mtaYamlName)) {
|
||||
if (!applicationName) {
|
||||
echo "'applicationName' not provided as parameter - will not try to generate mta.yml file"
|
||||
echo "'applicationName' not provided as parameter - will not try to generate ${mtaYamlName} file"
|
||||
} else {
|
||||
MtaUtils mtaUtils = new MtaUtils(this)
|
||||
mtaUtils.generateMtaDescriptorFromPackageJson("${pwd()}/package.json", mtaYmlName, applicationName)
|
||||
mtaUtils.generateMtaDescriptorFromPackageJson("package.json", mtaYamlName, applicationName)
|
||||
}
|
||||
}
|
||||
|
||||
def mtaYaml = readYaml file: "${pwd()}/mta.yaml"
|
||||
def mtaYaml = readYaml file: mtaYamlName
|
||||
|
||||
//[Q]: Why not yaml.dump()? [A]: This reformats the whole file.
|
||||
sh "sed -ie \"s/\\\${timestamp}/`date +%Y%m%d%H%M%S`/g\" \"${pwd()}/mta.yaml\""
|
||||
sh "sed -ie \"s/\\\${timestamp}/`date +%Y%m%d%H%M%S`/g\" \"${mtaYamlName}\""
|
||||
|
||||
def id = mtaYaml.ID
|
||||
if (!id) {
|
||||
error "Property 'ID' not found in mta.yaml file at: '${pwd()}'"
|
||||
error "Property 'ID' not found in ${mtaYamlName} file."
|
||||
}
|
||||
|
||||
def mtarFileName = "${id}.mtar"
|
||||
@ -74,7 +74,7 @@ def call(Map parameters = [:]) {
|
||||
$mtaCall
|
||||
"""
|
||||
|
||||
def mtarFilePath = "${pwd()}/${mtarFileName}"
|
||||
def mtarFilePath = "${mtarFileName}"
|
||||
script?.commonPipelineEnvironment?.setMtarFilePath(mtarFilePath)
|
||||
|
||||
return mtarFilePath
|
||||
|
Loading…
x
Reference in New Issue
Block a user