2019-02-14 13:29:13 +02:00
|
|
|
import static org.hamcrest.Matchers.allOf
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
|
2019-02-14 13:01:28 +02:00
|
|
|
import java.util.Map
|
|
|
|
|
2019-02-14 13:29:13 +02:00
|
|
|
import org.hamcrest.Matchers
|
|
|
|
import org.hamcrest.core.StringContains
|
2018-06-20 11:36:41 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
|
2018-09-25 09:12:07 +02:00
|
|
|
import com.sap.piper.cm.BackendType
|
2018-06-29 09:34:46 +02:00
|
|
|
import com.sap.piper.cm.ChangeManagement
|
|
|
|
import com.sap.piper.cm.ChangeManagementException
|
|
|
|
|
2018-06-20 11:36:41 +02:00
|
|
|
import util.BasePiperTest
|
2018-07-13 13:27:21 +02:00
|
|
|
import util.JenkinsCredentialsRule
|
2018-06-20 11:36:41 +02:00
|
|
|
import util.JenkinsStepRule
|
|
|
|
import util.JenkinsLoggingRule
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-06-20 11:36:41 +02:00
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import hudson.AbortException
|
|
|
|
|
|
|
|
public class TransportRequestCreateTest extends BasePiperTest {
|
|
|
|
|
|
|
|
private ExpectedException thrown = new ExpectedException()
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2019-01-22 10:22:15 +02:00
|
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
2018-06-20 11:36:41 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain ruleChain = Rules.getCommonRules(this)
|
2018-08-31 10:22:43 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2018-06-20 11:36:41 +02:00
|
|
|
.around(thrown)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2019-01-22 10:22:15 +02:00
|
|
|
.around(loggingRule)
|
2018-07-13 13:27:21 +02:00
|
|
|
.around(new JenkinsCredentialsRule(this)
|
|
|
|
.withCredentials('CM', 'anonymous', '********'))
|
2018-06-20 11:36:41 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setup() {
|
|
|
|
|
|
|
|
|
2018-07-17 09:21:56 +02:00
|
|
|
nullScript.commonPipelineEnvironment.configuration = [general:
|
|
|
|
[changeManagement:
|
2018-07-16 15:41:46 +02:00
|
|
|
|
2018-06-20 11:36:41 +02:00
|
|
|
[
|
2018-06-28 16:24:14 +02:00
|
|
|
credentialsId: 'CM',
|
2018-09-28 14:06:06 +02:00
|
|
|
type: 'SOLMAN',
|
2018-06-29 13:38:41 +02:00
|
|
|
endpoint: 'https://example.org/cm',
|
2018-07-17 09:21:56 +02:00
|
|
|
clientOpts: '-DmyProp=myVal',
|
|
|
|
changeDocumentLabel: 'ChangeId\\s?:',
|
|
|
|
git: [from: 'origin/master',
|
|
|
|
to: 'HEAD',
|
|
|
|
format: '%b']
|
2018-06-20 11:36:41 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-02-14 13:04:15 +02:00
|
|
|
public void changeIdNotProvidedSOLANTest() {
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2018-07-12 08:54:04 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
2018-07-13 09:28:41 +02:00
|
|
|
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
2018-07-10 14:43:15 +02:00
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
String getChangeDocumentId(
|
|
|
|
String from,
|
|
|
|
String to,
|
|
|
|
String label,
|
|
|
|
String format
|
|
|
|
) {
|
|
|
|
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestCreate(script: nullScript, developmentSystemId: '001', cmUtils: cm)
|
2018-06-20 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-02-14 13:04:15 +02:00
|
|
|
public void developmentSystemIdNotProvidedSOLMANTest() {
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2018-07-12 08:54:04 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR developmentSystemId")
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestCreate(script: nullScript, changeDocumentId: '001')
|
2018-06-20 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-02-14 13:04:15 +02:00
|
|
|
public void createTransportRequestFailureSOLMANTest() {
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2018-06-29 09:34:46 +02:00
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
|
2018-09-25 09:12:07 +02:00
|
|
|
String createTransportRequestSOLMAN(
|
|
|
|
String changeId,
|
2018-06-29 09:34:46 +02:00
|
|
|
String developmentSystemId,
|
|
|
|
String cmEndpoint,
|
2018-07-16 15:41:46 +02:00
|
|
|
String credentialId,
|
2018-06-29 13:38:41 +02:00
|
|
|
String clientOpts) {
|
2018-06-29 09:34:46 +02:00
|
|
|
|
|
|
|
throw new ChangeManagementException('Exception message.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:36:41 +02:00
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
2018-06-29 09:34:46 +02:00
|
|
|
thrown.expectMessage("Exception message.")
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
2018-06-20 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-09-25 09:12:07 +02:00
|
|
|
public void createTransportRequestSuccessSOLMANTest() {
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2018-06-29 09:34:46 +02:00
|
|
|
def result = [:]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
|
2018-09-25 09:12:07 +02:00
|
|
|
String createTransportRequestSOLMAN(
|
|
|
|
String changeId,
|
2018-06-29 09:34:46 +02:00
|
|
|
String developmentSystemId,
|
|
|
|
String cmEndpoint,
|
2018-07-16 15:41:46 +02:00
|
|
|
String credentialId,
|
2018-06-29 13:38:41 +02:00
|
|
|
String clientOpts) {
|
2018-06-29 09:34:46 +02:00
|
|
|
|
|
|
|
result.changeId = changeId
|
|
|
|
result.developmentSystemId = developmentSystemId
|
|
|
|
result.cmEndpoint = cmEndpoint
|
2018-07-16 15:41:46 +02:00
|
|
|
result.credentialId = credentialId
|
2018-06-29 13:38:41 +02:00
|
|
|
result.clientOpts = clientOpts
|
2018-06-29 09:34:46 +02:00
|
|
|
return '001'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2018-11-06 16:10:54 +02:00
|
|
|
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001'
|
2018-06-29 09:34:46 +02:00
|
|
|
assert result == [changeId: '001',
|
|
|
|
developmentSystemId: '001',
|
|
|
|
cmEndpoint: 'https://example.org/cm',
|
2018-07-16 15:41:46 +02:00
|
|
|
credentialId: 'CM',
|
2018-06-29 13:38:41 +02:00
|
|
|
clientOpts: '-DmyProp=myVal'
|
2018-06-29 09:34:46 +02:00
|
|
|
]
|
2018-06-20 11:36:41 +02:00
|
|
|
|
2019-01-22 10:22:15 +02:00
|
|
|
assert loggingRule.log.contains("[INFO] Creating transport request for change document '001' and development system '001'.")
|
|
|
|
assert loggingRule.log.contains("[INFO] Transport Request '001' has been successfully created.")
|
2018-06-20 11:36:41 +02:00
|
|
|
}
|
2018-09-25 09:12:07 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void createTransportRequestSuccessCTSTest() {
|
|
|
|
|
|
|
|
def result = [:]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
|
|
|
|
String createTransportRequestCTS(
|
|
|
|
String transportType,
|
|
|
|
String targetSystemId,
|
|
|
|
String description,
|
|
|
|
String endpoint,
|
|
|
|
String credentialsId,
|
2019-02-15 12:05:21 +02:00
|
|
|
String clientOpts) {
|
2018-09-25 09:12:07 +02:00
|
|
|
result.transportType = transportType
|
|
|
|
result.targetSystemId = targetSystemId
|
|
|
|
result.description = description
|
|
|
|
result.endpoint = endpoint
|
|
|
|
result.credentialsId = credentialsId
|
|
|
|
result.clientOpts = clientOpts
|
|
|
|
return '001'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.call(script: nullScript,
|
2018-11-06 16:10:54 +02:00
|
|
|
transportType: 'W',
|
|
|
|
targetSystem: 'XYZ',
|
|
|
|
description: 'desc',
|
|
|
|
changeManagement: [type: 'CTS'],
|
|
|
|
cmUtils: cm)
|
2018-09-25 09:12:07 +02:00
|
|
|
|
2018-11-06 16:10:54 +02:00
|
|
|
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001'
|
2018-09-25 09:12:07 +02:00
|
|
|
assert result == [transportType: 'W',
|
|
|
|
targetSystemId: 'XYZ',
|
|
|
|
description: 'desc',
|
|
|
|
endpoint: 'https://example.org/cm',
|
|
|
|
credentialsId: 'CM',
|
|
|
|
clientOpts: '-DmyProp=myVal'
|
|
|
|
]
|
|
|
|
|
2019-01-22 10:22:15 +02:00
|
|
|
assert loggingRule.log.contains("[INFO] Creating transport request.")
|
|
|
|
assert loggingRule.log.contains("[INFO] Transport Request '001' has been successfully created.")
|
2018-09-25 09:12:07 +02:00
|
|
|
}
|
|
|
|
|
2019-02-14 13:01:28 +02:00
|
|
|
@Test
|
|
|
|
public void createTransportRequestSuccessRFCTest() {
|
|
|
|
|
|
|
|
def result = [:]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
|
|
|
|
String createTransportRequestRFC(
|
|
|
|
Map docker,
|
|
|
|
String endpoint,
|
|
|
|
String developmentClient,
|
|
|
|
String developmentInstance,
|
|
|
|
String credentialsId,
|
2019-03-05 11:29:23 +02:00
|
|
|
String description,
|
|
|
|
boolean verbose) {
|
2019-02-14 13:01:28 +02:00
|
|
|
|
|
|
|
result.docker = docker
|
|
|
|
result.endpoint = endpoint
|
|
|
|
result.developmentClient = developmentClient
|
|
|
|
result.developmentInstance= developmentInstance
|
|
|
|
result.credentialsId = credentialsId
|
|
|
|
result.description = description
|
2019-03-05 11:29:23 +02:00
|
|
|
result.verbose = verbose
|
2019-02-14 13:01:28 +02:00
|
|
|
|
|
|
|
return '001'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.transportRequestCreate(
|
|
|
|
script: nullScript,
|
|
|
|
changeManagement: [
|
|
|
|
type: 'RFC',
|
|
|
|
rfc: [
|
|
|
|
developmentInstance: '01',
|
|
|
|
developmentClient: '001',
|
|
|
|
],
|
|
|
|
endpoint: 'https://example.org/rfc',
|
|
|
|
],
|
|
|
|
developmentSystemId: '001',
|
|
|
|
description: '',
|
2019-03-05 11:29:23 +02:00
|
|
|
cmUtils: cm,
|
|
|
|
verbose: true)
|
2019-02-14 13:01:28 +02:00
|
|
|
|
|
|
|
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001'
|
|
|
|
assert result == [
|
|
|
|
docker: [
|
|
|
|
image: 'rfc',
|
|
|
|
options: [],
|
|
|
|
envVars: [:],
|
2019-02-18 17:59:44 +02:00
|
|
|
pullImage: true
|
2019-02-14 13:01:28 +02:00
|
|
|
],
|
|
|
|
endpoint: 'https://example.org/rfc',
|
|
|
|
developmentClient: '01',
|
|
|
|
developmentInstance: '001',
|
|
|
|
credentialsId: 'CM',
|
2019-03-05 11:29:23 +02:00
|
|
|
description: '',
|
|
|
|
verbose: true
|
2019-02-14 13:01:28 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
assert loggingRule.log.contains("[INFO] Creating transport request.")
|
|
|
|
assert loggingRule.log.contains("[INFO] Transport Request '001' has been successfully created.")
|
|
|
|
}
|
|
|
|
|
2019-02-14 13:22:45 +02:00
|
|
|
@Test
|
|
|
|
public void createTransportRequestFailureRFCTest() {
|
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
|
|
|
thrown.expectMessage('upload failed')
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
|
|
|
|
String createTransportRequestRFC(
|
|
|
|
Map docker,
|
|
|
|
String endpoint,
|
|
|
|
String developmentClient,
|
|
|
|
String developmentInstance,
|
|
|
|
String credentialsId,
|
2019-03-05 11:29:23 +02:00
|
|
|
String description,
|
|
|
|
boolean verbose) {
|
2019-02-14 13:22:45 +02:00
|
|
|
|
|
|
|
throw new ChangeManagementException('upload failed')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.transportRequestCreate(
|
|
|
|
script: nullScript,
|
|
|
|
changeManagement: [
|
|
|
|
type: 'RFC',
|
|
|
|
rfc: [
|
|
|
|
developmentInstance: '01',
|
|
|
|
developmentClient: '001',
|
|
|
|
],
|
|
|
|
endpoint: 'https://example.org/rfc',
|
|
|
|
],
|
|
|
|
developmentSystemId: '001',
|
|
|
|
description: '',
|
|
|
|
cmUtils: cm)
|
|
|
|
}
|
|
|
|
|
2019-02-14 13:29:13 +02:00
|
|
|
@Test
|
|
|
|
public void createTransportRequestSanityChecksRFCTest() {
|
|
|
|
|
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage(allOf(
|
|
|
|
containsString('changeManagement/rfc/developmentInstance'),
|
|
|
|
containsString('changeManagement/rfc/developmentClient'),
|
|
|
|
))
|
|
|
|
stepRule.step.transportRequestCreate(
|
|
|
|
script: nullScript,
|
|
|
|
changeManagement: [
|
|
|
|
type: 'RFC',
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2018-09-28 13:45:26 +02:00
|
|
|
@Test
|
|
|
|
public void cmIntegrationSwichtedOffTest() {
|
|
|
|
|
2019-01-22 10:22:15 +02:00
|
|
|
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.transportRequestCreate(script: nullScript,
|
2018-09-28 13:45:26 +02:00
|
|
|
changeManagement: [type: 'NONE'])
|
|
|
|
}
|
2018-06-20 11:36:41 +02:00
|
|
|
}
|