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/TransportRequestReleaseTest.groovy

155 lines
5.8 KiB
Groovy
Raw Normal View History

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
import com.sap.piper.cm.BackendType
import com.sap.piper.cm.ChangeManagement
import com.sap.piper.cm.ChangeManagementException
2018-06-20 11:52:11 +02:00
import util.BasePiperTest
import util.JenkinsCredentialsRule
2018-06-20 11:52:11 +02:00
import util.JenkinsStepRule
import util.JenkinsLoggingRule
import util.JenkinsReadYamlRule
2018-06-20 11:52:11 +02:00
import util.Rules
import hudson.AbortException
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)
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
2018-06-20 11:52:11 +02:00
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
2018-06-20 11:52:11 +02:00
.around(thrown)
2019-01-22 10:25:42 +02:00
.around(stepRule)
.around(loggingRule)
.around(new JenkinsCredentialsRule(this)
.withCredentials('CM', 'anonymous', '********'))
2018-06-20 11:52:11 +02:00
@Before
public void setup() {
nullScript.commonPipelineEnvironment.configuration = [general:
[changeManagement:
2018-06-20 11:52:11 +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:52:11 +02:00
]
]
]
}
@Test
public void changeIdNotProvidedTest() {
ChangeManagement cm = new ChangeManagement(nullScript) {
String getChangeDocumentId(String from,
String to,
String label,
String format) {
throw new ChangeManagementException('Cannot retrieve change documentId')
}
}
thrown.expect(IllegalArgumentException)
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() {
ChangeManagement cm = new ChangeManagement(nullScript) {
String getTransportRequestId(String from,
String to,
String label,
String format) {
throw new ChangeManagementException('Cannot retrieve transportRequestId')
}
}
thrown.expect(IllegalArgumentException)
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
public void releaseTransportRequestFailureTest() {
thrown.expect(AbortException)
thrown.expectMessage("Something went wrong")
ChangeManagement cm = new ChangeManagement(nullScript) {
void releaseTransportRequestSOLMAN(
String changeId,
String transportRequestId,
String endpoint,
String credentialsId,
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
}
@Test
public void releaseTransportRequestSuccessSOLMANTest() {
2018-06-20 11:52:11 +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] Closing transport request '002' for change document '001'.")
loggingRule.expect("[INFO] Transport Request '002' has been successfully closed.")
Map receivedParams = [:]
ChangeManagement cm = new ChangeManagement(nullScript) {
void releaseTransportRequestSOLMAN(
String changeId,
String transportRequestId,
String endpoint,
String credentialsId,
String clientOpts) {
receivedParams.changeId = changeId
receivedParams.transportRequestId = transportRequestId
receivedParams.endpoint = endpoint
receivedParams.credentialsId = credentialsId
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
assert receivedParams == [
changeId: '001',
transportRequestId: '002',
endpoint: 'https://example.org/cm',
credentialsId: 'CM',
clientOpts: '']
2018-06-20 11:52:11 +02:00
}
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.transportRequestRelease(script: nullScript,
2018-09-28 13:45:26 +02:00
changeManagement: [type: 'NONE'])
}
2018-06-20 11:52:11 +02:00
}