mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
f6c71a8484
* Execute Maven inside Docker container * Fix test
67 lines
2.2 KiB
Groovy
67 lines
2.2 KiB
Groovy
package com.sap.piper.versioning
|
|
|
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
|
import org.junit.Before
|
|
import org.junit.Rule
|
|
import org.junit.Test
|
|
import org.junit.rules.ExpectedException
|
|
import org.junit.rules.RuleChain
|
|
import util.JenkinsReadMavenPomRule
|
|
import util.JenkinsShellCallRule
|
|
import util.Rules
|
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
class MavenArtifactVersioningTest extends BasePipelineTest{
|
|
|
|
Map dockerParameters
|
|
def mavenExecuteScript
|
|
def commonPipelineEnvironment
|
|
|
|
MavenArtifactVersioning av
|
|
|
|
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
|
ExpectedException thrown = ExpectedException.none()
|
|
|
|
@Rule
|
|
public RuleChain ruleChain = Rules.getCommonRules(this).around(jscr).around(thrown).around(new JenkinsReadMavenPomRule(this, 'test/resources/MavenArtifactVersioning'))
|
|
|
|
@Before
|
|
void init() {
|
|
dockerParameters = [:]
|
|
|
|
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
|
|
{ parameters, closure ->
|
|
dockerParameters = parameters
|
|
closure()
|
|
})
|
|
|
|
mavenExecuteScript = loadScript("mavenExecute.groovy").mavenExecute
|
|
commonPipelineEnvironment = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
|
|
|
|
prepareObjectInterceptors(this)
|
|
}
|
|
|
|
@Test
|
|
void testVersioning() {
|
|
av = new MavenArtifactVersioning(this, [filePath: 'pom.xml'])
|
|
assertEquals('1.2.3', av.getVersion())
|
|
av.setVersion('1.2.3-20180101')
|
|
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101', jscr.shell[0])
|
|
}
|
|
|
|
@Test
|
|
void testVersioningCustomFilePathSnapshot() {
|
|
av = new MavenArtifactVersioning(this, [filePath: 'snapshot/pom.xml'])
|
|
assertEquals('1.2.3', av.getVersion())
|
|
av.setVersion('1.2.3-20180101')
|
|
assertEquals('mvn --file \'snapshot/pom.xml\' versions:set -DnewVersion=1.2.3-20180101', jscr.shell[0])
|
|
}
|
|
|
|
void prepareObjectInterceptors(object) {
|
|
object.metaClass.invokeMethod = helper.getMethodInterceptor()
|
|
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
|
|
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
|
|
}
|
|
}
|