2018-06-22 13:56:33 +02:00
|
|
|
import org.junit.After
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
|
|
|
|
import com.sap.piper.GitUtils
|
|
|
|
import com.sap.piper.cm.ChangeManagement
|
|
|
|
import com.sap.piper.cm.ChangeManagementException
|
|
|
|
|
|
|
|
import hudson.AbortException
|
|
|
|
import util.BasePiperTest
|
2018-07-13 13:27:21 +02:00
|
|
|
import util.JenkinsCredentialsRule
|
2018-09-28 13:45:26 +02:00
|
|
|
import util.JenkinsLoggingRule
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-06-22 13:56:33 +02:00
|
|
|
import util.JenkinsStepRule
|
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
class CheckChangeInDevelopmentTest extends BasePiperTest {
|
|
|
|
|
|
|
|
private ExpectedException thrown = ExpectedException.none()
|
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-22 13:56:33 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
2018-08-31 10:22:43 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2018-06-22 13:56:33 +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)
|
2018-07-16 15:41:46 +02:00
|
|
|
.withCredentials('CM', 'anonymous', '********'))
|
2018-06-22 13:56:33 +02:00
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() {
|
|
|
|
cmUtilReceivedParams.clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map cmUtilReceivedParams = [:]
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void changeIsInStatusDevelopmentTest() {
|
|
|
|
|
|
|
|
ChangeManagement cm = getChangeManagementUtils(true)
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.checkChangeInDevelopment(
|
2018-10-25 08:41:50 +02:00
|
|
|
script: nullScript,
|
2018-10-30 17:49:53 +02:00
|
|
|
cmUtils: cm,
|
|
|
|
changeManagement: [
|
|
|
|
type: 'SOLMAN',
|
|
|
|
endpoint: 'https://example.org/cm'],
|
|
|
|
failIfStatusIsNotInDevelopment: true)
|
2018-06-22 13:56:33 +02:00
|
|
|
|
|
|
|
assert cmUtilReceivedParams == [
|
|
|
|
changeId: '001',
|
|
|
|
endpoint: 'https://example.org/cm',
|
2018-07-16 15:41:46 +02:00
|
|
|
credentialsId: 'CM',
|
2018-07-17 09:21:56 +02:00
|
|
|
cmclientOpts: ''
|
2018-06-22 13:56:33 +02:00
|
|
|
]
|
2018-10-11 09:31:19 +02:00
|
|
|
|
|
|
|
// no exception in thrown, so the change is in status 'in development'.
|
2018-06-22 13:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void changeIsNotInStatusDevelopmentTest() {
|
|
|
|
|
|
|
|
thrown.expect(AbortException)
|
|
|
|
thrown.expectMessage("Change '001' is not in status 'in development'")
|
|
|
|
|
|
|
|
ChangeManagement cm = getChangeManagementUtils(false)
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.checkChangeInDevelopment(
|
2018-09-21 16:55:31 +02:00
|
|
|
script: nullScript,
|
2018-06-22 13:56:33 +02:00
|
|
|
cmUtils: cm,
|
2018-09-28 14:06:06 +02:00
|
|
|
changeManagement: [type: 'SOLMAN',
|
|
|
|
endpoint: 'https://example.org/cm'])
|
2018-06-22 13:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void changeIsNotInStatusDevelopmentButWeWouldLikeToSkipFailureTest() {
|
|
|
|
|
|
|
|
ChangeManagement cm = getChangeManagementUtils(false)
|
2019-01-22 10:25:42 +02:00
|
|
|
boolean inDevelopment = stepRule.step.checkChangeInDevelopment(
|
2018-09-21 16:55:31 +02:00
|
|
|
script: nullScript,
|
2018-06-22 13:56:33 +02:00
|
|
|
cmUtils: cm,
|
2018-07-17 09:21:56 +02:00
|
|
|
changeManagement: [endpoint: 'https://example.org/cm'],
|
2018-06-22 13:56:33 +02:00
|
|
|
failIfStatusIsNotInDevelopment: false)
|
|
|
|
assert !inDevelopment
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void changeDocumentIdRetrievalFailsTest() {
|
|
|
|
|
2018-07-19 10:26:34 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage("No changeDocumentId provided. Neither via parameter 'changeDocumentId' nor via " +
|
|
|
|
"label 'ChangeDocument\\s?:' in commit range [from: origin/master, to: HEAD].")
|
2018-06-22 13:56:33 +02:00
|
|
|
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript, null) {
|
|
|
|
|
|
|
|
String getChangeDocumentId(
|
|
|
|
String filter,
|
|
|
|
String from,
|
|
|
|
String to,
|
|
|
|
String format) {
|
|
|
|
throw new ChangeManagementException('Something went wrong')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.checkChangeInDevelopment(
|
2018-09-21 16:55:31 +02:00
|
|
|
script: nullScript,
|
2018-06-22 13:56:33 +02:00
|
|
|
cmUtils: cm,
|
2018-09-28 14:06:06 +02:00
|
|
|
changeManagement: [type: 'SOLMAN',
|
|
|
|
endpoint: 'https://example.org/cm'])
|
2018-06-22 13:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void nullChangeDocumentIdTest() {
|
|
|
|
|
2018-07-12 08:54:04 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage("No changeDocumentId provided. Neither via parameter 'changeDocumentId' " +
|
2018-07-17 10:08:47 +02:00
|
|
|
"nor via label 'ChangeDocument\\s?:' in commit range " +
|
2018-07-12 08:54:04 +02:00
|
|
|
"[from: origin/master, to: HEAD].")
|
2018-06-22 13:56:33 +02:00
|
|
|
|
|
|
|
ChangeManagement cm = getChangeManagementUtils(false, null)
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.checkChangeInDevelopment(
|
2018-09-21 16:55:31 +02:00
|
|
|
script: nullScript,
|
2018-06-22 13:56:33 +02:00
|
|
|
cmUtils: cm,
|
2018-09-28 14:06:06 +02:00
|
|
|
changeManagement: [endpoint: 'https://example.org/cm',
|
|
|
|
type: 'SOLMAN'])
|
2018-06-22 13:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void emptyChangeDocumentIdTest() {
|
|
|
|
|
2018-07-12 08:54:04 +02:00
|
|
|
thrown.expect(IllegalArgumentException)
|
|
|
|
thrown.expectMessage("No changeDocumentId provided. Neither via parameter 'changeDocumentId' " +
|
2018-07-17 10:08:47 +02:00
|
|
|
"nor via label 'ChangeDocument\\s?:' in commit range " +
|
2018-07-12 08:54:04 +02:00
|
|
|
"[from: origin/master, to: HEAD].")
|
2018-06-22 13:56:33 +02:00
|
|
|
|
|
|
|
ChangeManagement cm = getChangeManagementUtils(false, '')
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.checkChangeInDevelopment(
|
2018-09-21 16:55:31 +02:00
|
|
|
script: nullScript,
|
2018-06-22 13:56:33 +02:00
|
|
|
cmUtils: cm,
|
2018-09-28 14:06:06 +02:00
|
|
|
changeManagement: [type: 'SOLMAN',
|
|
|
|
endpoint: 'https://example.org/cm'])
|
2018-06-22 13:56:33 +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.checkChangeInDevelopment(
|
2018-10-25 08:28:04 +02:00
|
|
|
script: nullScript,
|
2018-09-28 13:45:26 +02:00
|
|
|
changeManagement: [type: 'NONE'])
|
|
|
|
|
2018-06-22 13:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private ChangeManagement getChangeManagementUtils(boolean inDevelopment, String changeDocumentId = '001') {
|
|
|
|
|
|
|
|
return new ChangeManagement(nullScript, null) {
|
|
|
|
|
|
|
|
String getChangeDocumentId(
|
|
|
|
String filter,
|
|
|
|
String from,
|
|
|
|
String to,
|
|
|
|
String format) {
|
|
|
|
return changeDocumentId
|
|
|
|
}
|
|
|
|
|
2018-07-16 15:41:46 +02:00
|
|
|
boolean isChangeInDevelopment(String changeId, String endpoint, String credentialsId, String cmclientOpts) {
|
2018-06-22 13:56:33 +02:00
|
|
|
cmUtilReceivedParams.changeId = changeId
|
|
|
|
cmUtilReceivedParams.endpoint = endpoint
|
2018-07-16 15:41:46 +02:00
|
|
|
cmUtilReceivedParams.credentialsId = credentialsId
|
2018-06-25 12:37:33 +02:00
|
|
|
cmUtilReceivedParams.cmclientOpts = cmclientOpts
|
2018-06-22 13:56:33 +02:00
|
|
|
|
|
|
|
return inDevelopment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|