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

Commit 16bcaff

Browse files
author
Nikhil Bhoski
committed
Added Unit tests
1 parent b0140ea commit 16bcaff

File tree

5 files changed

+240
-10
lines changed

5 files changed

+240
-10
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ private String getInputArguments() {
418418
}
419419

420420
// Add Logging level
421-
System.out.println("Logging Level is " + getLoggingLevel());
422421
if (!getLoggingLevel().equalsIgnoreCase("default")) {
423422
inputArgsList.add("'" + MatlabBuilderConstants.LOGGING_LEVEL + "'" + "," + "'"
424423
+ getLoggingLevel() + "'");

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class RunMatlabTestsStep extends Step {
3434
private String modelCoverageCobertura;
3535
private String selectByTag;
3636
private String loggingLevel;
37-
private String outputLevel;
37+
private String outputDetail;
3838
private boolean useParallel;
3939
private boolean strict;
4040
private List<String> sourceFolder = new ArrayList<>();
@@ -136,13 +136,13 @@ public void setLoggingLevel(String loggingLevel) {
136136
this.loggingLevel = loggingLevel;
137137
}
138138

139-
public String getOutputLevel() {
140-
return outputLevel;
139+
public String getOutputDetail() {
140+
return outputDetail;
141141
}
142142

143143
@DataBoundSetter
144-
public void setOutputLevel(String outputLevel) {
145-
this.outputLevel = outputLevel;
144+
public void setOutputDetail(String outputDetail) {
145+
this.outputDetail = outputDetail;
146146
}
147147

148148
public boolean getUseParallel() {
@@ -219,7 +219,7 @@ private Map<String, String> getGenscriptArgs() {
219219
args.put(MatlabBuilderConstants.USE_PARALLEL, String.valueOf(getUseParallel()));
220220
args.put(MatlabBuilderConstants.STRICT, String.valueOf(getStrict()));
221221
args.put(MatlabBuilderConstants.LOGGING_LEVEL, getLoggingLevel());
222-
args.put(MatlabBuilderConstants.OUTPUT_DETAIL, getOutputLevel());
222+
args.put(MatlabBuilderConstants.OUTPUT_DETAIL, getOutputDetail());
223223
addFolderArgs("SourceFolder",getSourceFolder(),args);
224224
addFolderArgs("SelectByFolder",getSelectByFolder(),args);
225225
return args;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<f:textbox/>
3939
</f:entry>
4040

41-
<f:entry field="outputDetail" title="outputLevel: ">
41+
<f:entry field="outputDetail" title="outputDetail: ">
4242
<f:textbox/>
4343
</f:entry>
4444

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

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.net.URISyntaxException;
1212
import java.net.URL;
1313
import java.util.*;
14-
14+
import java.util.concurrent.ExecutionException;
1515
import com.gargoylesoftware.htmlunit.html.HtmlInput;
1616
import org.junit.After;
1717
import org.junit.Assert;
@@ -524,4 +524,135 @@ public void verifySystemTempDirDeleted() throws Exception {
524524
FreeStyleBuild build = project.scheduleBuild2(0).get();
525525
jenkins.assertLogContains("rmdir(tmpDir,'s')", build);
526526
}
527+
528+
/*
529+
* Test To verify if Logging level is set correctly
530+
*
531+
*/
532+
533+
@Test
534+
public void verifyLoggingLevelSet() throws Exception {
535+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
536+
Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
537+
project.getBuildWrappersList().add(this.buildWrapper);
538+
Map<String, String> logginggLevel = new HashMap<String, String>();
539+
logginggLevel.put("None", "'LoggingLevel', 0");
540+
logginggLevel.put("Terse", "'LoggingLevel', 1");
541+
logginggLevel.put("Concise", "'LoggingLevel', 2");
542+
logginggLevel.put("Detailed", "'LoggingLevel', 3");
543+
logginggLevel.put("Verbose", "'LoggingLevel', 4");
544+
logginggLevel.forEach((key, val) -> {
545+
testBuilder.setLoggingLevel(key);
546+
project.getBuildersList().add(this.testBuilder);
547+
FreeStyleBuild build;
548+
try {
549+
build = project.scheduleBuild2(0).get();
550+
jenkins.assertLogContains(val, build);
551+
} catch (InterruptedException | ExecutionException | IOException e) {
552+
System.out.println("Build Failed, refer logs for details");
553+
e.printStackTrace();
554+
}
555+
});
556+
}
557+
558+
/*
559+
* Test To verify if Output Detail is set correctly
560+
*
561+
*/
562+
563+
@Test
564+
public void verifyOutputDetailSet() throws Exception {
565+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
566+
Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
567+
project.getBuildWrappersList().add(this.buildWrapper);
568+
testBuilder.setLoggingLevel("None");
569+
Map<String, String> outputDetail = new HashMap<String, String>();
570+
outputDetail.put("none", "'OutputDetail', 0");
571+
outputDetail.put("terse", "'OutputDetail', 1");
572+
outputDetail.put("concise", "'OutputDetail', 2");
573+
outputDetail.put("detailed", "'OutputDetail', 3");
574+
outputDetail.put("verbose", "'OutputDetail', 4");
575+
outputDetail.forEach((key, val) -> {
576+
testBuilder.setOutputDetail(key);
577+
project.getBuildersList().add(this.testBuilder);
578+
FreeStyleBuild build;
579+
try {
580+
build = project.scheduleBuild2(0).get();
581+
jenkins.assertLogContains(val, build);
582+
} catch (InterruptedException | ExecutionException | IOException e) {
583+
System.out.println("Build Failed, refer logs for details");
584+
e.printStackTrace();
585+
}
586+
});
587+
}
588+
589+
/*
590+
* Test To verify when Strict option set
591+
*
592+
*/
593+
594+
@Test
595+
public void verifyStrictSet() throws Exception {
596+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
597+
Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
598+
project.getBuildWrappersList().add(this.buildWrapper);
599+
testBuilder.setLoggingLevel("None");
600+
testBuilder.setStrict(true);
601+
project.getBuildersList().add(this.testBuilder);
602+
FreeStyleBuild build = project.scheduleBuild2(0).get();
603+
jenkins.assertLogContains("FailOnWarningsPlugin", build);
604+
605+
}
606+
607+
/*
608+
* Test To verify when Strict option not set
609+
*
610+
*/
611+
612+
@Test
613+
public void verifyStrictNotSet() throws Exception {
614+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
615+
Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
616+
project.getBuildWrappersList().add(this.buildWrapper);
617+
testBuilder.setLoggingLevel("None");
618+
testBuilder.setStrict(false);
619+
project.getBuildersList().add(this.testBuilder);
620+
FreeStyleBuild build = project.scheduleBuild2(0).get();
621+
jenkins.assertLogNotContains("FailOnWarningsPlugin", build);
622+
623+
}
624+
625+
/*
626+
* Test To verify when Run in Parallel option is set
627+
*
628+
*/
629+
630+
@Test
631+
public void verifyRunParallelSet() throws Exception {
632+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
633+
Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
634+
project.getBuildWrappersList().add(this.buildWrapper);
635+
testBuilder.setLoggingLevel("None");
636+
testBuilder.setUseParallel(true);
637+
project.getBuildersList().add(this.testBuilder);
638+
FreeStyleBuild build = project.scheduleBuild2(0).get();
639+
jenkins.assertLogContains("runInParallel", build);
640+
}
641+
642+
/*
643+
* Test To verify when Run in Parallel option is set
644+
*
645+
*/
646+
647+
@Test
648+
public void verifyRunParallelNotSet() throws Exception {
649+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(
650+
Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
651+
project.getBuildWrappersList().add(this.buildWrapper);
652+
testBuilder.setLoggingLevel("None");
653+
testBuilder.setUseParallel(false);
654+
project.getBuildersList().add(this.testBuilder);
655+
FreeStyleBuild build = project.scheduleBuild2(0).get();
656+
jenkins.assertLogNotContains("runInParallel", build);
657+
}
527658
}

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

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
import java.io.IOException;
9-
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.concurrent.ExecutionException;
1012
import hudson.model.Result;
1113
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
1214
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
@@ -198,4 +200,102 @@ public void verifyTestSelectByTag () throws Exception {
198200
j.assertLogContains("myTestTag", build);
199201
j.assertBuildStatusSuccess(build);
200202
}
203+
204+
/*
205+
* Verify outPutDetail set
206+
*/
207+
@Test
208+
public void verifyOutputDetailSet() {
209+
Map<String, String> outputDetail = new HashMap<String, String>();
210+
outputDetail.put("none", "'OutputDetail', 0");
211+
outputDetail.put("terse", "'OutputDetail', 1");
212+
outputDetail.put("concise", "'OutputDetail', 2");
213+
outputDetail.put("detailed", "'OutputDetail', 3");
214+
outputDetail.put("verbose", "'OutputDetail', 4");
215+
outputDetail.forEach((key, val) -> {
216+
project.setDefinition(new CpsFlowDefinition(
217+
"node {runMATLABTests(outputDetail: '" + key + "')}", true));
218+
WorkflowRun build;
219+
220+
try {
221+
build = project.scheduleBuild2(0).get();
222+
j.assertLogContains(val, build);
223+
} catch (InterruptedException | ExecutionException | IOException e) {
224+
System.out.println("Build Failed, refer logs for details");
225+
e.printStackTrace();
226+
}
227+
});
228+
}
229+
230+
/*
231+
* Verify loggingLevel set
232+
*/
233+
234+
@Test
235+
public void verifyLoggingLevelSet() {
236+
Map<String, String> outputDetail = new HashMap<String, String>();
237+
outputDetail.put("none", "'LoggingLevel', 0");
238+
outputDetail.put("terse", "'LoggingLevel', 1");
239+
outputDetail.put("concise", "'LoggingLevel', 2");
240+
outputDetail.put("detailed", "'LoggingLevel', 3");
241+
outputDetail.put("verbose", "'LoggingLevel', 4");
242+
outputDetail.forEach((key, val) -> {
243+
project.setDefinition(new CpsFlowDefinition(
244+
"node {runMATLABTests(loggingLevel: '" + key + "', outputDetail: 'None')}",
245+
true));
246+
WorkflowRun build;
247+
248+
try {
249+
build = project.scheduleBuild2(0).get();
250+
j.assertLogContains(val, build);
251+
} catch (InterruptedException | ExecutionException | IOException e) {
252+
System.out.println("Build Failed, refer logs for details");
253+
e.printStackTrace();
254+
}
255+
});
256+
}
257+
258+
/*
259+
* Verify when useParallel Set
260+
*/
261+
@Test
262+
public void verifyRunParallelSet () throws Exception {
263+
project.setDefinition(new CpsFlowDefinition(
264+
"node {runMATLABTests(useParallel: true)}", true));
265+
WorkflowRun build = project.scheduleBuild2(0).get();
266+
j.assertLogContains("runInParallel", build);
267+
}
268+
269+
/*
270+
* Verify when useParallel Not Set
271+
*/
272+
@Test
273+
public void verifyRunParallelNotSet () throws Exception {
274+
project.setDefinition(new CpsFlowDefinition(
275+
"node {runMATLABTests(useParallel: false)}", true));
276+
WorkflowRun build = project.scheduleBuild2(0).get();
277+
j.assertLogNotContains("runInParallel", build);
278+
}
279+
280+
/*
281+
* Verify when strict Set
282+
*/
283+
@Test
284+
public void verifyStrictSet () throws Exception {
285+
project.setDefinition(new CpsFlowDefinition(
286+
"node {runMATLABTests(strict: true)}", true));
287+
WorkflowRun build = project.scheduleBuild2(0).get();
288+
j.assertLogContains("FailOnWarningsPlugin", build);
289+
}
290+
291+
/*
292+
* Verify when strict is not Set
293+
*/
294+
@Test
295+
public void verifyStrictNotSet () throws Exception {
296+
project.setDefinition(new CpsFlowDefinition(
297+
"node {runMATLABTests(strict: false)}", true));
298+
WorkflowRun build = project.scheduleBuild2(0).get();
299+
j.assertLogNotContains("FailOnWarningsPlugin", build);
300+
}
201301
}

0 commit comments

Comments
 (0)