mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Decouple tests: transport request create
This commit is contained in:
parent
3766bf4794
commit
5a73af4c02
@ -4,6 +4,9 @@ import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.sap.piper.cm.ChangeManagement
|
||||
import com.sap.piper.cm.ChangeManagementException
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
@ -75,20 +78,56 @@ public class TransportRequestCreateTest extends BasePiperTest {
|
||||
@Test
|
||||
public void createTransportRequestFailureTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> throw new AbortException('Exception message.') })
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
|
||||
String createTransportRequest(String changeId,
|
||||
String developmentSystemId,
|
||||
String cmEndpoint,
|
||||
String username,
|
||||
String password) {
|
||||
|
||||
throw new ChangeManagementException('Exception message.')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Cannot create a transport request for change id '001'. Exception message.")
|
||||
thrown.expectMessage("Exception message.")
|
||||
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', developmentSystemId: '001')
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportRequestSuccessTest() {
|
||||
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> return '001' })
|
||||
def result = [:]
|
||||
|
||||
jsr.step.call(script: nullScript, changeDocumentId: '001', developmentSystemId: '001')
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
|
||||
String createTransportRequest(String changeId,
|
||||
String developmentSystemId,
|
||||
String cmEndpoint,
|
||||
String username,
|
||||
String password) {
|
||||
|
||||
result.changeId = changeId
|
||||
result.developmentSystemId = developmentSystemId
|
||||
result.cmEndpoint = cmEndpoint
|
||||
result.username = username
|
||||
result.password = password
|
||||
return '001'
|
||||
}
|
||||
}
|
||||
|
||||
def transportId = jsr.step.call(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
||||
|
||||
assert transportId == '001'
|
||||
assert result == [changeId: '001',
|
||||
developmentSystemId: '001',
|
||||
cmEndpoint: 'https://example.org/cm',
|
||||
username: 'anonymous',
|
||||
password: '********'
|
||||
]
|
||||
|
||||
assert jlr.log.contains("[INFO] Creating transport request for change document '001' and development system '001'.")
|
||||
assert jlr.log.contains("[INFO] Transport Request '001' has been successfully created.")
|
||||
|
@ -22,12 +22,14 @@ import util.JenkinsLoggingRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.Rules
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
public class ChangeManagementTest extends BasePiperTest {
|
||||
|
||||
private ExpectedException thrown = ExpectedException.none()
|
||||
|
||||
private JenkinsShellCallRule script = new JenkinsShellCallRule(this)
|
||||
private JenkinsLoggingRule logging = new JenkinsLoggingRule(this)
|
||||
private JenkinsLoggingRule logging = new JenkinsLoggingRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain rules = Rules.getCommonRules(this)
|
||||
@ -176,6 +178,28 @@ public void testGetCommandLineWithCMClientOpts() {
|
||||
assertThat(commandLine, containsString('export CMCLIENT_OPTS="-Djavax.net.debug=all"'))
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTransportRequestSucceeds() {
|
||||
|
||||
script.setReturnValue(JenkinsShellCallRule.Type.REGEX, ".*cmclient.*create-transport -cID 001 -dID 002.*", '004')
|
||||
def transportRequestId = new ChangeManagement(nullScript).createTransportRequest('001', '002', '003', 'me', 'openSesame')
|
||||
|
||||
// the check for the transportRequestID is sufficient. This checks implicit the command line since that value is
|
||||
// returned only in case the shell call matches.
|
||||
assert transportRequestId == '004'
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTransportRequestFails() {
|
||||
|
||||
thrown.expect(ChangeManagementException)
|
||||
thrown.expectMessage('Cannot create a transport request for change id \'001\'. Exception message.')
|
||||
|
||||
//suggestion: enable shell call rule for throwing exceptions and switch to shell call rule afterwards.
|
||||
helper.registerAllowedMethod('sh', [Map], { throw new AbortException('Exception message') })
|
||||
new ChangeManagement(nullScript).createTransportRequest('001', '002', '003', 'me', 'openSesame')
|
||||
}
|
||||
|
||||
private GitUtils gitUtilsMock(boolean insideWorkTree, String[] changeIds) {
|
||||
return new GitUtils() {
|
||||
|
@ -28,7 +28,7 @@ def call(parameters = [:]) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
ChangeManagement cm = new ChangeManagement(script)
|
||||
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
|
||||
|
||||
Map configuration = ConfigurationMerger.merge(parameters.script, STEP_NAME,
|
||||
parameters, parameterKeys,
|
||||
|
Loading…
Reference in New Issue
Block a user