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

Commit 2ce87ae

Browse files
committed
Add tests for Customize Test Run
1 parent b8921ad commit 2ce87ae

File tree

1 file changed

+340
-0
lines changed

1 file changed

+340
-0
lines changed
Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
package com.mathworks.ci.systemTests;
2+
3+
import com.mathworks.ci.MatlabBuildWrapperContent;
4+
import com.mathworks.ci.Message;
5+
import com.mathworks.ci.UseMatlabVersionBuildWrapper;
6+
import com.mathworks.ci.freestyle.RunMatlabTestsBuilder;
7+
import com.mathworks.ci.freestyle.options.SourceFolder;
8+
import com.mathworks.ci.freestyle.options.SourceFolderPaths;
9+
import hudson.matrix.*;
10+
import hudson.model.FreeStyleBuild;
11+
import hudson.model.FreeStyleProject;
12+
import hudson.model.Result;
13+
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
14+
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
15+
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
16+
import org.junit.*;
17+
import org.junit.rules.Timeout;
18+
import org.jvnet.hudson.test.ExtractResourceSCM;
19+
import org.jvnet.hudson.test.JenkinsRule;
20+
21+
import java.io.IOException;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
public class RunMATLABTestsCustomizeRunIT {
26+
private FreeStyleProject project;
27+
private UseMatlabVersionBuildWrapper buildWrapper;
28+
private RunMatlabTestsBuilder testBuilder;
29+
30+
@Rule
31+
public Timeout timeout = Timeout.seconds(0);
32+
33+
@Rule
34+
public JenkinsRule jenkins = new JenkinsRule();
35+
36+
@BeforeClass
37+
public static void checkMatlabRoot() {
38+
// Check if the MATLAB_ROOT environment variable is defined
39+
String matlabRoot = System.getenv("MATLAB_ROOT");
40+
Assume.assumeTrue("Not running tests as MATLAB_ROOT environment variable is not defined", matlabRoot != null && !matlabRoot.isEmpty());
41+
}
42+
43+
@Before
44+
public void testSetup() throws IOException {
45+
this.project = jenkins.createFreeStyleProject();
46+
this.testBuilder = new RunMatlabTestsBuilder();
47+
this.buildWrapper = new UseMatlabVersionBuildWrapper();
48+
testBuilder.setLoggingLevel("default");
49+
testBuilder.setOutputDetail("default");
50+
}
51+
52+
@After
53+
public void testTearDown() {
54+
this.project = null;
55+
this.testBuilder = null;
56+
}
57+
58+
@Test
59+
public void verifyLoggingLevelSetToNone() throws Exception {
60+
61+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
62+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
63+
project.getBuildWrappersList().add(this.buildWrapper);
64+
testBuilder.setLoggingLevel("None");
65+
project.getBuildersList().add(this.testBuilder);
66+
FreeStyleBuild build;
67+
build = project.scheduleBuild2(0).get();
68+
jenkins.assertLogContains("LoggingLevel', 0", build);
69+
70+
}
71+
72+
@Test
73+
public void verifyLoggingLevelSetToTerse() throws Exception {
74+
75+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
76+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
77+
project.getBuildWrappersList().add(this.buildWrapper);
78+
testBuilder.setLoggingLevel("Terse");
79+
project.getBuildersList().add(this.testBuilder);
80+
FreeStyleBuild build;
81+
build = project.scheduleBuild2(0).get();
82+
jenkins.assertLogContains("LoggingLevel', 1", build);
83+
84+
}
85+
86+
@Test
87+
public void verifyLoggingLevelSetToConcise() throws Exception {
88+
89+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
90+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
91+
project.getBuildWrappersList().add(this.buildWrapper);
92+
testBuilder.setLoggingLevel("Concise");
93+
project.getBuildersList().add(this.testBuilder);
94+
FreeStyleBuild build;
95+
build = project.scheduleBuild2(0).get();
96+
jenkins.assertLogContains("LoggingLevel', 2", build);
97+
98+
}
99+
100+
@Test
101+
public void verifyLoggingLevelSetToDetailed() throws Exception {
102+
103+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
104+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
105+
project.getBuildWrappersList().add(this.buildWrapper);
106+
testBuilder.setLoggingLevel("Detailed");
107+
project.getBuildersList().add(this.testBuilder);
108+
FreeStyleBuild build;
109+
build = project.scheduleBuild2(0).get();
110+
jenkins.assertLogContains("LoggingLevel', 3", build);
111+
112+
}
113+
114+
/*@Integ
115+
* Test To verify if Output Detail is set correctly
116+
*
117+
*/
118+
119+
@Test
120+
public void verifyOutputDetailSetToNone() throws Exception {
121+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
122+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
123+
project.getBuildWrappersList().add(this.buildWrapper);
124+
testBuilder.setLoggingLevel("None");
125+
126+
testBuilder.setOutputDetail("None");
127+
project.getBuildersList().add(this.testBuilder);
128+
FreeStyleBuild build;
129+
build = project.scheduleBuild2(0).get();
130+
jenkins.assertLogContains("'OutputDetail', 0", build);
131+
}
132+
133+
@Test
134+
public void verifyOutputDetailSetToTerse() throws Exception {
135+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
136+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
137+
project.getBuildWrappersList().add(this.buildWrapper);
138+
testBuilder.setLoggingLevel("None");
139+
140+
testBuilder.setOutputDetail("Terse");
141+
project.getBuildersList().add(this.testBuilder);
142+
FreeStyleBuild build;
143+
build = project.scheduleBuild2(0).get();
144+
jenkins.assertLogContains("'OutputDetail', 1", build);
145+
}
146+
147+
@Test
148+
public void verifyOutputDetailSetToConcise() throws Exception {
149+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
150+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
151+
project.getBuildWrappersList().add(this.buildWrapper);
152+
testBuilder.setLoggingLevel("None");
153+
154+
testBuilder.setOutputDetail("Concise");
155+
project.getBuildersList().add(this.testBuilder);
156+
FreeStyleBuild build;
157+
build = project.scheduleBuild2(0).get();
158+
jenkins.assertLogContains("'OutputDetail', 2", build);
159+
}
160+
161+
@Test
162+
public void verifyOutputDetailSetToDetailed() throws Exception {
163+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
164+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
165+
project.getBuildWrappersList().add(this.buildWrapper);
166+
testBuilder.setLoggingLevel("None");
167+
168+
testBuilder.setOutputDetail("Detailed");
169+
project.getBuildersList().add(this.testBuilder);
170+
FreeStyleBuild build;
171+
build = project.scheduleBuild2(0).get();
172+
jenkins.assertLogContains("'OutputDetail', 3", build);
173+
}
174+
175+
@Test
176+
public void verifyStrictSet() throws Exception {
177+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
178+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
179+
project.getBuildWrappersList().add(this.buildWrapper);
180+
testBuilder.setLoggingLevel("None");
181+
testBuilder.setStrict(true);
182+
project.getBuildersList().add(this.testBuilder);
183+
FreeStyleBuild build = project.scheduleBuild2(0).get();
184+
jenkins.assertLogContains("FailOnWarningsPlugin", build);
185+
186+
}
187+
188+
@Test
189+
public void verifyStrictNotSet() throws Exception {
190+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
191+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
192+
project.getBuildWrappersList().add(this.buildWrapper);
193+
testBuilder.setLoggingLevel("None");
194+
testBuilder.setStrict(false);
195+
project.getBuildersList().add(this.testBuilder);
196+
FreeStyleBuild build = project.scheduleBuild2(0).get();
197+
jenkins.assertLogNotContains("FailOnWarningsPlugin", build);
198+
199+
}
200+
201+
@Test
202+
public void verifyRunParallelSet() throws Exception {
203+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
204+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
205+
project.getBuildWrappersList().add(this.buildWrapper);
206+
testBuilder.setLoggingLevel("None");
207+
testBuilder.setUseParallel(true);
208+
project.getBuildersList().add(this.testBuilder);
209+
FreeStyleBuild build = project.scheduleBuild2(0).get();
210+
jenkins.assertLogContains("runInParallel", build);
211+
}
212+
213+
@Test
214+
public void verifyRunParallelNotSet() throws Exception {
215+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
216+
Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
217+
project.getBuildWrappersList().add(this.buildWrapper);
218+
testBuilder.setLoggingLevel("None");
219+
testBuilder.setUseParallel(false);
220+
project.getBuildersList().add(this.testBuilder);
221+
FreeStyleBuild build = project.scheduleBuild2(0).get();
222+
jenkins.assertLogNotContains("runInParallel", build);
223+
}
224+
225+
@Test
226+
public void verifyRunInParallel() throws Exception {
227+
String script = "pipeline {\n" +
228+
" agent any\n" +
229+
MatlabRootSetup.getEnvironmentDSL() + "\n" +
230+
" stages{\n" +
231+
" stage('Run MATLAB Command') {\n" +
232+
" steps\n" +
233+
" {\n" +
234+
" runMATLABTests(useParallel:true)\n" +
235+
" }\n" +
236+
" }\n" +
237+
" }\n" +
238+
"}";
239+
WorkflowRun build = getPipelineBuild(script);
240+
jenkins.assertLogContains("runInParallel", build);
241+
jenkins.assertBuildStatus(Result.SUCCESS,build);
242+
}
243+
244+
@Test
245+
public void verifyStrictSetPipeline() throws Exception {
246+
String script = "pipeline {\n" +
247+
" agent any\n" +
248+
MatlabRootSetup.getEnvironmentDSL() + "\n" +
249+
" stages{\n" +
250+
" stage('Run MATLAB Command') {\n" +
251+
" steps\n" +
252+
" {\n" +
253+
" runMATLABTests(strict:true)\n" +
254+
" }\n" +
255+
" }\n" +
256+
" }\n" +
257+
"}";
258+
WorkflowRun build = getPipelineBuild(script);
259+
jenkins.assertLogContains("FailOnWarningsPlugin", build);
260+
jenkins.assertBuildStatus(Result.SUCCESS,build);
261+
}
262+
263+
@Test
264+
public void verifyLoggingLevelSet() throws Exception {
265+
String script = "pipeline {\n" +
266+
" agent any\n" +
267+
MatlabRootSetup.getEnvironmentDSL() + "\n" +
268+
" stages{\n" +
269+
" stage('Run MATLAB Command') {\n" +
270+
" steps\n" +
271+
" {\n" +
272+
" runMATLABTests(sourceFolder:['src'], loggingLevel:'None')\n" +
273+
" }\n" +
274+
" }\n" +
275+
" }\n" +
276+
"}";
277+
WorkflowRun build = getPipelineBuild(script);
278+
jenkins.assertLogContains("'LoggingLevel', 0", build);
279+
jenkins.assertBuildStatus(Result.SUCCESS,build);
280+
}
281+
282+
@Test
283+
public void verifyOutoutDetailSet() throws Exception {
284+
String script = "pipeline {\n" +
285+
" agent any\n" +
286+
MatlabRootSetup.getEnvironmentDSL() + "\n" +
287+
" stages{\n" +
288+
" stage('Run MATLAB Command') {\n" +
289+
" steps\n" +
290+
" {\n" +
291+
" runMATLABTests(outputDetail:'None')\n" +
292+
" }\n" +
293+
" }\n" +
294+
" }\n" +
295+
"}";
296+
WorkflowRun build = getPipelineBuild(script);
297+
jenkins.assertLogContains("'OutputDetail', 0", build);
298+
jenkins.assertBuildStatus(Result.SUCCESS,build);
299+
}
300+
301+
/*
302+
* Test to verify if Matrix build passes (mock MATLAB).
303+
*/
304+
@Test
305+
public void verifyMatrixBuildPasses() throws Exception {
306+
MatrixProject matrixProject = jenkins.createProject(MatrixProject.class);
307+
Axis axes = new Axis("VERSION", TestData.getPropValues("matlab.version"), TestData.getPropValues("matlab.matrix.version"));
308+
matrixProject.setAxes(new AxisList(axes));
309+
String matlabRoot = MatlabRootSetup.getMatlabRoot();
310+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(TestData.getPropValues("matlab.custom.location"), matlabRoot.replace(TestData.getPropValues("matlab.version"), "$VERSION")));
311+
matrixProject.getBuildWrappersList().add(this.buildWrapper);
312+
313+
testBuilder.setOutputDetail("None");
314+
testBuilder.setLoggingLevel("None");
315+
testBuilder.setStrict(true);
316+
testBuilder.setUseParallel(true);
317+
318+
matrixProject.getBuildersList().add(testBuilder);
319+
MatrixBuild build = matrixProject.scheduleBuild2(0).get();
320+
List<MatrixRun> runs = build.getRuns();
321+
322+
for (MatrixRun run : runs) {
323+
jenkins.assertLogContains("LoggingLevel', 0", run);
324+
jenkins.assertLogContains("OutputDetail', 0", run);
325+
jenkins.assertLogContains("FailOnWarningsPlugin", run);
326+
jenkins.assertLogContains("runInParallel", run);
327+
}
328+
329+
330+
jenkins.assertLogContains(TestData.getPropValues("matlab.version")+" completed", build);
331+
jenkins.assertLogContains(TestData.getPropValues("matlab.matrix.version")+" completed", build);
332+
}
333+
334+
335+
private WorkflowRun getPipelineBuild(String script) throws Exception{
336+
WorkflowJob project = jenkins.createProject(WorkflowJob.class);
337+
project.setDefinition(new CpsFlowDefinition(script,true));
338+
return project.scheduleBuild2(0).get();
339+
}
340+
}

0 commit comments

Comments
 (0)