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/com/sap/piper/UtilsTest.groovy

74 lines
1.9 KiB
Groovy
Raw Normal View History

2018-02-14 12:32:46 +02:00
package com.sap.piper
import org.junit.Rule
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import static org.junit.Assert.assertThat
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.hasItem
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.not
import util.JenkinsLoggingRule
import util.JenkinsShellCallRule
import util.BasePiperTest
import util.Rules
import com.sap.piper.Utils
class UtilsTest extends BasePiperTest {
private ExpectedException thrown = ExpectedException.none()
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
2019-01-22 10:19:28 +02:00
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(thrown)
2019-01-22 10:19:28 +02:00
.around(shellRule)
.around(loggingRule)
private parameters
@Before
void setup() {
parameters = [:]
}
@Test
void noValueGetMandatoryParameterTest() {
thrown.expect(Exception)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR test")
utils.getMandatoryParameter(parameters, 'test', null)
}
@Test
void defaultValueGetMandatoryParameterTest() {
assert utils.getMandatoryParameter(parameters, 'test', 'default') == 'default'
}
@Test
void valueGetmandatoryParameterTest() {
parameters.put('test', 'value')
assert utils.getMandatoryParameter(parameters, 'test', null) == 'value'
}
@Test
void testGenerateSHA1() {
def result = utils.generateSha1('ContinuousDelivery')
// asserts
// generated with "echo -n 'ContinuousDelivery' | sha1sum | sed 's/ -//'"
assertThat(result, is('0dad6c33b6246702132454f604dee80740f399ad'))
}
}