1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/com/sap/piper/mta/MtaMultiplexerTest.groovy
2018-06-27 14:38:57 +02:00

79 lines
3.1 KiB
Groovy

package com.sap.piper.mta
import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.hasEntry
import static org.hamcrest.Matchers.hasItem
import static org.hamcrest.Matchers.hasKey
import static org.hamcrest.Matchers.hasSize
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.not
import static org.junit.Assert.assertThat
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
class MtaMultiplexerTest extends BasePiperTest {
private ExpectedException thrown = ExpectedException.none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(jlr)
.around(thrown)
@Test
void testFilterFiles() {
// prepare test data
def files = [
new File("pom.xml"),
new File("some-ui${File.separator}pom.xml"),
new File("some-service${File.separator}pom.xml"),
new File("some-other-service${File.separator}pom.xml")
].toArray()
// execute test
def result = MtaMultiplexer.removeExcludedFiles(nullScript, files, ['pom.xml'])
// asserts
assertThat(result, not(hasItem('pom.xml')))
assertThat(result, hasSize(3))
assertThat(jlr.log, containsString('Skipping pom.xml'))
}
@Test
void testCreateJobs() {
def optionsList = []
// prepare test data
helper.registerAllowedMethod("findFiles", [Map.class], { map ->
if (map.glob == "**${File.separator}pom.xml") {
return [new File("some-service${File.separator}pom.xml"), new File("some-other-service${File.separator}pom.xml")].toArray()
}
if (map.glob == "**${File.separator}package.json") {
return [new File("some-ui${File.separator}package.json"), new File("somer-service-broker${File.separator}package.json")].toArray()
}
return [].toArray()
})
// execute test
def result = MtaMultiplexer.createJobs(nullScript, ['myParameters':'value'], [], 'TestJobs', 'pom.xml', 'maven'){
options -> optionsList.push(options)
}
// invoke jobs
for(Closure c : result.values()) c()
// asserts
assertThat(result.size(), is(2))
assertThat(result, hasKey('TestJobs - some-other-service'))
assertThat(jlr.log, containsString('Found 2 maven descriptor files!'))
assertThat(optionsList.get(0), hasEntry('myParameters', 'value'))
assertThat(optionsList.get(0), hasEntry('scanType', 'maven'))
assertThat(optionsList.get(0), hasEntry('buildDescriptorFile', "some-service${File.separator}pom.xml".toString()))
assertThat(optionsList.get(1), hasEntry('myParameters', 'value'))
assertThat(optionsList.get(1), hasEntry('scanType', 'maven'))
assertThat(optionsList.get(1), hasEntry('buildDescriptorFile', "some-other-service${File.separator}pom.xml".toString()))
}
}