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

Commit 3df9592

Browse files
committed
Address review comments
1 parent c50d60a commit 3df9592

File tree

10 files changed

+128
-173
lines changed

10 files changed

+128
-173
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
name: using mpm to install MATLAB
22
on: push
33
jobs:
4-
my-job:
4+
run-tests-job:
55
strategy:
66
matrix:
77
os: [ubuntu-latest, windows-latest, macos-latest]
88
name: Run System tests
99
runs-on: ${{ matrix.os }}
1010
steps:
1111
- name: Check out repository
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v4
1313

1414
- name: Setup Java 11
15-
uses: actions/setup-java@v3
15+
uses: actions/setup-java@v4
1616
with:
1717
java-version: '11'
1818
distribution: 'temurin'
19+
cache: maven
1920

2021
- name: Setup MATLAB
2122
id: setup-matlab

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@
132132
<groupId>com.jcabi</groupId>
133133
<artifactId>jcabi-xml</artifactId>
134134
<version>0.23.1</version>
135+
<scope>test</scope>
135136
</dependency>
136137
<!-- https://mvnrepository.com/artifact/org.jenkinsci.plugins/pipeline-model-definition -->
137138
<dependency>
138139
<groupId>org.jenkinsci.plugins</groupId>
139140
<artifactId>pipeline-model-definition</artifactId>
141+
<scope>test</scope>
140142
</dependency>
141143
<!-- Need unzip to add the files in pipeline workspace -->
142144
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins/pipeline-utility-steps -->
@@ -152,6 +154,7 @@
152154
<groupId>org.jenkins-ci.plugins</groupId>
153155
<artifactId>cobertura</artifactId>
154156
<version>1.16</version>
157+
<scope>test</scope>
155158
</dependency>
156159

157160
</dependencies>

src/test/java/com/mathworks/ci/systemTests/GlobalToolIT.java

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,25 @@
99
import hudson.model.FreeStyleBuild;
1010
import hudson.model.FreeStyleProject;
1111
import hudson.model.Result;
12-
import hudson.slaves.DumbSlave;
13-
import org.htmlunit.WebAssert;
1412
import org.htmlunit.html.*;
1513
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
1614
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
1715
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
1816
import org.junit.*;
19-
import org.junit.rules.Timeout;
2017
import org.jvnet.hudson.test.JenkinsRule;
2118

2219
import java.io.IOException;
2320
import java.util.ArrayList;
2421
import java.util.Arrays;
2522
import java.util.List;
2623

27-
import static junit.framework.TestCase.assertTrue;
24+
import static org.apache.commons.lang3.StringUtils.*;
25+
import static org.junit.Assert.assertEquals;
2826

2927
public class GlobalToolIT {
3028
private FreeStyleProject project;
3129
private RunMatlabCommandBuilder scriptBuilder;
3230
private UseMatlabVersionBuildWrapper buildWrapper;
33-
34-
@Rule
35-
public Timeout timeout = Timeout.seconds(0);
36-
3731
@Rule
3832
public JenkinsRule jenkins = new JenkinsRule();
3933

@@ -65,18 +59,19 @@ public void verifyGlobalToolForFreeStyle() throws Exception{
6559
Utilities.setMatlabInstallation("MATLAB_PATH", Utilities.getMatlabRoot(), jenkins);
6660

6761
// Selecting MATLAB that is defined as Global tool
68-
MatlabInstallation _inst = MatlabInstallation.getInstallation("MATLAB_PATH");
69-
MatlabBuildWrapperContent content = new MatlabBuildWrapperContent(_inst.getName(), null);
62+
MatlabInstallation inst = MatlabInstallation.getInstallation("MATLAB_PATH");
63+
MatlabBuildWrapperContent content = new MatlabBuildWrapperContent(inst.getName(), null);
7064
buildWrapper.setMatlabBuildWrapperContent(content);
7165
project.getBuildWrappersList().add(buildWrapper);
7266
scriptBuilder.setMatlabCommand("disp('apple')");
7367
project.getBuildersList().add(scriptBuilder);
7468

7569
FreeStyleBuild build = project.scheduleBuild2(0).get();
7670

77-
jenkins.assertLogContains(_inst.getHome(), build);
71+
jenkins.assertLogContains(inst.getHome(), build);
7872
jenkins.assertBuildStatus(Result.SUCCESS, build);
7973
jenkins.assertLogContains("apple", build);
74+
assertEquals(countMatches(jenkins.getLog(build), "apple"), 2);
8075
}
8176

8277
@Test
@@ -85,8 +80,8 @@ public void verifyBuildFailsForIncorrectToolPath() throws Exception{
8580
Utilities.setMatlabInstallation("MATLAB_PATH", "matlab/incorrect/path", jenkins);
8681

8782
// Selecting MATLAB that is defined as Global tool
88-
MatlabInstallation _inst = MatlabInstallation.getInstallation("MATLAB_PATH");
89-
MatlabBuildWrapperContent content = new MatlabBuildWrapperContent(_inst.getName(), null);
83+
MatlabInstallation inst = MatlabInstallation.getInstallation("MATLAB_PATH");
84+
MatlabBuildWrapperContent content = new MatlabBuildWrapperContent(inst.getName(), null);
9085
buildWrapper.setMatlabBuildWrapperContent(content);
9186
project.getBuildWrappersList().add(buildWrapper);
9287

@@ -96,6 +91,7 @@ public void verifyBuildFailsForIncorrectToolPath() throws Exception{
9691
FreeStyleBuild build = project.scheduleBuild2(0).get();
9792

9893
jenkins.assertBuildStatus(Result.FAILURE, build);
94+
// Note: This message might change in future based on Jenkins changes
9995
jenkins.assertLogContains("Verify global tool configuration for the specified node.", build);
10096
jenkins.assertLogContains("MATLAB_PATH", build);
10197
}
@@ -112,22 +108,13 @@ public void verifyAllToolsAreAvailable() throws Exception {
112108

113109
// Getting the Web page for UI testing
114110
HtmlPage configurePage = jenkins.createWebClient().goTo("job/test0/configure");
115-
HtmlCheckBoxInput matlabver=configurePage.getElementByName("com-mathworks-ci-UseMatlabVersionBuildWrapper");
116-
matlabver.setChecked(true);
111+
HtmlCheckBoxInput matlabVer = configurePage.getElementByName("com-mathworks-ci-UseMatlabVersionBuildWrapper");
112+
matlabVer.setChecked(true);
117113
Thread.sleep(2000);
118-
List<HtmlSelect> matlabver_1=configurePage.getByXPath("//select[contains(@class, \"dropdownList\")]");
119-
// One of the drop downlists should have three options
120-
boolean allOptionsAvailable = false;
121-
for (HtmlSelect e : matlabver_1){
122-
if(e.getOptionSize() == 3){
123-
if(e.getOption(0).getValueAttribute().equals("MATLAB_PATH_1") &&
124-
e.getOption(1).getValueAttribute().equals("MATLAB_PATH_2") &&
125-
e.getOption(2).getValueAttribute().equals("Custom...")) {
126-
allOptionsAvailable = true;
127-
}
128-
}
129-
}
130-
assertTrue(allOptionsAvailable);
114+
HtmlSelect matlabOptions = (HtmlSelect) configurePage.getByXPath("//select[contains(@class, \"dropdownList\")]").get(1);
115+
assertEquals(matlabOptions.getOption(0).getValueAttribute(),"MATLAB_PATH_1");
116+
assertEquals(matlabOptions.getOption(1).getValueAttribute(),"MATLAB_PATH_2");
117+
assertEquals(matlabOptions.getOption(2).getValueAttribute(),"Custom...");
131118
}
132119

133120
@Test
@@ -158,21 +145,21 @@ public void verifyGlobalToolDSLPipeline() throws Exception {
158145
Utilities.setMatlabInstallation("MATLAB_PATH_1", Utilities.getMatlabRoot(), jenkins);
159146
String script = "pipeline {\n" +
160147
" agent any\n" +
161-
Utilities.getEnvironmentDSL() + "\n" +
162148
" tools {\n" +
163149
" matlab 'MATLAB_PATH_1'\n" +
164150
" }\n" +
165151
" stages{\n" +
166152
" stage('Run MATLAB Command') {\n" +
167153
" steps\n" +
168154
" {\n" +
169-
" runMATLABCommand 'version'\n" +
155+
" runMATLABCommand 'matlabroot'\n" +
170156
" } \n" +
171157
" } \n" +
172158
" } \n" +
173159
"}";
174160
WorkflowRun build = getPipelineBuild(script);
175161
jenkins.assertBuildStatus(Result.SUCCESS,build);
162+
assertEquals(countMatches(jenkins.getLog(build), Utilities.getMatlabRoot()), 1);
176163
}
177164
@Test
178165
public void verifyGlobalToolScriptedPipeline() throws Exception {
@@ -186,17 +173,14 @@ public void verifyGlobalToolScriptedPipeline() throws Exception {
186173
" }else{\n" +
187174
" env.PATH = \"${matlabver}\\\\bin;${env.PATH}\" // Windows agent\n" +
188175
" } \n" +
189-
" runMATLABCommand 'version'\n" +
176+
" runMATLABCommand 'matlabroot'\n" +
190177
" }\n" +
191178
"}";
192179
WorkflowRun build = getPipelineBuild(script);
193180
jenkins.assertBuildStatus(Result.SUCCESS, build);
181+
assertEquals(countMatches(jenkins.getLog(build), Utilities.getMatlabRoot()), 1);
194182
}
195183

196-
/*
197-
* Test to verify if Matrix build passes .
198-
*/
199-
200184
private WorkflowRun getPipelineBuild(String script) throws Exception{
201185
WorkflowJob project = jenkins.createProject(WorkflowJob.class);
202186
project.setDefinition(new CpsFlowDefinition(script,true));

src/test/java/com/mathworks/ci/systemTests/RunMATLABCommandIT.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import java.util.Arrays;
2727
import java.util.List;
2828

29+
import static org.apache.commons.lang3.StringUtils.countMatches;
30+
import static org.junit.Assert.assertEquals;
31+
2932
public class RunMATLABCommandIT {
3033
@Rule
3134
public JenkinsRule jenkins = new JenkinsRule();
@@ -71,15 +74,14 @@ public void verifyBuildPassesWhenMatlabCommandPasses() throws Exception {
7174

7275
FreeStyleBuild build = project.scheduleBuild2(0).get();
7376
jenkins.assertBuildStatus(Result.SUCCESS, build);
74-
jenkins.assertLogContains("apple", build);
7577
jenkins.assertLogContains(Utilities.getMatlabRoot(), build);
7678
jenkins.assertLogContains("run-matlab-command", build);
79+
assertEquals(countMatches(jenkins.getLog(build), "apple"), 2);
7780
}
7881

7982
/*
8083
* Test to verify if Build FAILS when matlab command fails
8184
*/
82-
8385
@Test
8486
public void verifyBuildFailureWhenMatlabCommandFails() throws Exception {
8587
FreeStyleProject project = jenkins.createFreeStyleProject();
@@ -92,7 +94,7 @@ public void verifyBuildFailureWhenMatlabCommandFails() throws Exception {
9294
scriptBuilder.setMatlabCommand("apple");
9395
project.getBuildersList().add(scriptBuilder);
9496
FreeStyleBuild build = project.scheduleBuild2(0).get();
95-
jenkins.assertLogContains("apple", build);
97+
assertEquals(countMatches(jenkins.getLog(build), "apple"), 3);
9698
jenkins.assertBuildStatus(Result.FAILURE, build);
9799
jenkins.assertLogContains(String.format(Message.getValue("matlab.execution.exception.prefix"), 1), build);
98100
}
@@ -122,28 +124,28 @@ public void verifyMatrixBuildPassesWithMATLABCommand() throws Exception {
122124

123125
Combination c = new Combination(new AxisList(new MatlabInstallationAxis(Arrays.asList("MATLAB_PATH_1"))), "MATLAB_PATH_1");
124126
MatrixRun run = build.getRun(c);
125-
jenkins.assertLogContains("disp('apple')", run);
127+
assertEquals(countMatches(jenkins.getLog(run), "apple"), 2);
126128
jenkins.assertLogContains(matlabRoot, run);
127129
jenkins.assertLogNotContains(matlabRoot22b, run);
128130

129131
c = new Combination(new AxisList(new MatlabInstallationAxis(Arrays.asList("MATLAB_PATH_22b"))), "MATLAB_PATH_22b");
130132
run = build.getRun(c);
131-
jenkins.assertLogContains("disp('apple')", run);
133+
assertEquals(countMatches(jenkins.getLog(run), "apple"), 2);
132134
jenkins.assertLogContains(matlabRoot22b, run);
133135

134136
jenkins.assertBuildStatus(Result.SUCCESS, build);
135137
}
136138

137139
@Test
138-
public void verifyBuildPassesWhenMatlabCommandPassesPipeline() throws Exception {
140+
public void verifyBuildPassesWhenMatlabCommandPassesInPipeline() throws Exception {
139141
String script = "pipeline {\n" +
140142
" agent any\n" +
141143
Utilities.getEnvironmentDSL() + "\n" +
142144
" stages{\n" +
143145
" stage('Run MATLAB Command') {\n" +
144146
" steps\n" +
145147
" {\n" +
146-
" runMATLABCommand 'version' \n" +
148+
" runMATLABCommand 'matlabroot' \n" +
147149
" }\n" +
148150
" }\n" +
149151
" }\n" +
@@ -154,10 +156,11 @@ public void verifyBuildPassesWhenMatlabCommandPassesPipeline() throws Exception
154156
WorkflowRun build = project.scheduleBuild2(0).get();
155157

156158
jenkins.assertBuildStatus(Result.SUCCESS, build);
159+
assertEquals(countMatches(jenkins.getLog(build), Utilities.getMatlabRoot()), 1);
157160
}
158161

159162
@Test
160-
public void verifyBuildFailsWhenMatlabCommandFails() throws Exception {
163+
public void verifyBuildFailsWhenMatlabCommandFailsInPipeline() throws Exception {
161164
String script = "pipeline {\n" +
162165
" agent any\n" +
163166
Utilities.getEnvironmentDSL() + "\n" +
@@ -175,20 +178,25 @@ public void verifyBuildFailsWhenMatlabCommandFails() throws Exception {
175178
project.setDefinition(new CpsFlowDefinition(script, true));
176179
WorkflowRun build = project.scheduleBuild2(0).get();
177180

178-
jenkins.assertLogContains("apple", build);
181+
assertEquals(countMatches(jenkins.getLog(build), "apple"), 3);
179182
jenkins.assertBuildStatus(Result.FAILURE, build);
180183
}
181184

182185
@Test
183186
public void verifyPipelineOnSlave() throws Exception {
184187
DumbSlave s = jenkins.createOnlineSlave();
185-
String script = "node('!built-in') { runMATLABCommand(command: 'pwd')}";
188+
String script = "node ('!built-in'){\n" +
189+
Utilities.getEnvironmentScriptedPipeline() + "\n" +
190+
" runMATLABCommand 'matlabroot'\n" +
191+
"}";
186192

187193
WorkflowJob project = jenkins.createProject(WorkflowJob.class);
188194
project.setDefinition(new CpsFlowDefinition(script, true));
189195
WorkflowRun build = project.scheduleBuild2(0).get();
190196

191197
jenkins.assertLogNotContains("Running on Jenkins", build);
198+
jenkins.assertBuildStatus(Result.SUCCESS, build);
199+
assertEquals(countMatches(jenkins.getLog(build), Utilities.getMatlabRoot()), 1);
192200
}
193201

194202
@Test

src/test/java/com/mathworks/ci/systemTests/RunMATLABTestsArtifactsIT.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
2121
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
2222
import org.junit.*;
23-
import org.junit.rules.Timeout;
2423
import org.jvnet.hudson.test.ExtractResourceSCM;
2524
import org.jvnet.hudson.test.JenkinsRule;
2625

@@ -38,9 +37,6 @@ public class RunMATLABTestsArtifactsIT {
3837
private UseMatlabVersionBuildWrapper buildWrapper;
3938
private RunMatlabTestsBuilder testBuilder;
4039

41-
@Rule
42-
public Timeout timeout = Timeout.seconds(0);
43-
4440
@Rule
4541
public JenkinsRule jenkins = new JenkinsRule();
4642

@@ -85,7 +81,7 @@ public void verifyJUnitFilePathInput() throws Exception{
8581
junitChkbx.setChecked(true);
8682
Thread.sleep(2000);
8783

88-
HtmlTextInput junitFilePathInput=(HtmlTextInput) page.getElementByName("_.junitReportFilePath");
84+
HtmlTextInput junitFilePathInput = (HtmlTextInput) page.getElementByName("_.junitReportFilePath");
8985
Assert.assertEquals(TestMessage.getValue("junit.file.path"),junitFilePathInput.getValueAttribute());
9086
}
9187

@@ -100,7 +96,7 @@ public void verifyTAPTestFilePathInput() throws Exception{
10096
tapChkbx.setChecked(true);
10197
Thread.sleep(2000);
10298

103-
HtmlTextInput tapFilePathInput=(HtmlTextInput) page.getElementByName("_.tapReportFilePath");
99+
HtmlTextInput tapFilePathInput = (HtmlTextInput) page.getElementByName("_.tapReportFilePath");
104100
Assert.assertEquals(TestMessage.getValue("taptestresult.file.path"),tapFilePathInput.getValueAttribute());
105101

106102
}
@@ -202,7 +198,7 @@ public void verifyCustomFilePathInputForArtifacts() throws Exception{
202198
}
203199

204200
@Test
205-
public void verifyCustomeFilenamesForArtifactsPipeline() throws Exception {
201+
public void verifyCustomFilenamesForArtifactsPipeline() throws Exception {
206202
String script = "pipeline {\n" +
207203
" agent any\n" +
208204
Utilities.getEnvironmentDSL() + "\n" +
@@ -212,6 +208,7 @@ public void verifyCustomeFilenamesForArtifactsPipeline() throws Exception {
212208
" {\n" +
213209
" unzip '" + Utilities.getRunMATLABTestsData().getPath() + "'" + "\n" +
214210
" runMATLABTests(sourceFolder:['src'], testResultsTAP: 'test-results/results.tap',\n" +
211+
" testResultsPDF: 'test-results/results.pdf'\n" +
215212
" testResultsJUnit: 'test-results/results.xml',\n" +
216213
" testResultsSimulinkTest: 'test-results/results.mldatx',\n" +
217214
" codeCoverageCobertura: 'code-coverage/coverage.xml',\n" +
@@ -222,6 +219,13 @@ public void verifyCustomeFilenamesForArtifactsPipeline() throws Exception {
222219
"}";
223220
WorkflowRun build = getPipelineBuild(script);
224221
jenkins.assertBuildStatus(Result.SUCCESS,build);
222+
jenkins.assertLogContains("test-results/results.mldatx", build);
223+
jenkins.assertLogContains("model-coverage/coverage.xml", build);
224+
225+
assertTrue(new FilePath(jenkins.getInstance().getWorkspaceFor(project), "test-results/results.pdf").exists());
226+
assertTrue(new FilePath(jenkins.getInstance().getWorkspaceFor(project), "test-results/results.tap").exists());
227+
assertTrue(new FilePath(jenkins.getInstance().getWorkspaceFor(project), "test-results/results.xml").exists());
228+
assertTrue(new FilePath(jenkins.getInstance().getWorkspaceFor(project), "code-coverage/coverage.xml").exists());
225229
}
226230

227231
@Test

0 commit comments

Comments
 (0)