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

Commit 2c88f5a

Browse files
author
Nikhil Bhoski
committed
Updated tests.
1 parent befb084 commit 2c88f5a

File tree

3 files changed

+70
-84
lines changed

3 files changed

+70
-84
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ public class MatlabBuilderConstants {
2424
static final String STM_RESULTS = "'SimulinkTestResults'";
2525
static final String COBERTURA_CODE_COVERAGE = "'CoberturaCodeCoverage'";
2626
static final String COBERTURA_MODEL_COVERAGE = "'CoberturaModelCoverage'";
27-
static final String PDF_REPORT_PATH = "'PDFReportPath'";
28-
static final String TAP_RESULTS_PATH ="'TAPResultsPath'";
29-
static final String JUNIT_RESULTS_PATH = "'JUnitResultsPath'";
30-
static final String STM_RESULTS_PATH = "'SimulinkTestResultsPath'";
31-
static final String COBERTURA_CODE_COVERAGE_PATH = "'CoberturaCodeCoveragePath'";
32-
static final String COBERTURA_MODEL_COVERAGE_PATH = "'CoberturaModelCoveragePath'";
33-
27+
3428
// Matlab Runner files
3529
static final String BAT_RUNNER_SCRIPT = "run_matlab_command.bat";
3630
static final String SHELL_RUNNER_SCRIPT = "run_matlab_command.sh";

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

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import java.io.IOException;
1212
import java.util.ArrayList;
1313
import java.util.Arrays;
14+
import java.util.HashMap;
1415
import java.util.List;
16+
import java.util.Map;
1517
import javax.annotation.Nonnull;
18+
import org.apache.commons.collections.map.HashedMap;
1619
import org.apache.commons.io.FilenameUtils;
1720
import org.jenkinsci.Symbol;
1821
import org.kohsuke.stapler.DataBoundConstructor;
@@ -222,17 +225,21 @@ public String constructCommandForTest(String inputArguments) {
222225
// Concatenate the input arguments
223226
private String getInputArguments() {
224227

225-
final List<String> inputArgs = new ArrayList<String>();
228+
final List<String> inputArgsList = new ArrayList<String>();
229+
final Map<String,String> args = new HashMap<String,String>();
230+
226231
final List<Artifact> artifactList =
227232
new ArrayList<Artifact>(Arrays.asList(getPdfReportArtifact(), getTapArtifact(),
228233
getJunitArtifact(), getStmResultsArtifact(), getCoberturaArtifact(),
229234
getModelCoverageArtifact()));
230235

231236
for (Artifact artifact : artifactList) {
232-
artifact.addFilePathArgTo(inputArgs);
237+
artifact.addFilePathArgTo(args);
233238
}
234239

235-
return String.join(",", inputArgs);
240+
args.forEach((key, val) -> inputArgsList.add("'" + key + "'" + "," + "'" + val + "'"));
241+
242+
return String.join(",", inputArgsList);
236243
}
237244

238245

@@ -247,149 +254,141 @@ private String getInputArguments() {
247254
*
248255
*/
249256
public static class PdfArtifact extends AbstractArtifactImpl {
250-
257+
258+
static final String PDF_REPORT_PATH = "PDFReportPath";
259+
251260
@DataBoundConstructor
252261
public PdfArtifact(String pdfReportFilePath) {
253-
super(pdfReportFilePath);
262+
super(pdfReportFilePath);
254263
}
255-
264+
256265
@Override
257-
public void addFilePathArgTo(List<String> inputArgs) {
258-
inputArgs.add(MatlabBuilderConstants.PDF_REPORT_PATH + "," + "'"
259-
+ getFilePath() + "'");
266+
public void addFilePathArgTo(Map<String, String> inputArgs) {
267+
inputArgs.put(PDF_REPORT_PATH, getFilePath());
260268
}
261269
}
262270

263271
public static class TapArtifact extends AbstractArtifactImpl {
264272

273+
static final String TAP_RESULTS_PATH = "TAPResultsPath";
274+
265275
@DataBoundConstructor
266276
public TapArtifact(String tapReportFilePath) {
267277
super(tapReportFilePath);
268-
}
269-
278+
}
270279

271280
@Override
272-
public void addFilePathArgTo(List<String> inputArgs) {
273-
inputArgs.add(MatlabBuilderConstants.TAP_RESULTS_PATH + "," + "'"
274-
+ getFilePath() + "'");
281+
public void addFilePathArgTo(Map<String, String> inputArgs) {
282+
inputArgs.put(TAP_RESULTS_PATH, getFilePath());
275283
}
276-
277284
}
278285

279286
public static class JunitArtifact extends AbstractArtifactImpl {
280287

288+
static final String JUNIT_RESULTS_PATH = "JUnitResultsPath";
289+
281290
@DataBoundConstructor
282291
public JunitArtifact(String junitReportFilePath) {
283292
super(junitReportFilePath);
284-
}
293+
}
285294

286295
@Override
287-
public void addFilePathArgTo(List<String> inputArgs) {
288-
inputArgs.add(MatlabBuilderConstants.JUNIT_RESULTS_PATH + "," + "'"
289-
+ getFilePath() + "'");
296+
public void addFilePathArgTo(Map<String, String> inputArgs) {
297+
inputArgs.put(JUNIT_RESULTS_PATH, getFilePath());
290298
}
291-
292299
}
293300

294301
public static class CoberturaArtifact extends AbstractArtifactImpl {
295302

303+
static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath";
304+
296305
@DataBoundConstructor
297306
public CoberturaArtifact(String coberturaReportFilePath) {
298307
super(coberturaReportFilePath);
299-
}
300-
308+
}
301309

302310
@Override
303-
public void addFilePathArgTo(List<String> inputArgs) {
304-
inputArgs.add(MatlabBuilderConstants.COBERTURA_CODE_COVERAGE_PATH + "," + "'"
305-
+ getFilePath() + "'");
311+
public void addFilePathArgTo(Map<String, String> inputArgs) {
312+
inputArgs.put(COBERTURA_CODE_COVERAGE_PATH, getFilePath());
306313
}
307-
308314
}
309315

310316
public static class StmResultsArtifact extends AbstractArtifactImpl {
311317

318+
static final String STM_RESULTS_PATH = "SimulinkTestResultsPath";
319+
312320
@DataBoundConstructor
313321
public StmResultsArtifact(String stmResultsFilePath) {
314322
super(stmResultsFilePath);
315-
}
316-
317-
323+
}
318324

319325
@Override
320-
public void addFilePathArgTo(List<String> inputArgs) {
321-
inputArgs.add(MatlabBuilderConstants.STM_RESULTS_PATH + "," + "'"
322-
+ getFilePath() + "'");
326+
public void addFilePathArgTo(Map<String, String> inputArgs) {
327+
inputArgs.put(STM_RESULTS_PATH, getFilePath());
323328
}
324-
325329
}
326330

327331
public static class ModelCovArtifact extends AbstractArtifactImpl {
328332

333+
static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath";
334+
329335
@DataBoundConstructor
330336
public ModelCovArtifact(String modelCoverageFilePath) {
331337
super(modelCoverageFilePath);
332-
}
333-
338+
}
334339

335340
@Override
336-
public void addFilePathArgTo(List<String> inputArgs) {
337-
inputArgs.add(MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE_PATH + "," + "'"
338-
+ getFilePath() + "'");
341+
public void addFilePathArgTo(Map<String, String> inputArgs) {
342+
inputArgs.put(COBERTURA_MODEL_COVERAGE_PATH, getFilePath());
339343
}
340-
341344
}
342-
343-
public static class NullArtifact implements Artifact {
345+
346+
public static class NullArtifact implements Artifact {
344347

345348
@Override
346-
public void addFilePathArgTo(List<String> inputArgs) {
349+
public void addFilePathArgTo(Map<String, String> inputArgs) {
347350

348351
}
349352

350353
@Override
351354
public boolean getDefault() {
352-
353355
return false;
354356
}
355357

356358
@Override
357359
public String getFilePath() {
358-
359360
return null;
360361
}
361362

362363
}
363-
364-
//Andys code
364+
365365
public static abstract class AbstractArtifactImpl implements Artifact {
366366

367367
private String filePath;
368368

369-
protected AbstractArtifactImpl(String path){
369+
protected AbstractArtifactImpl(String path) {
370370
this.filePath = path;
371371
}
372372

373-
374-
public boolean getDefault(){
373+
public boolean getDefault() {
375374
return true;
376375
}
377376

378-
public void setFilePath(String path){
377+
public void setFilePath(String path) {
379378
this.filePath = path;
380379
}
381-
public String getFilePath(){
380+
381+
public String getFilePath() {
382382
return this.filePath;
383383
}
384384
}
385385

386-
386+
387387
public interface Artifact {
388-
public void addFilePathArgTo(List<String> inputArgs);
388+
public void addFilePathArgTo(Map<String, String> inputArgs);
389389

390390
public String getFilePath();
391391

392392
public boolean getDefault();
393-
//public List<String> getNameAndValue();
394393
}
395394
}

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,9 @@ public void verifyVerlessThan() throws Exception {
229229
public void verifySpecificTestArtifactsParameters() throws Exception {
230230
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
231231
project.getBuildWrappersList().add(this.buildWrapper);
232-
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact();
233-
tap.setTapReportFilePath("mytap/report.tap");
232+
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact("mytap/report.tap");
234233

235-
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact();
236-
stmResults.setStmResultsFilePath("mystm/results.mldatx");
234+
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact("mystm/results.mldatx");
237235

238236
testBuilder.setTapArtifact(tap);
239237
testBuilder.setStmResultsArtifact(stmResults);
@@ -287,23 +285,17 @@ public void verifyDefaultArtifactLocation() throws Exception {
287285
public void verifyAllTestArtifactsParameters() throws Exception {
288286
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
289287
project.getBuildWrappersList().add(this.buildWrapper);
290-
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact();
291-
tap.setTapReportFilePath("mytap/report.tap");
288+
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact("mytap/report.tap");
292289

293-
RunMatlabTestsBuilder.PdfArtifact pdf = new PdfArtifact();
294-
pdf.setPdfReportFilePath("mypdf/report.pdf");
290+
RunMatlabTestsBuilder.PdfArtifact pdf = new PdfArtifact("mypdf/report.pdf");
291+
292+
RunMatlabTestsBuilder.JunitArtifact junit = new JunitArtifact("myjunit/report.xml");
295293

296-
RunMatlabTestsBuilder.JunitArtifact junit = new JunitArtifact();
297-
junit.setJunitReportFilePath("myjunit/report.xml");
294+
RunMatlabTestsBuilder.CoberturaArtifact cobertura = new CoberturaArtifact("mycobertura/report.xml");
298295

299-
RunMatlabTestsBuilder.CoberturaArtifact cobertura = new CoberturaArtifact();
300-
cobertura.setCoberturaReportFilePath("mycobertura/report.xml");
296+
RunMatlabTestsBuilder.ModelCovArtifact modelCov = new ModelCovArtifact("mymodel/report.xml");
301297

302-
RunMatlabTestsBuilder.ModelCovArtifact modelCov = new ModelCovArtifact();
303-
modelCov.setModelCoverageFilePath("mymodel/report.xml");
304-
305-
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact();
306-
stmResults.setStmResultsFilePath("mystm/results.mldatx");
298+
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact("mystm/results.mldatx");
307299

308300
testBuilder.setTapArtifact(tap);
309301
testBuilder.setPdfReportArtifact(pdf);
@@ -316,12 +308,13 @@ public void verifyAllTestArtifactsParameters() throws Exception {
316308
project.getBuildersList().add(this.testBuilder);
317309
FreeStyleBuild build = project.scheduleBuild2(0).get();
318310
jenkins.assertLogContains("run_matlab_command", build);
319-
jenkins.assertLogContains("\'PDFReportPath\',\'mypdf/report.pdf\',"
320-
+ "\'TAPResultsPath\',\'mytap/report.tap\',"
321-
+ "\'JUnitResultsPath\',\'myjunit/report.xml\',"
322-
+ "\'SimulinkTestResultsPath\',\'mystm/results.mldatx\',"
323-
+ "\'CoberturaCodeCoveragePath\',\'mycobertura/report.xml\',"
324-
+ "\'CoberturaModelCoveragePath\',\'mymodel/report.xml\'", build);
311+
jenkins.assertLogContains("\'PDFReportPath\',\'mypdf/report.pdf\'",build);
312+
jenkins.assertLogContains("\'TAPResultsPath\',\'mytap/report.tap\'",build);
313+
jenkins.assertLogContains("\'JUnitResultsPath\',\'myjunit/report.xml\'",build);
314+
jenkins.assertLogContains("\'SimulinkTestResultsPath\',\'mystm/results.mldatx\'",build);
315+
jenkins.assertLogContains("\'CoberturaCodeCoveragePath\',\'mycobertura/report.xml\'",build);
316+
jenkins.assertLogContains("\'CoberturaModelCoveragePath\',\'mymodel/report.xml\'",build);
317+
325318
}
326319

327320
/*

0 commit comments

Comments
 (0)