2019-01-28 12:32:24 +02:00
|
|
|
import util.CommandLineMatcher
|
|
|
|
import util.JenkinsLockRule
|
|
|
|
import util.JenkinsWithEnvRule
|
2020-03-17 10:19:09 +02:00
|
|
|
import util.JenkinsWriteFileRule
|
2019-01-28 12:32:24 +02:00
|
|
|
|
2019-01-15 14:32:01 +02:00
|
|
|
import static org.hamcrest.Matchers.allOf
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
import static org.hamcrest.Matchers.equalTo
|
|
|
|
import static org.hamcrest.Matchers.hasItem
|
|
|
|
import static org.hamcrest.Matchers.is
|
|
|
|
import static org.hamcrest.Matchers.subString
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
|
|
|
import org.hamcrest.Matchers
|
|
|
|
import org.junit.Assert
|
2020-09-24 13:47:20 +02:00
|
|
|
import org.junit.After
|
2019-01-15 14:32:01 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
2020-10-15 13:29:52 +02:00
|
|
|
import org.junit.rules.ExpectedException
|
2019-01-15 14:32:01 +02:00
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
|
|
|
|
import com.sap.piper.JenkinsUtils
|
2020-09-24 13:47:20 +02:00
|
|
|
import com.sap.piper.Utils
|
2019-01-15 14:32:01 +02:00
|
|
|
|
|
|
|
import util.BasePiperTest
|
|
|
|
import util.JenkinsCredentialsRule
|
|
|
|
import util.JenkinsReadYamlRule
|
|
|
|
import util.JenkinsShellCallRule
|
|
|
|
import util.JenkinsStepRule
|
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
|
|
|
|
|
|
|
|
/* This scenario builds a fiori app and deploys it into an neo account.
|
|
|
|
The build is performed using mta, which delegates to grunt. grunt in
|
|
|
|
turn makes use of the 'sap/grunt-sapui5-bestpractice-build' plugin.
|
|
|
|
The dependencies are resolved via npm.
|
|
|
|
|
2020-09-24 07:41:06 +02:00
|
|
|
In order to run the scenario the project needs to fulfill these
|
2019-01-15 14:32:01 +02:00
|
|
|
prerequisites:
|
|
|
|
|
|
|
|
Build tools:
|
|
|
|
* mta.jar available
|
|
|
|
* npm installed
|
|
|
|
|
|
|
|
Project configuration:
|
|
|
|
* sap registry `@sap:registry=https://npm.sap.com` configured in
|
|
|
|
.npmrc (either in the project or on any other suitable level)
|
|
|
|
* dependency to `@sap/grunt-sapui5-bestpractice-build` declared in
|
|
|
|
package.json
|
|
|
|
* npmTask `@sap/grunt-sapui5-bestpractice-build` loaded inside
|
|
|
|
Gruntfile.js and configure default tasks (e.g. lint, clean, build)
|
|
|
|
* mta.yaml
|
|
|
|
*/
|
2020-10-15 13:29:52 +02:00
|
|
|
private ExpectedException thrown = new ExpectedException().none()
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2019-01-22 10:27:01 +02:00
|
|
|
JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
|
2019-01-22 10:19:28 +02:00
|
|
|
JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
2020-03-17 10:19:09 +02:00
|
|
|
JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
|
2019-01-28 12:32:24 +02:00
|
|
|
private JenkinsLockRule jlr = new JenkinsLockRule(this)
|
2019-01-15 14:32:01 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
2019-01-22 10:27:01 +02:00
|
|
|
.around(readYamlRule)
|
2020-10-15 13:29:52 +02:00
|
|
|
.around(thrown)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2019-01-22 10:19:28 +02:00
|
|
|
.around(shellRule)
|
2019-01-28 12:32:24 +02:00
|
|
|
.around(jlr)
|
2020-03-17 10:19:09 +02:00
|
|
|
.around(writeFileRule)
|
2019-01-28 12:32:24 +02:00
|
|
|
.around(new JenkinsWithEnvRule(this))
|
2019-01-15 14:32:01 +02:00
|
|
|
.around(new JenkinsCredentialsRule(this)
|
|
|
|
.withCredentials('CI_CREDENTIALS_ID', 'foo', 'terceSpot'))
|
|
|
|
|
2020-10-15 13:29:52 +02:00
|
|
|
private writeInfluxMap = [:]
|
|
|
|
|
|
|
|
class JenkinsUtilsMock extends JenkinsUtils {
|
|
|
|
def isJobStartedByUser() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 14:32:01 +02:00
|
|
|
@Before
|
|
|
|
void setup() {
|
|
|
|
//
|
2020-05-19 08:51:18 +02:00
|
|
|
// needed since we have dockerExecute inside neoDeploy
|
2019-01-15 14:32:01 +02:00
|
|
|
JenkinsUtils.metaClass.static.isPluginActive = {def s -> false}
|
|
|
|
|
|
|
|
//
|
|
|
|
// there is a check for the mta.yaml file and for the deployable test.mtar file
|
|
|
|
helper.registerAllowedMethod('fileExists', [String],{
|
|
|
|
|
|
|
|
it ->
|
|
|
|
|
|
|
|
// called inside neo deploy, this file gets deployed
|
|
|
|
it == 'test.mtar'
|
|
|
|
})
|
|
|
|
|
2019-03-21 13:40:38 +02:00
|
|
|
helper.registerAllowedMethod("deleteDir",[], null)
|
|
|
|
|
|
|
|
binding.setVariable('scm', null)
|
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
helper.registerAllowedMethod('pwd', [], { return "./" })
|
2020-05-19 08:51:18 +02:00
|
|
|
|
|
|
|
helper.registerAllowedMethod('mtaBuild', [Map], {
|
|
|
|
m -> m.script.commonPipelineEnvironment.mtarFilePath = 'test.mtar'
|
|
|
|
})
|
2020-09-24 13:47:20 +02:00
|
|
|
|
|
|
|
Utils.metaClass.echo = { def m -> }
|
2020-10-15 13:29:52 +02:00
|
|
|
|
|
|
|
helper.registerAllowedMethod('influxWriteData', [Map.class], { m ->
|
|
|
|
writeInfluxMap = m
|
|
|
|
})
|
|
|
|
|
|
|
|
UUID.metaClass.static.randomUUID = { -> 1 }
|
2020-09-24 13:47:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() {
|
|
|
|
Utils.metaClass = null
|
2020-10-15 13:29:52 +02:00
|
|
|
UUID.metaClass = null
|
2019-01-15 14:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-15 13:29:52 +02:00
|
|
|
void straightForwardTestNeo() {
|
2019-01-15 14:32:01 +02:00
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = [steps:
|
2020-10-15 13:29:52 +02:00
|
|
|
[mtaBuild:
|
|
|
|
[
|
|
|
|
platform: 'NEO'
|
|
|
|
],
|
|
|
|
neoDeploy:
|
2019-01-28 13:35:35 +02:00
|
|
|
[neo:
|
|
|
|
[ host: 'hana.example.com',
|
|
|
|
account: 'myTestAccount',
|
|
|
|
]
|
|
|
|
]
|
2019-01-15 14:32:01 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2020-10-15 13:29:52 +02:00
|
|
|
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript)
|
2019-01-15 14:32:01 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// the deployable is exchanged between the involved steps via this property:
|
2020-05-19 08:51:18 +02:00
|
|
|
// From the presence of this value we can conclude that mtaBuild has been called
|
|
|
|
// this value is set on the commonPipelineEnvironment in the corresponding mock.
|
2019-01-15 14:32:01 +02:00
|
|
|
assertThat(nullScript.commonPipelineEnvironment.getMtarFilePath(), is(equalTo('test.mtar')))
|
|
|
|
|
|
|
|
//
|
|
|
|
// the neo deploy call:
|
2019-01-28 12:32:24 +02:00
|
|
|
Assert.assertThat(shellRule.shell,
|
|
|
|
new CommandLineMatcher()
|
2019-03-07 13:53:25 +02:00
|
|
|
.hasProlog("neo.sh deploy-mta")
|
2019-01-28 12:32:24 +02:00
|
|
|
.hasSingleQuotedOption('host', 'hana\\.example\\.com')
|
|
|
|
.hasSingleQuotedOption('account', 'myTestAccount')
|
|
|
|
.hasSingleQuotedOption('password', 'terceSpot')
|
|
|
|
.hasSingleQuotedOption('user', 'foo')
|
|
|
|
.hasSingleQuotedOption('source', 'test.mtar')
|
|
|
|
.hasArgument('synchronous'))
|
2019-01-15 14:32:01 +02:00
|
|
|
}
|
2020-10-15 13:29:52 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void straightForwardTestCF() {
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = [steps:
|
|
|
|
[mtaBuild:
|
|
|
|
[
|
|
|
|
platform: 'CF'
|
|
|
|
],
|
|
|
|
cloudFoundryDeploy:
|
|
|
|
[ deployTool: 'mtaDeployPlugin',
|
|
|
|
cloudFoundry:
|
|
|
|
[ apiEndpoint: 'https://api.cf.hana.example.com',
|
|
|
|
org: 'testOrg',
|
|
|
|
space: 'testSpace',
|
|
|
|
credentialsId: 'CI_CREDENTIALS_ID'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
stepRule.step.fioriOnCloudPlatformPipeline(
|
|
|
|
script: nullScript,
|
|
|
|
jenkinsUtilsStub: new JenkinsUtilsMock()
|
|
|
|
)
|
|
|
|
|
|
|
|
assertThat(shellRule.shell, hasItem(containsString('cf login -u "foo" -p \'terceSpot\' -a https://api.cf.hana.example.com -o "testOrg" -s "testSpace"')))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void errorNoTargetDefined() {
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = [steps:
|
|
|
|
[neoDeploy:
|
|
|
|
[neo:
|
|
|
|
[ host: 'hana.example.com',
|
|
|
|
account: 'myTestAccount',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
thrown.expect(Exception)
|
|
|
|
thrown.expectMessage('Deployment failed: no valid deployment target defined')
|
|
|
|
|
|
|
|
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void errorUnknownTargetDefined() {
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = [steps:
|
|
|
|
[mtaBuild:
|
|
|
|
[
|
|
|
|
platform: 'UNKNOWN'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
thrown.expect(Exception)
|
|
|
|
thrown.expectMessage('Deployment failed: no valid deployment target defined')
|
|
|
|
|
|
|
|
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript)
|
|
|
|
}
|
2019-01-15 14:32:01 +02:00
|
|
|
}
|