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

Commit f2a7e2f

Browse files
authored
Merge pull request #172 from mathworks/test_filter_freestyle
Test filter freestyle
2 parents 9f6db19 + 60f9195 commit f2a7e2f

File tree

10 files changed

+192
-24
lines changed

10 files changed

+192
-24
lines changed

src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import hudson.Extension;
2222
import hudson.FilePath;
2323
import hudson.Launcher;
24+
import hudson.Util;
25+
import hudson.model.AbstractDescribableImpl;
2426
import hudson.model.AbstractProject;
27+
import hudson.model.Descriptor;
2528
import hudson.model.Result;
2629
import hudson.model.Run;
2730
import hudson.model.TaskListener;
@@ -53,13 +56,17 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep, M
5356
private Artifact stmResultsArtifact = new NullArtifact();
5457
private Artifact modelCoverageArtifact = new NullArtifact();
5558
private Artifact pdfReportArtifact = new NullArtifact();
59+
5660
private SourceFolder sourceFolder;
61+
private SelectByFolder selectByFolder;
62+
private SelectByTag selectByTag;
63+
5764

5865
@DataBoundConstructor
5966
public RunMatlabTestsBuilder() {
6067

6168
}
62-
69+
6370
// Getter and Setters to access local members
6471

6572
@DataBoundSetter
@@ -91,11 +98,21 @@ public void setModelCoverageArtifact(ModelCovArtifact modelCoverageArtifact) {
9198
public void setPdfReportArtifact(PdfArtifact pdfReportArtifact) {
9299
this.pdfReportArtifact = pdfReportArtifact;
93100
}
94-
101+
102+
@DataBoundSetter
103+
public void setSelectByTag(SelectByTag selectByTag) {
104+
this.selectByTag = selectByTag;
105+
}
106+
95107
@DataBoundSetter
96108
public void setSourceFolder(SourceFolder sourceFolder) {
97109
this.sourceFolder = sourceFolder;
98110
}
111+
112+
@DataBoundSetter
113+
public void setSelectByFolder(SelectByFolder selectByFolder) {
114+
this.selectByFolder = selectByFolder;
115+
}
99116

100117

101118
public String getTapReportFilePath() {
@@ -145,10 +162,16 @@ public Artifact getPdfReportArtifact() {
145162
public String getPdfReportFilePath() {
146163
return this.getPdfReportArtifact().getFilePath();
147164
}
148-
165+
public SelectByTag getSelectByTag() {
166+
return this.selectByTag;
167+
}
149168
public SourceFolder getSourceFolder() {
150169
return this.sourceFolder;
151170
}
171+
172+
public SelectByFolder getSelectByFolder(){
173+
return this.selectByFolder;
174+
}
152175

153176
private Artifact getArtifactObject(boolean isChecked, Artifact returnVal) {
154177
// If previously checked assign valid artifact object else NullArtifact.
@@ -311,6 +334,18 @@ private String getInputArguments() {
311334
.map(SourceFolderPaths::getSrcFolderPath)
312335
.collect(Collectors.toList())));
313336
}
337+
338+
// Add Test folders
339+
if (getSelectByFolder() != null && !getSelectByFolder().getTestFolderPaths().isEmpty()) {
340+
getSelectByFolder().addSourceToInputArgs(inputArgsList,
341+
Utilities.getCellArrayFrmList(getSelectByFolder().getTestFolderPaths().stream()
342+
.map(TestFolders::getTestFolders).collect(Collectors.toList())));
343+
}
344+
345+
// Add Tag to arguments
346+
if (getSelectByTag() != null && !getSelectByTag().getTestTag().isEmpty()) {
347+
getSelectByTag().addTagToInputArgs(inputArgsList);
348+
}
314349

315350
return String.join(",", inputArgsList);
316351
}
@@ -465,4 +500,27 @@ public interface Artifact {
465500

466501
public boolean getSelected();
467502
}
503+
504+
public static final class SelectByTag extends AbstractDescribableImpl<SelectByTag> {
505+
private String testTag;
506+
private static final String SELECT_BY_TAG = "SelectByTag";
507+
508+
@DataBoundConstructor
509+
public SelectByTag(String testTag) {
510+
this.testTag = Util.fixNull(testTag);
511+
}
512+
513+
public String getTestTag() {
514+
return this.testTag;
515+
}
516+
517+
public void addTagToInputArgs(List<String> inputArgsList) {
518+
inputArgsList.add("'" + SELECT_BY_TAG + "'" + "," + "'"
519+
+ getTestTag().replaceAll("'", "''") + "'");
520+
}
521+
522+
@Extension
523+
public static class DescriptorImpl extends Descriptor<SelectByTag> {
524+
}
525+
}
468526
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.mathworks.ci;
2+
3+
import java.util.List;
4+
5+
import org.kohsuke.stapler.DataBoundConstructor;
6+
import org.kohsuke.stapler.DataBoundSetter;
7+
8+
import hudson.Extension;
9+
import hudson.Util;
10+
import hudson.model.AbstractDescribableImpl;
11+
import hudson.model.Descriptor;
12+
13+
public class SelectByFolder extends AbstractDescribableImpl<SelectByFolder> {
14+
private List<TestFolders> testFolderPaths;
15+
private static final String SELECT_BY_FOLDER = "SelectByFolder";
16+
17+
@DataBoundConstructor
18+
public SelectByFolder(List<TestFolders> testFolderPaths) {
19+
this.testFolderPaths = Util.fixNull(testFolderPaths);
20+
}
21+
22+
public List<TestFolders> getTestFolderPaths() {
23+
return this.testFolderPaths;
24+
}
25+
26+
public void addSourceToInputArgs(List<String> inputArgsList, String cellArraySourceVal) {
27+
// Concatenate all source folders to MATLAB cell array string.
28+
inputArgsList.add("'" + SELECT_BY_FOLDER + "'" + "," + cellArraySourceVal);
29+
}
30+
31+
@Extension public static class DescriptorImpl extends Descriptor<SelectByFolder> {}
32+
}

src/main/java/com/mathworks/ci/SourceFolder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public void addSourceToInputArgs(List<String> inputArgsList, String cellArraySo
3535
inputArgsList.add("'" + SOURCE_FOLDER + "'" + "," + cellArraySourceVal);
3636
}
3737

38-
@Extension public static class DescriptorImpl extends Descriptor<SourceFolder> {
39-
@Override
40-
public String getDisplayName() {
41-
return "";
42-
}
43-
}
38+
@Extension public static class DescriptorImpl extends Descriptor<SourceFolder> {}
4439

4540
}

src/main/java/com/mathworks/ci/SourceFolderPaths.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,5 @@ public String getSrcFolderPath() {
2626
return this.srcFolderPath;
2727
}
2828

29-
@Extension
30-
public static final class DescriptorImpl extends Descriptor<SourceFolderPaths> {
31-
32-
@Override
33-
public String getDisplayName() {
34-
return "";
35-
}
36-
}
29+
@Extension public static final class DescriptorImpl extends Descriptor<SourceFolderPaths> {}
3730
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.mathworks.ci;
2+
3+
import org.kohsuke.stapler.DataBoundConstructor;
4+
5+
import hudson.Extension;
6+
import hudson.model.AbstractDescribableImpl;
7+
import hudson.model.Descriptor;
8+
9+
public class TestFolders extends AbstractDescribableImpl<TestFolders> {
10+
11+
private String testFolders;
12+
13+
@DataBoundConstructor
14+
public TestFolders(String testFolders) {
15+
this.testFolders = testFolders;
16+
}
17+
18+
public String getTestFolders() {
19+
return this.testFolders;
20+
}
21+
22+
@Extension public static final class DescriptorImpl extends Descriptor<TestFolders> {}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
3+
<f:entry field="testTag" title="Tag name: ">
4+
<f:textbox/>
5+
</f:entry>
6+
</j:jelly>

src/main/resources/com/mathworks/ci/RunMatlabTestsBuilder/config.jelly

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33

44
<f:block>
55
<br></br>
6-
<f:optionalProperty field="sourceFolder" title="Source Folder" />
6+
<f:optionalProperty field="sourceFolder" title="Source folder" />
7+
</f:block>
8+
9+
<f:block>
10+
<br></br>
11+
<b>Filter Tests</b>
12+
<f:optionalProperty field="selectByFolder" title="By folder name" />
13+
<br></br>
14+
<f:optionalProperty field="selectByTag" title="By tag" />
715
</f:block>
816

917
<f:block>
@@ -14,7 +22,7 @@
1422
<f:textbox default="matlabTestArtifacts/testreport.pdf"/>
1523
</f:entry>
1624
</f:optionalBlock>
17-
25+
1826
<f:optionalBlock name="tapArtifact" field="tapArtifact" title="TAP test results" checked="${instance.tapArtifact.selected}">
1927
<f:entry field="tapReportFilePath" title="File path: ">
2028
<f:textbox default="matlabTestArtifacts/taptestresults.tap"/>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
3+
<f:entry title="">
4+
<f:repeatable minimum="1" name="testFolderPaths" field="testFolderPaths" add="Add folder">
5+
<table width="100%">
6+
<f:textbox field="testFolders"/>
7+
<input type="button" value="Delete" class="repeatable-delete show-if-not-only" style="margin-left: 0px; margin-top: 0px; padding-top: 0px"/>
8+
</table>
9+
</f:repeatable>
10+
</f:entry>
11+
</j:jelly>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
3+
<f:entry field="testTag" title="Tag name: ">
4+
<f:textbox/>
5+
</f:entry>
6+
</j:jelly>

src/test/java/com/mathworks/ci/RunMatlabTestsBuilderTest.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ public void verifyDefaultArtifactLocation() throws Exception {
264264
HtmlCheckBoxInput coberturaArtifact = page.getElementByName("coberturaArtifact");
265265
HtmlCheckBoxInput modelCoverageArtifact = page.getElementByName("modelCoverageArtifact");
266266

267-
tapArtifact.click();
268-
pdfReportArtifact.click();
269-
junitArtifact.click();
270-
stmResultsArtifact.click();
271-
coberturaArtifact.click();
267+
tapArtifact.click();
268+
pdfReportArtifact.click();
269+
junitArtifact.click();
270+
stmResultsArtifact.click();
271+
coberturaArtifact.click();
272272
modelCoverageArtifact.click();
273273
Thread.sleep(2000);
274274

@@ -296,6 +296,42 @@ public void verifySourceFolderDefaultState() throws Exception {
296296
HtmlInput srcFolderPath = page.getElementByName("_.srcFolderPath");
297297
assertEquals("", srcFolderPath.getTextContent());
298298
}
299+
300+
/*
301+
* Test to verify text box shows up on SelectBy option click and text is empty.
302+
*/
303+
304+
@Test
305+
public void verifySelectByFolderDefaultState() throws Exception {
306+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2017a"));
307+
project.getBuildWrappersList().add(this.buildWrapper);
308+
project.getBuildersList().add(this.testBuilder);
309+
HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure");
310+
HtmlCheckBoxInput sourceFolder = page.getElementByName("_.selectByFolder");
311+
sourceFolder.click();
312+
Thread.sleep(2000);
313+
WebAssert.assertElementPresentByXPath(page, "//input[@name=\"_.testFolders\"]");
314+
HtmlInput srcFolderPath = page.getElementByName("_.testFolders");
315+
assertEquals("", srcFolderPath.getTextContent());
316+
}
317+
318+
/*
319+
* Test to verify text box shows up on SelectByTag option click and text is empty.
320+
*/
321+
322+
@Test
323+
public void verifySelectByTagDefaultState() throws Exception {
324+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2017a"));
325+
project.getBuildWrappersList().add(this.buildWrapper);
326+
project.getBuildersList().add(this.testBuilder);
327+
HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure");
328+
HtmlCheckBoxInput sourceFolder = page.getElementByName("_.selectByTag");
329+
sourceFolder.click();
330+
Thread.sleep(2000);
331+
WebAssert.assertElementPresentByXPath(page, "//input[@name=\"_.testTag\"]");
332+
HtmlInput srcFolderPath = page.getElementByName("_.testTag");
333+
assertEquals("", srcFolderPath.getTextContent());
334+
}
299335

300336
/*
301337
* Test to verify only specific test atrtifact are passed.

0 commit comments

Comments
 (0)