-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4945891
commit be85b92
Showing
5 changed files
with
336 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ConverterUtilTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2024 tracetronic GmbH | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
package de.tracetronic.jenkins.plugins.ecutestexecution.util | ||
|
||
|
||
import de.tracetronic.jenkins.plugins.ecutestexecution.model.PackageParameter | ||
import de.tracetronic.jenkins.plugins.ecutestexecution.model.RecordingAsSetting | ||
import spock.lang.Specification | ||
|
||
class ConverterUtilTest extends Specification { | ||
|
||
def "should return empty list"() { | ||
expect: | ||
ConverterUtil.recordingConverter(new ArrayList<RecordingAsSetting>()) | ||
.isEmpty() | ||
} | ||
|
||
def "should convert single RecordingAsSetting to Recording"() { | ||
given: | ||
def recordingAsSetting = new RecordingAsSetting("/test/path") | ||
recordingAsSetting.setRecordingGroup("testGroup") | ||
recordingAsSetting.setMappingNames(["mapping1", "mapping2"]) | ||
recordingAsSetting.setDeviceName("testDevice") | ||
recordingAsSetting.setFormatDetails("testFormat") | ||
|
||
when: | ||
def result = ConverterUtil.recordingConverter([recordingAsSetting]) | ||
|
||
then: | ||
result.size() == 1 | ||
with(result[0]) { | ||
path == "/test/path" | ||
recordingGroup == "testGroup" | ||
mappingNames == ["mapping1", "mapping2"] | ||
deviceName == "testDevice" | ||
formatDetails == "testFormat" | ||
} | ||
} | ||
|
||
def "should convert multiple RecordingAsSettings to Recordings"() { | ||
given: | ||
def recordingAsSetting1 = new RecordingAsSetting("/test/path") | ||
recordingAsSetting1.setRecordingGroup("testGroup") | ||
recordingAsSetting1.setMappingNames(["mapping1", "mapping2"]) | ||
recordingAsSetting1.setDeviceName("testDevice") | ||
recordingAsSetting1.setFormatDetails("testFormat") | ||
|
||
def recordingAsSetting2 = new RecordingAsSetting("/test/path2") | ||
recordingAsSetting2.setRecordingGroup("testGroup2") | ||
recordingAsSetting2.setMappingNames(["mapping3", "mapping4"]) | ||
recordingAsSetting2.setDeviceName("testDevice2") | ||
recordingAsSetting2.setFormatDetails("testFormat2") | ||
|
||
when: | ||
def result = ConverterUtil.recordingConverter([recordingAsSetting1, recordingAsSetting2]) | ||
|
||
then: | ||
result.size() == 2 | ||
with(result[0]) { | ||
path == "/test/path" | ||
recordingGroup == "testGroup" | ||
mappingNames == ["mapping1", "mapping2"] | ||
deviceName == "testDevice" | ||
formatDetails == "testFormat" | ||
} | ||
with(result[1]) { | ||
path == "/test/path2" | ||
recordingGroup == "testGroup2" | ||
mappingNames == ["mapping3", "mapping4"] | ||
deviceName == "testDevice2" | ||
formatDetails == "testFormat2" | ||
} | ||
} | ||
|
||
def "should convert empty list of PackageParameter to empty list of LabeledValue"() { | ||
expect: | ||
ConverterUtil.labeledValueConverter(new ArrayList<PackageParameter>()).isEmpty() | ||
} | ||
|
||
def "should convert PackageParameter to LabeledValue"() { | ||
given: | ||
def pkgParam = new PackageParameter('label', 'value') | ||
|
||
when: | ||
def result = ConverterUtil.labeledValueConverter([pkgParam]) | ||
|
||
then: | ||
result.size() == 1 | ||
with(result[0]) { | ||
it.label == "label" | ||
it.value == "value" | ||
} | ||
} | ||
|
||
def "should convert multiple PackageParameter to LabeledValues"() { | ||
given: | ||
def pkgParam1 = new PackageParameter('label', 'value') | ||
def pkgParam2 = new PackageParameter('label2', 'value2') | ||
|
||
when: | ||
def result = ConverterUtil.labeledValueConverter([pkgParam1, pkgParam2]) | ||
|
||
then: | ||
result.size() == 2 | ||
with(result[0]) { | ||
it.label == "label" | ||
it.value == "value" | ||
} | ||
with(result[1]) { | ||
it.label == "label2" | ||
it.value == "value2" | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/EnvVarUtilTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024 tracetronic GmbH | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
package de.tracetronic.jenkins.plugins.ecutestexecution.util | ||
|
||
import hudson.EnvVars | ||
import spock.lang.Specification | ||
|
||
class EnvVarUtilTest extends Specification { | ||
|
||
def "Unsupported class exception"() { | ||
when: | ||
new EnvVarUtil() | ||
then: | ||
def e = thrown(UnsupportedOperationException) | ||
e.cause == null | ||
e.message == "Utility class" | ||
|
||
} | ||
|
||
def "expandVar should return '#expectedResult' for envVar=#envVar and envVars=#vars"() { | ||
given: | ||
def envVars = new EnvVars() | ||
vars.each { k, v -> envVars.put(k, v) } | ||
|
||
when: | ||
def result = EnvVarUtil.expandVar(envVar, envVars, "default") | ||
|
||
then: | ||
result == expectedResult | ||
|
||
where: | ||
envVar | vars | expectedResult | ||
'TEST_VAR' | [TEST_VAR: "value"] | "TEST_VAR" | ||
'MISSING_VAR' | [TEST_VAR: "value"] | "MISSING_VAR" | ||
'${TEST_VAR}' | [TEST_VAR: "value"] | "value" | ||
'${VAR1} ${VAR2}' | [VAR1: "Hello", VAR2: "World"] | "Hello World" | ||
} | ||
|
||
def "expandVar should return default value"() { | ||
given: | ||
def envVars = new EnvVars() | ||
|
||
when: | ||
def result = EnvVarUtil.expandVar(envVar, envVars, "default") | ||
|
||
then: | ||
result == "default" | ||
|
||
where: | ||
envVar << [null, "", " "] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.