mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-16 11:09:33 +02:00
def66f4ffa
* add extension mechanism for analytics * add sha1 hashing * correct return types * correct registerEventListener method * decrese visibility of createInstance * correct typo * catch exceptions from tests * correct test case * Update Analytics.groovy * rename to Telemetry * rename file * fix typo * add test case for generateSha1 * expose methods to tests * add clear method for tests * change return type * add test for Telemetry class * replace UtilsTests * remove unused imports * make default reporter static * add stage parameters to payload * simplify SHA1 method * remove obsolete method * remove obsolete methods * remove outdated tests
74 lines
1.9 KiB
Groovy
74 lines
1.9 KiB
Groovy
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)
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
|
|
|
@Rule
|
|
public RuleChain rules = Rules
|
|
.getCommonRules(this)
|
|
.around(thrown)
|
|
.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'))
|
|
}
|
|
}
|