mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
fe89155a04
Adding lesfurets test framwork improvements via helper classes
77 lines
2.1 KiB
Groovy
77 lines
2.1 KiB
Groovy
package com.sap.piper
|
|
|
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
|
import org.junit.Before
|
|
import org.junit.Rule
|
|
import org.junit.Test
|
|
import org.junit.rules.ExpectedException
|
|
import org.junit.rules.RuleChain
|
|
import util.JenkinsLoggingRule
|
|
import util.JenkinsSetupRule
|
|
import util.SharedLibraryCreator
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
import static org.hamcrest.Matchers.hasSize
|
|
import static org.junit.Assert.assertEquals
|
|
import static org.junit.Assert.assertThat
|
|
|
|
class UtilsTest extends BasePipelineTest {
|
|
|
|
@Rule
|
|
public ExpectedException exception = ExpectedException.none()
|
|
|
|
@Rule
|
|
public JenkinsSetupRule setUpRule = new JenkinsSetupRule(this, SharedLibraryCreator.lazyLoadedLibrary)
|
|
|
|
Utils utils
|
|
|
|
@Before
|
|
void init() throws Exception {
|
|
utils = new Utils()
|
|
prepareObjectInterceptors(utils)
|
|
}
|
|
|
|
void prepareObjectInterceptors(object) {
|
|
object.metaClass.invokeMethod = helper.getMethodInterceptor()
|
|
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
|
|
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
|
|
}
|
|
|
|
@Test
|
|
void testGetMandatoryParameterValid() {
|
|
|
|
def sourceMap = [test1: 'value1', test2: 'value2']
|
|
|
|
def defaultFallbackMap = [myDefault1: 'default1']
|
|
|
|
assertEquals('value1', utils.getMandatoryParameter(sourceMap, 'test1', null))
|
|
|
|
assertEquals('value1', utils.getMandatoryParameter(sourceMap, 'test1', ''))
|
|
|
|
assertEquals('value1', utils.getMandatoryParameter(sourceMap, 'test1', 'customValue'))
|
|
|
|
}
|
|
|
|
@Test
|
|
void testGetMandatoryParameterDefaultFallback() {
|
|
|
|
def myMap = [test1: 'value1', test2: 'value2']
|
|
|
|
assertEquals('', utils.getMandatoryParameter(myMap, 'test3', ''))
|
|
assertEquals('customValue', utils.getMandatoryParameter(myMap, 'test3', 'customValue'))
|
|
}
|
|
|
|
|
|
@Test
|
|
void testGetMandatoryParameterFail() {
|
|
|
|
def myMap = [test1: 'value1', test2: 'value2']
|
|
|
|
exception.expect(Exception.class)
|
|
|
|
exception.expectMessage("ERROR - NO VALUE AVAILABLE FOR")
|
|
|
|
utils.getMandatoryParameter(myMap, 'test3', null)
|
|
}
|
|
}
|