From 0ec2e3f6b6bed4fe79962d4baa4a9d0d1f1dd8de Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Mon, 21 Oct 2024 10:11:19 +0200 Subject: [PATCH] Add review notes (#164) - remove keep - ajust jelly, avdanvedDocs, and tests --- docs/AdvancedUsage.md | 23 +++++-------- .../configs/TestConfig.groovy | 4 +++ .../util/ValidationUtil.groovy | 4 +-- .../configs/TestConfig/config.jelly | 32 +++++++++++-------- .../configs/TestConfig/config.properties | 11 ++----- .../steps/RunPackageStepIT.groovy | 25 ++------------- .../steps/RunProjectStepIT.groovy | 24 ++------------ .../steps/RunTestFolderStepIT.groovy | 27 ++-------------- .../util/ValidationUtilTest.groovy | 2 -- 9 files changed, 41 insertions(+), 111 deletions(-) diff --git a/docs/AdvancedUsage.md b/docs/AdvancedUsage.md index d4f64f9c..11065d66 100644 --- a/docs/AdvancedUsage.md +++ b/docs/AdvancedUsage.md @@ -91,25 +91,18 @@ node { ## TestConfig -| Properties | Default Value | Description | -|----------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **tbcPath**: String | '' | The relative path of the .tbc file in the Configurations directory to be started for this execution. Use "KEEP" to use the currently loaded test bench configuration. If empty, no test bench configuration will be loaded. | -| **tcfPath**: String | '' | The relative path of the .tcf file in the Configurations directory to be started for this execution. Use "KEEP" to use the currently loaded test configuration. If empty, no test configuration will be loaded. | -| **forceConfigurationReload**: boolean | false | If true, always reload the configuration even if the same one is still active. Hint: This flag is only required for ecu.test versions less than 2023.4! | -| **constants**: List\<[Constant](#constant)> | [] | The configured global constants remain available throughout the entire test execution. | +| Properties | Default Value | Description | +|----------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **tbcPath**: String | '' | The relative path of the .tbc file in the Configurations directory to be started for this execution. If empty, no test bench configuration will be loaded. | +| **tcfPath**: String | '' | The relative path of the .tcf file in the Configurations directory to be started for this execution. If empty, no test configuration will be loaded. | +| **forceConfigurationReload**: boolean | false | If true, always reload the configuration even if the same one is still active. Hint: This flag is only required for ecu.test versions less than 2023.4! | +| **constants**: List\<[Constant](#constant)> | [] | The configured global constants remain available throughout the entire test execution. | ### Configuration Change Options -- **New Configurations**: Both `.tbc` and `.tcf` files must be explicitly set whenever a new configuration is needed. - -- **KEEP Option**: The `KEEP` option prevents reloading new configurations and keeps the currently active ones. - This feature is considered **advanced** and is not recommended for most use cases. - `KEEP` must always be set for both configurations and no constants may be set. - +- **Load Configuration**: Both `.tbc` and `.tcf` files must be explicitly set whenever a new configuration is needed. +- **Keep Configuration**: In ecu.test versions prior to 2023.4, setting `forceConfigurationReload` to `true` forces a configuration reload, even if the same configuration is still active. - **Unload Configurations**: Keeping values empty, such as `[tbcPath: '', tcfPath: '']` will unload the configuration. - Providing an invalid data type for `testConfig` (e.g., an empty list) will result in an error and halt the pipeline execution. - -- **Force Reload**: In ecu.test versions prior to 2023.4, setting `forceConfigurationReload` to `true` forces a configuration reload, even if the same configuration is still active. ## PublishConfig diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig.groovy index 1bce7628..b367fd6c 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig.groovy @@ -12,7 +12,11 @@ import hudson.Extension import hudson.model.AbstractDescribableImpl import hudson.model.Descriptor import hudson.util.FormValidation +import net.sf.json.JSONObject import org.apache.commons.lang.StringUtils +import org.jinterop.dcom.test.Test +import org.kohsuke.stapler.Stapler +import org.kohsuke.stapler.StaplerRequest import org.kohsuke.stapler.DataBoundConstructor import org.kohsuke.stapler.DataBoundSetter import org.kohsuke.stapler.QueryParameter diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtil.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtil.groovy index da36ac0f..2611895e 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtil.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtil.groovy @@ -57,9 +57,9 @@ class ValidationUtil { static validateConfigFile(String configFilePath, String fileExtension) { FormValidation returnValue = validateParameterizedValue(configFilePath, false) if (returnValue == FormValidation.ok() && !StringUtils.isEmpty(configFilePath)) { - if (!configFilePath.endsWith(fileExtension) && (configFilePath != 'KEEP')) { + if (!configFilePath.endsWith(fileExtension)) { returnValue = FormValidation.error( - "${configFilePath} has to be empty, either of file type ${fileExtension} or \"KEEP\".") + "${configFilePath} has to be empty or of file type ${fileExtension}.") } } return returnValue diff --git a/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.jelly b/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.jelly index be71ba08..294d132a 100644 --- a/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.jelly +++ b/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.jelly @@ -2,20 +2,24 @@ ${%configSection.description} - - - - - - - - - - - - + + + - + + + + + + + + + + + + + + diff --git a/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.properties b/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.properties index b59885d1..ac048d0c 100644 --- a/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.properties +++ b/src/main/resources/de/tracetronic/jenkins/plugins/ecutestexecution/configs/TestConfig/config.properties @@ -1,6 +1,7 @@ configSection.title=Test Configuration -configSection.description=Both the Test Bench Configuration and Test Configuration must be provided to load new configurations. \ - For invalid data types, such as testConfig: [], an Error will be thrown. +configSection.description=It is recommended to choose one of the following options:

\ +
  • Load Configuration: Both the Test Bench Configuration and Test Configuration must be provided to load new configurations.
  • \ +
  • Keep Configuration: Enabling this option retains the existing configuration for continued use throughout the execution.
  • constants.add=Add Global Constant constants.description=The configured global constants remain available throughout the entire test execution. constants.title=Global Constants @@ -10,14 +11,8 @@ packageParameters.add=Add Package Parameter packageParameters.description=Parameters for package execution. packageParameters.title=Package Parameters tbcPath.description=The relative path of the .tbc file in the Configurations directory to be started for this execution. \ - Use "KEEP" to use the currently loaded test bench configuration. \ - The "KEEP" option is considered advanced and not recommended for typical use cases. \ - "KEEP" must always be set for both configurations. \ If empty, no test bench configuration will be loaded. tbcPath.title=Test Bench Configuration tcfPath.description=The relative path of the .tcf file in the Configurations directory to be started for this execution. \ - Use "KEEP" to use the currently loaded test configuration. \ - The "KEEP" option is considered advanced and not recommended for typical use cases. \ - "KEEP" must always be set for both configurations. \ If empty, no test configuration will be loaded. tcfPath.title=Test Configuration diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy index 02e85ea5..342efec5 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy @@ -183,11 +183,11 @@ class RunPackageStepIT extends IntegrationTestBase { jenkins.assertLogContains("-> With TCF=test.tcf", run) } - def 'Run pipeline by declaring KEEP in testConfig'() { + def 'Run pipeline by forcing configuration to reload in testConfig'() { given: WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') job.setDefinition(new CpsFlowDefinition("node { ttRunPackage testCasePath: 'test.pkg', " + - "testConfig: [tbcPath: 'KEEP', tcfPath: 'KEEP'] }", true)) + "testConfig: [forceConfigurationReload: true] }", true)) GroovyMock(RestApiClientFactory, global: true) RestApiClientFactory.getRestApiClient() >> new MockRestApiClient() @@ -195,29 +195,8 @@ class RunPackageStepIT extends IntegrationTestBase { expect: WorkflowRun run = job.scheduleBuild2(0).get() jenkins.assertLogContains("Executing package 'test.pkg'...", run) - jenkins.assertLogContains("-> With TBC=KEEP", run) - jenkins.assertLogContains("-> With TCF=KEEP", run) - } - def 'Run pipeline with invalid data type for testConfig'() { - given: - WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') - job.setDefinition(new CpsFlowDefinition("node { ttRunPackage testCasePath: 'test.pkg', " + - "testConfig: [] }", true)) - - GroovyMock(RestApiClientFactory, global: true) - RestApiClientFactory.getRestApiClient() >> new MockRestApiClient() - - expect: - WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) - jenkins.assertLogContains("java.lang.ClassCastException", run) - jenkins.assertLogContains("expects class " + - "de.tracetronic.jenkins.plugins.ecutestexecution.configs.TestConfig", run) - jenkins.assertLogContains("but received class java.util.ArrayList", run) - } - - def 'Run pipeline with package check'(){ given: GroovyMock(RestApiClientFactory, global: true) diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy index f8c7a378..e9cbdb48 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy @@ -131,11 +131,11 @@ class RunProjectStepIT extends IntegrationTestBase { jenkins.assertLogContains("-> With TCF=test.tcf", run) } - def 'Run pipeline by declaring KEEP in testConfig'() { + def 'Run pipeline by forcing configuration to reload in testConfig'() { given: WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') job.setDefinition(new CpsFlowDefinition("node { ttRunProject testCasePath: 'test.prj', " + - "testConfig: [tbcPath: 'KEEP', tcfPath: 'KEEP'] }", true)) + "testConfig: [forceConfigurationReload: true] }", true)) GroovyMock(RestApiClientFactory, global: true) RestApiClientFactory.getRestApiClient() >> new MockRestApiClient() @@ -143,26 +143,6 @@ class RunProjectStepIT extends IntegrationTestBase { expect: WorkflowRun run = job.scheduleBuild2(0).get() jenkins.assertLogContains("Executing project 'test.prj'...", run) - jenkins.assertLogContains("-> With TBC=KEEP", run) - jenkins.assertLogContains("-> With TCF=KEEP", run) - - } - - def 'Run pipeline with invalid data type for testConfig'() { - given: - WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') - job.setDefinition(new CpsFlowDefinition("node { ttRunProject testCasePath: 'test.prj', " + - "testConfig: [] }", true)) - - GroovyMock(RestApiClientFactory, global: true) - RestApiClientFactory.getRestApiClient() >> new MockRestApiClient() - - expect: - WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) - jenkins.assertLogContains("java.lang.ClassCastException", run) - jenkins.assertLogContains("expects class " + - "de.tracetronic.jenkins.plugins.ecutestexecution.configs.TestConfig", run) - jenkins.assertLogContains("but received class java.util.ArrayList", run) } def 'Run pipeline with package check'() { diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy index 824d09dd..d7cf6bcd 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy @@ -210,14 +210,14 @@ class RunTestFolderStepIT extends IntegrationTestBase { jenkins.assertLogContains("-> With TCF=test.tcf", run) } - def 'Run pipeline by declaring KEEP in testConfig'() { + def 'Run pipeline by forcing configuration to reload in testConfig'() { given: setupTestFolder() WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') job.setDefinition(new CpsFlowDefinition( "node { ttRunTestFolder recursiveScan: true, " + "testCasePath: '${folder.getRoot().getAbsolutePath().replace('\\', '\\\\')}'" + - ", testConfig: [tbcPath: 'KEEP', tcfPath: 'KEEP'] }", + ", testConfig: [forceConfigurationReload: true] }", true)) GroovyMock(RestApiClientFactory, global: true) @@ -228,29 +228,6 @@ class RunTestFolderStepIT extends IntegrationTestBase { jenkins.assertLogContains('Found 3 package(s)', run) jenkins.assertLogContains('Found 3 project(s)', run) jenkins.assertLogContains("Executing package '${subPackage.getAbsolutePath()}'", run) - jenkins.assertLogContains("-> With TBC=KEEP", run) - jenkins.assertLogContains("-> With TCF=KEEP", run) - } - - def 'Run pipeline with invalid data type for testConfig'() { - given: - setupTestFolder() - WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') - job.setDefinition(new CpsFlowDefinition( - "node { ttRunTestFolder recursiveScan: true, " + - "testCasePath: '${folder.getRoot().getAbsolutePath().replace('\\', '\\\\')}'" + - ", testConfig: [] }", - true)) - - GroovyMock(RestApiClientFactory, global: true) - RestApiClientFactory.getRestApiClient() >> new MockRestApiClient() - - expect: - WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) - jenkins.assertLogContains("java.lang.ClassCastException", run) - jenkins.assertLogContains("expects class " + - "de.tracetronic.jenkins.plugins.ecutestexecution.configs.TestConfig", run) - jenkins.assertLogContains("but received class java.util.ArrayList", run) } def 'Run recursive scan pipeline'() { diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtilTest.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtilTest.groovy index cb8ab5d5..a5a14c13 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtilTest.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/util/ValidationUtilTest.groovy @@ -73,8 +73,6 @@ class ValidationUtilTest extends Specification { configFilePath | fileExtension | expectedKind 'test.tcf' | '.tcf' | FormValidation.Kind.OK 'test.tcf' | '.tbc' | FormValidation.Kind.ERROR - 'KEEP' | '' | FormValidation.Kind.OK - 'KEEP' | '.tcf' | FormValidation.Kind.OK '${CONFIG}' | '' | FormValidation.Kind.WARNING '' | '' | FormValidation.Kind.OK null | null | FormValidation.Kind.OK