mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
52bb1e842d
- In case a parameter is missing we do not thrown and AbortException anmore, but an IllegalArgumentExcpetion, since that exception is thrown by the configuration helper. The difference is: AbortExceptions are contained in the log without stacktrace, other exceptions are printed with stack trace. - Exception messages are changed to the standard error message triggered inside the configuration helper. In case the changeDocumentId is retrieved also from the commit history we keep an exception message pointing to that. - Having references to the parameters is droped. Instead the parameters are directly used from the configuration map. - in case of long signatures line breaks are inserted in order to simplify reading the code.
141 lines
4.7 KiB
Groovy
141 lines
4.7 KiB
Groovy
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.ChangeManagement
|
|
import com.sap.piper.cm.ChangeManagementException
|
|
|
|
import util.BasePiperTest
|
|
import util.JenkinsStepRule
|
|
import util.JenkinsLoggingRule
|
|
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(thrown)
|
|
.around(jsr)
|
|
.around(jlr)
|
|
|
|
@Before
|
|
public void setup() {
|
|
|
|
helper.registerAllowedMethod('usernamePassword', [Map.class], {m -> return m})
|
|
|
|
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
|
|
|
|
credentialsId = l[0].credentialsId
|
|
binding.setProperty('username', 'anonymous')
|
|
binding.setProperty('password', '********')
|
|
try {
|
|
c()
|
|
} finally {
|
|
binding.setProperty('username', null)
|
|
binding.setProperty('password', null)
|
|
}
|
|
})
|
|
|
|
helper.registerAllowedMethod('sh', [Map], { Map m -> return 0 })
|
|
|
|
nullScript.commonPipelineEnvironment.configuration = [steps:
|
|
[transportRequestCreate:
|
|
[
|
|
credentialsId: 'CM',
|
|
endpoint: 'https://example.org/cm',
|
|
clientOpts: '-DmyProp=myVal'
|
|
]
|
|
]
|
|
]
|
|
}
|
|
|
|
@Test
|
|
public void changeIdNotProvidedTest() {
|
|
|
|
thrown.expect(IllegalArgumentException)
|
|
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR changeDocumentId")
|
|
|
|
jsr.step.call(script: nullScript, developmentSystemId: '001')
|
|
}
|
|
|
|
@Test
|
|
public void developmentSystemIdNotProvidedTest() {
|
|
|
|
thrown.expect(IllegalArgumentException)
|
|
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR developmentSystemId")
|
|
|
|
jsr.step.call(script: nullScript, changeDocumentId: '001')
|
|
}
|
|
|
|
@Test
|
|
public void createTransportRequestFailureTest() {
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
String createTransportRequest(String changeId,
|
|
String developmentSystemId,
|
|
String cmEndpoint,
|
|
String username,
|
|
String password,
|
|
String clientOpts) {
|
|
|
|
throw new ChangeManagementException('Exception message.')
|
|
}
|
|
}
|
|
|
|
|
|
thrown.expect(AbortException)
|
|
thrown.expectMessage("Exception message.")
|
|
|
|
jsr.step.call(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
|
}
|
|
|
|
@Test
|
|
public void createTransportRequestSuccessTest() {
|
|
|
|
def result = [:]
|
|
|
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
|
|
|
String createTransportRequest(String changeId,
|
|
String developmentSystemId,
|
|
String cmEndpoint,
|
|
String username,
|
|
String password,
|
|
String clientOpts) {
|
|
|
|
result.changeId = changeId
|
|
result.developmentSystemId = developmentSystemId
|
|
result.cmEndpoint = cmEndpoint
|
|
result.username = username
|
|
result.password = password
|
|
result.clientOpts = clientOpts
|
|
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: '********',
|
|
clientOpts: '-DmyProp=myVal'
|
|
]
|
|
|
|
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.")
|
|
}
|
|
}
|