2018-06-25 14:53:28 +02:00
|
|
|
package com.sap.piper.mta
|
|
|
|
|
2018-06-25 22:49:34 +02:00
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
import static org.hamcrest.Matchers.hasEntry
|
2018-06-25 14:53:28 +02:00
|
|
|
import static org.hamcrest.Matchers.hasItem
|
2018-06-25 22:45:43 +02:00
|
|
|
import static org.hamcrest.Matchers.hasKey
|
2018-06-25 14:53:28 +02:00
|
|
|
import static org.hamcrest.Matchers.hasSize
|
2018-06-25 22:45:43 +02:00
|
|
|
import static org.hamcrest.Matchers.is
|
2018-06-25 22:49:34 +02:00
|
|
|
import static org.hamcrest.Matchers.not
|
2018-06-25 14:53:28 +02:00
|
|
|
|
|
|
|
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 = [
|
2018-06-27 14:19:40 +02:00
|
|
|
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")
|
2018-06-25 14:53:28 +02:00
|
|
|
].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'))
|
|
|
|
}
|
2018-06-25 22:45:43 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testCreateJobs() {
|
|
|
|
def optionsList = []
|
|
|
|
// prepare test data
|
|
|
|
helper.registerAllowedMethod("findFiles", [Map.class], { map ->
|
2018-06-27 14:19:40 +02:00
|
|
|
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()
|
2018-06-25 22:45:43 +02:00
|
|
|
}
|
2018-06-27 14:19:40 +02:00
|
|
|
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()
|
2018-06-25 22:45:43 +02:00
|
|
|
}
|
2018-06-27 14:19:40 +02:00
|
|
|
return [].toArray()
|
2018-06-25 22:45:43 +02:00
|
|
|
})
|
|
|
|
// 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'))
|
2018-06-27 14:38:57 +02:00
|
|
|
assertThat(optionsList.get(0), hasEntry('buildDescriptorFile', "some-service${File.separator}pom.xml".toString()))
|
2018-06-25 22:45:43 +02:00
|
|
|
assertThat(optionsList.get(1), hasEntry('myParameters', 'value'))
|
|
|
|
assertThat(optionsList.get(1), hasEntry('scanType', 'maven'))
|
2018-06-27 14:38:57 +02:00
|
|
|
assertThat(optionsList.get(1), hasEntry('buildDescriptorFile', "some-other-service${File.separator}pom.xml".toString()))
|
2018-06-25 22:45:43 +02:00
|
|
|
}
|
2018-06-25 14:53:28 +02:00
|
|
|
}
|