Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Commit edabb8e

Browse files
authored
tech : improving custom framework (#223)
* tech : improving custom framework
1 parent d7154e3 commit edabb8e

File tree

7 files changed

+183
-123
lines changed

7 files changed

+183
-123
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@
470470
<dependency>
471471
<artifactId>integrations-sdk</artifactId>
472472
<groupId>com.hpe.adm.octane.ciplugins</groupId>
473-
<version>2.0.62</version>
473+
<version>2.0.63</version>
474474
</dependency>
475475

476476
<!--BUILDER providers integration-->

src/main/java/com/microfocus/application/automation/tools/model/TestsFramework.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,17 @@ public class TestsFramework {
2525
private String description;
2626
private String name;
2727
private String format;
28-
private String delimiter;
2928

3029
public TestsFramework() {
3130
this.name = "";
3231
this.description = "";
3332
this.format = "";
34-
this.delimiter = "";
3533
}
3634

37-
public TestsFramework(String name, String description, String format, String delimiter) {
35+
public TestsFramework(String name, String description, String format) {
3836
this.name = name;
3937
this.description = description;
4038
this.format = format;
41-
this.delimiter = delimiter;
4239
}
4340

4441
public String getDescription() {
@@ -53,8 +50,4 @@ public String getFormat() {
5350
return format;
5451
}
5552

56-
public String getDelimiter() {
57-
return delimiter;
58-
}
59-
6053
}

src/main/java/com/microfocus/application/automation/tools/octane/testrunner/TestsToRunConverterBuilder.java

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
package com.microfocus.application.automation.tools.octane.testrunner;
2323

24-
import com.hp.octane.integrations.executor.TestsToRunConverter;
2524
import com.hp.octane.integrations.executor.TestsToRunConverterResult;
2625
import com.hp.octane.integrations.executor.TestsToRunConvertersFactory;
2726
import com.hp.octane.integrations.executor.TestsToRunFramework;
@@ -46,9 +45,7 @@
4645
import javax.annotation.Nonnull;
4746
import java.io.IOException;
4847
import java.util.ArrayList;
49-
import java.util.HashMap;
5048
import java.util.List;
51-
import java.util.Map;
5249

5350
/**
5451
* Builder for available frameworks for converting
@@ -63,12 +60,12 @@ public class TestsToRunConverterBuilder extends Builder implements SimpleBuildSt
6360
private static final String CHECKOUT_DIRECTORY_PARAMETER = "testsToRunCheckoutDirectory";
6461

6562
public TestsToRunConverterBuilder(String framework) {
66-
this.framework = new TestsToRunConverterModel(framework, "", "");
63+
this.framework = new TestsToRunConverterModel(framework, "");
6764
}
6865

6966
@DataBoundConstructor
70-
public TestsToRunConverterBuilder(String framework, String format, String delimiter) {
71-
this.framework = new TestsToRunConverterModel(framework, format, delimiter);
67+
public TestsToRunConverterBuilder(String framework, String format) {
68+
this.framework = new TestsToRunConverterModel(framework, format);
7269
}
7370

7471
@Override
@@ -115,16 +112,14 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath filePath, @Nonnu
115112
}
116113
String frameworkName = getFramework();
117114
String frameworkFormat = getFormat();
118-
String frameworkDelimiter = getDelimiter();
119115
printToConsole(listener, "Selected framework = " + frameworkName);
120116
if (SdkStringUtils.isNotEmpty(frameworkFormat)) {
121117
printToConsole(listener, "Using format = " + frameworkFormat);
122-
printToConsole(listener, "Using delimiter = " + frameworkDelimiter);
123118
}
124119

125120
TestsToRunFramework testsToRunFramework = TestsToRunFramework.fromValue(frameworkName);
126121
TestsToRunConverterResult convertResult = TestsToRunConvertersFactory.createConverter(testsToRunFramework)
127-
.setProperties(this.getProperties())
122+
.setFormat(frameworkFormat)
128123
.convert(rawTests, executingDirectory);
129124
printToConsole(listener, "Found #tests : " + convertResult.getTestsData().size());
130125
printToConsole(listener, "Set to parameter : " + convertResult.getTestsToRunConvertedParameterName() + " = " + convertResult.getConvertedTestsString());
@@ -146,16 +141,6 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath filePath, @Nonnu
146141
}
147142
}
148143

149-
public Map<String, String> getProperties() {
150-
Map<String, String> properties = new HashMap();
151-
152-
if (TestsToRunFramework.Custom.value().equals(getFramework())) {
153-
properties.put(TestsToRunConverter.CONVERTER_FORMAT, getFormat());
154-
properties.put(TestsToRunConverter.CONVERTER_DELIMITER, getDelimiter());
155-
}
156-
return properties;
157-
}
158-
159144
/***
160145
* Used in UI
161146
* @return
@@ -172,14 +157,14 @@ public String getFramework() {
172157
return framework.getFramework().getName();
173158
}
174159

175-
public String getDelimiter() {
176-
return framework.getFramework().getDelimiter();
177-
}
178-
179160
public String getFormat() {
180161
return framework.getFramework().getFormat();
181162
}
182163

164+
public boolean getIsCustom(){
165+
return TestsToRunFramework.Custom.value().equals(framework.getFramework().getName());
166+
}
167+
183168
private void printToConsole(TaskListener listener, String msg) {
184169
listener.getLogger().println(this.getClass().getSimpleName() + " : " + msg);
185170
}
@@ -201,8 +186,7 @@ public String getDisplayName() {
201186
public FormValidation doTestConvert(
202187
@QueryParameter("testsToRun") String rawTests,
203188
@QueryParameter("teststorunconverter.framework") String framework,
204-
@QueryParameter("teststorunconverter.format") String format,
205-
@QueryParameter("teststorunconverter.delimiter") String delimiter) {
189+
@QueryParameter("teststorunconverter.format") String format) {
206190

207191
try {
208192

@@ -214,20 +198,13 @@ public FormValidation doTestConvert(
214198
throw new IllegalArgumentException("'Framework' parameter is missing");
215199
}
216200

217-
if (StringUtils.isEmpty(format)) {
218-
throw new IllegalArgumentException("'Format' parameter is missing");
219-
}
220-
221-
Map<String, String> properties = new HashMap();
222-
223201
TestsToRunFramework testsToRunFramework = TestsToRunFramework.fromValue(framework);
224-
if (TestsToRunFramework.Custom.equals(testsToRunFramework)) {
225-
properties.put(TestsToRunConverter.CONVERTER_FORMAT, format);
226-
properties.put(TestsToRunConverter.CONVERTER_DELIMITER, delimiter);
202+
if (TestsToRunFramework.Custom.equals(testsToRunFramework) && StringUtils.isEmpty(format)) {
203+
throw new IllegalArgumentException("'Format' parameter is missing");
227204
}
228205

229206
TestsToRunConverterResult convertResult = TestsToRunConvertersFactory.createConverter(testsToRunFramework)
230-
.setProperties(properties)
207+
.setFormat(format)
231208
.convert(rawTests, TestsToRunConverterBuilder.DEFAULT_EXECUTING_DIRECTORY);
232209
return ConfigurationValidator.wrapWithFormValidation(true, "Conversion is successful : <div style=\"margin-top:20px\">" + convertResult.getConvertedTestsString() + "</div>");
233210
} catch (Exception e) {
@@ -244,5 +221,6 @@ public List<TestsFramework> getFrameworks() {
244221

245222
return TestsToRunConverterModel.Frameworks;
246223
}
224+
247225
}
248226
}

src/main/java/com/microfocus/application/automation/tools/octane/testrunner/TestsToRunConverterModel.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,30 @@ public class TestsToRunConverterModel implements Serializable {
3535

3636
private static final long serialVersionUID = 1L;
3737

38-
public final static TestsFramework none = new TestsFramework("", "", "", "");
38+
public final static TestsFramework none = new TestsFramework("", "", "");
3939

4040
public final static List<TestsFramework> Frameworks;
4141

4242
private String framework;
4343
private String format;
44-
private String delimiter;
4544

4645
static {
4746
List<TestsFramework> temp = new ArrayList<>();
4847
temp.add(none);
4948
for (TestsToRunFramework fr : TestsToRunFramework.values()) {
50-
temp.add(new TestsFramework(fr.value(), fr.getDesc(), fr.getFormat(), fr.getDelimiter()));
49+
temp.add(new TestsFramework(fr.value(), fr.getDesc(), fr.getFormat()));
5150
}
5251
Frameworks = temp;
5352
}
5453

5554
@DataBoundConstructor
56-
public TestsToRunConverterModel(String framework, String format, String delimiter) {
55+
public TestsToRunConverterModel(String framework, String format) {
5756
this.framework = framework;
5857
this.format = format;
59-
this.delimiter = delimiter;
6058
}
6159

6260
public TestsFramework getFramework() {
63-
return new TestsFramework(framework, "", format, delimiter);
61+
return new TestsFramework(framework, "", format);
6462
}
6563

6664
}

src/main/resources/com/microfocus/application/automation/tools/octane/testrunner/TestsToRunConverterBuilder/config.jelly

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,110 @@
3434

3535
<j:forEach var="myFramework" items="${descriptor.Frameworks}">
3636
<f:textbox id="format+${myFramework.name}" value="${myFramework.format}" hidden="hidden"/>
37-
<f:textbox id="delimiter+${myFramework.name}" value="${myFramework.delimiter}" hidden="hidden"/>
3837
</j:forEach>
38+
<f:entry title="Custom configuration" field="format">
39+
<textarea id="format" name="teststorunconverter.format" type="text" disabled="disabled" class="setting-input" style="resize: vertical; min-height:90px;">
40+
${instance.testsToRunConverterModel.framework.format}
41+
</textarea>
42+
<select id="fillFormat" onchange="insertFormat(this)" style="visibility: hidden; float: right;position: relative;font-size: smaller;">
43+
<f:option value="title">Fill configuration ...</f:option>
44+
<f:option value="basic">Minimal configuration</f:option>
45+
<f:option value="extended">Extended configuration</f:option>
46+
</select>
47+
</f:entry>
3948

40-
41-
<j:if test="${instance.testsToRunConverterModel.framework.name == 'custom'}">
42-
<f:entry title="Format" field="format" >
43-
<textarea id="format" name="teststorunconverter.format" type="text" class="setting-input" style="resize: vertical; min-height:30px;">
44-
${instance.testsToRunConverterModel.framework.format}
45-
</textarea>
46-
</f:entry>
47-
48-
<f:entry title="Delimiter" field="delimiter" >
49-
<f:textbox id="delimiter" name="teststorunconverter.delimiter" value="${instance.testsToRunConverterModel.framework.delimiter}" />
50-
</f:entry>
51-
</j:if>
52-
<j:if test="${instance.testsToRunConverterModel.framework.name != 'custom'}">
53-
<f:entry title="Format" field="format">
54-
<textarea id="format" name="teststorunconverter.format" type="text" class="setting-input" disabled="true" style="resize: vertical; min-height:30px;">
55-
${instance.testsToRunConverterModel.framework.format}
56-
</textarea>
57-
</f:entry>
58-
59-
<f:entry title="Delimiter" field="delimiter" >
60-
<f:textbox id="delimiter" name="teststorunconverter.delimiter" value="${instance.testsToRunConverterModel.framework.delimiter}" disabled="true"/>
61-
</f:entry>
62-
</j:if>
6349
<f:advanced>
6450
<f:section title="Test conversion"/>
6551
<f:entry title="Tests to run" description="Tests to run in raw format, for example : v1:package1|className1|testName1;package2|className2|testName2">
6652
<f:textbox field="testsToRun" />
6753
</f:entry>
6854
<f:validateButton title="Convert" progress="Evaluating..."
69-
method="testConvert" with="framework,teststorunconverter.framework,teststorunconverter.format,teststorunconverter.delimiter,testsToRun"/>
55+
method="testConvert" with="teststorunconverter.framework,teststorunconverter.format,testsToRun"/>
7056
</f:advanced>
7157

7258
<script>
59+
function init(){
60+
var isCustom=false;
61+
var txtFormat = document.getElementById('format');
7362

63+
if(txtFormat){
64+
var index = txtFormat.selectedIndex;
65+
isCustom=true;//${instance.isCustom};
66+
}
67+
enableElements(isCustom);
68+
}
69+
function insertFormat(sender){
70+
var index = sender.selectedIndex;
71+
var options = sender.options;
72+
var txtFormat = document.getElementById('format');
7473

75-
function selectionChanged(sender) {
74+
if(options[index].value === 'basic'){
75+
txtFormat.value = "{\n\t\"testPattern\": \"$$package.$$class#$$testName\",\n\t\"testDelimiter\": \",\"\n}";
76+
}
77+
else if(options[index].value === 'extended'){
78+
79+
txtFormat.value = "{"+
80+
"\n\t\"testPattern\": \"$$package.$$class#$$testName\","+
81+
"\n\t\"testDelimiter\": \",\","+
82+
"\n\t\"prefix\": \"\","+
83+
"\n\t\"suffix\": \"\","+
84+
"\n\t\"replacements\": ["+
85+
86+
"\n\t\{"+
87+
"\n\t\t\"type\": \"replaceString\","+
88+
"\n\t\t\"target\": \"$$package|$$class|$$testName\","+
89+
"\n\t\t\"string\": \"aaa\","+
90+
"\n\t\t\"replacement\": \"bbb\""+
91+
"\n\t\}"+
92+
93+
"\n\t\{"+
94+
"\n\t\t\"type\": \"replaceRegexFirst\","+
95+
"\n\t\t\"target\": \"$$package|$$class|$$testName\","+
96+
"\n\t\t\"regex\": \"aaa\","+
97+
"\n\t\t\"replacement\": \"bbb\""+
98+
"\n\t\}"+
99+
100+
"\n\t\{"+
101+
"\n\t\t\"type\": \"joinString\","+
102+
"\n\t\t\"target\": \"$$package|$$class|$$testName\","+
103+
"\n\t\t\"prefix\": \"\","+
104+
"\n\t\t\"suffix\": \"\""+
105+
"\n\t\}"+
106+
107+
"\n\t]"+
108+
"\n}";
109+
}
110+
sender.selectedIndex = 0;
111+
}
76112

113+
function selectionChanged(sender) {
77114
var x = sender.selectedIndex;
78115
var y = sender.options;
79-
var txtFormat = document.getElementById('format');
80-
var txtDelimiter = document.getElementById('delimiter');
81-
82116
var bCustom = y[x].value === 'custom' ? true : false;
83-
84-
txtFormat.disabled = !bCustom;
85-
txtDelimiter.disabled = !bCustom;
86-
117+
enableElements(bCustom);
87118
var optionFormat = document.getElementById('format+' + y[x].value);
88-
var optionDelimiter = document.getElementById('delimiter+' + y[x].value);
89-
119+
var txtFormat = document.getElementById('format');
90120
txtFormat.value = optionFormat ? optionFormat.value : "";
91-
txtDelimiter.value = optionDelimiter ? optionDelimiter.value : "";
92121
}
93122

123+
function enableElements(isCustom, secondTry){
124+
var txtFormat = document.getElementById('format');
125+
if(txtFormat){
126+
txtFormat.disabled = !isCustom;
127+
}else{
128+
if(!secondTry){
129+
setTimeout(function(){ enableElements(isCustom,true); }, 500);
130+
return;
131+
}
132+
}
133+
134+
var fillFormat = document.getElementById('fillFormat');
135+
if(fillFormat){
136+
fillFormat.style.visibility = isCustom ? "visible" : "hidden";
137+
}
138+
}
139+
init();
140+
94141
</script>
95142

96143
</j:jelly>

src/main/resources/com/microfocus/application/automation/tools/octane/testrunner/TestsToRunConverterBuilder/help-delimiter.html

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)