Skip to content

Commit

Permalink
Update loadConfig process (#164)
Browse files Browse the repository at this point in the history
- adapt Docs
- add help information in jelly
- provide TestConfig tests
  • Loading branch information
MartinGroscheTT committed Nov 15, 2024
1 parent 0fb68b1 commit 271a5b1
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 197 deletions.
4 changes: 2 additions & 2 deletions docs/AdvancedUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ node {

### Configuration Change Options

- **Load Configuration**: Both `.tbc` and `.tcf` files must be explicitly set whenever a new configuration is needed. Setting `forceConfigurationReload` to `true` forces a configuration reload, even if the same configuration is still active. If empty, Test Configuration will be unloaded.
- **Keep Configuration**: Enabling this option retains the existing configuration for continued use throughout the execution.
- **Load Configuration**: The TestConfiguration and/or the TestBenchConfiguration files must be explicitly set whenever a new configuration is needed. If both are empty, Test Configuration will be unloaded. Setting `forceConfigurationReload` to `true` forces a configuration reload, even if the same configuration is still active.
- **Keep Configuration**: Enable this option by not specify the testConfig property for example `ttRunTestPackage '<myPackageName>.pkg'` this option retains the existing configuration for continued use throughout the execution.

## PublishConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ class RestApiClientV2 extends RestApiClientV2WithIdleHandle implements RestApiCl
.constants(constants)
.action(ConfigurationOrder.ActionEnum.START)
try {
if(executionOrder.configOption == 'loadConfig') {
if(executionOrder.loadConfig) {
ConfigurationApi configApi = new ConfigurationApi(apiClient)

Closure<Boolean> checkConfigStatus = { ModelConfiguration configuration ->
configuration?.status?.key in [null, ConfigurationStatus.KeyEnum.WAITING, ConfigurationStatus.KeyEnum.RUNNING]
}

if(executionOrder.loadConfig) {
if(executionOrder.forceReload) {
ConfigurationOrder loadConfigOrder = new ConfigurationOrder().action(ConfigurationOrder.ActionEnum.STOP)
configApi.manageConfiguration(loadConfigOrder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@ class ExecutionOrder implements Serializable {

public String testCasePath
public AdditionalSettings additionalSetting
public String configOption
public boolean loadConfig
public boolean forceReload
@Nullable public String tbcPath
@Nullable public String tcfPath
@Nullable public List<Constant> constants

ExecutionOrder(String testCasePath, AdditionalSettings additionalSetting,
String tbcPath, String tcfPath, List<Constant> constants, String configOption) {
this.testCasePath = testCasePath
this.additionalSetting = additionalSetting
this.tbcPath = tbcPath
this.tcfPath = tcfPath
this.constants = constants
this.configOption = configOption
}

ExecutionOrder(String testCasePath, AdditionalSettings additionalSetting) {
this.testCasePath = testCasePath
this.additionalSetting = additionalSetting
Expand All @@ -45,8 +35,8 @@ class ExecutionOrder implements Serializable {
this.tbcPath = testConfig.tbcPath
this.tcfPath = testConfig.tcfPath
this.constants = testConfig.constants
this.configOption = testConfig.configOption
this.loadConfig = testConfig.forceConfigurationReload
this.loadConfig = testConfig.loadConfig
this.forceReload = testConfig.forceConfigurationReload
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import hudson.model.AbstractDescribableImpl
import hudson.model.Descriptor
import hudson.util.FormValidation
import jline.internal.Nullable
import net.sf.json.JSONObject
import org.apache.commons.lang.StringUtils
import org.kohsuke.stapler.DataBoundConstructor
import org.kohsuke.stapler.DataBoundSetter
import org.kohsuke.stapler.QueryParameter
import org.kohsuke.stapler.StaplerRequest

class TestConfig extends AbstractDescribableImpl<TestConfig> implements ExpandableConfig, Serializable {

private static final long serialVersionUID = 1L
private static transient String configOption

private boolean loadConfig
private String tbcPath
private String tcfPath
private boolean forceConfigurationReload
Expand All @@ -34,14 +36,14 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab
this.tbcPath = null
this.constants = []
this.forceConfigurationReload = false
this.loadConfig = false
}

TestConfig(TestConfig config) {
this()

configOption = getConfigOption()

if(configOption == 'loadConfig') {
this.loadConfig = config.tcfPath != null || config.tbcPath != null
if(this.loadConfig) {
this.tbcPath = config.getTbcPath()
this.tcfPath = config.getTcfPath()
this.constants = config.getConstants()
Expand All @@ -56,7 +58,7 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab

@DataBoundSetter
void setTbcPath(String tbcPath) {
this.tbcPath = tbcPath || configOption == 'loadConfig' ? StringUtils.trimToEmpty(tbcPath) : null
this.tbcPath = tbcPath
}

@Nullable
Expand All @@ -66,7 +68,7 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab

@DataBoundSetter
void setTcfPath(String tcfPath) {
this.tcfPath = tcfPath || configOption == 'loadConfig' ? StringUtils.trimToEmpty(tcfPath) : null
this.tcfPath = tcfPath
}

boolean isForceConfigurationReload() {
Expand All @@ -87,13 +89,8 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab
this.constants = constants ? removeEmptyConstants(constants) : []
}

@DataBoundSetter
void setConfigOption(String value) {
configOption = value
}

String getConfigOption() {
return configOption ?: 'keepConfig'
boolean getLoadConfig() {
return loadConfig
}

@Override
Expand All @@ -103,7 +100,7 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab
-> tcfPath: ${tcfPath}
-> forceConfigurationReload: ${forceConfigurationReload}
-> constants: ${constants.each { it }}
-> configOption: ${configOption}
-> loadConfig: ${loadConfig}
""".stripIndent().trim()
}

Expand All @@ -112,6 +109,7 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab
TestConfig expConfig = new TestConfig()
expConfig.setTbcPath(envVars.expand(tbcPath))
expConfig.setTcfPath(envVars.expand(tcfPath))
expConfig.setForceConfigurationReload(forceConfigurationReload)
expConfig.setConstants(constants.collect { constant -> constant.expand(envVars) })
return expConfig
}
Expand All @@ -128,12 +126,31 @@ class TestConfig extends AbstractDescribableImpl<TestConfig> implements Expandab
'TestConfig'
}

/**
* Creates a new instance of {@link TestConfig} from form data.
* If loadConfig is present and false, removes tbcPath and tcfPath from the form data
* before creating the instance to ensure they are null in the resulting configuration.
*/
@Override
TestConfig newInstance(StaplerRequest req, JSONObject formData) throws FormException {
def processedFormData = processFormData(formData)
return (TestConfig) super.newInstance(req, processedFormData);
}

FormValidation doCheckTbcPath(@QueryParameter String value) {
return ValidationUtil.validateConfigFile(value, '.tbc')
return ValidationUtil.validateFileExtension(value, '.tbc')
}

FormValidation doCheckTcfPath(@QueryParameter final String value) {
return ValidationUtil.validateConfigFile(value, '.tcf')
return ValidationUtil.validateFileExtension(value, '.tcf')
}

protected static JSONObject processFormData(JSONObject formData) {
if (formData.containsKey("loadConfig") && !formData.getBoolean("loadConfig")) {
formData.remove("tbcPath")
formData.remove("tcfPath")
}
return formData
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ class RunPackageStep extends RunTestStep {
* @return the form validation
*/
FormValidation doCheckTestCasePath(@QueryParameter String value) {
return ValidationUtil.validateParameterizedValue(value, true)
FormValidation valid = ValidationUtil.validateParameterizedValue(value, true)
if (valid == FormValidation.ok()) {
return ValidationUtil.validateFileExtension(value, '.pkg')
}
return valid
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ class RunProjectStep extends RunTestStep {
* @return the form validation
*/
FormValidation doCheckTestCasePath(@QueryParameter String value) {
return ValidationUtil.validateParameterizedValue(value, true)
FormValidation valid = ValidationUtil.validateParameterizedValue(value, true)
if (valid == FormValidation.ok()) {
return ValidationUtil.validateFileExtension(value, '.prj')
}
return valid
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ class LogConfigUtil implements Serializable {
}

private void logTestConfig() {
if (testConfig.tbcPath) {
listener.logger.println("-> With TBC=${testConfig.tbcPath}")
}
if (testConfig.tcfPath) {
listener.logger.println("-> With TCF=${testConfig.tcfPath}")
if (!testConfig.loadConfig) {
return
}

listener.logger.println("-> With TBC='${testConfig.tbcPath}'")
listener.logger.println("-> With TCF='${testConfig.tcfPath}'")

if (testConfig.constants) {
listener.logger.println("-> With global constants=[${testConfig.constants.each { it.toString() }}]")
}
if (testConfig.configOption) {
listener.logger.println("-> With TestConfig=${testConfig.configOption}")
if (testConfig.forceConfigurationReload) {
listener.logger.println("-> With ForceConfigurationReload=${testConfig.forceConfigurationReload}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class ValidationUtil {
return returnValue
}

static validateConfigFile(String configFilePath, String fileExtension) {
static validateFileExtension(String configFilePath, String fileExtension) {
FormValidation returnValue = validateParameterizedValue(configFilePath, false)
if (returnValue == FormValidation.ok() && !StringUtils.isEmpty(configFilePath)) {
if (!configFilePath.endsWith(fileExtension)) {
returnValue = FormValidation.error(
"${configFilePath} has to be empty or of file type ${fileExtension}.")
"${configFilePath} has to be of file type '${fileExtension}'")
}
}
return returnValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:section title="${%configSection.title}">
<f:radioBlock name="configOption" title="${%configOption.keepConfig}" value="keepConfig" checked="${instance.configOption == null || configOption == 'keepConfig'}" inline="true">
<f:description>${%keepConfig.description}</f:description>
</f:radioBlock>
<f:radioBlock name="configOption" title="${%configOption.loadConfig}" value="loadConfig" checked="${instance.configOption == 'loadConfig'}" inline="true">
<f:optionalBlock name="loadConfig" title="${%configOption.loadConfig}"
help="/plugin/ecu-test-execution/help/TestConfig/loadConfig.html" inline="true"
checked="${instance.loadConfig}"
>
<j:set var="tbcValue" value="${it.loadConfig ? instance.tbcPath : null}"/>
<j:set var="tcfValue" value="${it.loadConfig ? instance.tcfPath : null}"/>

<f:description>${%loadConfig.description}</f:description>
<f:entry title="${%tbcPath.title}" description="${%tbcPath.description}" field="tbcPath">
<f:textbox />
<f:textbox value="${tbcValue}"/>
</f:entry>
<f:entry title="${%tcfPath.title}" description="${%tcfPath.description}" field="tcfPath">
<f:textbox />
<f:textbox value="${tcfValue}"/>
</f:entry>
<f:advanced title="${%constants.title}">
<f:entry title="${%constants.title}" description="${%constants.description}" field="constants">
Expand All @@ -20,6 +23,6 @@
<f:entry title="${%forceConfigurationReload.title}" description="${%forceConfigurationReload.description}" field="forceConfigurationReload">
<f:checkbox />
</f:entry>
</f:radioBlock>
</f:optionalBlock>
</f:section>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
configSection.title=Test Configuration
configOption.loadConfig=Load Configuration
configOption.keepConfig=Keep Configuration
loadConfig.description=Both the Test Bench Configuration and Test Configuration must be provided to load new configurations. \
Setting <tt>forceConfigurationReload</tt> to <tt>true</tt> forces a configuration reload, even if the same configuration is still active. \
If empty, Test Configuration will be unloaded.
keepConfig.description=Enabling this option retains the existing configuration for continued use throughout the execution.
loadConfig.description=The TestConfiguration and/or the TestBenchConfiguration files must be explicitly set whenever\
a new configuration is needed. If both are empty, Test Configuration will be unloaded. \
Setting <tt>forceConfigurationReload</tt> to <tt>true</tt> forces a configuration reload,\
even if the same configuration is still active.
constants.add=Add Global Constant
constants.description=The configured global constants remain available throughout the entire test execution.
constants.title=Global Constants
Expand Down
14 changes: 14 additions & 0 deletions src/main/webapp/help/TestConfig/loadConfig.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<div>
<!--Need more ui examples and classes see https://weekly.ci.jenkins.io/design-library/-->
<dl class="jenkins-form-description">
<dt><b>Unchecked (default):</b></dt>
<dd>Enabling this option retains the existing configuration for continued use throughout the execution.</dd>
<dt><b>Checked:</b></dt>
<dd>The TestConfiguration and/or the TestBenchConfiguration files must be explicitly set whenever
a new configuration is needed. If both are empty, Test Configuration will be unloaded.
Setting `forceConfigurationReload` to `true` forces a configuration reload,
even if the same configuration is still active.
</dd>
</dl>
</div>
Loading

0 comments on commit 271a5b1

Please sign in to comment.