mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
Fix sanity checks for warPropertiesFile deploy mode. (#574)
* Fix sanity checks for warPropertiesFile deploy mode. * improve tests for the sanity checks The sanity checks are performed per deploy mode. All parameters are checked at once. * Explict check for host, account not found by sanity checks for deploy mode war properties
This commit is contained in:
parent
80d288ae57
commit
1a36a775f4
@ -1,5 +1,11 @@
|
||||
import com.sap.piper.Utils
|
||||
import hudson.AbortException
|
||||
|
||||
import static org.hamcrest.Matchers.allOf
|
||||
import static org.hamcrest.Matchers.containsString
|
||||
import static org.hamcrest.Matchers.not
|
||||
|
||||
import org.hamcrest.Matchers
|
||||
import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
@ -196,16 +202,6 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
void archiveNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR source')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void wrongArchivePathProvidedTest() {
|
||||
|
||||
@ -217,14 +213,55 @@ class NeoDeployTest extends BasePiperTest {
|
||||
|
||||
|
||||
@Test
|
||||
void scriptNotProvidedTest() {
|
||||
void sanityChecksDeployModeMTATest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/host')
|
||||
thrown.expectMessage(
|
||||
allOf(
|
||||
containsString('ERROR - NO VALUE AVAILABLE FOR:'),
|
||||
containsString('neo/host'),
|
||||
containsString('neo/account'),
|
||||
containsString('source')))
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript, source: archiveName)
|
||||
// deployMode mta is the default, but for the sake of transparency it is better to repeat it.
|
||||
stepRule.step.neoDeploy(script: nullScript, deployMode: 'mta')
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanityChecksDeployModeWarPropertiesFileTest() {
|
||||
|
||||
thrown.expect(IllegalArgumentException)
|
||||
// using this deploy mode 'account' and 'host' are provided by the properties file
|
||||
thrown.expectMessage(
|
||||
allOf(
|
||||
containsString('ERROR - NO VALUE AVAILABLE FOR source'),
|
||||
not(containsString('neo/host')),
|
||||
not(containsString('neo/account'))))
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript, deployMode: 'warPropertiesFile')
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanityChecksDeployModeWarParamsTest() {
|
||||
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage(
|
||||
allOf(
|
||||
containsString('ERROR - NO VALUE AVAILABLE FOR:'),
|
||||
containsString('source'),
|
||||
containsString('neo/application'),
|
||||
containsString('neo/runtime'),
|
||||
containsString('neo/runtimeVersion'),
|
||||
containsString('neo/host'),
|
||||
containsString('neo/account')))
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript, deployMode: 'warParams')
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -414,52 +451,6 @@ class NeoDeployTest extends BasePiperTest {
|
||||
.hasSingleQuotedOption('source', '.*\\.war'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void applicationNameNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/application')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: warArchiveName,
|
||||
deployMode: 'warParams',
|
||||
neo: [
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125'
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/runtime')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: warArchiveName,
|
||||
neo: [
|
||||
application: 'testApp',
|
||||
runtimeVersion: '2.125'
|
||||
],
|
||||
deployMode: 'warParams')
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeVersionNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/runtimeVersion')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: warArchiveName,
|
||||
neo: [
|
||||
application: 'testApp',
|
||||
runtime: 'neo-javaee6-wp'
|
||||
],
|
||||
deployMode: 'warParams')
|
||||
}
|
||||
|
||||
@Test
|
||||
void illegalDeployModeTest() {
|
||||
|
||||
|
@ -41,23 +41,28 @@ void call(parameters = [:]) {
|
||||
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName ?: env.STAGE_NAME, STEP_CONFIG_KEYS)
|
||||
.addIfEmpty('source', script.commonPipelineEnvironment.getMtarFilePath())
|
||||
.mixin(parameters, PARAMETER_KEYS)
|
||||
.withMandatoryProperty('neo/host')
|
||||
.withMandatoryProperty('neo/account')
|
||||
.withMandatoryProperty('source')
|
||||
.withMandatoryProperty('neo/credentialsId')
|
||||
.collectValidationFailures()
|
||||
.withPropertyInValues('deployMode', DeployMode.stringValues())
|
||||
|
||||
Map configuration = configHelper.use()
|
||||
|
||||
DeployMode deployMode = DeployMode.fromString(configuration.deployMode)
|
||||
|
||||
def isWarParamsDeployMode = { deployMode == DeployMode.WAR_PARAMS }
|
||||
def isWarParamsDeployMode = { deployMode == DeployMode.WAR_PARAMS },
|
||||
isNotWarPropertiesDeployMode = {deployMode != DeployMode.WAR_PROPERTIES_FILE}
|
||||
|
||||
configHelper
|
||||
.withMandatoryProperty('source')
|
||||
.withMandatoryProperty('neo/credentialsId')
|
||||
.withMandatoryProperty('neo/application', null, isWarParamsDeployMode)
|
||||
.withMandatoryProperty('neo/runtime', null, isWarParamsDeployMode)
|
||||
.withMandatoryProperty('neo/runtimeVersion', null, isWarParamsDeployMode)
|
||||
|
||||
.withMandatoryProperty('neo/host', null, isNotWarPropertiesDeployMode)
|
||||
.withMandatoryProperty('neo/account', null, isNotWarPropertiesDeployMode)
|
||||
//
|
||||
// call 'use()' a second time in order to get the collected validation failures
|
||||
// since the map did not change, it is not required to replace the previous configuration map.
|
||||
.use()
|
||||
|
||||
utils.pushToSWA([
|
||||
step: STEP_NAME,
|
||||
|
Loading…
Reference in New Issue
Block a user