mirror of
https://github.com/SAP/jenkins-library.git
synced 2026-06-19 22:58:55 +02:00
Merge pull request #224 from marcusholl/pr/transportRequestReleaseDecoupleTests
Release transport request: decouple tests
This commit is contained in:
@@ -83,22 +83,53 @@ public class TransportRequestReleaseTest extends BasePiperTest {
|
||||
@Test
|
||||
public void releaseTransportRequestFailureTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> return 1 })
|
||||
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Cannot release Transport Request '001'. Return code from cmclient: 1.")
|
||||
thrown.expectMessage("Something went wrong")
|
||||
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', transportRequestId: '001')
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
|
||||
void releaseTransportRequest(String changeId,
|
||||
String transportRequestId,
|
||||
String endpoint,
|
||||
String credentialsId,
|
||||
String clientOpts) {
|
||||
|
||||
throw new ChangeManagementException('Something went wrong')
|
||||
}
|
||||
}
|
||||
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', transportRequestId: '001', cmUtils: cm)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseTransportRequestSuccessTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> return 0 })
|
||||
jlr.expect("[INFO] Closing transport request '002' for change document '001'.")
|
||||
jlr.expect("[INFO] Transport Request '002' has been successfully closed.")
|
||||
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', transportRequestId: '001')
|
||||
Map receivedParams = [:]
|
||||
|
||||
assert jlr.log.contains("[INFO] Closing transport request '001' for change document '001'.")
|
||||
assert jlr.log.contains("[INFO] Transport Request '001' has been successfully closed.")
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
void releaseTransportRequest(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
|
||||
}
|
||||
}
|
||||
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', transportRequestId: '002', cmUtils: cm)
|
||||
|
||||
assert receivedParams == [changeId: '001',
|
||||
transportRequestId: '002',
|
||||
endpoint: 'https://example.org/cm',
|
||||
credentialsId: 'CM',
|
||||
clientOpts: '']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,39 @@ public void testGetCommandLineWithCMClientOpts() {
|
||||
'me')
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseTransportRequestSucceeds() {
|
||||
|
||||
// the regex provided below is an implicit check that the command line is fine.
|
||||
script.setReturnValue(JenkinsShellCallRule.Type.REGEX, 'release-transport.*-cID 001.*-tID 002', 0)
|
||||
|
||||
new ChangeManagement(nullScript).releaseTransportRequest('001',
|
||||
'002',
|
||||
'https://example.org',
|
||||
'me',
|
||||
'openSesame')
|
||||
|
||||
// no assert required here, since the regex registered above to the script rule is an implicit check for
|
||||
// the command line.
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseTransportRequestFails() {
|
||||
|
||||
thrown.expect(ChangeManagementException)
|
||||
thrown.expectMessage("Cannot release Transport Request '002'. Return code from cmclient: 1.")
|
||||
|
||||
// the regex provided below is an implicit check that the command line is fine.
|
||||
script.setReturnValue(JenkinsShellCallRule.Type.REGEX, 'release-transport.*-cID 001.*-tID 002', 1)
|
||||
|
||||
new ChangeManagement(nullScript).releaseTransportRequest('001',
|
||||
'002',
|
||||
'https://example.org',
|
||||
'me',
|
||||
'openSesame')
|
||||
}
|
||||
|
||||
|
||||
private GitUtils gitUtilsMock(boolean insideWorkTree, String[] changeIds) {
|
||||
return new GitUtils() {
|
||||
public boolean insideWorkTree() {
|
||||
|
||||
Reference in New Issue
Block a user