1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/TransportRequestUploadFileTest.groovy

599 lines
24 KiB
Groovy
Raw Normal View History

2019-01-30 18:19:19 +02:00
import static org.hamcrest.Matchers.allOf
import static org.hamcrest.Matchers.containsString
2019-01-30 17:57:25 +02:00
import java.util.List
import java.util.Map
2019-01-30 18:19:19 +02:00
import org.hamcrest.Matchers
import org.junit.After
2018-06-20 11:46:28 +02:00
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import com.sap.piper.JenkinsUtils
import com.sap.piper.Utils
import com.sap.piper.cm.BackendType
import com.sap.piper.cm.ChangeManagement
import com.sap.piper.cm.ChangeManagementException
2018-06-20 11:46:28 +02:00
import util.BasePiperTest
import util.JenkinsCredentialsRule
2018-06-20 11:46:28 +02:00
import util.JenkinsStepRule
import util.JenkinsLoggingRule
import util.JenkinsReadYamlRule
2019-02-28 10:47:30 +02:00
import util.JenkinsDockerExecuteRule
2018-06-20 11:46:28 +02:00
import util.Rules
import hudson.AbortException
public class TransportRequestUploadFileTest extends BasePiperTest {
private ExpectedException thrown = new ExpectedException()
2019-01-22 10:25:42 +02:00
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
2018-06-20 11:46:28 +02:00
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(new JenkinsReadYamlRule(this))
2019-01-22 10:25:42 +02:00
.around(stepRule)
.around(loggingRule)
.around(new JenkinsCredentialsRule(this)
.withCredentials('CM', 'anonymous', '********'))
2018-06-20 11:46:28 +02:00
private Map cmUtilReceivedParams = [:]
2018-06-20 11:46:28 +02:00
@Before
public void setup() {
cmUtilReceivedParams.clear()
2018-06-20 11:46:28 +02:00
nullScript.commonPipelineEnvironment.configuration = [general:
[changeManagement:
2018-06-20 11:46:28 +02:00
[
2018-06-28 16:24:14 +02:00
credentialsId: 'CM',
type: 'SOLMAN',
2018-06-28 16:24:14 +02:00
endpoint: 'https://example.org/cm'
2018-06-20 11:46:28 +02:00
]
]
]
Utils.metaClass.echo = { def m -> }
}
@After
public void tearDown() {
Utils.metaClass = null
2018-06-20 11:46:28 +02:00
}
@Test
public void changeDocumentIdNotProvidedSOLMANTest() {
// we expect the failure only for SOLMAN (which is the default).
// Use case for CTS without change document id is checked by the
// straight forward test case for CTS
2018-06-20 11:46:28 +02:00
thrown.expect(IllegalArgumentException)
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' provided to the step call or via commit history).")
2018-06-20 11:46:28 +02:00
ChangeManagement cm = new ChangeManagement(nullScript) {
String getChangeDocumentId(
String from,
String to,
String pattern,
String format
) {
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
}
}
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript, transportRequestId: '001', applicationId: 'app', filePath: '/path', cmUtils: cm)
2018-06-20 11:46:28 +02:00
}
@Test
public void transportRequestIdNotProvidedTest() {
ChangeManagement cm = new ChangeManagement(nullScript) {
String getTransportRequestId(
String from,
String to,
String pattern,
String format
) {
throw new ChangeManagementException('Cannot retrieve transport request id from git commits.')
}
}
thrown.expect(IllegalArgumentException)
thrown.expectMessage("Transport request id not provided (parameter: 'transportRequestId' provided to the step call or via commit history).")
2018-06-20 11:46:28 +02:00
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript, changeDocumentId: '001', applicationId: 'app', filePath: '/path', cmUtils: cm)
2018-06-20 11:46:28 +02:00
}
@Test
public void applicationIdNotProvidedSOLMANTest() {
// we expect the failure only for SOLMAN (which is the default).
// Use case for CTS without applicationId is checked by the
// straight forward test case for CTS
2018-06-20 11:46:28 +02:00
thrown.expect(IllegalArgumentException)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR applicationId")
2018-06-20 11:46:28 +02:00
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript, changeDocumentId: '001', transportRequestId: '001', filePath: '/path')
2018-06-20 11:46:28 +02:00
}
@Test
public void filePathNotProvidedTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR filePath")
2018-06-20 11:46:28 +02:00
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript, changeDocumentId: '001', transportRequestId: '001', applicationId: 'app')
2018-06-20 11:46:28 +02:00
}
@Test
public void uploadFileToTransportRequestSOLMANFailureTest() {
2018-06-20 11:46:28 +02:00
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestSOLMAN(
2019-02-28 11:31:52 +02:00
Map docker,
String changeId,
String transportRequestId,
String applicationId,
String filePath,
String endpoint,
String credentialsId,
String cmclientOpts) {
throw new ChangeManagementException('Exception message')
}
}
2018-06-20 11:46:28 +02:00
thrown.expect(AbortException)
thrown.expectMessage("Exception message")
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
changeDocumentId: '001',
transportRequestId: '001',
applicationId: 'app',
filePath: '/path',
cmUtils: cm)
2018-06-20 11:46:28 +02:00
}
@Test
public void uploadFileToTransportRequestCTSSuccessTest() {
loggingRule.expect("[INFO] Uploading application 'myApp' to transport request '002'.")
loggingRule.expect("[INFO] Application 'myApp' has been successfully uploaded to transport request '002'.")
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestCTS(
2019-02-28 10:47:30 +02:00
Map docker,
String transportRequestId,
String endpoint,
String client,
String appName,
String appDescription,
String abapPackage,
String osDeployUser,
def deployToolsDependencies,
def npmInstallArgs,
String deployConfigFile,
String credentialsId) {
2019-02-28 10:47:30 +02:00
cmUtilReceivedParams.docker = docker
cmUtilReceivedParams.transportRequestId = transportRequestId
cmUtilReceivedParams.endpoint = endpoint
cmUtilReceivedParams.client = client
cmUtilReceivedParams.appName = appName
cmUtilReceivedParams.appDescription = appDescription
cmUtilReceivedParams.abapPackage = abapPackage
cmUtilReceivedParams.osDeployUser = osDeployUser
cmUtilReceivedParams.deployToolDependencies = deployToolsDependencies
cmUtilReceivedParams.npmInstallOpts = npmInstallArgs
cmUtilReceivedParams.deployConfigFile = deployConfigFile
cmUtilReceivedParams.credentialsId = credentialsId
}
}
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
changeManagement: [
type: 'CTS',
client: '001',
cts: [
osDeployUser: 'node2',
deployToolDependencies: ['@ui5/cli', '@sap/ux-ui5-tooling', '@ui5/logger', '@ui5/fs', '@dummy/foo'],
npmInstallOpts: ['--verbose'],
]
],
applicationName: 'myApp',
applicationDescription: 'the description',
abapPackage: 'myPackage',
transportRequestId: '002',
cmUtils: cm)
assert cmUtilReceivedParams ==
[
2019-02-28 10:47:30 +02:00
docker: [
image: 'node',
2019-02-28 10:47:30 +02:00
options:[],
envVars:[:],
pullImage:true
],
transportRequestId: '002',
endpoint: 'https://example.org/cm',
client: '001',
appName: 'myApp',
appDescription: 'the description',
abapPackage: 'myPackage',
osDeployUser: 'node2',
deployToolDependencies: ['@ui5/cli', '@sap/ux-ui5-tooling', '@ui5/logger', '@ui5/fs', '@dummy/foo'],
npmInstallOpts: ['--verbose'],
deployConfigFile: 'ui5-deploy.yaml',
credentialsId: 'CM',
]
}
2019-01-30 18:19:19 +02:00
@Test
public void uploadFileToTransportRequestRFCSanityChecksTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage(allOf(
containsString('NO VALUE AVAILABLE FOR'),
containsString('applicationUrl'),
containsString('developmentInstance'),
containsString('developmentClient'),
containsString('applicationDescription'),
containsString('abapPackage'),
containsString('applicationName')))
2019-01-30 18:19:19 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
transportRequestId: '123456', //no sanity check, can be read from git history
changeManagement: [type: 'RFC'],
)
}
@Test
public void uploadFileToTransportRequestRFCSuccessTest() {
2019-01-30 17:57:25 +02:00
def cmUtilsReceivedParams
2019-01-30 17:57:25 +02:00
nullScript.commonPipelineEnvironment.configuration =
[general:
[changeManagement:
[
endpoint: 'https://example.org/rfc'
]
]
]
def cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestRFC(
2019-02-12 14:44:09 +02:00
Map docker,
2019-01-30 17:57:25 +02:00
String transportRequestId,
String applicationId,
String applicationURL,
String endpoint,
String credentialsId,
String developmentInstance,
String developmentClient,
String applicationDescription,
2019-02-14 10:36:51 +02:00
String abapPackage,
2019-02-14 14:51:24 +02:00
String codePage,
boolean acceptUnixStyleLineEndings,
2019-02-15 13:52:44 +02:00
boolean failUploadOnWarning,
boolean verbose) {
2019-01-30 17:57:25 +02:00
cmUtilsReceivedParams = [
2019-02-12 14:44:09 +02:00
docker: docker,
2019-01-30 17:57:25 +02:00
transportRequestId: transportRequestId,
applicationName: applicationId,
2019-01-30 17:57:25 +02:00
applicationURL: applicationURL,
endpoint: endpoint,
credentialsId: credentialsId,
developmentInstance: developmentInstance,
developmentClient: developmentClient,
applicationDescription: applicationDescription,
2019-02-14 10:36:51 +02:00
abapPackage: abapPackage,
2019-02-14 14:51:24 +02:00
codePage: codePage,
acceptUnixStyleLineEndings: acceptUnixStyleLineEndings,
failUploadOnWarning: failUploadOnWarning,
]
2019-01-30 17:57:25 +02:00
}
}
stepRule.step.transportRequestUploadFile(script: nullScript,
applicationUrl: 'http://example.org/blobstore/xyz.zip',
2019-02-14 10:36:51 +02:00
codePage: 'UTF-9',
2019-02-14 14:51:24 +02:00
acceptUnixStyleLineEndings: true,
transportRequestId: '123456',
changeManagement: [
type: 'RFC',
rfc: [
developmentClient: '002',
developmentInstance: '001'
]
],
applicationName: '42',
applicationDescription: 'Lorem ipsum',
2019-01-30 17:57:25 +02:00
abapPackage: 'XYZ',
cmUtils: cm,)
2019-01-30 17:57:25 +02:00
assert cmUtilsReceivedParams ==
[
2019-02-12 14:44:09 +02:00
docker: [
image: 'rfc',
options: [],
envVars: [:],
2019-02-18 17:59:44 +02:00
pullImage: true
2019-02-12 14:44:09 +02:00
],
2019-01-30 17:57:25 +02:00
transportRequestId: '123456',
applicationName: '42',
2019-01-30 17:57:25 +02:00
applicationURL: 'http://example.org/blobstore/xyz.zip',
endpoint: 'https://example.org/rfc',
credentialsId: 'CM',
developmentInstance: '001',
developmentClient: '002',
applicationDescription: 'Lorem ipsum',
2019-02-14 10:36:51 +02:00
abapPackage:'XYZ',
codePage: 'UTF-9',
2019-02-14 14:51:24 +02:00
acceptUnixStyleLineEndings: true,
failUploadOnWarning: true,
2019-01-30 17:57:25 +02:00
]
}
2019-01-30 18:27:27 +02:00
@Test
public void uploadFileToTransportRequestRFCUploadFailsTest() {
thrown.expect(AbortException)
thrown.expectMessage('upload failed')
def cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestRFC(
2019-02-12 14:44:09 +02:00
Map docker,
2019-01-30 18:27:27 +02:00
String transportRequestId,
String applicationId,
String applicationURL,
String endpoint,
String credentialsId,
String developmentInstance,
String developmentClient,
String applicationDescription,
2019-02-14 10:36:51 +02:00
String abapPackage,
2019-02-14 14:51:24 +02:00
String codePage,
boolean acceptUnixStyleLineEndings,
2019-02-15 13:52:44 +02:00
boolean failOnUploadWarning,
boolean verbose) {
2019-01-30 18:27:27 +02:00
throw new ChangeManagementException('upload failed')
}
}
stepRule.step.transportRequestUploadFile(script: nullScript,
applicationUrl: 'http://example.org/blobstore/xyz.zip',
2019-02-14 10:36:51 +02:00
codePage: 'UTF-9',
2019-02-14 14:51:24 +02:00
acceptUnixStyleLineEndings: true,
2019-01-30 18:27:27 +02:00
transportRequestId: '123456',
changeManagement: [
type: 'RFC',
rfc: [
2019-02-12 14:44:09 +02:00
docker: [
image: 'rfc',
options: [],
envVars: [:],
2019-02-18 17:59:44 +02:00
pullImage: false,
2019-02-12 14:44:09 +02:00
],
developmentClient: '002',
developmentInstance: '001',
]
],
applicationName: '42',
2019-01-30 18:27:27 +02:00
applicationDescription: 'Lorem ipsum',
abapPackage: 'XYZ',
cmUtils: cm,)
}
@Test
public void uploadFileToTransportRequestSOLMANSuccessTest() {
2018-06-20 11:46:28 +02:00
// Here we test only the case where the transportRequestId is
// provided via parameters. The other cases are tested by
// corresponding tests for StepHelpers#getTransportRequestId(./.)
loggingRule.expect("[INFO] Uploading file '/path' to transport request '002' of change document '001'.")
loggingRule.expect("[INFO] File '/path' has been successfully uploaded to transport request '002' of change document '001'.")
2018-06-20 11:46:28 +02:00
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestSOLMAN(
2019-02-28 11:31:52 +02:00
Map docker,
String changeId,
String transportRequestId,
String applicationId,
String filePath,
String endpoint,
String credentialsId,
String cmclientOpts) {
2018-06-20 11:46:28 +02:00
2019-02-28 11:31:52 +02:00
cmUtilReceivedParams.docker = docker
cmUtilReceivedParams.changeId = changeId
cmUtilReceivedParams.transportRequestId = transportRequestId
cmUtilReceivedParams.applicationId = applicationId
cmUtilReceivedParams.filePath = filePath
cmUtilReceivedParams.endpoint = endpoint
cmUtilReceivedParams.credentialsId = credentialsId
cmUtilReceivedParams.cmclientOpts = cmclientOpts
}
}
2018-06-20 11:46:28 +02:00
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
2018-07-13 14:40:29 +02:00
changeDocumentId: '001',
transportRequestId: '002',
2018-07-13 14:40:29 +02:00
applicationId: 'app',
filePath: '/path',
cmUtils: cm)
assert cmUtilReceivedParams ==
[
2019-02-28 11:31:52 +02:00
docker: [
image: 'ppiper/cm-client',
pullImage: true,
envVars: [:],
options: [],
],
changeId: '001',
transportRequestId: '002',
applicationId: 'app',
filePath: '/path',
endpoint: 'https://example.org/cm',
credentialsId: 'CM',
cmclientOpts: ''
]
2018-06-20 11:46:28 +02:00
}
@Test
public void uploadFileToTransportRequestSOLMANSuccessApplicationIdFromConfigurationTest() {
nullScript.commonPipelineEnvironment.configuration.put(['steps',
[transportRequestUploadFile:
[applicationId: 'AppIdfromConfig']]])
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestSOLMAN(
2019-02-28 11:31:52 +02:00
Map docker,
String changeId,
String transportRequestId,
String applicationId,
String filePath,
String endpoint,
String credentialsId,
String cmclientOpts) {
cmUtilReceivedParams.applicationId = applicationId
}
}
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(
script: nullScript,
changeDocumentId: '001',
transportRequestId: '002',
filePath: '/path',
cmUtils: cm)
assert cmUtilReceivedParams.applicationId == 'AppIdfromConfig'
}
@Test
public void uploadFileToTransportRequestSOLMANFilePathFromParameters() {
// this one is not used when file path is provided via signature
nullScript.commonPipelineEnvironment.setMtarFilePath('/path2')
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestSOLMAN(
2019-02-28 11:31:52 +02:00
Map docker,
String changeId,
String transportRequestId,
String applicationId,
String filePath,
String endpoint,
String credentialsId,
String cmclientOpts) {
cmUtilReceivedParams.filePath = filePath
}
}
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
changeDocumentId: '001',
transportRequestId: '002',
applicationId: 'app',
filePath: '/path',
cmUtils: cm)
assert cmUtilReceivedParams.filePath == '/path'
}
@Test
public void uploadFileToTransportRequestSOLMANFilePathFromCommonPipelineEnvironment() {
// this one is used since there is nothing in the signature
nullScript.commonPipelineEnvironment.setMtarFilePath('/path2')
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestSOLMAN(
2019-02-28 11:31:52 +02:00
Map docker,
String changeId,
String transportRequestId,
String applicationId,
String filePath,
String endpoint,
String credentialsId,
String cmclientOpts) {
cmUtilReceivedParams.filePath = filePath
}
}
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
changeDocumentId: '001',
transportRequestId: '002',
applicationId: 'app',
cmUtils: cm)
assert cmUtilReceivedParams.filePath == '/path2'
}
@Test
public void uploadFileToTransportRequestSOLMANUploadFailureTest() {
thrown.expect(AbortException)
thrown.expectMessage('Upload failure.')
2018-06-20 11:46:28 +02:00
ChangeManagement cm = new ChangeManagement(nullScript) {
void uploadFileToTransportRequestSOLMAN(
2019-02-28 11:31:52 +02:00
Map docker,
String changeId,
String transportRequestId,
String applicationId,
String filePath,
String endpoint,
String credentialsId,
String cmclientOpts) {
throw new ChangeManagementException('Upload failure.')
}
}
2018-06-20 11:46:28 +02:00
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
changeDocumentId: '001',
transportRequestId: '001',
applicationId: 'app',
filePath: '/path',
cmUtils: cm)
2018-06-20 11:46:28 +02:00
}
2018-09-18 14:49:06 +02:00
@Test
public void invalidBackendTypeTest() {
thrown.expect(AbortException)
thrown.expectMessage('Invalid backend type: \'DUMMY\'. Valid values: [SOLMAN, CTS, RFC, NONE]. ' +
2018-09-18 14:49:06 +02:00
'Configuration: \'changeManagement/type\'.')
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
2018-09-18 14:49:06 +02:00
applicationId: 'app',
filePath: '/path',
changeManagement: [type: 'DUMMY'])
}
2018-09-28 13:45:26 +02:00
@Test
public void cmIntegrationSwichtedOffTest() {
loggingRule.expect('[INFO] Change management integration intentionally switched off.')
2018-09-28 13:45:26 +02:00
2019-01-22 10:25:42 +02:00
stepRule.step.transportRequestUploadFile(script: nullScript,
2018-09-28 13:45:26 +02:00
changeManagement: [type: 'NONE'])
}
2018-06-20 11:46:28 +02:00
}