2017-12-06 13:03:06 +02:00
|
|
|
package com.sap.piper
|
|
|
|
|
|
|
|
import org.junit.Assert
|
2018-02-28 12:42:19 +02:00
|
|
|
import org.junit.Rule
|
2017-12-06 13:03:06 +02:00
|
|
|
import org.junit.Test
|
|
|
|
|
2018-02-28 12:42:19 +02:00
|
|
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
|
|
|
|
|
|
|
import util.JenkinsResetDefaultCacheRule
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
class ConfigurationMergerTest {
|
|
|
|
|
2018-02-28 12:42:19 +02:00
|
|
|
@Rule
|
|
|
|
public JenkinsResetDefaultCacheRule resetDefaultValueCacheRule = new JenkinsResetDefaultCacheRule()
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
@Test
|
|
|
|
void testMerge(){
|
|
|
|
Map defaults = [dockerImage: 'mvn']
|
|
|
|
Map parameters = [goals: 'install', flags: '']
|
2018-02-19 13:53:08 +02:00
|
|
|
Set parameterKeys = ['flags']
|
2017-12-06 13:03:06 +02:00
|
|
|
Map configuration = [flags: '-B']
|
2018-02-19 13:53:08 +02:00
|
|
|
Set configurationKeys = ['flags']
|
2017-12-06 13:03:06 +02:00
|
|
|
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
|
|
|
|
Assert.assertEquals('mvn', merged.dockerImage)
|
|
|
|
Assert.assertNull(merged.goals)
|
|
|
|
Assert.assertEquals('', merged.flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMergeParameterWithDefault(){
|
|
|
|
Map defaults = [nonErpDestinations: []]
|
|
|
|
Map parameters = [nonErpDestinations: null]
|
2018-02-19 13:53:08 +02:00
|
|
|
Set parameterKeys = ['nonErpDestinations']
|
2017-12-06 13:03:06 +02:00
|
|
|
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, defaults)
|
|
|
|
Assert.assertEquals([], merged.nonErpDestinations)
|
|
|
|
}
|
2018-01-24 10:55:38 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMergeCustomPipelineValues(){
|
|
|
|
Map defaults = [dockerImage: 'mvn']
|
|
|
|
Map parameters = [goals: 'install', flags: '']
|
2018-02-19 13:53:08 +02:00
|
|
|
Set parameterKeys = ['flags']
|
2018-01-24 10:55:38 +02:00
|
|
|
Map configuration = [flags: '-B']
|
2018-02-19 13:53:08 +02:00
|
|
|
Set configurationKeys = ['flags']
|
2018-01-24 10:55:38 +02:00
|
|
|
Map pipelineDataMap = [artifactVersion: '1.2.3', flags: 'test']
|
|
|
|
Map merged = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, configuration, configurationKeys, defaults)
|
|
|
|
Assert.assertEquals('', merged.flags)
|
|
|
|
Assert.assertEquals('1.2.3', merged.artifactVersion)
|
|
|
|
}
|
2018-02-01 13:16:21 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMergeDeepStructure(){
|
2018-04-23 13:41:22 +02:00
|
|
|
Map defaults = [fruits: [apples: 1, oranges: 10, bananas: 0]]
|
|
|
|
Map configuration = [fruits: [bananas: 50, cucumbers: 1000]]
|
2018-02-19 13:53:08 +02:00
|
|
|
Set configurationKeys = ['fruits']
|
2018-02-07 13:01:46 +02:00
|
|
|
Map parameters = [fruits: [apples: 18], veggie: []]
|
2018-02-19 13:53:08 +02:00
|
|
|
Set parameterKeys = ['fruits']
|
2018-02-05 21:31:30 +02:00
|
|
|
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
|
2018-04-23 13:41:22 +02:00
|
|
|
Assert.assertEquals(50, merged.fruits.bananas)
|
2018-02-01 13:16:21 +02:00
|
|
|
Assert.assertEquals(18, merged.fruits.apples)
|
2018-02-05 20:54:04 +02:00
|
|
|
Assert.assertEquals(10, merged.fruits.oranges)
|
2018-02-07 13:01:46 +02:00
|
|
|
Assert.assertEquals(1000, merged.fruits.cucumbers)
|
|
|
|
Assert.assertEquals(null, merged.veggie)
|
2018-02-01 13:16:21 +02:00
|
|
|
}
|
2018-02-28 12:42:19 +02:00
|
|
|
|
2018-04-23 13:41:22 +02:00
|
|
|
@Test
|
|
|
|
void testMergeDeepStructureWithMissingDefaults(){
|
|
|
|
Map defaults = [others:[apples: 18]]
|
|
|
|
Map configuration = [fruits: [bananas: 50, cucumbers: 1000]]
|
|
|
|
Set configurationKeys = ['fruits']
|
|
|
|
Map merged = ConfigurationMerger.merge(configuration, configurationKeys, defaults)
|
|
|
|
Assert.assertEquals(50, merged.fruits.bananas)
|
|
|
|
Assert.assertEquals(18, merged.others.apples)
|
|
|
|
Assert.assertEquals(1000, merged.fruits.cucumbers)
|
|
|
|
}
|
|
|
|
|
2018-02-28 12:42:19 +02:00
|
|
|
@Test
|
|
|
|
void testReadConfigInsideMerge() {
|
|
|
|
DefaultValueCache.createInstance([steps:[myStep:[overwrite: 'x', defaultKey1:'defaultValue1']]])
|
|
|
|
def config = [commonPipelineEnvironment: [configuration: [steps:[myStep:[overwrite: 'y', key1:'value1']]]]]
|
|
|
|
def mergeResult = ConfigurationMerger.merge(config, "myStep", [:], (Set)[], [:], (Set)['overwrite', 'key1'])
|
|
|
|
Assert.assertEquals('y', mergeResult.overwrite)
|
|
|
|
Assert.assertEquals('defaultValue1', mergeResult.defaultKey1)
|
|
|
|
Assert.assertEquals('value1', mergeResult.key1)
|
|
|
|
}
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|