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/MavenExecuteTest.groovy
Daniel Kurzynski 22ee06dc17 Enable configuration via yaml file + mavenExecute as example (#18)
* Enable configuration via yaml file
* Add documentation 
* Add tests
2017-12-06 12:03:06 +01:00

45 lines
1.5 KiB
Groovy

import junit.framework.TestCase
import org.junit.Before
import org.junit.Test
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
class MavenExecuteTest extends PiperTestBase {
Map dockerParameters
List shellCalls
@Before
void setUp() {
super.setUp()
shellCalls = []
dockerParameters = [:]
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
{ parameters, closure ->
dockerParameters = parameters
closure()
})
helper.registerAllowedMethod('sh', [String], { s -> shellCalls.add(s) })
}
@Test
void testExecuteBasicMavenCommand() throws Exception {
def script = loadScript("test/resources/pipelines/mavenExecuteTest/executeBasicMavenCommand.groovy")
script.execute()
assertEquals('maven:3.5-jdk-7', dockerParameters.dockerImage)
assertTrue(shellCalls.contains('mvn clean install'))
}
@Test
void testExecuteMavenCommandWithParameter() throws Exception {
def script = loadScript("test/resources/pipelines/mavenExecuteTest/executeMavenCommandWithParameters.groovy")
script.execute()
assertEquals('maven:3.5-jdk-8-alpine', dockerParameters.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(shellCalls.contains(mvnCommand))
}
}