2019-02-01 14:23:08 +02:00
|
|
|
import static org.hamcrest.Matchers.allOf
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
|
|
|
|
import org.hamcrest.Matchers
|
2018-06-20 11:52:11 +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 10:44:53 +02:00
|
|
|
import com.sap.piper.cm.BackendType
|
2018-07-12 15:23:12 +02:00
|
|
|
import com.sap.piper.cm.ChangeManagement
|
|
|
|
import com.sap.piper.cm.ChangeManagementException
|
|
|
|
|
2018-06-20 11:52:11 +02:00
|
|
|
import util.BasePiperTest
|
2018-07-13 13:27:21 +02:00
|
|
|
import util.JenkinsCredentialsRule
|
2019-02-01 14:04:25 +02:00
|
|
|
import util.JenkinsDockerExecuteRule
|
2018-06-20 11:52:11 +02:00
|
|
|
import util.JenkinsStepRule
|
|
|
|
import util.JenkinsLoggingRule
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-06-20 11:52:11 +02:00
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import hudson.AbortException
|
2018-07-12 15:23:12 +02:00
|
|
|
import hudson.scm.NullSCM
|
2018-06-20 11:52:11 +02:00
|
|
|
|
|
|
|
public class TransportRequestReleaseTest 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:52:11 +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:52:11 +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:52:11 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setup() {
|
|
|
|
|
2018-07-17 09:21:56 +02:00
|
|
|
nullScript.commonPipelineEnvironment.configuration = [general:
|
|
|
|
[changeManagement:
|
2018-06-20 11:52:11 +02:00
|
|
|
[
|
2018-06-28 16:24:14 +02:00
|
|
|
credentialsId: 'CM',
|
2018-09-28 14:06:06 +02:00
|
|
|
type: 'SOLMAN',
|
2018-06-28 16:24:14 +02:00
|
|
|
endpoint: 'https://example.org/cm'
|
2018-06-20 11:52:11 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-02-06 16:16:27 +02:00
|
|
|
public void changeDocumentIdNotProvidedSOLMANTest() {
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2018-07-10 16:33:23 +02:00
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
String getChangeDocumentId(String from,
|
|
|
|
String to,
|
|
|
|
String label,
|
|
|
|
String format) {
|
|
|
|
throw new ChangeManagementException('Cannot retrieve change documentId')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 08:54:04 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
2018-07-19 10:06:40 +02:00
|
|
|
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestRelease(script: nullScript, transportRequestId: '001', cmUtils: cm)
|
2018-06-20 11:52:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void transportRequestIdNotProvidedTest() {
|
|
|
|
|
2018-07-12 15:23:12 +02:00
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
String getTransportRequestId(String from,
|
|
|
|
String to,
|
|
|
|
String label,
|
|
|
|
String format) {
|
|
|
|
throw new ChangeManagementException('Cannot retrieve transportRequestId')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 08:54:04 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
2018-07-16 12:09:49 +02:00
|
|
|
thrown.expectMessage("Transport request id not provided (parameter: 'transportRequestId' or via commit history).")
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestRelease(script: nullScript, changeDocumentId: '001', cmUtils: cm)
|
2018-06-20 11:52:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-02-05 18:29:45 +02:00
|
|
|
public void releaseTransportRequestFailsSOLMANTest() {
|
2018-06-20 11:52:11 +02:00
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
2018-07-19 11:18:52 +02:00
|
|
|
thrown.expectMessage("Something went wrong")
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
2018-08-14 10:56:34 +02:00
|
|
|
|
2019-02-01 10:50:53 +02:00
|
|
|
void releaseTransportRequestSOLMAN(
|
2018-09-25 10:44:53 +02:00
|
|
|
String changeId,
|
2018-07-19 11:18:52 +02:00
|
|
|
String transportRequestId,
|
|
|
|
String endpoint,
|
2018-08-14 10:56:34 +02:00
|
|
|
String credentialsId,
|
2018-07-19 11:18:52 +02:00
|
|
|
String clientOpts) {
|
|
|
|
|
|
|
|
throw new ChangeManagementException('Something went wrong')
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestRelease(script: nullScript, changeDocumentId: '001', transportRequestId: '001', cmUtils: cm)
|
2018-06-20 11:52:11 +02:00
|
|
|
}
|
|
|
|
|
2019-02-05 18:29:45 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestFailsCTSTest() {
|
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
|
|
|
thrown.expectMessage("Something went wrong")
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration
|
|
|
|
.general
|
|
|
|
.changeManagement
|
|
|
|
.type = 'CTS'
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
|
|
|
|
void releaseTransportRequestCTS(
|
|
|
|
String transportRequestId,
|
|
|
|
String endpoint,
|
|
|
|
String credentialsId,
|
|
|
|
String clientOpts) {
|
|
|
|
|
|
|
|
throw new ChangeManagementException('Something went wrong')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
transportRequestId: '001',
|
|
|
|
cmUtils: cm)
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:04:25 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestSuccessRFCTest() {
|
|
|
|
|
|
|
|
def receivedParameters
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration
|
|
|
|
.general
|
|
|
|
.changeManagement =
|
|
|
|
[
|
|
|
|
credentialsId: 'CM',
|
|
|
|
type: 'RFC',
|
|
|
|
endpoint: 'https://example.org/rfc',
|
2019-02-12 14:44:09 +02:00
|
|
|
rfc: [
|
|
|
|
dockerImage: 'rfc',
|
|
|
|
dockerOptions: [],
|
|
|
|
]
|
2019-02-01 14:04:25 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
void releaseTransportRequestRFC(
|
2019-02-13 15:58:46 +02:00
|
|
|
Map docker,
|
2019-02-01 14:04:25 +02:00
|
|
|
String transportRequestId,
|
|
|
|
String endpoint,
|
2019-02-07 12:46:45 +02:00
|
|
|
String developmentInstance,
|
2019-02-01 14:04:25 +02:00
|
|
|
String developmentClient,
|
|
|
|
String credentialsId) {
|
|
|
|
|
|
|
|
receivedParameters = [
|
2019-02-13 15:58:46 +02:00
|
|
|
docker: docker,
|
2019-02-01 14:04:25 +02:00
|
|
|
transportRequestId: transportRequestId,
|
|
|
|
endpoint: endpoint,
|
2019-02-07 12:46:45 +02:00
|
|
|
developmentInstance: developmentInstance,
|
2019-02-01 14:04:25 +02:00
|
|
|
developmentClient: developmentClient,
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
transportRequestId: '002',
|
2019-02-07 12:46:45 +02:00
|
|
|
changeManagement: [
|
|
|
|
rfc: [
|
|
|
|
developmentClient: '003',
|
|
|
|
developmentInstance: '002',
|
|
|
|
]
|
|
|
|
],
|
2019-02-01 14:04:25 +02:00
|
|
|
cmUtils: cm)
|
|
|
|
|
|
|
|
assert receivedParameters == [
|
2019-02-13 15:58:46 +02:00
|
|
|
docker: [
|
|
|
|
image: 'rfc',
|
|
|
|
options: [],
|
|
|
|
envVars: [:],
|
2019-02-18 17:59:44 +02:00
|
|
|
pullImage: true,
|
2019-02-13 15:58:46 +02:00
|
|
|
],
|
2019-02-01 14:04:25 +02:00
|
|
|
transportRequestId: '002',
|
|
|
|
endpoint: 'https://example.org/rfc',
|
2019-02-07 12:46:45 +02:00
|
|
|
developmentInstance: '002',
|
2019-02-01 14:04:25 +02:00
|
|
|
developmentClient: '003',
|
|
|
|
credentialsId: 'CM',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-02-06 15:23:00 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestSuccessCTSTest() {
|
|
|
|
|
|
|
|
def receivedParameters
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration
|
|
|
|
.general
|
|
|
|
.changeManagement =
|
|
|
|
[
|
|
|
|
credentialsId: 'CM',
|
|
|
|
type: 'CTS',
|
|
|
|
endpoint: 'https://example.org/cts'
|
|
|
|
]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
void releaseTransportRequestCTS(
|
|
|
|
String transportRequestId,
|
|
|
|
String endpoint,
|
|
|
|
String credentialsId,
|
|
|
|
String clientOpts = '') {
|
|
|
|
|
|
|
|
receivedParameters = [
|
|
|
|
transportRequestId: transportRequestId,
|
|
|
|
endpoint: endpoint,
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
clientOpts: clientOpts
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
transportRequestId: '002',
|
|
|
|
cmUtils: cm)
|
|
|
|
|
|
|
|
assert receivedParameters == [
|
|
|
|
transportRequestId: '002',
|
|
|
|
endpoint: 'https://example.org/cts',
|
|
|
|
credentialsId: 'CM',
|
|
|
|
clientOpts: ''
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:29:41 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestFailsRFCTest() {
|
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
|
|
|
thrown.expectMessage('Failed releasing transport request.')
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration
|
|
|
|
.general
|
|
|
|
.changeManagement =
|
|
|
|
[
|
|
|
|
credentialsId: 'CM',
|
|
|
|
type: 'RFC',
|
|
|
|
endpoint: 'https://example.org/rfc',
|
|
|
|
rfc: [dockerImage: 'rfc']
|
|
|
|
]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
void releaseTransportRequestRFC(
|
2019-02-13 15:58:46 +02:00
|
|
|
Map docker,
|
2019-02-01 14:29:41 +02:00
|
|
|
String transportRequestId,
|
|
|
|
String endpoint,
|
2019-02-07 12:46:45 +02:00
|
|
|
String developmentInstance,
|
2019-02-01 14:29:41 +02:00
|
|
|
String developmentClient,
|
|
|
|
String credentialsId) {
|
|
|
|
|
|
|
|
throw new ChangeManagementException('Failed releasing transport request.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
transportRequestId: '002',
|
2019-02-07 12:46:45 +02:00
|
|
|
changeManagement: [
|
|
|
|
rfc: [
|
|
|
|
developmentClient: '003',
|
|
|
|
developmentInstance: '002'
|
|
|
|
]
|
|
|
|
],
|
2019-02-01 14:29:41 +02:00
|
|
|
cmUtils: cm)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:16:27 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestSanityChecksSOLMANTest() {
|
|
|
|
|
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage(allOf(
|
|
|
|
containsString('ERROR - NO VALUE AVAILABLE FOR'),
|
|
|
|
containsString('changeManagement/endpoint')))
|
|
|
|
|
|
|
|
// changeDocumentId and transportRequestId are not checked
|
|
|
|
// by the sanity checks here since they are looked up from
|
|
|
|
// commit history in case they are not provided.
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = null
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
changeManagement: [type: 'SOLMAN']
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:31:50 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestSanityChecksCTSTest() {
|
|
|
|
|
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage(allOf(
|
|
|
|
containsString('ERROR - NO VALUE AVAILABLE FOR'),
|
|
|
|
containsString('changeManagement/endpoint')))
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = null
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
changeManagement: [type: 'CTS']
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-02-01 14:23:08 +02:00
|
|
|
@Test
|
|
|
|
public void releaseTransportRequestSanityChecksRFCTest() {
|
|
|
|
|
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage(allOf(
|
|
|
|
containsString('ERROR - NO VALUE AVAILABLE FOR:'),
|
|
|
|
containsString('changeManagement/endpoint'),
|
|
|
|
containsString('developmentClient')))
|
|
|
|
|
|
|
|
nullScript
|
|
|
|
.commonPipelineEnvironment
|
|
|
|
.configuration = null
|
|
|
|
|
|
|
|
stepRule.step.transportRequestRelease(
|
|
|
|
script: nullScript,
|
|
|
|
changeManagement: [type: 'RFC'],
|
|
|
|
transportRequestId: '002')
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:52:11 +02:00
|
|
|
@Test
|
2019-02-01 10:50:53 +02:00
|
|
|
public void releaseTransportRequestSuccessSOLMANTest() {
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2018-11-06 14:47:32 +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(./.)
|
|
|
|
|
2019-01-22 10:22:15 +02:00
|
|
|
loggingRule.expect("[INFO] Closing transport request '002' for change document '001'.")
|
|
|
|
loggingRule.expect("[INFO] Transport Request '002' has been successfully closed.")
|
2018-07-19 11:18:52 +02:00
|
|
|
|
|
|
|
Map receivedParams = [:]
|
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
2019-02-01 10:50:53 +02:00
|
|
|
void releaseTransportRequestSOLMAN(
|
2018-09-25 10:44:53 +02:00
|
|
|
String changeId,
|
2018-07-19 11:18:52 +02:00
|
|
|
String transportRequestId,
|
|
|
|
String endpoint,
|
2018-08-14 10:56:34 +02:00
|
|
|
String credentialsId,
|
2018-07-19 11:18:52 +02:00
|
|
|
String clientOpts) {
|
|
|
|
|
|
|
|
receivedParams.changeId = changeId
|
|
|
|
receivedParams.transportRequestId = transportRequestId
|
|
|
|
receivedParams.endpoint = endpoint
|
2018-08-14 10:56:34 +02:00
|
|
|
receivedParams.credentialsId = credentialsId
|
2018-07-19 11:18:52 +02:00
|
|
|
receivedParams.clientOpts = clientOpts
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.transportRequestRelease(script: nullScript, changeDocumentId: '001', transportRequestId: '002', cmUtils: cm)
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2019-02-01 10:50:53 +02:00
|
|
|
assert receivedParams == [
|
2018-09-25 10:44:53 +02:00
|
|
|
changeId: '001',
|
2018-07-19 11:18:52 +02:00
|
|
|
transportRequestId: '002',
|
|
|
|
endpoint: 'https://example.org/cm',
|
2018-08-14 10:56:34 +02:00
|
|
|
credentialsId: 'CM',
|
|
|
|
clientOpts: '']
|
2018-06-20 11:52:11 +02:00
|
|
|
}
|
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.transportRequestRelease(script: nullScript,
|
2018-09-28 13:45:26 +02:00
|
|
|
changeManagement: [type: 'NONE'])
|
|
|
|
}
|
2018-06-20 11:52:11 +02:00
|
|
|
}
|