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/ConfigurationLoaderTest.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

60 lines
2.1 KiB
Groovy

package com.sap.piper
import org.junit.Assert
import org.junit.Test
class ConfigurationLoaderTest {
private static getScript() {
Map configuration = [:]
configuration.general = [productiveBranch: 'master']
configuration.steps = [executeMaven: [dockerImage: 'maven:3.2-jdk-8-onbuild']]
configuration.stages = [staticCodeChecks: [pmdExcludes: '**']]
Map defaultConfiguration = [:]
defaultConfiguration.general = [productiveBranch: 'develop']
defaultConfiguration.steps = [executeGradle: [dockerImage: 'gradle:4.0.1-jdk8']]
defaultConfiguration.stages = [staticCodeChecks: [pmdExcludes: '*.java']]
def pipelineEnvironment = [configuration: configuration]
DefaultValueCache.createInstance(defaultConfiguration)
return [commonPipelineEnvironment: pipelineEnvironment]
}
@Test
void testLoadStepConfiguration() {
Map config = ConfigurationLoader.stepConfiguration(getScript(), 'executeMaven')
Assert.assertEquals('maven:3.2-jdk-8-onbuild', config.dockerImage)
}
@Test
void testLoadStageConfiguration() {
Map config = ConfigurationLoader.stageConfiguration(getScript(), 'staticCodeChecks')
Assert.assertEquals('**', config.pmdExcludes)
}
@Test
void testLoadGeneralConfiguration() {
Map config = ConfigurationLoader.generalConfiguration(getScript())
Assert.assertEquals('master', config.productiveBranch)
}
@Test
void testLoadDefaultStepConfiguration() {
Map config = ConfigurationLoader.defaultStepConfiguration(getScript(), 'executeGradle')
Assert.assertEquals('gradle:4.0.1-jdk8', config.dockerImage)
}
@Test
void testLoadDefaultStageConfiguration() {
Map config = ConfigurationLoader.defaultStageConfiguration(getScript(), 'staticCodeChecks')
Assert.assertEquals('*.java', config.pmdExcludes)
}
@Test
void testLoadDefaultGeneralConfiguration() {
Map config = ConfigurationLoader.defaultGeneralConfiguration(getScript())
Assert.assertEquals('develop', config.productiveBranch)
}
}