2017-07-11 15:12:03 +02:00
import hudson.AbortException
2017-12-11 12:15:51 +02:00
2017-07-11 15:12:03 +02:00
import org.junit.rules.TemporaryFolder
2018-01-16 18:06:25 +02:00
2018-02-12 12:03:07 +02:00
import org.junit.BeforeClass
import org.junit.ClassRule
2018-03-08 10:07:25 +02:00
import org.junit.Ignore
2018-09-03 11:09:09 +02:00
2018-05-28 11:56:06 +02:00
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
2018-09-03 11:09:09 +02:00
import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException
2018-05-28 11:56:06 +02:00
import org.junit.Assert
2017-07-11 15:12:03 +02:00
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
2018-01-16 10:33:13 +02:00
import org.junit.rules.RuleChain
2018-08-31 10:22:43 +02:00
2018-06-06 11:19:19 +02:00
import util.BasePiperTest
2018-09-03 11:09:09 +02:00
import util.JenkinsCredentialsRule
2018-01-16 10:33:13 +02:00
import util.JenkinsLoggingRule
2018-08-31 10:22:43 +02:00
import util.JenkinsReadYamlRule
2018-01-16 16:03:00 +02:00
import util.JenkinsShellCallRule
2018-02-28 14:11:09 +02:00
import util.JenkinsStepRule
2018-01-26 15:55:15 +02:00
import util.Rules
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
class NeoDeployTest extends BasePiperTest {
2018-02-20 14:10:14 +02:00
def toolJavaValidateCalled = false
2018-02-12 12:03:07 +02:00
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder ( )
2018-01-16 10:33:13 +02:00
private ExpectedException thrown = new ExpectedException ( ) . none ( )
private JenkinsLoggingRule jlr = new JenkinsLoggingRule ( this )
2018-01-16 16:03:00 +02:00
private JenkinsShellCallRule jscr = new JenkinsShellCallRule ( this )
2018-02-28 14:11:09 +02:00
private JenkinsStepRule jsr = new JenkinsStepRule ( this )
2017-07-11 15:12:03 +02:00
@Rule
2018-02-28 14:11:09 +02:00
public RuleChain ruleChain = Rules
. getCommonRules ( this )
2018-08-31 10:22:43 +02:00
. around ( new JenkinsReadYamlRule ( this ) )
2018-02-28 14:11:09 +02:00
. around ( thrown )
. around ( jlr )
. around ( jscr )
2018-09-03 11:09:09 +02:00
. around ( new JenkinsCredentialsRule ( this )
. withCredentials ( 'myCredentialsId' , 'anonymous' , '********' )
. withCredentials ( 'CI_CREDENTIALS_ID' , 'defaultUser' , '********' ) )
2018-02-28 14:11:09 +02:00
. around ( jsr )
2018-01-18 11:40:18 +02:00
2018-02-12 12:03:07 +02:00
private static workspacePath
private static warArchiveName
private static propertiesFileName
private static archiveName
2017-07-11 15:12:03 +02:00
2018-03-12 17:50:32 +02:00
2018-02-12 12:03:07 +02:00
@BeforeClass
static void createTestFiles ( ) {
2017-07-11 15:12:03 +02:00
2018-02-12 11:52:13 +02:00
workspacePath = "${tmp.getRoot()}"
2018-01-18 11:40:18 +02:00
warArchiveName = 'warArchive.war'
propertiesFileName = 'config.properties'
2018-02-12 12:03:07 +02:00
archiveName = 'archive.mtar'
2018-02-13 16:06:09 +02:00
tmp . newFile ( warArchiveName ) < < 'dummy war archive'
tmp . newFile ( propertiesFileName ) < < 'dummy properties file'
tmp . newFile ( archiveName ) < < 'dummy archive'
2018-02-12 12:03:07 +02:00
}
@Before
void init ( ) {
2017-07-11 15:12:03 +02:00
2017-12-13 11:05:19 +02:00
helper . registerAllowedMethod ( 'dockerExecute' , [ Map , Closure ] , null )
2018-01-18 11:40:18 +02:00
helper . registerAllowedMethod ( 'fileExists' , [ String ] , { s - > return new File ( workspacePath , s ) . exists ( ) } )
2018-03-12 17:50:32 +02:00
helper . registerAllowedMethod ( 'sh' , [ Map ] , { Map m - > getVersionWithEnvVars ( m ) } )
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . configuration = [ steps: [ neoDeploy: [ host: 'test.deploy.host.com' , account: 'trialuser123' ] ] ]
2017-07-11 15:12:03 +02:00
}
@Test
2017-12-11 12:15:51 +02:00
void straightForwardTestConfigViaConfigProperties ( ) {
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . setConfigProperty ( 'DEPLOY_HOST' , 'test.deploy.host.com' )
nullScript . commonPipelineEnvironment . setConfigProperty ( 'CI_DEPLOY_ACCOUNT' , 'trialuser123' )
nullScript . commonPipelineEnvironment . configuration = [ : ]
2018-01-16 18:06:25 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: archiveName ,
2018-01-16 18:06:25 +02:00
neoCredentialsId: 'myCredentialsId'
)
2017-07-11 15:12:03 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'test\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'trialuser123' )
. hasOption ( 'synchronous' , '' )
. hasSingleQuotedOption ( 'user' , 'anonymous' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*' ) )
2017-07-11 15:12:03 +02:00
}
2017-12-11 12:15:51 +02:00
@Test
void straightForwardTestConfigViaConfiguration ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2017-12-11 12:15:51 +02:00
archivePath: archiveName ,
neoCredentialsId: 'myCredentialsId'
2018-02-28 14:11:09 +02:00
)
2017-12-11 12:15:51 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'test\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'trialuser123' )
. hasOption ( 'synchronous' , '' )
. hasSingleQuotedOption ( 'user' , 'anonymous' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*' ) )
2017-12-11 12:15:51 +02:00
}
@Test
void straightForwardTestConfigViaConfigurationAndViaConfigProperties ( ) {
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . setConfigProperty ( 'DEPLOY_HOST' , 'configProperties.deploy.host.com' )
nullScript . commonPipelineEnvironment . setConfigProperty ( 'CI_DEPLOY_ACCOUNT' , 'configPropsUser123' )
2017-12-11 12:15:51 +02:00
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . configuration = [ steps: [ neoDeploy: [ host: 'configuration-frwk.deploy.host.com' ,
2018-02-12 12:21:29 +02:00
account: 'configurationFrwkUser123' ] ] ]
2017-12-11 12:15:51 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2017-12-11 12:15:51 +02:00
archivePath: archiveName ,
neoCredentialsId: 'myCredentialsId'
)
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'configuration-frwk\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'configurationFrwkUser123' )
. hasOption ( 'synchronous' , '' )
. hasSingleQuotedOption ( 'user' , 'anonymous' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*' ) )
2017-12-11 12:15:51 +02:00
}
2018-08-17 12:52:01 +02:00
@Test
void archivePathFromCPETest ( ) {
nullScript . commonPipelineEnvironment . setMtarFilePath ( 'archive.mtar' )
jsr . step . call ( script: nullScript )
Assert . assertThat ( jscr . shell ,
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
. hasDoubleQuotedOption ( 'source' , 'archive.mtar' ) )
}
@Test
void archivePathFromParamsHasHigherPrecedenceThanCPETest ( ) {
nullScript . commonPipelineEnvironment . setMtarFilePath ( 'archive2.mtar' )
jsr . step . call ( script: nullScript ,
archivePath: "archive.mtar" )
Assert . assertThat ( jscr . shell ,
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
. hasDoubleQuotedOption ( 'source' , 'archive.mtar' ) )
}
2017-07-11 15:12:03 +02:00
@Test
void badCredentialsIdTest ( ) {
2018-09-03 11:09:09 +02:00
thrown . expect ( CredentialNotFoundException )
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: archiveName ,
2018-01-16 18:06:25 +02:00
neoCredentialsId: 'badCredentialsId'
)
2017-07-11 15:12:03 +02:00
}
@Test
void credentialsIdNotProvidedTest ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: archiveName
2018-01-16 18:06:25 +02:00
)
2017-07-11 15:12:03 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'test\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'trialuser123' )
. hasOption ( 'synchronous' , '' )
. hasSingleQuotedOption ( 'user' , 'defaultUser' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*' ) )
2017-07-11 15:12:03 +02:00
}
2018-07-27 14:09:08 +02:00
@Test
void neoHomeNotSetTest ( ) {
helper . registerAllowedMethod ( 'sh' , [ Map ] , { Map m - > getVersionWithPath ( m ) } )
jsr . step . call ( script: nullScript ,
archivePath: archiveName
)
assert jscr . shell . find { c - > c . contains ( '"neo.sh" deploy-mta' ) }
assert jlr . log . contains ( 'SAP Cloud Platform Console Client is on PATH.' )
assert jlr . log . contains ( "Using SAP Cloud Platform Console Client 'neo.sh'." )
}
@Test
void neoHomeAsParameterTest ( ) {
helper . registerAllowedMethod ( 'sh' , [ Map ] , { Map m - > getVersionWithPath ( m ) } )
jsr . step . call ( script: nullScript ,
archivePath: archiveName ,
neoCredentialsId: 'myCredentialsId' ,
neoHome: '/param/neo'
)
assert jscr . shell . find { c - > c = "\"/param/neo/tools/neo.sh\" deploy-mta" }
assert jlr . log . contains ( "SAP Cloud Platform Console Client home '/param/neo' retrieved from configuration." )
assert jlr . log . contains ( "Using SAP Cloud Platform Console Client '/param/neo/tools/neo.sh'." )
}
@Test
void neoHomeFromEnvironmentTest ( ) {
jsr . step . call ( script: nullScript ,
archivePath: archiveName
)
assert jscr . shell . find { c - > c . contains ( "\"/opt/neo/tools/neo.sh\" deploy-mta" ) }
assert jlr . log . contains ( "SAP Cloud Platform Console Client home '/opt/neo' retrieved from environment." )
assert jlr . log . contains ( "Using SAP Cloud Platform Console Client '/opt/neo/tools/neo.sh'." )
}
@Test
void neoHomeFromCustomStepConfigurationTest ( ) {
helper . registerAllowedMethod ( 'sh' , [ Map ] , { Map m - > getVersionWithPath ( m ) } )
nullScript . commonPipelineEnvironment . configuration = [ steps: [ neoDeploy: [ host: 'test.deploy.host.com' , account: 'trialuser123' , neoHome: '/config/neo' ] ] ]
jsr . step . call ( script: nullScript ,
archivePath: archiveName
)
assert jscr . shell . find { c - > c = "\"/config/neo/tools/neo.sh\" deploy-mta" }
assert jlr . log . contains ( "SAP Cloud Platform Console Client home '/config/neo' retrieved from configuration." )
assert jlr . log . contains ( "Using SAP Cloud Platform Console Client '/config/neo/tools/neo.sh'." )
}
2017-07-11 15:12:03 +02:00
@Test
void archiveNotProvidedTest ( ) {
thrown . expect ( Exception )
2017-12-11 12:15:51 +02:00
thrown . expectMessage ( 'Archive path not configured (parameter "archivePath").' )
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript )
2017-07-11 15:12:03 +02:00
}
@Test
void wrongArchivePathProvidedTest ( ) {
thrown . expect ( AbortException )
2018-02-13 16:06:09 +02:00
thrown . expectMessage ( 'Archive cannot be found' )
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-02-12 12:03:07 +02:00
archivePath: 'wrongArchiveName' )
2017-07-11 15:12:03 +02:00
}
@Test
void scriptNotProvidedTest ( ) {
thrown . expect ( Exception )
2017-12-11 12:15:51 +02:00
thrown . expectMessage ( 'ERROR - NO VALUE AVAILABLE FOR host' )
2017-07-11 15:12:03 +02:00
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . configuration = [ : ]
2018-02-12 12:21:29 +02:00
2018-08-17 12:52:01 +02:00
jsr . step . call ( script: nullScript , archivePath: archiveName )
2017-07-11 15:12:03 +02:00
}
2018-01-11 16:25:58 +02:00
@Test
void mtaDeployModeTest ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript , archivePath: archiveName , deployMode: 'mta' )
2018-01-16 18:06:25 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy-mta" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'test\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'trialuser123' )
. hasOption ( 'synchronous' , '' )
. hasSingleQuotedOption ( 'user' , 'defaultUser' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*' ) )
2018-01-11 16:25:58 +02:00
}
@Test
void warFileParamsDeployModeTest ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-16 18:06:25 +02:00
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
deployMode: 'warParams' ,
vmSize: 'lite' ,
warAction: 'deploy' ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName )
2018-01-11 16:25:58 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'test\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'trialuser123' )
. hasSingleQuotedOption ( 'application' , 'testApp' )
. hasSingleQuotedOption ( 'runtime' , 'neo-javaee6-wp' )
. hasSingleQuotedOption ( 'runtime-version' , '2\\.125' )
. hasSingleQuotedOption ( 'size' , 'lite' )
. hasSingleQuotedOption ( 'user' , 'defaultUser' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*\\.war' ) )
2018-01-11 16:25:58 +02:00
}
2018-01-17 15:01:15 +02:00
@Test
void warFileParamsDeployModeRollingUpdateTest ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'warParams' ,
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
warAction: 'rolling-update' ,
vmSize: 'lite' )
2018-01-17 15:01:15 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" rolling-update" )
2018-05-28 11:56:06 +02:00
. hasSingleQuotedOption ( 'host' , 'test\\.deploy\\.host\\.com' )
. hasSingleQuotedOption ( 'account' , 'trialuser123' )
. hasSingleQuotedOption ( 'application' , 'testApp' )
. hasSingleQuotedOption ( 'runtime' , 'neo-javaee6-wp' )
. hasSingleQuotedOption ( 'runtime-version' , '2\\.125' )
. hasSingleQuotedOption ( 'size' , 'lite' )
. hasSingleQuotedOption ( 'user' , 'defaultUser' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*\\.war' ) )
2018-01-17 15:01:15 +02:00
}
2018-01-11 16:25:58 +02:00
@Test
void warPropertiesFileDeployModeTest ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'warPropertiesFile' ,
2018-01-18 11:40:18 +02:00
propertiesFile: propertiesFileName ,
2018-01-16 18:06:25 +02:00
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
warAction: 'deploy' ,
vmSize: 'lite' )
2018-01-11 16:25:58 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" deploy" )
2018-05-28 11:56:06 +02:00
. hasArgument ( "config.properties" )
. hasSingleQuotedOption ( 'user' , 'defaultUser' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*\\.war' ) )
2018-01-11 16:25:58 +02:00
}
2018-01-17 15:01:15 +02:00
@Test
void warPropertiesFileDeployModeRollingUpdateTest ( ) {
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'warPropertiesFile' ,
2018-01-18 11:40:18 +02:00
propertiesFile: propertiesFileName ,
2018-01-16 18:06:25 +02:00
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
warAction: 'rolling-update' ,
vmSize: 'lite' )
2018-01-17 15:01:15 +02:00
2018-05-28 11:56:06 +02:00
Assert . assertThat ( jscr . shell ,
2018-07-27 14:09:08 +02:00
new CommandLineMatcher ( ) . hasProlog ( "#!/bin/bash \"/opt/neo/tools/neo.sh\" rolling-update" )
2018-05-28 11:56:06 +02:00
. hasArgument ( 'config.properties' )
. hasSingleQuotedOption ( 'user' , 'defaultUser' )
. hasSingleQuotedOption ( 'password' , '\\*\\*\\*\\*\\*\\*\\*\\*' )
. hasDoubleQuotedOption ( 'source' , '.*\\.war' ) )
2018-01-17 15:01:15 +02:00
}
2018-01-11 16:25:58 +02:00
@Test
void applicationNameNotProvidedTest ( ) {
thrown . expect ( Exception )
thrown . expectMessage ( 'ERROR - NO VALUE AVAILABLE FOR applicationName' )
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'warParams' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125'
)
2018-01-11 16:25:58 +02:00
}
@Test
void runtimeNotProvidedTest ( ) {
thrown . expect ( Exception )
thrown . expectMessage ( 'ERROR - NO VALUE AVAILABLE FOR runtime' )
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
applicationName: 'testApp' ,
deployMode: 'warParams' ,
runtimeVersion: '2.125' )
2018-01-11 16:25:58 +02:00
}
@Test
void runtimeVersionNotProvidedTest ( ) {
thrown . expect ( Exception )
thrown . expectMessage ( 'ERROR - NO VALUE AVAILABLE FOR runtimeVersion' )
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
applicationName: 'testApp' ,
deployMode: 'warParams' ,
runtime: 'neo-javaee6-wp' )
2018-01-16 11:54:17 +02:00
}
@Test
void illegalDeployModeTest ( ) {
2018-01-17 12:19:02 +02:00
thrown . expect ( Exception )
2018-04-20 12:23:26 +02:00
thrown . expectMessage ( "[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: [mta, warParams, warPropertiesFile]" )
2018-01-16 11:54:17 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'illegalMode' ,
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
warAction: 'deploy' ,
vmSize: 'lite' )
2018-01-16 11:54:17 +02:00
}
@Test
void illegalVMSizeTest ( ) {
2018-01-17 12:19:02 +02:00
thrown . expect ( Exception )
2018-04-20 12:24:37 +02:00
thrown . expectMessage ( "[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: [lite, pro, prem, prem-plus]." )
2018-01-16 11:54:17 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'warParams' ,
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
warAction: 'deploy' ,
vmSize: 'illegalVM' )
2018-01-16 11:54:17 +02:00
}
@Test
void illegalWARActionTest ( ) {
2018-01-17 12:19:02 +02:00
thrown . expect ( Exception )
2018-04-20 12:25:15 +02:00
thrown . expectMessage ( "[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: [deploy, rolling-update]." )
2018-01-16 11:54:17 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-18 11:40:18 +02:00
archivePath: warArchiveName ,
2018-01-16 18:06:25 +02:00
deployMode: 'warParams' ,
applicationName: 'testApp' ,
runtime: 'neo-javaee6-wp' ,
runtimeVersion: '2.125' ,
warAction: 'illegalWARAction' ,
vmSize: 'lite' )
2017-07-11 15:12:03 +02:00
}
2018-01-29 13:50:59 +02:00
@Test
void deployHostProvidedAsDeprecatedParameterTest ( ) {
2018-02-12 12:03:07 +02:00
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . setConfigProperty ( 'CI_DEPLOY_ACCOUNT' , 'configPropsUser123' )
2018-01-29 13:50:59 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-29 13:50:59 +02:00
archivePath: archiveName ,
deployHost: "my.deploy.host.com"
)
assert jlr . log . contains ( "[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead." )
}
@Test
void deployAccountProvidedAsDeprecatedParameterTest ( ) {
2018-02-12 12:03:07 +02:00
2018-06-06 11:19:19 +02:00
nullScript . commonPipelineEnvironment . setConfigProperty ( 'CI_DEPLOY_ACCOUNT' , 'configPropsUser123' )
2018-01-29 13:50:59 +02:00
2018-06-06 11:19:19 +02:00
jsr . step . call ( script: nullScript ,
2018-01-29 13:50:59 +02:00
archivePath: archiveName ,
host: "my.deploy.host.com" ,
deployAccount: "myAccount"
)
assert jlr . log . contains ( "Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead." )
}
2018-03-06 17:09:03 +02:00
2018-03-12 17:50:32 +02:00
private getVersionWithEnvVars ( Map m ) {
if ( m . script . contains ( 'java -version' ) ) {
return '' ' openjdk version \ "1.8.0_121\"
OpenJDK Runtime Environment ( build 1.8 . 0 _121 - 8 u121 - b13 - 1 ~ bpo8 + 1 - b13 )
OpenJDK 64 - Bit Server VM ( build 25.121 - b13 , mixed mode ) '' '
} else if ( m . script . contains ( 'neo.sh version' ) ) {
return '' ' SAP Cloud Platform Console Client
SDK version : 3.39 . 10
Runtime : neo - java - web '' '
} else {
return getEnvVars ( m )
}
}
2018-03-20 16:14:02 +02:00
private getVersionWithPath ( Map m ) {
2018-03-12 17:50:32 +02:00
if ( m . script . contains ( 'java -version' ) ) {
return '' ' openjdk version \ "1.8.0_121\"
OpenJDK Runtime Environment ( build 1.8 . 0 _121 - 8 u121 - b13 - 1 ~ bpo8 + 1 - b13 )
OpenJDK 64 - Bit Server VM ( build 25.121 - b13 , mixed mode ) '' '
} else if ( m . script . contains ( 'neo.sh version' ) ) {
return '' ' SAP Cloud Platform Console Client
SDK version : 3.39 . 10
Runtime : neo - java - web '' '
} else {
2018-03-20 16:14:02 +02:00
return getPath ( m )
2018-03-12 17:50:32 +02:00
}
}
private getEnvVars ( Map m ) {
if ( m . script . contains ( 'JAVA_HOME' ) ) {
return '/opt/java'
2018-07-27 14:09:08 +02:00
} else if ( m . script . contains ( 'NEO_HOME' ) ) {
return '/opt/neo'
2018-03-20 16:14:02 +02:00
} else if ( m . script . contains ( 'which java' ) ) {
2018-04-10 18:23:44 +02:00
return 0
2018-07-27 14:09:08 +02:00
} else if ( m . script . contains ( 'which neo' ) ) {
return 0
2018-03-12 17:50:32 +02:00
} else {
return 0
}
}
2018-03-20 16:14:02 +02:00
private getPath ( Map m ) {
2018-03-12 17:50:32 +02:00
if ( m . script . contains ( 'JAVA_HOME' ) ) {
return ''
2018-07-27 14:09:08 +02:00
} else if ( m . script . contains ( 'NEO_HOME' ) ) {
return ''
2018-03-20 16:14:02 +02:00
} else if ( m . script . contains ( 'which java' ) ) {
2018-04-10 18:23:44 +02:00
return 0
2018-07-27 14:09:08 +02:00
} else if ( m . script . contains ( 'which neo' ) ) {
return 0
2018-03-12 17:50:32 +02:00
} else {
return 0
}
}
2018-05-28 11:56:06 +02:00
class CommandLineMatcher extends BaseMatcher {
String prolog
Set < String > args = ( Set ) [ ]
Set < MapEntry > opts = ( Set ) [ ]
String hint = ''
CommandLineMatcher hasProlog ( prolog ) {
this . prolog = prolog
return this
}
CommandLineMatcher hasDoubleQuotedOption ( String key , String value ) {
hasOption ( key , "\"${value}\"" )
return this
}
CommandLineMatcher hasSingleQuotedOption ( String key , String value ) {
hasOption ( key , "\'${value}\'" )
return this
}
CommandLineMatcher hasOption ( String key , String value ) {
this . opts . add ( new MapEntry ( key , value ) )
return this
}
CommandLineMatcher hasArgument ( String arg ) {
this . args . add ( arg )
return this
}
@Override
boolean matches ( Object o ) {
for ( String cmd : o ) {
hint = ''
boolean matches = true
if ( ! cmd . matches ( /${prolog}.*/ ) ) {
hint = "A command line starting with \'${prolog}\'."
matches = false
}
for ( MapEntry opt : opts ) {
if ( ! cmd . matches ( /.*[\s]*--${opt.key}[\s]*${opt.value}.*/ ) ) {
hint = "A command line containing option \'${opt.key}\' with value \'${opt.value}\'"
matches = false
}
}
for ( String arg : args ) {
if ( ! cmd . matches ( /.*[\s]*${arg}[\s]*.*/ ) ) {
hint = "A command line having argument '${arg}'."
matches = false
}
}
if ( matches )
return true
}
return false
}
@Override
public void describeTo ( Description description ) {
description . appendText ( hint )
}
}
2017-07-11 15:12:03 +02:00
}