1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-05 15:15:44 +02:00

Merge pull request #237 from SAP/CCFenner-patch-2

ConfigurationHelper: add condition to withMandatoryProperty
This commit is contained in:
Christopher Fenner 2018-08-01 10:43:11 +02:00 committed by GitHub
commit 43d1576cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -162,8 +162,13 @@ class ConfigurationHelper implements Serializable {
return paramValue
}
def withMandatoryProperty(key, errorMessage = null){
getMandatoryProperty(key, null, errorMessage)
def withMandatoryProperty(key, errorMessage = null, condition = null){
if(condition){
if(condition(this.config))
getMandatoryProperty(key, null, errorMessage)
}else{
getMandatoryProperty(key, null, errorMessage)
}
return this
}
}

View File

@ -248,4 +248,25 @@ class ConfigurationHelperTest {
public void testWithMandoryParameterDefaultCustomFailureMessageNotProvidedSucceeds() {
new ConfigurationHelper([myKey: 'myValue']).withMandatoryProperty('myKey')
}
@Test
public void testWithMandoryWithFalseCondition() {
new ConfigurationHelper([verify: false])
.withMandatoryProperty('missingKey', null, { c -> return c.get('verify') })
}
@Test
public void testWithMandoryWithTrueConditionMissingValue() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR missingKey')
new ConfigurationHelper([verify: true])
.withMandatoryProperty('missingKey', null, { c -> return c.get('verify') })
}
@Test
public void testWithMandoryWithTrueConditionExistingValue() {
new ConfigurationHelper([existingKey: 'anyValue', verify: true])
.withMandatoryProperty('existingKey', null, { c -> return c.get('verify') })
}
}