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

198 lines
7.2 KiB
Groovy
Raw Normal View History

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
import com.sap.piper.cm.ChangeManagement
import com.sap.piper.cm.ChangeManagementException
2018-06-20 11:36:41 +02:00
import util.BasePiperTest
import util.JenkinsCredentialsRule
2018-06-20 11:36:41 +02:00
import util.JenkinsStepRule
import util.JenkinsLoggingRule
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()
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
2018-06-20 11:36:41 +02:00
.around(thrown)
.around(jsr)
.around(jlr)
.around(new JenkinsCredentialsRule(this)
.withCredentials('CM', 'anonymous', '********'))
2018-06-20 11:36:41 +02:00
@Before
public void setup() {
nullScript.commonPipelineEnvironment.configuration = [general:
[changeManagement:
2018-06-20 11:36:41 +02:00
[
2018-06-28 16:24:14 +02:00
credentialsId: 'CM',
type: 'SOLMAN',
endpoint: 'https://example.org/cm',
clientOpts: '-DmyProp=myVal',
changeDocumentLabel: 'ChangeId\\s?:',
git: [from: 'origin/master',
to: 'HEAD',
format: '%b']
2018-06-20 11:36:41 +02:00
]
]
]
}
@Test
public void changeIdNotProvidedTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
ChangeManagement cm = new ChangeManagement(nullScript) {
String getChangeDocumentId(
String from,
String to,
String label,
String format
) {
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
}
}
jsr.step.transportRequestCreate(script: nullScript, developmentSystemId: '001', cmUtils: cm)
2018-06-20 11:36:41 +02:00
}
@Test
public void developmentSystemIdNotProvidedTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR developmentSystemId")
2018-06-20 11:36:41 +02:00
jsr.step.transportRequestCreate(script: nullScript, changeDocumentId: '001')
2018-06-20 11:36:41 +02:00
}
@Test
public void createTransportRequestFailureTest() {
ChangeManagement cm = new ChangeManagement(nullScript) {
2018-09-25 09:12:07 +02:00
String createTransportRequestSOLMAN(
String changeId,
String developmentSystemId,
String cmEndpoint,
String credentialId,
String clientOpts) {
throw new ChangeManagementException('Exception message.')
}
}
2018-06-20 11:36:41 +02:00
thrown.expect(AbortException)
thrown.expectMessage("Exception message.")
2018-06-20 11:36:41 +02:00
jsr.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
def result = [:]
ChangeManagement cm = new ChangeManagement(nullScript) {
2018-09-25 09:12:07 +02:00
String createTransportRequestSOLMAN(
String changeId,
String developmentSystemId,
String cmEndpoint,
String credentialId,
String clientOpts) {
result.changeId = changeId
result.developmentSystemId = developmentSystemId
result.cmEndpoint = cmEndpoint
result.credentialId = credentialId
result.clientOpts = clientOpts
return '001'
}
}
def transportId = jsr.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
2018-06-20 11:36:41 +02:00
assert transportId == '001'
assert result == [changeId: '001',
developmentSystemId: '001',
cmEndpoint: 'https://example.org/cm',
credentialId: 'CM',
clientOpts: '-DmyProp=myVal'
]
2018-06-20 11:36:41 +02:00
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.")
}
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,
String clientOpts
) {
result.transportType = transportType
result.targetSystemId = targetSystemId
result.description = description
result.endpoint = endpoint
result.credentialsId = credentialsId
result.clientOpts = clientOpts
return '001'
}
}
def transportId = jsr.step.transportRequestCreate(script: nullScript,
2018-09-25 09:12:07 +02:00
transportType: 'W',
targetSystem: 'XYZ',
description: 'desc',
changeManagement: [type: 'CTS'],
cmUtils: cm)
assert transportId == '001'
assert result == [transportType: 'W',
targetSystemId: 'XYZ',
description: 'desc',
endpoint: 'https://example.org/cm',
credentialsId: 'CM',
clientOpts: '-DmyProp=myVal'
]
assert jlr.log.contains("[INFO] Creating transport request.")
assert jlr.log.contains("[INFO] Transport Request '001' has been successfully created.")
}
2018-09-28 13:45:26 +02:00
@Test
public void cmIntegrationSwichtedOffTest() {
jlr.expect('[INFO] Change management integration intentionally switched off.')
jsr.step.transportRequestCreate(script: nullScript,
2018-09-28 13:45:26 +02:00
changeManagement: [type: 'NONE'])
}
2018-06-20 11:36:41 +02:00
}