From b7b737a78677cd3baaa125a0c9624a1dc47aba0f Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 1 Aug 2024 10:57:43 +0530 Subject: [PATCH 01/33] commit to draft test procedure --- pom.xml | 28 +- .../com/mathworks/ci/BuildArtifactAction.java | 2 + .../mathworks/ci/MatlabBuilderConstants.java | 6 + src/main/java/com/mathworks/ci/TestCase.java | 109 +++++++ .../com/mathworks/ci/TestDiagnostics.java | 40 +++ src/main/java/com/mathworks/ci/TestFile.java | 96 ++++++ .../mathworks/ci/TestResultsViewAction.java | 288 ++++++++++++++++++ .../ci/actions/RunMatlabBuildAction.java | 18 ++ .../ci/actions/RunMatlabCommandAction.java | 50 ++- .../ci/actions/RunMatlabTestsAction.java | 24 ++ .../ci/TestResultsViewAction/index.jelly | 238 +++++++++++++++ .../ci/TestResultsViewAction/summary.jelly | 28 ++ .../RunMatlabTestsBuilder/config.jelly | 8 + .../RunMatlabTestsBuilder/help-json.html | 5 + 14 files changed, 934 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/mathworks/ci/TestCase.java create mode 100644 src/main/java/com/mathworks/ci/TestDiagnostics.java create mode 100644 src/main/java/com/mathworks/ci/TestFile.java create mode 100644 src/main/java/com/mathworks/ci/TestResultsViewAction.java create mode 100644 src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly create mode 100644 src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly create mode 100644 src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/help-json.html diff --git a/pom.xml b/pom.xml index 40f11548..69e28577 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 3.57 + 4.47 matlab @@ -18,8 +18,13 @@ - 2.164.3 - 8 + + + 2.350 + + + 8 + MATLAB Plugin Jenkins plugin for MATLAB @@ -52,14 +57,27 @@ io.jenkins.tools.bom - bom-2.164.x - 4 + + + bom-2.346.x + + + + + + 1763.v092b_8980a_f5e + import pom + + com.googlecode.json-simple diff --git a/src/main/java/com/mathworks/ci/BuildArtifactAction.java b/src/main/java/com/mathworks/ci/BuildArtifactAction.java index ad359725..d176a264 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactAction.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactAction.java @@ -60,6 +60,8 @@ public String getUrlName() { return "buildresults"; } + // add link to test results table + public List getBuildArtifact() throws ParseException, InterruptedException, IOException { List artifactData = new ArrayList(); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + BUILD_ARTIFACT_FILE)); diff --git a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java index 6a84b96f..dffc54e6 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java +++ b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java @@ -43,4 +43,10 @@ public class MatlabBuilderConstants { "disp(testScript.Contents);", "fprintf('___________________________________\\n\\n');", "run(testScript);"); + + //Default and add-on plugins + public static final String DEFAULT_PLUGIN = "+ciplugins/+jenkins/getDefaultPlugins.m"; + public static final String TEST_RESULTS_VIEW_PLUGIN = "+ciplugins/+jenkins/TestResultsViewPlugin.m"; + // rename artifact to matlabTestResults.json + public static final String TEST_RESULTS_VIEW_ARTIFACT = "testArtifact"; } diff --git a/src/main/java/com/mathworks/ci/TestCase.java b/src/main/java/com/mathworks/ci/TestCase.java new file mode 100644 index 00000000..35610bd4 --- /dev/null +++ b/src/main/java/com/mathworks/ci/TestCase.java @@ -0,0 +1,109 @@ +package com.mathworks.ci; + +import java.util.List; + +import org.apache.commons.lang.RandomStringUtils; + +import java.util.ArrayList; + +public class TestCase { + private String name; + private List diagnostics; + private boolean passed; + private boolean failed; + private boolean incomplete; + private String status; + private Double duration; + + private String id; + + public TestCase() { + name = ""; + diagnostics = new ArrayList(); + passed = false; + failed = false; + incomplete = false; + status = "NotRun"; + duration = 0.0; + + id = RandomStringUtils.randomAlphanumeric(8); + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public List getDiagnostics() { + return this.diagnostics; + } + + public void setDiagnostics(List diagnostics) { + this.diagnostics = diagnostics; + } + + public void updateDiagnostics(TestDiagnostics diagnostic) { + this.diagnostics.add(diagnostic); + } + + public boolean getPassed() { + return this.passed; + } + + public void setPassed(boolean passed) { + this.passed = passed; + } + + public boolean getFailed() { + return this.failed; + } + + public void setFailed(boolean failed) { + this.failed = failed; + } + + public boolean getIncomplete() { + return this.incomplete; + } + + public void setIncomplete(boolean incomplete) { + this.incomplete = incomplete; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(String status) { + this.status = status; + } + + public void updateStatus() { + if (failed){ + status = "Failed"; + } + else if (incomplete) { + status = "Incomplete"; + } + else if(passed) { + status = "Passed"; + } + } + + public Double getDuration() { + return this.duration; + } + + public void setDuration(Double duration) { + this.duration = duration; + } + + public String getId() { + // String id = this.filePath + "-" + this.name; + // return id.replaceAll(File.separator, "-"); + return id; + } +} \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/TestDiagnostics.java b/src/main/java/com/mathworks/ci/TestDiagnostics.java new file mode 100644 index 00000000..ce7717df --- /dev/null +++ b/src/main/java/com/mathworks/ci/TestDiagnostics.java @@ -0,0 +1,40 @@ +package com.mathworks.ci; + +import org.apache.commons.lang.RandomStringUtils; + +public class TestDiagnostics { + private String event; + private String report; + + private String id; + + public TestDiagnostics() { + event = ""; + report = ""; + + id = RandomStringUtils.randomAlphanumeric(8); + } + + public String getEvent() { + return this.event; + } + + public void setEvent(String event) { + this.event = event; + } + + public String getReport() { + return this.report; + } + + public void setReport(String report) { + this.report = report; + } + + public String getId() { + // String id = this.filePath + "-" + this.name; + // return id.replaceAll(File.separator, "-"); + return id; + } + +} diff --git a/src/main/java/com/mathworks/ci/TestFile.java b/src/main/java/com/mathworks/ci/TestFile.java new file mode 100644 index 00000000..8a0b6808 --- /dev/null +++ b/src/main/java/com/mathworks/ci/TestFile.java @@ -0,0 +1,96 @@ +package com.mathworks.ci; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.RandomStringUtils; + +public class TestFile { + private String filePath; + private String name; + private Double duration; + private String status; + private List testCases; + + private String id; + + public TestFile() { + filePath = ""; + name = ""; + duration = 0.0; + status = "NotRun"; + testCases = new ArrayList(); + + id = RandomStringUtils.randomAlphanumeric(8); + } + + public String getFilePath() { + return this.filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getDuration() { + return this.duration; + } + + public void setDuration(Double duration) { + this.duration = duration; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(String status) { + this.status = status; + } + + public List getTestCases() { + return this.testCases; + } + + public void setTestCases(List testCases) { + this.testCases = testCases; + } + + public String getId() { + // String id = this.filePath + "-" + this.name; + // return id.replaceAll(File.separator, "-"); + return id; + } + + public void incrementDuration(Double testCaseDuration) { + this.duration += testCaseDuration; + } + + public void updateStatus(TestCase testCase) { + if (!status.equals("Failed")){ + if (testCase.getFailed()){ + status = "Failed"; + } + else if (!status.equals("Incomplete")){ + if (testCase.getIncomplete()){ + status = "Incomplete"; + } + else if (testCase.getPassed()){ + status = "Passed"; + } + } + } + } + + public void addTestCase(TestCase testCase) { + this.testCases.add(testCase); + } +} diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java new file mode 100644 index 00000000..2a78c18a --- /dev/null +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -0,0 +1,288 @@ +package com.mathworks.ci; + +import hudson.FilePath; +import jenkins.model.RunAction2; +import hudson.model.Run; +import hudson.model.TaskListener; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.annotation.CheckForNull; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +public class TestResultsViewAction implements RunAction2 { + private Run build; + private FilePath workspace; + private String id; + private int totalCount; + private int passedCount; + private int failedCount; + private int incompleteCount; + private int notRunCount; + public TaskListener listener; + // private List artidactData; + + public TestResultsViewAction(Run build, String id, FilePath workspace, TaskListener listener) throws InterruptedException, IOException { + this.build = build; + this.id = id; + + // check again at last + totalCount = 0; + passedCount = 0; + failedCount = 0; + incompleteCount = 0; + notRunCount = 0; + this.workspace = workspace; + this.listener = listener; + + try{ + getTestResults(); + // listener.getLogger().println("Hello after test results"); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + throw e; + } catch (ParseException e) { + e.printStackTrace(); + } + } + + public List getTestResults() throws ParseException, InterruptedException, IOException { + List testResults = new ArrayList(); + FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.id + ".json")); + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { + Object obj = new JSONParser().parse(reader); + JSONObject jsonTestArtifact = (JSONObject) obj; + JSONArray jsonTestResult = (JSONArray) jsonTestArtifact.get("TestResult"); + JSONArray jsonTestSuite = (JSONArray) jsonTestArtifact.get("TestSuite"); + + Iterator testResultIterator = jsonTestResult.iterator(); + Iterator testSuiteIterator = jsonTestSuite.iterator(); + Map map = new HashMap(); + + totalCount = jsonTestResult.size(); + passedCount = 0; + failedCount = 0; + incompleteCount = 0; + notRunCount = totalCount; + + // add single element test case + + while(testResultIterator.hasNext()) { + JSONObject test = testResultIterator.next(); + JSONObject suite = testSuiteIterator.next(); + + // Not OS dependent + String[] testNameSplit = test.get("Name").toString().split("/"); + String testFileName = testNameSplit[0]; + String testCaseName = testNameSplit[1]; + + // String testCaseName = test.get("Name").toString().split("/")[1]; + // String testFileName; + // if (suite.get("TestClass") instanceof String) { + // testFileName = (String) suite.get("TestClass"); + // } + // else{ + // testFileName = testCaseName; + // } + String baseFolder = (String) suite.get("BaseFolder"); + + // handle same test file name + TestFile testFile = map.get(baseFolder + File.separator + testFileName); + if(testFile == null) { + testFile = new TestFile(); + testFile.setName(testFileName); + + map.put(baseFolder + File.separator + testFileName, testFile); + testResults.add(testFile); + } + + // Calculate the relative path + Path path1 = Paths.get(baseFolder); + Path path2 = Paths.get(this.workspace.toURI()); + Path filePath = path2.relativize(path1); + testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); + + // re-evaluate casting if necessary or not + TestCase testCase = new TestCase(); + testCase.setName(testCaseName); + testCase.setPassed((boolean) test.get("Passed")); + testCase.setFailed((boolean) test.get("Failed")); + testCase.setIncomplete((boolean) test.get("Incomplete")); + if (test.get("Duration") instanceof Long) { + testCase.setDuration(((Long) test.get("Duration")).doubleValue()); + } else if (test.get("Duration") instanceof Double) { + testCase.setDuration(((Double) test.get("Duration"))); + } + testCase.updateStatus(); + + // should we instead check for non-empty? + Object diagnostics = ((JSONObject)test.get("Details")).get("DiagnosticRecord"); + if(diagnostics instanceof JSONObject) { + TestDiagnostics testDiagnostics = new TestDiagnostics(); + testDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); + testDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); + testCase.updateDiagnostics(testDiagnostics); + } + else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0) { + // diagnostics = (JSONArray)diagnostics; + Iterator diagnosticsIterator = ((JSONArray)diagnostics).iterator(); + while(diagnosticsIterator.hasNext()) { + JSONObject diagnosticItem = diagnosticsIterator.next(); + + TestDiagnostics testDiagnostics = new TestDiagnostics(); + testDiagnostics.setEvent(diagnosticItem.get("Event").toString()); + testDiagnostics.setReport(diagnosticItem.get("Report").toString()); + testCase.updateDiagnostics(testDiagnostics); + } + } + + testFile.incrementDuration(testCase.getDuration()); + testFile.updateStatus(testCase); + testFile.addTestCase(testCase); + updateCount(testCase); + } + } + catch (Exception e) { + // TODO: handle exception + this.listener.getLogger().println(e.getMessage()); + } + + // for(TestFile testFile : testResults) { + // for(TestCase testCase : testFile.getTestCases()) { + // this.listener.getLogger().println(testCase.getName()); + // } + // } + + return testResults; + } + + private void updateCount(TestCase testCase) { + if (!testCase.getStatus().equals("NotRun")) { + if (testCase.getPassed()) { + passedCount += 1; + } + else if (testCase.getFailed()) { + failedCount += 1; + } + else if (testCase.getIncomplete()) { + incompleteCount += 1; + } + notRunCount -= 1; + } + } + + // private TestFile checkIfFileExists(List testResults, String fileName){ + // for(int i = 0; i < testResults.size(); i++){ + // if(testResults.get(i).getName().equals(fileName)){ + // return testResults.get(i); + // } + // } + + // return null; + // } + + private transient Run run; + + public Run getRun() { + return run; + } + + @Override + public void onAttached(Run run) { + this.run = run; + } + + @Override + public void onLoad(Run run) { + this.run = run; + } + + @CheckForNull + @Override + public String getDisplayName() { + return "MATLAB Test Results"; + } + + @CheckForNull + @Override + public String getUrlName() { + return "matlabTestResults" + this.id; + } + + @CheckForNull + @Override + public String getIconFileName() { + return "document.png"; + } + + public Run getOwner() { + return this.build; + } + + /** + * @param owner the owner to set + */ + public void setOwner(Run owner) { + this.build = owner; + } + + public FilePath getWorkspace() { + return this.workspace; + } + + public String getId() { + return id; + } + + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + public int getTotalCount() { + return this.totalCount; + } + + public void setPassedCount(int passedCount) { + this.passedCount = passedCount; + } + + public int getPassedCount() { + return this.passedCount; + } + + public void setFailedCount(int failedCount) { + this.failedCount = failedCount; + } + + public int getFailedCount() { + return this.failedCount; + } + + public void setIncompleteCount(int incompleteCount) { + this.incompleteCount = incompleteCount; + } + + public int getIncompleteCount() { + return this.incompleteCount; + } + + public void setNotRunCount(int notRunCount) { + this.notRunCount = notRunCount; + } + + public int getNotRunCount() { + return this.notRunCount; + } +} \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java index 9cfa0a41..2dc25451 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java @@ -14,7 +14,9 @@ import com.mathworks.ci.BuildArtifactAction; import com.mathworks.ci.BuildConsoleAnnotator; +import com.mathworks.ci.MatlabBuilderConstants; import com.mathworks.ci.MatlabExecutionException; +import com.mathworks.ci.TestResultsViewAction; import com.mathworks.ci.parameters.BuildActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; @@ -97,5 +99,21 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep jsonFile.delete(); build.addAction(new BuildArtifactAction(build, this.params.getWorkspace())); } + + // Handle test result + jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json"); + if (jsonFile.exists()) { + FilePath rootLocation = new FilePath( + new File( + build.getRootDir() + .getAbsolutePath() + + File.separator + + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + // + this.id + + ".json")); + jsonFile.copyTo(rootLocation); + jsonFile.delete(); + // build.addAction(new TestResultsViewAction(build, this.params.getWorkspace())); + } } } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java index 82ec5bf2..37b81075 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java @@ -7,17 +7,29 @@ import java.io.IOException; +import org.apache.commons.lang.RandomStringUtils; + import com.mathworks.ci.MatlabExecutionException; +import com.mathworks.ci.TestFile; +import com.mathworks.ci.TestResultsViewAction; import com.mathworks.ci.parameters.RunActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; +import java.io.File; +import hudson.FilePath; +import hudson.model.Run; + +import com.mathworks.ci.MatlabBuilderConstants; + public class RunMatlabCommandAction { private RunActionParameters params; private MatlabCommandRunner runner; + private String id; public RunMatlabCommandAction(MatlabCommandRunner runner, RunActionParameters params) { this.runner = runner; this.params = params; + id = RandomStringUtils.randomAlphanumeric(8); } public RunMatlabCommandAction(RunActionParameters params) throws IOException, InterruptedException { @@ -31,6 +43,42 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep this.params.getTaskListener().getLogger() .println(e.getMessage()); throw(e); - } + } finally{ + + Run build = this.params.getBuild(); + FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json"); + + if (jsonFile.exists()) { + FilePath rootLocation = new FilePath( + new File( + build.getRootDir() + .getAbsolutePath() + + File.separator + + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.id + ".json")); + jsonFile.copyTo(rootLocation); + jsonFile.delete(); + TestResultsViewAction testResultsViewAction = new TestResultsViewAction(build, this.id, this.params.getWorkspace(), this.params.getTaskListener()); + build.addAction(testResultsViewAction); + // try{ + + // for(TestFile testFile : testResultsViewAction.getTestResults()){ + // this.params.getTaskListener().getLogger().println(testFile.getName()); + // } + // } + // catch(Exception e){ + // String whatYouWant = testResultsViewAction.getWhatYouWant(); + // this.params.getTaskListener().getLogger().println(whatYouWant); + // String[] whatYouWantSplit = whatYouWant.split("/"); + // this.params.getTaskListener().getLogger().println(whatYouWantSplit[0]); + // this.params.getTaskListener().getLogger().println(whatYouWantSplit[1]); + // this.params.getTaskListener().getLogger().println(e.getMessage()); + // // throw(e); + // } + } + } + } + + public String getId() { + return id; } } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java index d9228d66..ccc229b3 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java @@ -5,15 +5,18 @@ * */ +import java.io.File; import java.io.IOException; import java.util.List; import java.util.ArrayList; import hudson.FilePath; +import hudson.model.Run; import com.mathworks.ci.Utilities; import com.mathworks.ci.MatlabBuilderConstants; import com.mathworks.ci.MatlabExecutionException; +import com.mathworks.ci.TestResultsViewAction; import com.mathworks.ci.parameters.TestActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; @@ -41,6 +44,10 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep String command = MatlabBuilderConstants.TEST_RUNNER_SCRIPT; command = command.replace("${TEMP_FOLDER}", runner.getTempFolder().getRemote()); command = command.replace("${PARAMS}", getParameterString()); + + // generate json file + // command += "fid = fopen('.matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.id + ".json" + // + "','w');fprintf(fid,'%s',jsonencode(results, 'PrettyPrint', true));fclose(fid);"; // Run the command try { @@ -51,6 +58,23 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep .println(e.getMessage()); throw(e); } + + // Handle test result + Run build = this.params.getBuild(); + FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json"); + if (jsonFile.exists()) { + FilePath rootLocation = new FilePath( + new File( + build.getRootDir() + .getAbsolutePath() + + File.separator + + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + // + this.id + + ".json")); + jsonFile.copyTo(rootLocation); + jsonFile.delete(); + // build.addAction(new TestResultsViewAction(build, this.params.getWorkspace())); + } } private String singleQuotify(String in) { diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly new file mode 100644 index 00000000..53bdfba7 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Test Name + + Duration (seconds) +
+ + + + + + + + + + + + + +
+ ${p.name} +
+ + + + + + + + +
+ ${p.duration} +
+
+
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly new file mode 100644 index 00000000..36c8fad2 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly @@ -0,0 +1,28 @@ + + + +

MATLAB Test Results

+ +

+ + Tests run: ${it.totalCount} + +

+
+ Passed: ${it.passedCount} +
+
+ Failed: ${it.failedCount} +
+
+ Incomplete: ${it.incompleteCount} +
+
+ Not Run: ${it.notRunCount} +
+
+
\ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/config.jelly b/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/config.jelly index 090f6ecc..01f6465e 100644 --- a/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/config.jelly +++ b/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/config.jelly @@ -85,4 +85,12 @@ + + + + + + + + diff --git a/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/help-json.html b/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/help-json.html new file mode 100644 index 00000000..bd3a9e6d --- /dev/null +++ b/src/main/resources/com/mathworks/ci/freestyle/RunMatlabTestsBuilder/help-json.html @@ -0,0 +1,5 @@ +
+
+Generate a MATLAB Test Results report if you have a valid MATLAB Test license. +
+
\ No newline at end of file From a65e93f151c5677073b0ef716905d73eb2bf487a Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 3 Sep 2024 10:09:25 +0530 Subject: [PATCH 02/33] update finally block --- .../ci/actions/RunMatlabBuildAction.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java index 2dc25451..a1a0b512 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java @@ -83,37 +83,37 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep throw(e); } finally { annotator.forceEol(); - } - - // Handle build result - Run build = this.params.getBuild(); - FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + "buildArtifact.json"); - if (jsonFile.exists()) { - FilePath rootLocation = new FilePath( - new File( - build.getRootDir() - .getAbsolutePath() - + File.separator - + "buildArtifact.json")); - jsonFile.copyTo(rootLocation); - jsonFile.delete(); - build.addAction(new BuildArtifactAction(build, this.params.getWorkspace())); - } - // Handle test result - jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json"); - if (jsonFile.exists()) { - FilePath rootLocation = new FilePath( - new File( - build.getRootDir() - .getAbsolutePath() - + File.separator - + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT - // + this.id - + ".json")); - jsonFile.copyTo(rootLocation); - jsonFile.delete(); - // build.addAction(new TestResultsViewAction(build, this.params.getWorkspace())); + // Handle build result + Run build = this.params.getBuild(); + FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + "buildArtifact.json"); + if (jsonFile.exists()) { + FilePath rootLocation = new FilePath( + new File( + build.getRootDir() + .getAbsolutePath() + + File.separator + + "buildArtifact.json")); + jsonFile.copyTo(rootLocation); + jsonFile.delete(); + build.addAction(new BuildArtifactAction(build, this.params.getWorkspace())); + } + + // Handle test result + jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json"); + if (jsonFile.exists()) { + FilePath rootLocation = new FilePath( + new File( + build.getRootDir() + .getAbsolutePath() + + File.separator + + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + // + this.id + + ".json")); + jsonFile.copyTo(rootLocation); + jsonFile.delete(); + // build.addAction(new TestResultsViewAction(build, this.params.getWorkspace())); + } } } } From a7bd44b38b6faf1cd50c906c00b436f04b5f2d24 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Mon, 16 Sep 2024 18:05:56 +0530 Subject: [PATCH 03/33] Update actions --- pom.xml | 8 - .../mathworks/ci/MatlabBuilderConstants.java | 13 +- .../mathworks/ci/TestResultsViewAction.java | 215 +++++++--------- .../mathworks/ci/actions/MatlabAction.java | 47 +++- .../ci/actions/RunMatlabBuildAction.java | 4 +- .../ci/actions/RunMatlabCommandAction.java | 37 +-- .../ci/actions/RunMatlabTestsAction.java | 3 +- .../+jenkins/TestResultsViewPlugin.m | 32 +++ .../+plugins/TestResultsViewPluginService.m | 14 ++ .../ci/TestResultsViewAction/index.jelly | 234 +++++++++--------- 10 files changed, 304 insertions(+), 303 deletions(-) create mode 100644 src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m create mode 100644 src/main/resources/+matlab/+unittest/+internal/+services/+plugins/TestResultsViewPluginService.m diff --git a/pom.xml b/pom.xml index de4f09dd..12b10ec8 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,6 @@ - 2.350 @@ -62,9 +61,6 @@ bom-2.346.x - - - 1763.v092b_8980a_f5e import @@ -73,10 +69,6 @@
- diff --git a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java index ceabe819..2eed0834 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java +++ b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java @@ -34,10 +34,15 @@ public class MatlabBuilderConstants { //Temporary MATLAB folder name in workspace public static final String TEMP_MATLAB_FOLDER_NAME = ".matlab"; - // MATLAB default function/plugin paths + // MATLAB default function, plugin, service paths public static final String DEFAULT_PLUGIN = "+ciplugins/+jenkins/getDefaultPlugins.m"; public static final String BUILD_REPORT_PLUGIN = "+ciplugins/+jenkins/BuildReportPlugin.m"; public static final String TASK_RUN_PROGRESS_PLUGIN = "+ciplugins/+jenkins/TaskRunProgressPlugin.m"; + public static final String TEST_RESULTS_VIEW_PLUGIN = "+ciplugins/+jenkins/TestResultsViewPlugin.m"; + public static final String TEST_RESULTS_VIEW_PLUGIN_SERVICE = "+matlab/+unittest/+internal/+services/+plugins/TestResultsViewPluginService.m"; + + // rename artifact to matlabTestResults.json + public static final String TEST_RESULTS_VIEW_ARTIFACT = "testArtifact"; public static final String BUILD_ARTIFACT = "buildArtifact"; public static final String NEW_LINE = System.getProperty("line.separator"); @@ -50,10 +55,4 @@ public class MatlabBuilderConstants { "disp(testScript.Contents);", "fprintf('___________________________________\\n\\n');", "run(testScript);"); - - //Default and add-on plugins - public static final String DEFAULT_PLUGIN = "+ciplugins/+jenkins/getDefaultPlugins.m"; - public static final String TEST_RESULTS_VIEW_PLUGIN = "+ciplugins/+jenkins/TestResultsViewPlugin.m"; - // rename artifact to matlabTestResults.json - public static final String TEST_RESULTS_VIEW_ARTIFACT = "testArtifact"; } diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 2a78c18a..608e66bd 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -3,7 +3,6 @@ import hudson.FilePath; import jenkins.model.RunAction2; import hudson.model.Run; -import hudson.model.TaskListener; import java.io.File; import java.io.FileInputStream; @@ -25,18 +24,17 @@ public class TestResultsViewAction implements RunAction2 { private Run build; private FilePath workspace; - private String id; + private String actionID; private int totalCount; private int passedCount; private int failedCount; private int incompleteCount; private int notRunCount; - public TaskListener listener; - // private List artidactData; - public TestResultsViewAction(Run build, String id, FilePath workspace, TaskListener listener) throws InterruptedException, IOException { + public TestResultsViewAction(Run build, FilePath workspace, String actionID) throws InterruptedException, IOException { this.build = build; - this.id = id; + this.workspace = workspace; + this.actionID = actionID; // check again at last totalCount = 0; @@ -44,12 +42,9 @@ public TestResultsViewAction(Run build, String id, FilePath workspace, Tas failedCount = 0; incompleteCount = 0; notRunCount = 0; - this.workspace = workspace; - this.listener = listener; try{ getTestResults(); - // listener.getLogger().println("Hello after test results"); } catch (InterruptedException | IOException e) { e.printStackTrace(); throw e; @@ -58,141 +53,121 @@ public TestResultsViewAction(Run build, String id, FilePath workspace, Tas } } - public List getTestResults() throws ParseException, InterruptedException, IOException { - List testResults = new ArrayList(); - FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.id + ".json")); + public List> getTestResults() throws ParseException, InterruptedException, IOException { + List> testResults = new ArrayList<>(); + FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { Object obj = new JSONParser().parse(reader); - JSONObject jsonTestArtifact = (JSONObject) obj; - JSONArray jsonTestResult = (JSONArray) jsonTestArtifact.get("TestResult"); - JSONArray jsonTestSuite = (JSONArray) jsonTestArtifact.get("TestSuite"); - Iterator testResultIterator = jsonTestResult.iterator(); - Iterator testSuiteIterator = jsonTestSuite.iterator(); - Map map = new HashMap(); - - totalCount = jsonTestResult.size(); + totalCount = 0; passedCount = 0; failedCount = 0; incompleteCount = 0; notRunCount = totalCount; - // add single element test case - - while(testResultIterator.hasNext()) { - JSONObject test = testResultIterator.next(); - JSONObject suite = testSuiteIterator.next(); - - // Not OS dependent - String[] testNameSplit = test.get("Name").toString().split("/"); - String testFileName = testNameSplit[0]; - String testCaseName = testNameSplit[1]; - - // String testCaseName = test.get("Name").toString().split("/")[1]; - // String testFileName; - // if (suite.get("TestClass") instanceof String) { - // testFileName = (String) suite.get("TestClass"); - // } - // else{ - // testFileName = testCaseName; - // } - String baseFolder = (String) suite.get("BaseFolder"); - - // handle same test file name - TestFile testFile = map.get(baseFolder + File.separator + testFileName); - if(testFile == null) { - testFile = new TestFile(); - testFile.setName(testFileName); - - map.put(baseFolder + File.separator + testFileName, testFile); - testResults.add(testFile); - } + JSONArray jsonTestArtifact = (JSONArray) obj; + Iterator testArtifactIterator = jsonTestArtifact.iterator(); - // Calculate the relative path - Path path1 = Paths.get(baseFolder); - Path path2 = Paths.get(this.workspace.toURI()); - Path filePath = path2.relativize(path1); - testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); - - // re-evaluate casting if necessary or not - TestCase testCase = new TestCase(); - testCase.setName(testCaseName); - testCase.setPassed((boolean) test.get("Passed")); - testCase.setFailed((boolean) test.get("Failed")); - testCase.setIncomplete((boolean) test.get("Incomplete")); - if (test.get("Duration") instanceof Long) { - testCase.setDuration(((Long) test.get("Duration")).doubleValue()); - } else if (test.get("Duration") instanceof Double) { - testCase.setDuration(((Double) test.get("Duration"))); - } - testCase.updateStatus(); - - // should we instead check for non-empty? - Object diagnostics = ((JSONObject)test.get("Details")).get("DiagnosticRecord"); - if(diagnostics instanceof JSONObject) { - TestDiagnostics testDiagnostics = new TestDiagnostics(); - testDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); - testDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); - testCase.updateDiagnostics(testDiagnostics); - } - else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0) { - // diagnostics = (JSONArray)diagnostics; - Iterator diagnosticsIterator = ((JSONArray)diagnostics).iterator(); - while(diagnosticsIterator.hasNext()) { - JSONObject diagnosticItem = diagnosticsIterator.next(); + while(testArtifactIterator.hasNext()){ + JSONArray jsonTestSessionResults = testArtifactIterator.next(); + Iterator testSessionIterator = jsonTestSessionResults.iterator(); + + List testSessionResults = new ArrayList<>(); + Map map = new HashMap<>(); + while(testSessionIterator.hasNext()){ + JSONObject jsonTestCase = testSessionIterator.next(); + String baseFolder = jsonTestCase.get("BaseFolder").toString(); + JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); + + // add single element test case + + // Not OS dependent + String[] testNameSplit = testCaseResult.get("Name").toString().split("/"); + String testFileName = testNameSplit[0]; + String testCaseName = testNameSplit[1]; + + // handle same test file name + TestFile testFile = map.get(baseFolder + File.separator + testFileName); + if(testFile == null) { + testFile = new TestFile(); + testFile.setName(testFileName); + + map.put(baseFolder + File.separator + testFileName, testFile); + testSessionResults.add(testFile); + } + + // Calculate the relative path + Path path1 = Paths.get(baseFolder); + Path path2 = Paths.get(this.workspace.toURI()); + Path filePath = path2.relativize(path1); + testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); + + // re-evaluate casting if necessary or not + TestCase testCase = new TestCase(); + testCase.setName(testCaseName); + testCase.setPassed((boolean) testCaseResult.get("Passed")); + testCase.setFailed((boolean) testCaseResult.get("Failed")); + testCase.setIncomplete((boolean) testCaseResult.get("Incomplete")); + if (testCaseResult.get("Duration") instanceof Long) { + testCase.setDuration(((Long) testCaseResult.get("Duration")).doubleValue()); + } else if (testCaseResult.get("Duration") instanceof Double) { + testCase.setDuration(((Double) testCaseResult.get("Duration"))); + } + testCase.updateStatus(); + // should we instead check for non-empty? + Object diagnostics = ((JSONObject)testCaseResult.get("Details")).get("DiagnosticRecord"); + if(diagnostics instanceof JSONObject) { TestDiagnostics testDiagnostics = new TestDiagnostics(); - testDiagnostics.setEvent(diagnosticItem.get("Event").toString()); - testDiagnostics.setReport(diagnosticItem.get("Report").toString()); + testDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); + testDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); testCase.updateDiagnostics(testDiagnostics); } - } + else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0) { + // diagnostics = (JSONArray)diagnostics; + Iterator diagnosticsIterator = ((JSONArray)diagnostics).iterator(); + while(diagnosticsIterator.hasNext()) { + JSONObject diagnosticItem = diagnosticsIterator.next(); + + TestDiagnostics testDiagnostics = new TestDiagnostics(); + testDiagnostics.setEvent(diagnosticItem.get("Event").toString()); + testDiagnostics.setReport(diagnosticItem.get("Report").toString()); + testCase.updateDiagnostics(testDiagnostics); + } + } - testFile.incrementDuration(testCase.getDuration()); - testFile.updateStatus(testCase); - testFile.addTestCase(testCase); - updateCount(testCase); + testFile.incrementDuration(testCase.getDuration()); + testFile.updateStatus(testCase); + testFile.addTestCase(testCase); + updateCount(testCase); + } + testResults.add(testSessionResults); } } catch (Exception e) { // TODO: handle exception - this.listener.getLogger().println(e.getMessage()); + // throw new IOException(e.getLocalizedMessage()); } - // for(TestFile testFile : testResults) { - // for(TestCase testCase : testFile.getTestCases()) { - // this.listener.getLogger().println(testCase.getName()); - // } - // } - return testResults; } private void updateCount(TestCase testCase) { - if (!testCase.getStatus().equals("NotRun")) { - if (testCase.getPassed()) { - passedCount += 1; - } - else if (testCase.getFailed()) { - failedCount += 1; - } - else if (testCase.getIncomplete()) { - incompleteCount += 1; - } - notRunCount -= 1; + totalCount += 1; + if (testCase.getStatus().equals("NotRun")) { + notRunCount += 1; + } + else if (testCase.getPassed()) { + passedCount += 1; + } + else if (testCase.getFailed()) { + failedCount += 1; + } + else if (testCase.getIncomplete()) { + incompleteCount += 1; } } - // private TestFile checkIfFileExists(List testResults, String fileName){ - // for(int i = 0; i < testResults.size(); i++){ - // if(testResults.get(i).getName().equals(fileName)){ - // return testResults.get(i); - // } - // } - - // return null; - // } - private transient Run run; public Run getRun() { @@ -218,7 +193,7 @@ public String getDisplayName() { @CheckForNull @Override public String getUrlName() { - return "matlabTestResults" + this.id; + return "matlabTestResults" + this.actionID; } @CheckForNull @@ -242,8 +217,8 @@ public FilePath getWorkspace() { return this.workspace; } - public String getId() { - return id; + public String getActionID() { + return actionID; } public void setTotalCount(int totalCount) { diff --git a/src/main/java/com/mathworks/ci/actions/MatlabAction.java b/src/main/java/com/mathworks/ci/actions/MatlabAction.java index df93b8d0..5ea8b6a7 100644 --- a/src/main/java/com/mathworks/ci/actions/MatlabAction.java +++ b/src/main/java/com/mathworks/ci/actions/MatlabAction.java @@ -8,9 +8,13 @@ import com.mathworks.ci.BuildArtifactAction; import com.mathworks.ci.BuildConsoleAnnotator; import com.mathworks.ci.MatlabBuilderConstants; +import com.mathworks.ci.TestResultsViewAction; +import com.mathworks.ci.parameters.MatlabActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; + import hudson.FilePath; import hudson.model.Run; + import org.apache.commons.lang.RandomStringUtils; import java.io.File; @@ -36,29 +40,40 @@ public MatlabAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator) } public void copyBuildPluginsToTemp() throws IOException, InterruptedException { - // Copy plugins and override default plugins function - runner.copyFileToTempFolder(MatlabBuilderConstants.DEFAULT_PLUGIN, MatlabBuilderConstants.DEFAULT_PLUGIN); - runner.copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, MatlabBuilderConstants.BUILD_REPORT_PLUGIN); - runner.copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); + // Copy BuildRunner plugins and override default plugins function + if(this.annotator != null) { + runner.copyFileToTempFolder(MatlabBuilderConstants.DEFAULT_PLUGIN, MatlabBuilderConstants.DEFAULT_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, MatlabBuilderConstants.BUILD_REPORT_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); + } + + // Copy TestRunner plugins and services + runner.copyFileToTempFolder(MatlabBuilderConstants.TEST_RESULTS_VIEW_PLUGIN, MatlabBuilderConstants.TEST_RESULTS_VIEW_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.TEST_RESULTS_VIEW_PLUGIN_SERVICE, MatlabBuilderConstants.TEST_RESULTS_VIEW_PLUGIN_SERVICE); } public void setBuildEnvVars() throws IOException, InterruptedException { // Set environment variable - runner.addEnvironmentVariable( - "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", - "ciplugins.jenkins.getDefaultPlugins"); - runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID",this.getActionID()); runner.addEnvironmentVariable( "MW_MATLAB_TEMP_FOLDER", runner.getTempFolder().toString()); + + if(this.annotator != null) { + runner.addEnvironmentVariable( + "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", + "ciplugins.jenkins.getDefaultPlugins"); + runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID", this.getActionID()); + } } - public void teardownAction(Run build) { + public void teardownAction(MatlabActionParameters params) { // Handle build result if(this.annotator != null) { - moveJsonArtifactToBuildRoot(build, MatlabBuilderConstants.BUILD_ARTIFACT); + moveJsonArtifactToBuildRoot(params, MatlabBuilderConstants.BUILD_ARTIFACT); } + moveJsonArtifactToBuildRoot(params, MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT); + try { this.runner.removeTempFolder(); } catch (Exception e) { @@ -66,10 +81,13 @@ public void teardownAction(Run build) { } } - private void moveJsonArtifactToBuildRoot(Run build, String artifactBaseName) { + private void moveJsonArtifactToBuildRoot(MatlabActionParameters params, String artifactBaseName) { try { FilePath file = new FilePath(this.runner.getTempFolder(), artifactBaseName + ".json"); if (file.exists()) { + Run build = params.getBuild(); + FilePath workspace = params.getWorkspace(); + FilePath rootLocation = new FilePath( new File( build.getRootDir().getAbsolutePath(), @@ -77,7 +95,12 @@ private void moveJsonArtifactToBuildRoot(Run build, String artifactBaseName ); file.copyTo(rootLocation); file.delete(); - build.addAction(new BuildArtifactAction(build, this.getActionID())); + + if(artifactBaseName.equals(MatlabBuilderConstants.BUILD_ARTIFACT)) { + build.addAction(new BuildArtifactAction(build, this.getActionID())); + } else if(artifactBaseName.equals(MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT)) { + build.addAction(new TestResultsViewAction(build, workspace, this.getActionID())); + } } } catch (Exception e) { // Don't want to override more important error diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java index 2ad7298d..c2d9114f 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java @@ -62,9 +62,7 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep throw(e); } finally { annotator.forceEol(); - - Run build = this.params.getBuild(); - super.teardownAction(build); + super.teardownAction(params); } } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java index b6e8473b..a2382d6d 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java @@ -55,42 +55,9 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep this.params.getTaskListener().getLogger() .println(e.getMessage()); throw(e); - } finally{ + } finally { annotator.forceEol(); - - Run build = this.params.getBuild(); - super.teardownAction(build); - - FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json"); - - if (jsonFile.exists()) { - FilePath rootLocation = new FilePath( - new File( - build.getRootDir() - .getAbsolutePath() - + File.separator - + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.id + ".json")); - jsonFile.copyTo(rootLocation); - jsonFile.delete(); - TestResultsViewAction testResultsViewAction = new TestResultsViewAction(build, this.id, this.params.getWorkspace(), this.params.getTaskListener()); - build.addAction(testResultsViewAction); - - // try{ - - // for(TestFile testFile : testResultsViewAction.getTestResults()){ - // this.params.getTaskListener().getLogger().println(testFile.getName()); - // } - // } - // catch(Exception e){ - // String whatYouWant = testResultsViewAction.getWhatYouWant(); - // this.params.getTaskListener().getLogger().println(whatYouWant); - // String[] whatYouWantSplit = whatYouWant.split("/"); - // this.params.getTaskListener().getLogger().println(whatYouWantSplit[0]); - // this.params.getTaskListener().getLogger().println(whatYouWantSplit[1]); - // this.params.getTaskListener().getLogger().println(e.getMessage()); - // // throw(e); - // } - } + super.teardownAction(params); } } } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java index d16a0fb5..fcd22008 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java @@ -57,8 +57,7 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep .println(e.getMessage()); throw(e); } finally { - Run build = this.params.getBuild(); - super.teardownAction(build); + super.teardownAction(params); } } diff --git a/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m b/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m new file mode 100644 index 00000000..39c7ade1 --- /dev/null +++ b/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m @@ -0,0 +1,32 @@ +classdef TestResultsViewPlugin < matlab.unittest.plugins.TestRunnerPlugin + % Copyright 2024 The MathWorks, Inc. + + methods (Access=protected) + function reportFinalizedSuite(plugin, pluginData) + % Checkout MATLAB Test license + license('checkout', 'matlab_test'); + + testDetails = {}; + for idx = 1:numel(pluginData.TestResult) + testDetails(idx).TestResult = pluginData.TestResult(idx); + testDetails(idx).BaseFolder = pluginData.TestSuite(idx).BaseFolder; + end + + testArtifactFile = fullfile(getenv("MW_MATLAB_TEMP_FOLDER"),"testArtifact.json"); + if isfile(testArtifactFile) + testResults = {jsondecode(fileread(testArtifactFile))}; + else + testResults = {}; + end + testResults{end+1} = testDetails; + JsonTestResults = jsonencode(testResults, "PrettyPrint", true); + + fID = fopen(testArtifactFile, "w"); + fprintf(fID, '%s', JsonTestResults); + fclose(fID); + + % Invoke the superclass method + reportFinalizedSuite@matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData); + end + end +end \ No newline at end of file diff --git a/src/main/resources/+matlab/+unittest/+internal/+services/+plugins/TestResultsViewPluginService.m b/src/main/resources/+matlab/+unittest/+internal/+services/+plugins/TestResultsViewPluginService.m new file mode 100644 index 00000000..31ddbb8e --- /dev/null +++ b/src/main/resources/+matlab/+unittest/+internal/+services/+plugins/TestResultsViewPluginService.m @@ -0,0 +1,14 @@ +classdef TestResultsViewPluginService < matlab.buildtool.internal.services.ciplugins.CITestRunnerPluginService + % Copyright 2024 The MathWorks, Inc. + + methods + function plugins = providePlugins(~, ~) + % Check if MATLAB Test license is available + if license('test', 'matlab_test') + plugins = ciplugins.jenkins.TestResultsViewPlugin(); + else + plugins = matlab.unittest.plugins.TestRunnerPlugin.empty(1,0); + end + end + end +end \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly index 53bdfba7..983ed471 100644 --- a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly @@ -39,127 +39,129 @@


Not Run

- - - - - - - - - - - - + + + + +
- Test Name - - Duration (seconds) -
- - - - - - - - - - - - - -
- ${p.name} -
- - - - - - - - +
+ ${testFile.duration} +
+ - - \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly index 36c8fad2..5e4361f0 100644 --- a/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly @@ -2,11 +2,6 @@

MATLAB Test Results

-

Tests run: ${it.totalCount} From 12ebdc36d508cfb576fbad66aa6d31fc460c4d77 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 18 Sep 2024 10:15:31 +0530 Subject: [PATCH 06/33] add tests --- pom.xml | 17 +- .../mathworks/ci/MatlabBuilderConstants.java | 3 +- src/main/java/com/mathworks/ci/TestCase.java | 32 +- .../com/mathworks/ci/TestDiagnostics.java | 5 - src/main/java/com/mathworks/ci/TestFile.java | 47 +- .../mathworks/ci/TestResultsViewAction.java | 193 ++++----- .../ci/actions/RunMatlabTestsAction.java | 4 - .../+jenkins/TestResultsViewPlugin.m | 3 +- .../ci/BuildArtifactAction/index.jelly | 6 +- .../ci/BuildArtifactAction/summary.jelly | 7 +- .../ci/TestResultsViewAction/index.jelly | 8 +- .../ci/TestResultsViewAction/summary.jelly | 1 + .../ci/TestResultsViewActionTest.java | 407 ++++++++++++++++++ .../testArtifacts/t1/matlabTestResults.json | 73 ++++ 14 files changed, 623 insertions(+), 183 deletions(-) create mode 100644 src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java create mode 100644 src/test/resources/testArtifacts/t1/matlabTestResults.json diff --git a/pom.xml b/pom.xml index 12b10ec8..4d1c4782 100644 --- a/pom.xml +++ b/pom.xml @@ -18,12 +18,8 @@ - - 2.350 - - - 8 - + 2.350 + 8 MATLAB Plugin Jenkins plugin for MATLAB @@ -56,13 +52,8 @@ io.jenkins.tools.bom - - - bom-2.346.x - - - 1763.v092b_8980a_f5e - + bom-2.346.x + 1763.v092b_8980a_f5e import pom diff --git a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java index 9eb66fa1..8ec055a7 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java +++ b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java @@ -41,8 +41,7 @@ public class MatlabBuilderConstants { public static final String TEST_RESULTS_VIEW_PLUGIN = "+ciplugins/+jenkins/TestResultsViewPlugin.m"; public static final String TEST_RESULTS_VIEW_PLUGIN_SERVICE = "+matlab/+unittest/+internal/+services/+plugins/TestResultsViewPluginService.m"; - // rename artifact to matlabTestResults.json - public static final String TEST_RESULTS_VIEW_ARTIFACT = "testArtifact"; + public static final String TEST_RESULTS_VIEW_ARTIFACT = "matlabTestResults"; public static final String BUILD_ARTIFACT = "buildArtifact"; public static final String NEW_LINE = System.getProperty("line.separator"); diff --git a/src/main/java/com/mathworks/ci/TestCase.java b/src/main/java/com/mathworks/ci/TestCase.java index 6a355ece..d82f6e6c 100644 --- a/src/main/java/com/mathworks/ci/TestCase.java +++ b/src/main/java/com/mathworks/ci/TestCase.java @@ -18,7 +18,6 @@ public class TestCase { private boolean incomplete; private String status; private Double duration; - private String id; public TestCase() { @@ -29,9 +28,20 @@ public TestCase() { incomplete = false; status = "NotRun"; duration = 0.0; - id = RandomStringUtils.randomAlphanumeric(8); } + + public void updateStatus() { + if (failed){ + status = "Failed"; + } + else if (incomplete) { + status = "Incomplete"; + } + else if(passed) { + status = "Passed"; + } + } public String getName() { return this.name; @@ -49,10 +59,6 @@ public void setDiagnostics(List diagnostics) { this.diagnostics = diagnostics; } - public void updateDiagnostics(TestDiagnostics diagnostic) { - this.diagnostics.add(diagnostic); - } - public boolean getPassed() { return this.passed; } @@ -85,18 +91,6 @@ public void setStatus(String status) { this.status = status; } - public void updateStatus() { - if (failed){ - status = "Failed"; - } - else if (incomplete) { - status = "Incomplete"; - } - else if(passed) { - status = "Passed"; - } - } - public Double getDuration() { return this.duration; } @@ -106,8 +100,6 @@ public void setDuration(Double duration) { } public String getId() { - // String id = this.filePath + "-" + this.name; - // return id.replaceAll(File.separator, "-"); return id; } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/TestDiagnostics.java b/src/main/java/com/mathworks/ci/TestDiagnostics.java index c8828628..6df882a7 100644 --- a/src/main/java/com/mathworks/ci/TestDiagnostics.java +++ b/src/main/java/com/mathworks/ci/TestDiagnostics.java @@ -10,13 +10,11 @@ public class TestDiagnostics { private String event; private String report; - private String id; public TestDiagnostics() { event = ""; report = ""; - id = RandomStringUtils.randomAlphanumeric(8); } @@ -37,9 +35,6 @@ public void setReport(String report) { } public String getId() { - // String id = this.filePath + "-" + this.name; - // return id.replaceAll(File.separator, "-"); return id; } - } diff --git a/src/main/java/com/mathworks/ci/TestFile.java b/src/main/java/com/mathworks/ci/TestFile.java index 6e4d1a91..b4453dc0 100644 --- a/src/main/java/com/mathworks/ci/TestFile.java +++ b/src/main/java/com/mathworks/ci/TestFile.java @@ -16,7 +16,6 @@ public class TestFile { private Double duration; private String status; private List testCases; - private String id; public TestFile() { @@ -29,6 +28,26 @@ public TestFile() { id = RandomStringUtils.randomAlphanumeric(8); } + public void incrementDuration(Double testCaseDuration) { + this.duration += testCaseDuration; + } + + public void updateStatus(TestCase testCase) { + if (!status.equals("Failed")){ + if (testCase.getFailed()){ + status = "Failed"; + } + else if (!status.equals("Incomplete")){ + if (testCase.getIncomplete()){ + status = "Incomplete"; + } + else if (testCase.getPassed()){ + status = "Passed"; + } + } + } + } + public String getFilePath() { return this.filePath; } @@ -70,32 +89,6 @@ public void setTestCases(List testCases) { } public String getId() { - // String id = this.filePath + "-" + this.name; - // return id.replaceAll(File.separator, "-"); return id; } - - public void incrementDuration(Double testCaseDuration) { - this.duration += testCaseDuration; - } - - public void updateStatus(TestCase testCase) { - if (!status.equals("Failed")){ - if (testCase.getFailed()){ - status = "Failed"; - } - else if (!status.equals("Incomplete")){ - if (testCase.getIncomplete()){ - status = "Incomplete"; - } - else if (testCase.getPassed()){ - status = "Passed"; - } - } - } - } - - public void addTestCase(TestCase testCase) { - this.testCases.add(testCase); - } } diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index baac4267..9e6301d3 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -30,7 +30,7 @@ import jenkins.model.RunAction2; public class TestResultsViewAction implements RunAction2 { - private Run build; + private transient Run build; private FilePath workspace; private String actionID; private int totalCount; @@ -44,122 +44,126 @@ public TestResultsViewAction(Run build, FilePath workspace, String actionI this.workspace = workspace; this.actionID = actionID; - // check again at last totalCount = 0; passedCount = 0; failedCount = 0; incompleteCount = 0; notRunCount = 0; - try{ - getTestResults(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - throw e; - } catch (ParseException e) { - e.printStackTrace(); - } + try{ + getTestResults(); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + throw e; + } catch (ParseException e) { + e.printStackTrace(); + } } public List> getTestResults() throws ParseException, InterruptedException, IOException { List> testResults = new ArrayList<>(); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { - Object obj = new JSONParser().parse(reader); - totalCount = 0; passedCount = 0; failedCount = 0; incompleteCount = 0; notRunCount = totalCount; - JSONArray jsonTestArtifact = (JSONArray) obj; - Iterator testArtifactIterator = jsonTestArtifact.iterator(); + JSONArray testArtifact = (JSONArray) new JSONParser().parse(reader); + Iterator testArtifactIterator = testArtifact.iterator(); while(testArtifactIterator.hasNext()){ - JSONArray jsonTestSessionResults = testArtifactIterator.next(); - Iterator testSessionIterator = jsonTestSessionResults.iterator(); + Object jsonTestSessionResults = testArtifactIterator.next(); List testSessionResults = new ArrayList<>(); Map map = new HashMap<>(); - while(testSessionIterator.hasNext()){ - JSONObject jsonTestCase = testSessionIterator.next(); - String baseFolder = jsonTestCase.get("BaseFolder").toString(); - JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); - - // add single element test case - - // Not OS dependent - String[] testNameSplit = testCaseResult.get("Name").toString().split("/"); - String testFileName = testNameSplit[0]; - String testCaseName = testNameSplit[1]; - - // handle same test file name - TestFile testFile = map.get(baseFolder + File.separator + testFileName); - if(testFile == null) { - testFile = new TestFile(); - testFile.setName(testFileName); - - map.put(baseFolder + File.separator + testFileName, testFile); - testSessionResults.add(testFile); - } - // Calculate the relative path - Path path1 = Paths.get(baseFolder); - Path path2 = Paths.get(this.workspace.toURI()); - Path filePath = path2.relativize(path1); - testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); - - // re-evaluate casting if necessary or not - TestCase testCase = new TestCase(); - testCase.setName(testCaseName); - testCase.setPassed((boolean) testCaseResult.get("Passed")); - testCase.setFailed((boolean) testCaseResult.get("Failed")); - testCase.setIncomplete((boolean) testCaseResult.get("Incomplete")); - if (testCaseResult.get("Duration") instanceof Long) { - testCase.setDuration(((Long) testCaseResult.get("Duration")).doubleValue()); - } else if (testCaseResult.get("Duration") instanceof Double) { - testCase.setDuration(((Double) testCaseResult.get("Duration"))); - } - testCase.updateStatus(); - - // should we instead check for non-empty? - Object diagnostics = ((JSONObject)testCaseResult.get("Details")).get("DiagnosticRecord"); - if(diagnostics instanceof JSONObject) { - TestDiagnostics testDiagnostics = new TestDiagnostics(); - testDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); - testDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); - testCase.updateDiagnostics(testDiagnostics); - } - else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0) { - // diagnostics = (JSONArray)diagnostics; - Iterator diagnosticsIterator = ((JSONArray)diagnostics).iterator(); - while(diagnosticsIterator.hasNext()) { - JSONObject diagnosticItem = diagnosticsIterator.next(); - - TestDiagnostics testDiagnostics = new TestDiagnostics(); - testDiagnostics.setEvent(diagnosticItem.get("Event").toString()); - testDiagnostics.setReport(diagnosticItem.get("Report").toString()); - testCase.updateDiagnostics(testDiagnostics); - } - } + if(jsonTestSessionResults instanceof JSONArray){ + JSONArray jsonTestSessionResultsArray = (JSONArray) jsonTestSessionResults; + Iterator testSessionResultsIterator = jsonTestSessionResultsArray.iterator(); - testFile.incrementDuration(testCase.getDuration()); - testFile.updateStatus(testCase); - testFile.addTestCase(testCase); - updateCount(testCase); + while(testSessionResultsIterator.hasNext()){ + JSONObject jsonTestCase = testSessionResultsIterator.next(); + getTestSessionResults(testSessionResults, jsonTestCase, map); + } + } + else if(jsonTestSessionResults instanceof JSONObject) { + JSONObject jsonTestCase = (JSONObject) jsonTestSessionResults; + getTestSessionResults(testSessionResults, jsonTestCase, map); } + testResults.add(testSessionResults); } } catch (Exception e) { - // TODO: handle exception - // throw new IOException(e.getLocalizedMessage()); + throw new IOException(e.getLocalizedMessage()); } return testResults; } + private void getTestSessionResults(List testSessionResults, JSONObject jsonTestCase, Map map) throws IOException, InterruptedException { + String baseFolder = jsonTestCase.get("BaseFolder").toString(); + JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); + + // Not OS dependent + String[] testNameSplit = testCaseResult.get("Name").toString().split("/"); + String testFileName = testNameSplit[0]; + String testCaseName = testNameSplit[1]; + + TestFile testFile = map.get(baseFolder + File.separator + testFileName); + if(testFile == null) { + testFile = new TestFile(); + testFile.setName(testFileName); + + map.put(baseFolder + File.separator + testFileName, testFile); + testSessionResults.add(testFile); + } + + // Calculate the relative path + Path path1 = Paths.get(baseFolder); + Path path2 = Paths.get(this.workspace.toURI()); + Path filePath = path2.relativize(path1); + testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); + + TestCase testCase = new TestCase(); + testCase.setName(testCaseName); + testCase.setPassed((boolean) testCaseResult.get("Passed")); + testCase.setFailed((boolean) testCaseResult.get("Failed")); + testCase.setIncomplete((boolean) testCaseResult.get("Incomplete")); + if (testCaseResult.get("Duration") instanceof Long) { + testCase.setDuration(((Long) testCaseResult.get("Duration")).doubleValue()); + } else if (testCaseResult.get("Duration") instanceof Double) { + testCase.setDuration(((Double) testCaseResult.get("Duration"))); + } + testCase.updateStatus(); + + Object diagnostics = ((JSONObject)testCaseResult.get("Details")).get("DiagnosticRecord"); + if(diagnostics instanceof JSONObject) { + TestDiagnostics testDiagnostics = new TestDiagnostics(); + testDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); + testDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); + testCase.getDiagnostics().add(testDiagnostics); + } + else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0) { + Iterator diagnosticsIterator = ((JSONArray)diagnostics).iterator(); + while(diagnosticsIterator.hasNext()) { + JSONObject diagnosticItem = diagnosticsIterator.next(); + + TestDiagnostics testDiagnostics = new TestDiagnostics(); + testDiagnostics.setEvent(diagnosticItem.get("Event").toString()); + testDiagnostics.setReport(diagnosticItem.get("Report").toString()); + testCase.getDiagnostics().add(testDiagnostics); + } + } + + testFile.incrementDuration(testCase.getDuration()); + testFile.updateStatus(testCase); + testFile.getTestCases().add(testCase); + updateCount(testCase); + } + private void updateCount(TestCase testCase) { totalCount += 1; if (testCase.getStatus().equals("NotRun")) { @@ -176,20 +180,18 @@ else if (testCase.getIncomplete()) { } } - private transient Run run; - - public Run getRun() { - return run; - } - @Override public void onAttached(Run run) { - this.run = run; + this.build = run; } @Override public void onLoad(Run run) { - this.run = run; + onAttached(run); + } + + public Run getBuild() { + return build; } @CheckForNull @@ -210,17 +212,6 @@ public String getIconFileName() { return "document.png"; } - public Run getOwner() { - return this.build; - } - - /** - * @param owner the owner to set - */ - public void setOwner(Run owner) { - this.build = owner; - } - public FilePath getWorkspace() { return this.workspace; } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java index bf90fa23..f10e61f1 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java @@ -40,10 +40,6 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep String command = MatlabBuilderConstants.TEST_RUNNER_SCRIPT; command = command.replace("${TEMP_FOLDER}", runner.getTempFolder().getRemote()); command = command.replace("${PARAMS}", getParameterString()); - - // generate json file - // command += "fid = fopen('.matlab" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.id + ".json" - // + "','w');fprintf(fid,'%s',jsonencode(results, 'PrettyPrint', true));fclose(fid);"; // Run the command try { diff --git a/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m b/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m index 39c7ade1..af0d36a8 100644 --- a/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m +++ b/src/main/resources/+ciplugins/+jenkins/TestResultsViewPlugin.m @@ -12,7 +12,8 @@ function reportFinalizedSuite(plugin, pluginData) testDetails(idx).BaseFolder = pluginData.TestSuite(idx).BaseFolder; end - testArtifactFile = fullfile(getenv("MW_MATLAB_TEMP_FOLDER"),"testArtifact.json"); + % If test results artifact exists, update the same file + testArtifactFile = fullfile(getenv("MW_MATLAB_TEMP_FOLDER"),"matlabTestResults.json"); if isfile(testArtifactFile) testResults = {jsondecode(fileread(testArtifactFile))}; else diff --git a/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly b/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly index cd4c3dd7..29bdce87 100644 --- a/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly +++ b/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly @@ -32,7 +32,7 @@

-
+
${(it.failCount)} Failed @@ -74,11 +74,11 @@ - Succeeded + Succeeded - + Skipped (${p.skipReason}) diff --git a/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly b/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly index ae679b08..0f67c399 100644 --- a/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly +++ b/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly @@ -9,15 +9,16 @@

MATLAB Build Results

-
Unable to generate a build artifact.
+
Unable to generate a build artifact.
-

Tasks run: ${it.totalCount}

+

Tasks run: ${it.totalCount}

+


Failed: ${it.failCount}

- Skipped: ${it.skipCount} + Skipped: ${it.skipCount}
\ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly index e6a5eebc..ca7ce93d 100644 --- a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly @@ -2,7 +2,7 @@ - + @@ -92,7 +92,7 @@ Diagnostics - Duration = ${testFile.duration} + Duration (seconds) = ${testFile.duration} @@ -112,12 +112,12 @@ - ${testCase.name} + ${testCase.name}
- ${diagnostic.event} + ${diagnostic.event} diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly index 5e4361f0..dcae1e12 100644 --- a/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/summary.jelly @@ -7,6 +7,7 @@ Tests run: ${it.totalCount}

+


Passed: ${it.passedCount}
diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java new file mode 100644 index 00000000..4b0739cf --- /dev/null +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -0,0 +1,407 @@ +package com.mathworks.ci; + +import java.io.File; + +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +import org.json.simple.parser.ParseException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + +import com.mathworks.ci.freestyle.RunMatlabBuildBuilder; + +import hudson.FilePath; +import hudson.model.FreeStyleBuild; +import hudson.model.FreeStyleProject; + +public class TestResultsViewActionTest { + private FreeStyleProject project; + private UseMatlabVersionBuildWrapper buildWrapper; + private RunMatlabBuildBuilder scriptBuilder; + + private static String VERSION_INFO_XML_FILE = "VersionInfo.xml"; + + public TestResultsViewActionTest(){ + } + + @Rule + public JenkinsRule jenkins = new JenkinsRule(); + + + @Before + public void testSetup() throws IOException { + this.project = jenkins.createFreeStyleProject(); + this.scriptBuilder = new RunMatlabBuildBuilder(); + this.buildWrapper = new UseMatlabVersionBuildWrapper(); + } + + @After + public void testTearDown() { + this.project = null; + this.scriptBuilder = null; + } + + private String getMatlabroot(String version) throws URISyntaxException { + String defaultVersionInfo = "versioninfo/R2017a/" + VERSION_INFO_XML_FILE; + String userVersionInfo = "versioninfo/" + version + "/" + VERSION_INFO_XML_FILE; + URL matlabRootURL = Optional.ofNullable(getResource(userVersionInfo)) + .orElseGet(() -> getResource(defaultVersionInfo)); + File matlabRoot = new File(matlabRootURL.toURI()); + return matlabRoot.getAbsolutePath().replace(File.separator + VERSION_INFO_XML_FILE, "") + .replace("R2017a", version); + } + + private URL getResource(String resource) { + return TestResultsViewAction.class.getClassLoader().getResource(resource); + } + + /** + * Verify if all test results are returned from artifact + * + */ + + @Test + public void verifyAllTestsReturned() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + int actualTestSessions = ta.size(); + Assert.assertEquals("Incorrect test sessions",2,actualTestSessions); + int actualTestFiles1 = ta.get(0).size(); + Assert.assertEquals("Incorrect test files",1,actualTestFiles1); + int actualTestFiles2 = ta.get(1).size(); + Assert.assertEquals("Incorrect test files",1,actualTestFiles2); + int actualTestResults1 = ta.get(0).get(0).getTestCases().size(); + Assert.assertEquals("Incorrect test results",3,actualTestResults1); + int actualTestResults2 = ta.get(1).get(0).getTestCases().size(); + Assert.assertEquals("Incorrect test results",1,actualTestResults2); + } + + /** + * Verify if total test results count is correct + * + */ + + @Test + public void verifyTotalTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + int actualCount = ac.getTotalCount(); + Assert.assertEquals("Incorrect total tests count",4,actualCount); + } + + /** + * Verify if passed tests count is correct + * + */ + + @Test + public void verifyPassedTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + int actualCount = ac.getPassedCount(); + Assert.assertEquals("Incorrect passed tests count",2,actualCount); + } + + /** + * Verify if failed tests count is correct + * + */ + + @Test + public void verifyFailedTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + int actualCount = ac.getFailedCount(); + Assert.assertEquals("Incorrect failed tests count",1,actualCount); + } + + /** + * Verify if incomplete tests count is correct + * + */ + + @Test + public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + int actualCount = ac.getIncompleteCount(); + Assert.assertEquals("Incorrect incomplete tests count",0,actualCount); + } + + /** + * Verify if not run tests count is correct + * + */ + + @Test + public void verifyNotRunTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + int actualCount = ac.getNotRunCount(); + Assert.assertEquals("Incorrect not run tests count",1,actualCount); + } + + /** + * Verify if test file path is correct + * + */ + + @Test + public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + String actualPath1 = ta.get(0).get(0).getFilePath(); + Assert.assertEquals("Incorrect test file path","workspace\\visualization\\tests",actualPath1); + String actualPath2 = ta.get(1).get(0).getFilePath(); + Assert.assertEquals("Incorrect test file path","workspace\\visualization\\duplicate tests",actualPath2); + } + + /** + * Verify if test file name is correct + * + */ + + @Test + public void verifyTestFileName() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + String actualName1 = ta.get(0).get(0).getName(); + Assert.assertEquals("Incorrect test file name","TestExamples1",actualName1); + String actualName2 = ta.get(1).get(0).getName(); + Assert.assertEquals("Incorrect test file name","TestExamples2",actualName2); + } + + /** + * Verify if test file duration is correct + * + */ + + @Test + public void verifyTestFileDuration() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + Double actualDuration1 = ta.get(0).get(0).getDuration(); + Assert.assertEquals("Incorrect test file duration",(Double) 0.5,actualDuration1); + Double actualDuration2 = ta.get(1).get(0).getDuration(); + Assert.assertEquals("Incorrect test file duration",(Double) 0.1,actualDuration2); + } + + /** + * Verify if test file status is correct + * + */ + + @Test + public void verifyTestFileStatus() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + String actualStatus1 = ta.get(0).get(0).getStatus(); + Assert.assertEquals("Incorrect test file status","Failed",actualStatus1); + String actualStatus2 = ta.get(1).get(0).getStatus(); + Assert.assertEquals("Incorrect test file status","Passed",actualStatus2); + } + + /** + * Verify if test case name is correct + * + */ + + @Test + public void verifyTestCaseName() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + String actualName1_1 = ta.get(0).get(0).getTestCases().get(0).getName(); + Assert.assertEquals("Incorrect test case name","testNonLeapYear",actualName1_1); + String actualName1_2 = ta.get(0).get(0).getTestCases().get(1).getName(); + Assert.assertEquals("Incorrect test case name","testLeapYear",actualName1_2); + String actualName1_3 = ta.get(0).get(0).getTestCases().get(2).getName(); + Assert.assertEquals("Incorrect test case name","testInvalidDateFormat",actualName1_3); + String actualName2 = ta.get(1).get(0).getTestCases().get(0).getName(); + Assert.assertEquals("Incorrect test case name","testNonLeapYear",actualName2); + } + + /** + * Verify if test case status is correct + * + */ + + @Test + public void verifyTestCaseStatus() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + String actualStatus1_1 = ta.get(0).get(0).getTestCases().get(0).getStatus(); + Assert.assertEquals("Incorrect test case status","Passed",actualStatus1_1); + String actualStatus1_2 = ta.get(0).get(0).getTestCases().get(1).getStatus(); + Assert.assertEquals("Incorrect test case status","Failed",actualStatus1_2); + String actualStatus1_3 = ta.get(0).get(0).getTestCases().get(2).getStatus(); + Assert.assertEquals("Incorrect test case status","NotRun",actualStatus1_3); + String actualStatus2 = ta.get(1).get(0).getTestCases().get(0).getStatus(); + Assert.assertEquals("Incorrect test case status","Passed",actualStatus2); + } + + /** + * Verify if test case duration is correct + * + */ + + @Test + public void verifyTestCaseDuration() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + Double actualDuration1_1 = ta.get(0).get(0).getTestCases().get(0).getDuration(); + Assert.assertEquals("Incorrect test case duration",(Double) 0.1,actualDuration1_1); + Double actualDuration1_2 = ta.get(0).get(0).getTestCases().get(1).getDuration(); + Assert.assertEquals("Incorrect test case duration",(Double) 0.4,actualDuration1_2); + Double actualDuration1_3 = ta.get(0).get(0).getTestCases().get(2).getDuration(); + Assert.assertEquals("Incorrect test case duration",(Double) 0.0,actualDuration1_3); + Double actualDuration2 = ta.get(1).get(0).getTestCases().get(0).getDuration(); + Assert.assertEquals("Incorrect test case duration",(Double) 0.1,actualDuration2); + } + + /** + * Verify if test case diagnostics is correct + * + */ + + @Test + public void verifyTestCaseDiagnostics() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + List> ta = ac.getTestResults(); + TestDiagnostics diagnostics = ta.get(0).get(0).getTestCases().get(1).getDiagnostics().get(0); + String actualDiagnosticsEvent = diagnostics.getEvent(); + Assert.assertEquals("Incorrect test diagnostics event","SampleDiagnosticsEvent",actualDiagnosticsEvent); + String actualDiagnosticsReport = diagnostics.getReport(); + Assert.assertEquals("Incorrect test diagnostics report","SampleDiagnosticsReport",actualDiagnosticsReport); + } + + /** + * Verify if actionID is set correctly + * + */ + + @Test + public void verifyActionID() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final FilePath workspace = new FilePath(new File("", "workspace")); + final String actionID = "abc123"; + final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); + String actualActionID = ac.getActionID(); + Assert.assertEquals("Incorrect action ID",actionID,actualActionID); + } + + private void copyFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) + throws IOException, InterruptedException { + final ClassLoader classLoader = getClass().getClassLoader(); + FilePath targetFilePath = new FilePath(targetWorkspace, targetFile); + InputStream in = classLoader.getResourceAsStream(sourceFile); + targetFilePath.copyFrom(in); + // set executable permission + targetFilePath.chmod(0777); + } + + private FreeStyleBuild getFreestyleBuild() throws ExecutionException, InterruptedException, URISyntaxException { + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + project.getBuildWrappersList().add(this.buildWrapper); + scriptBuilder.setTasks(""); + project.getBuildersList().add(this.scriptBuilder); + FreeStyleBuild build = project.scheduleBuild2(0).get(); + return build; + } +} diff --git a/src/test/resources/testArtifacts/t1/matlabTestResults.json b/src/test/resources/testArtifacts/t1/matlabTestResults.json new file mode 100644 index 00000000..b0da2dcb --- /dev/null +++ b/src/test/resources/testArtifacts/t1/matlabTestResults.json @@ -0,0 +1,73 @@ +[ + [ + { + "TestResult": { + "Duration": 0.1, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples1/testNonLeapYear", + "Passed": true, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "C:\\workspace\\visualization\\tests" + }, + { + "TestResult": { + "Duration": 0.4, + "Details": { + "SimulinkTestManagerResults": [], + "DiagnosticRecord": { + "TestDiagnosticResults": [], + "FrameworkDiagnosticResults": { + "Artifacts": [], + "DiagnosticText": "SampleDiagnosticsText" + }, + "AdditionalDiagnosticResults": [], + "Stack": { + "file": "C:\\workspace\\visualization\\tests\\TestExamples1.m", + "name": "TestExamples1.testLeapYear", + "line": 35 + }, + "Event": "SampleDiagnosticsEvent", + "EventScope": "TestMethod", + "EventLocation": "TestExamples1/testLeapYear", + "Report": "SampleDiagnosticsReport" + } + }, + "Name": "TestExamples1/testLeapYear", + "Passed": false, + "Failed": true, + "Incomplete": true + }, + "BaseFolder": "C:\\workspace\\visualization\\tests" + }, + { + "TestResult": { + "Duration": 0.0, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples1/testInvalidDateFormat", + "Passed": false, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "C:\\workspace\\visualization\\tests" + } + ], + { + "TestResult": { + "Duration": 0.1, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples2/testNonLeapYear", + "Passed": true, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "C:\\workspace\\visualization\\duplicate tests" + } +] \ No newline at end of file From f917c1f4efbf3db7b3799a629eab075062522a47 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 18 Sep 2024 10:55:09 +0530 Subject: [PATCH 07/33] remove extra comments --- src/main/java/com/mathworks/ci/BuildArtifactAction.java | 2 -- .../java/integ/com/mathworks/ci/BuildArtifactActionTest.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/main/java/com/mathworks/ci/BuildArtifactAction.java b/src/main/java/com/mathworks/ci/BuildArtifactAction.java index b856e7a4..cc50f9b7 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactAction.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactAction.java @@ -67,8 +67,6 @@ public String getUrlName() { return (this.actionID == null) ? "buildresults" : "buildresults" + this.actionID ; } - // add link to test results table - public List getBuildArtifact() throws ParseException, InterruptedException, IOException { List artifactData = new ArrayList(); FilePath fl; diff --git a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java index d9aba437..bde289cd 100644 --- a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java @@ -271,8 +271,6 @@ public void verifyActionIDisAppropriate() throws ExecutionException, Interrupted Assert.assertEquals("Incorrect ActionID",actionID,ac.getActionID()); } - - private void copyFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) throws IOException, InterruptedException { final ClassLoader classLoader = getClass().getClassLoader(); From 284d2dfc1a5c9cd3c4279fbf4d79ac8ab27df600 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 10:50:35 +0530 Subject: [PATCH 08/33] try fix for ci test failure --- .../integ/com/mathworks/ci/TestResultsViewActionTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index 4b0739cf..ff2da476 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -1,12 +1,11 @@ package com.mathworks.ci; -import java.io.File; - /** * Copyright 2024 The MathWorks, Inc. * */ +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; @@ -163,7 +162,7 @@ public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedE final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts" + File.separator + "t1" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getIncompleteCount(); Assert.assertEquals("Incorrect incomplete tests count",0,actualCount); From 0f4b8017f2930082fef5b9c09c2540e0d8ef667a Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 11:08:30 +0530 Subject: [PATCH 09/33] try fix for ci test failure --- src/main/java/com/mathworks/ci/TestResultsViewAction.java | 1 + .../integ/com/mathworks/ci/TestResultsViewActionTest.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 9e6301d3..71553523 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -51,6 +51,7 @@ public TestResultsViewAction(Run build, FilePath workspace, String actionI notRunCount = 0; try{ + // Set test results counts getTestResults(); } catch (InterruptedException | IOException e) { e.printStackTrace(); diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index ff2da476..93f8c299 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -158,11 +158,11 @@ public void verifyFailedTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = build.getWorkspace(); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts" + File.separator + "t1" + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getIncompleteCount(); Assert.assertEquals("Incorrect incomplete tests count",0,actualCount); From fe6fab83ce14662329b1c36ceb76ddd49aa5be36 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 11:37:20 +0530 Subject: [PATCH 10/33] add debug statements --- src/main/java/com/mathworks/ci/TestResultsViewAction.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 71553523..79b600b4 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -63,6 +63,7 @@ public TestResultsViewAction(Run build, FilePath workspace, String actionI public List> getTestResults() throws ParseException, InterruptedException, IOException { List> testResults = new ArrayList<>(); + System.out.println("Line 66"); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { totalCount = 0; @@ -71,6 +72,7 @@ public List> getTestResults() throws ParseException, InterruptedE incompleteCount = 0; notRunCount = totalCount; + System.out.println("Line 75"); JSONArray testArtifact = (JSONArray) new JSONParser().parse(reader); Iterator testArtifactIterator = testArtifact.iterator(); @@ -86,14 +88,17 @@ public List> getTestResults() throws ParseException, InterruptedE while(testSessionResultsIterator.hasNext()){ JSONObject jsonTestCase = testSessionResultsIterator.next(); + System.out.println("Line 91"); getTestSessionResults(testSessionResults, jsonTestCase, map); } } else if(jsonTestSessionResults instanceof JSONObject) { JSONObject jsonTestCase = (JSONObject) jsonTestSessionResults; + System.out.println("Line 97"); getTestSessionResults(testSessionResults, jsonTestCase, map); } + System.out.println("Line 101"); testResults.add(testSessionResults); } } From cfb17958e4c833707cf18811541a01defbdfa3bf Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 14:06:59 +0530 Subject: [PATCH 11/33] debug failure --- .../java/com/mathworks/ci/TestResultsViewAction.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 79b600b4..c5b08825 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -63,7 +63,7 @@ public TestResultsViewAction(Run build, FilePath workspace, String actionI public List> getTestResults() throws ParseException, InterruptedException, IOException { List> testResults = new ArrayList<>(); - System.out.println("Line 66"); +// throw new Exception("Line 66"); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { totalCount = 0; @@ -72,7 +72,7 @@ public List> getTestResults() throws ParseException, InterruptedE incompleteCount = 0; notRunCount = totalCount; - System.out.println("Line 75"); + // throw new Exception("Line 75"); JSONArray testArtifact = (JSONArray) new JSONParser().parse(reader); Iterator testArtifactIterator = testArtifact.iterator(); @@ -88,17 +88,17 @@ public List> getTestResults() throws ParseException, InterruptedE while(testSessionResultsIterator.hasNext()){ JSONObject jsonTestCase = testSessionResultsIterator.next(); - System.out.println("Line 91"); + throw new Exception("Line 91"); getTestSessionResults(testSessionResults, jsonTestCase, map); } } else if(jsonTestSessionResults instanceof JSONObject) { JSONObject jsonTestCase = (JSONObject) jsonTestSessionResults; - System.out.println("Line 97"); + throw new Exception("Line 97"); getTestSessionResults(testSessionResults, jsonTestCase, map); } - System.out.println("Line 101"); + throw new Exception("Line 101"); testResults.add(testSessionResults); } } From 2071d66f08b3b1535ef644a0ccf71156313db6fa Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 14:12:05 +0530 Subject: [PATCH 12/33] debug --- src/main/java/com/mathworks/ci/TestResultsViewAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index c5b08825..a99a4574 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -89,17 +89,17 @@ public List> getTestResults() throws ParseException, InterruptedE while(testSessionResultsIterator.hasNext()){ JSONObject jsonTestCase = testSessionResultsIterator.next(); throw new Exception("Line 91"); - getTestSessionResults(testSessionResults, jsonTestCase, map); +// getTestSessionResults(testSessionResults, jsonTestCase, map); } } else if(jsonTestSessionResults instanceof JSONObject) { JSONObject jsonTestCase = (JSONObject) jsonTestSessionResults; throw new Exception("Line 97"); - getTestSessionResults(testSessionResults, jsonTestCase, map); +// getTestSessionResults(testSessionResults, jsonTestCase, map); } throw new Exception("Line 101"); - testResults.add(testSessionResults); +// testResults.add(testSessionResults); } } catch (Exception e) { From e50a7c71739bf46fcb0fb0e25ab1f823632d2734 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 14:24:16 +0530 Subject: [PATCH 13/33] update input stream --- .../com/mathworks/ci/TestResultsViewAction.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index a99a4574..078aae2d 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -9,6 +9,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -65,7 +66,8 @@ public List> getTestResults() throws ParseException, InterruptedE List> testResults = new ArrayList<>(); // throw new Exception("Line 66"); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); - try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { + Path path = Paths.get(fl.toURI()); + try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(path), "UTF-8")) { totalCount = 0; passedCount = 0; failedCount = 0; @@ -88,18 +90,15 @@ public List> getTestResults() throws ParseException, InterruptedE while(testSessionResultsIterator.hasNext()){ JSONObject jsonTestCase = testSessionResultsIterator.next(); - throw new Exception("Line 91"); -// getTestSessionResults(testSessionResults, jsonTestCase, map); + getTestSessionResults(testSessionResults, jsonTestCase, map); } } else if(jsonTestSessionResults instanceof JSONObject) { JSONObject jsonTestCase = (JSONObject) jsonTestSessionResults; - throw new Exception("Line 97"); -// getTestSessionResults(testSessionResults, jsonTestCase, map); + getTestSessionResults(testSessionResults, jsonTestCase, map); } - throw new Exception("Line 101"); -// testResults.add(testSessionResults); + testResults.add(testSessionResults); } } catch (Exception e) { From 620bceb918d3b97b2b27aee26fdc66e5cc505116 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Wed, 25 Sep 2024 15:44:30 +0530 Subject: [PATCH 14/33] update paths --- src/main/java/com/mathworks/ci/TestResultsViewAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 078aae2d..567e53f6 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -127,8 +127,8 @@ private void getTestSessionResults(List testSessionResults, JSONObject } // Calculate the relative path - Path path1 = Paths.get(baseFolder); - Path path2 = Paths.get(this.workspace.toURI()); + Path path1 = Paths.get(baseFolder).toAbsolutePath(); + Path path2 = Paths.get(this.workspace.toURI()).toAbsolutePath(); Path filePath = path2.relativize(path1); testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); From 1c068e42fff2c42b1e732719ce918c1dce9467dd Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 26 Sep 2024 10:52:02 +0530 Subject: [PATCH 15/33] update test workspace --- .../com/mathworks/ci/TestResultsViewAction.java | 13 ++++++------- .../com/mathworks/ci/TestResultsViewActionTest.java | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 567e53f6..7ef71ac3 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -6,9 +6,9 @@ */ import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -64,17 +64,14 @@ public TestResultsViewAction(Run build, FilePath workspace, String actionI public List> getTestResults() throws ParseException, InterruptedException, IOException { List> testResults = new ArrayList<>(); -// throw new Exception("Line 66"); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); - Path path = Paths.get(fl.toURI()); - try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(path), "UTF-8")) { + try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(Paths.get(fl.toURI())), StandardCharsets.UTF_8)) { totalCount = 0; passedCount = 0; failedCount = 0; incompleteCount = 0; notRunCount = totalCount; - // throw new Exception("Line 75"); JSONArray testArtifact = (JSONArray) new JSONParser().parse(reader); Iterator testArtifactIterator = testArtifact.iterator(); @@ -109,7 +106,7 @@ else if(jsonTestSessionResults instanceof JSONObject) { } private void getTestSessionResults(List testSessionResults, JSONObject jsonTestCase, Map map) throws IOException, InterruptedException { - String baseFolder = jsonTestCase.get("BaseFolder").toString(); + FilePath baseFolder = new FilePath(new File(jsonTestCase.get("BaseFolder").toString())); JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); // Not OS dependent @@ -127,9 +124,11 @@ private void getTestSessionResults(List testSessionResults, JSONObject } // Calculate the relative path - Path path1 = Paths.get(baseFolder).toAbsolutePath(); + Path path1 = Paths.get(baseFolder.toURI()).toAbsolutePath(); Path path2 = Paths.get(this.workspace.toURI()).toAbsolutePath(); Path filePath = path2.relativize(path1); + + // String filePath = baseFolder.toString().replace(this.workspace.getRemote(), ""); testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); TestCase testCase = new TestCase(); diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index 93f8c299..67e8de8b 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -158,7 +158,7 @@ public void verifyFailedTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = build.getWorkspace(); + final FilePath workspace = new FilePath(new File( "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -194,7 +194,7 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); From 7725c3afbeba5171f95497c9e6f6d20ef04e1333 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 11 Oct 2024 19:19:53 +0530 Subject: [PATCH 16/33] more debugging --- src/main/java/com/mathworks/ci/TestResultsViewAction.java | 4 ++-- .../integ/com/mathworks/ci/TestResultsViewActionTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 7ef71ac3..ab93f61d 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -125,11 +125,11 @@ private void getTestSessionResults(List testSessionResults, JSONObject // Calculate the relative path Path path1 = Paths.get(baseFolder.toURI()).toAbsolutePath(); - Path path2 = Paths.get(this.workspace.toURI()).toAbsolutePath(); + Path path2 = Paths.get(this.workspace.getParent().toURI()).toAbsolutePath(); Path filePath = path2.relativize(path1); // String filePath = baseFolder.toString().replace(this.workspace.getRemote(), ""); - testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); + testFile.setFilePath(filePath.toString()); TestCase testCase = new TestCase(); testCase.setName(testCaseName); diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index 67e8de8b..3bb2f5f5 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -158,7 +158,7 @@ public void verifyFailedTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File( "workspace")); + final FilePath workspace = new FilePath(new File("", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -194,7 +194,7 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("workspace")); + final FilePath workspace = new FilePath(new File("", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); From 16f09880b520d94fc7f6698001d356e709eb5912 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 11 Oct 2024 21:14:13 +0530 Subject: [PATCH 17/33] fix testcase workspace --- .gitignore | 1 + src/main/java/com/mathworks/ci/TestResultsViewAction.java | 2 ++ .../java/integ/com/mathworks/ci/TestResultsViewActionTest.java | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 61d648e0..5f1e8a6c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ src/main/resources/**/run-matlab-command* src/main/resources/license.txt .idea/ +matlab.iml **/.DS_Store \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index ab93f61d..ca521a5a 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -128,6 +128,8 @@ private void getTestSessionResults(List testSessionResults, JSONObject Path path2 = Paths.get(this.workspace.getParent().toURI()).toAbsolutePath(); Path filePath = path2.relativize(path1); + // System.out.println(String.format("%s, %s, %s", path1, path2, filePath)); + // String filePath = baseFolder.toString().replace(this.workspace.getRemote(), ""); testFile.setFilePath(filePath.toString()); diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index 3bb2f5f5..bb0effd6 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -194,7 +194,7 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:\\workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); From 213cfad7e83eeb29f01366ebe135d4b201f23fbd Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 11 Oct 2024 21:38:05 +0530 Subject: [PATCH 18/33] final fix (hopefully) --- .../ci/TestResultsViewActionTest.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index bb0effd6..e520137e 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -77,7 +77,7 @@ private URL getResource(String resource) { @Test public void verifyAllTestsReturned() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -104,7 +104,7 @@ public void verifyAllTestsReturned() throws ExecutionException, InterruptedExcep @Test public void verifyTotalTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -122,7 +122,7 @@ public void verifyTotalTestsCount() throws ExecutionException, InterruptedExcept @Test public void verifyPassedTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -140,7 +140,7 @@ public void verifyPassedTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyFailedTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -158,7 +158,7 @@ public void verifyFailedTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -176,7 +176,7 @@ public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedE @Test public void verifyNotRunTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -194,7 +194,7 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("C:\\workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -215,7 +215,7 @@ public void verifyTestFilePath() throws ExecutionException, InterruptedException @Test public void verifyTestFileName() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -236,7 +236,7 @@ public void verifyTestFileName() throws ExecutionException, InterruptedException @Test public void verifyTestFileDuration() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -257,7 +257,7 @@ public void verifyTestFileDuration() throws ExecutionException, InterruptedExcep @Test public void verifyTestFileStatus() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -278,7 +278,7 @@ public void verifyTestFileStatus() throws ExecutionException, InterruptedExcepti @Test public void verifyTestCaseName() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -303,7 +303,7 @@ public void verifyTestCaseName() throws ExecutionException, InterruptedException @Test public void verifyTestCaseStatus() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -328,7 +328,7 @@ public void verifyTestCaseStatus() throws ExecutionException, InterruptedExcepti @Test public void verifyTestCaseDuration() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -353,7 +353,7 @@ public void verifyTestCaseDuration() throws ExecutionException, InterruptedExcep @Test public void verifyTestCaseDiagnostics() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -375,7 +375,7 @@ public void verifyTestCaseDiagnostics() throws ExecutionException, InterruptedEx @Test public void verifyActionID() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("", "workspace")); + final FilePath workspace = new FilePath(new File("C:", "workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); From 46666c988563a8d15fb5a78ee138ce218008d984 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 11 Oct 2024 22:12:15 +0530 Subject: [PATCH 19/33] revert filepath --- .../java/com/mathworks/ci/TestResultsViewAction.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index ca521a5a..d3a4c8b0 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -125,13 +125,10 @@ private void getTestSessionResults(List testSessionResults, JSONObject // Calculate the relative path Path path1 = Paths.get(baseFolder.toURI()).toAbsolutePath(); - Path path2 = Paths.get(this.workspace.getParent().toURI()).toAbsolutePath(); + Path path2 = Paths.get(this.workspace.toURI()).toAbsolutePath(); Path filePath = path2.relativize(path1); - - // System.out.println(String.format("%s, %s, %s", path1, path2, filePath)); - - // String filePath = baseFolder.toString().replace(this.workspace.getRemote(), ""); - testFile.setFilePath(filePath.toString()); + + testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); TestCase testCase = new TestCase(); testCase.setName(testCaseName); From cb2f6e829a1ab1ae0b078fa4c375d458db02da21 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Fri, 11 Oct 2024 22:48:39 +0530 Subject: [PATCH 20/33] remove absolute path --- src/main/java/com/mathworks/ci/TestResultsViewAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index d3a4c8b0..4f5a3dfa 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -124,10 +124,10 @@ private void getTestSessionResults(List testSessionResults, JSONObject } // Calculate the relative path - Path path1 = Paths.get(baseFolder.toURI()).toAbsolutePath(); - Path path2 = Paths.get(this.workspace.toURI()).toAbsolutePath(); + Path path1 = Paths.get(baseFolder.toURI()); + Path path2 = Paths.get(this.workspace.toURI()); Path filePath = path2.relativize(path1); - + testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); TestCase testCase = new TestCase(); From fb7793b0fa836b3c2e0b47a85a7138a787b9eb93 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Mon, 14 Oct 2024 09:59:51 +0530 Subject: [PATCH 21/33] update workspace path --- .../integ/com/mathworks/ci/TestResultsViewActionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index e520137e..eb485d7f 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -176,7 +176,7 @@ public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedE @Test public void verifyNotRunTestsCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("C:", "workspace")); + final FilePath workspace = new FilePath(new File("C:\\workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); @@ -194,7 +194,7 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("C:", "workspace")); + final FilePath workspace = new FilePath(new File("C:\\workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); From 678a12def958868f1a43ebb944e721654780ef56 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Mon, 14 Oct 2024 10:32:21 +0530 Subject: [PATCH 22/33] add logger --- .../com/mathworks/ci/TestResultsViewAction.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 4f5a3dfa..0e49bd63 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -30,6 +30,8 @@ import jenkins.model.RunAction2; +import java.util.logging.Logger; + public class TestResultsViewAction implements RunAction2 { private transient Run build; private FilePath workspace; @@ -106,6 +108,8 @@ else if(jsonTestSessionResults instanceof JSONObject) { } private void getTestSessionResults(List testSessionResults, JSONObject jsonTestCase, Map map) throws IOException, InterruptedException { + final Logger logger = Logger.getLogger(TestResultsViewAction.class.getName()); + FilePath baseFolder = new FilePath(new File(jsonTestCase.get("BaseFolder").toString())); JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); @@ -123,11 +127,20 @@ private void getTestSessionResults(List testSessionResults, JSONObject testSessionResults.add(testFile); } + logger.info(baseFolder.toString()); + logger.info(baseFolder.toURI().toString()); + logger.info(this.workspace.toString()); + logger.info(this.workspace.toURI().toString() + "\n"); + // Calculate the relative path Path path1 = Paths.get(baseFolder.toURI()); Path path2 = Paths.get(this.workspace.toURI()); Path filePath = path2.relativize(path1); + logger.info(filePath.toString() + "\n"); + + logger.info(this.workspace.getName() + File.separator + filePath.toString() + "\n"); + testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); TestCase testCase = new TestCase(); From 7b746fd72eccc127953a8d1734f1b1193ea9d8c5 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 15 Oct 2024 11:46:36 +0530 Subject: [PATCH 23/33] update test --- .../mathworks/ci/TestResultsViewAction.java | 13 ---- .../ci/TestResultsViewActionTest.java | 29 +++++++- .../t1/linux/matlabTestResults.json | 73 +++++++++++++++++++ .../t1/mac/matlabTestResults.json | 73 +++++++++++++++++++ .../t1/{ => windows}/matlabTestResults.json | 2 +- 5 files changed, 172 insertions(+), 18 deletions(-) create mode 100644 src/test/resources/testArtifacts/t1/linux/matlabTestResults.json create mode 100644 src/test/resources/testArtifacts/t1/mac/matlabTestResults.json rename src/test/resources/testArtifacts/t1/{ => windows}/matlabTestResults.json (93%) diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 0e49bd63..4f5a3dfa 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -30,8 +30,6 @@ import jenkins.model.RunAction2; -import java.util.logging.Logger; - public class TestResultsViewAction implements RunAction2 { private transient Run build; private FilePath workspace; @@ -108,8 +106,6 @@ else if(jsonTestSessionResults instanceof JSONObject) { } private void getTestSessionResults(List testSessionResults, JSONObject jsonTestCase, Map map) throws IOException, InterruptedException { - final Logger logger = Logger.getLogger(TestResultsViewAction.class.getName()); - FilePath baseFolder = new FilePath(new File(jsonTestCase.get("BaseFolder").toString())); JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); @@ -127,20 +123,11 @@ private void getTestSessionResults(List testSessionResults, JSONObject testSessionResults.add(testFile); } - logger.info(baseFolder.toString()); - logger.info(baseFolder.toURI().toString()); - logger.info(this.workspace.toString()); - logger.info(this.workspace.toURI().toString() + "\n"); - // Calculate the relative path Path path1 = Paths.get(baseFolder.toURI()); Path path2 = Paths.get(this.workspace.toURI()); Path filePath = path2.relativize(path1); - logger.info(filePath.toString() + "\n"); - - logger.info(this.workspace.getName() + File.separator + filePath.toString() + "\n"); - testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); TestCase testCase = new TestCase(); diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index eb485d7f..619ce29e 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -194,17 +194,38 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep @Test public void verifyTestFilePath() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); - final FilePath workspace = new FilePath(new File("C:\\workspace")); final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + + String os = System.getProperty("os.name").toLowerCase(); + String testFolder = "testArtifacts/t1/"; + String workspaceParent = ""; + String expectedParentPath = ""; + if (os.contains("win")) { + testFolder += "windows/"; + workspaceParent = "C:\\"; + expectedParentPath = "workspace\\visualization\\"; + } else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) { + testFolder += "linux/"; + workspaceParent = "/home/user/"; + expectedParentPath = "workspace/visualization/"; + } else if (os.contains("mac")) { + testFolder += "mac/"; + workspaceParent = "/Users/username/"; + expectedParentPath = "workspace/visualization/"; + } else { + throw new RuntimeException("Unsupported OS: " + os); + } + copyFileInWorkspace(testFolder + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + final FilePath workspace = new FilePath(new File(workspaceParent + "workspace")); + TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); String actualPath1 = ta.get(0).get(0).getFilePath(); - Assert.assertEquals("Incorrect test file path","workspace\\visualization\\tests",actualPath1); + Assert.assertEquals("Incorrect test file path",expectedParentPath + "tests",actualPath1); String actualPath2 = ta.get(1).get(0).getFilePath(); - Assert.assertEquals("Incorrect test file path","workspace\\visualization\\duplicate tests",actualPath2); + Assert.assertEquals("Incorrect test file path",expectedParentPath + "duplicate_tests",actualPath2); } /** diff --git a/src/test/resources/testArtifacts/t1/linux/matlabTestResults.json b/src/test/resources/testArtifacts/t1/linux/matlabTestResults.json new file mode 100644 index 00000000..b2357737 --- /dev/null +++ b/src/test/resources/testArtifacts/t1/linux/matlabTestResults.json @@ -0,0 +1,73 @@ +[ + [ + { + "TestResult": { + "Duration": 0.1, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples1/testNonLeapYear", + "Passed": true, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "/home/user/workspace/visualization/tests" + }, + { + "TestResult": { + "Duration": 0.4, + "Details": { + "SimulinkTestManagerResults": [], + "DiagnosticRecord": { + "TestDiagnosticResults": [], + "FrameworkDiagnosticResults": { + "Artifacts": [], + "DiagnosticText": "SampleDiagnosticsText" + }, + "AdditionalDiagnosticResults": [], + "Stack": { + "file": "/home/user/workspace/visualization/tests/TestExamples1.m", + "name": "TestExamples1.testLeapYear", + "line": 35 + }, + "Event": "SampleDiagnosticsEvent", + "EventScope": "TestMethod", + "EventLocation": "TestExamples1/testLeapYear", + "Report": "SampleDiagnosticsReport" + } + }, + "Name": "TestExamples1/testLeapYear", + "Passed": false, + "Failed": true, + "Incomplete": true + }, + "BaseFolder": "/home/user/workspace/visualization/tests" + }, + { + "TestResult": { + "Duration": 0.0, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples1/testInvalidDateFormat", + "Passed": false, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "/home/user/workspace/visualization/tests" + } + ], + { + "TestResult": { + "Duration": 0.1, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples2/testNonLeapYear", + "Passed": true, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "/home/user/workspace/visualization/duplicate_tests" + } +] \ No newline at end of file diff --git a/src/test/resources/testArtifacts/t1/mac/matlabTestResults.json b/src/test/resources/testArtifacts/t1/mac/matlabTestResults.json new file mode 100644 index 00000000..790d34ad --- /dev/null +++ b/src/test/resources/testArtifacts/t1/mac/matlabTestResults.json @@ -0,0 +1,73 @@ +[ + [ + { + "TestResult": { + "Duration": 0.1, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples1/testNonLeapYear", + "Passed": true, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "/Users/username/workspace/visualization/tests" + }, + { + "TestResult": { + "Duration": 0.4, + "Details": { + "SimulinkTestManagerResults": [], + "DiagnosticRecord": { + "TestDiagnosticResults": [], + "FrameworkDiagnosticResults": { + "Artifacts": [], + "DiagnosticText": "SampleDiagnosticsText" + }, + "AdditionalDiagnosticResults": [], + "Stack": { + "file": "/Users/username/workspace/visualization/tests/TestExamples1.m", + "name": "TestExamples1.testLeapYear", + "line": 35 + }, + "Event": "SampleDiagnosticsEvent", + "EventScope": "TestMethod", + "EventLocation": "TestExamples1/testLeapYear", + "Report": "SampleDiagnosticsReport" + } + }, + "Name": "TestExamples1/testLeapYear", + "Passed": false, + "Failed": true, + "Incomplete": true + }, + "BaseFolder": "/Users/username/workspace/visualization/tests" + }, + { + "TestResult": { + "Duration": 0.0, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples1/testInvalidDateFormat", + "Passed": false, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "/Users/username/workspace/visualization/tests" + } + ], + { + "TestResult": { + "Duration": 0.1, + "Details": { + "SimulinkTestManagerResults": [] + }, + "Name": "TestExamples2/testNonLeapYear", + "Passed": true, + "Failed": false, + "Incomplete": false + }, + "BaseFolder": "/Users/username/workspace/visualization/duplicate_tests" + } +] \ No newline at end of file diff --git a/src/test/resources/testArtifacts/t1/matlabTestResults.json b/src/test/resources/testArtifacts/t1/windows/matlabTestResults.json similarity index 93% rename from src/test/resources/testArtifacts/t1/matlabTestResults.json rename to src/test/resources/testArtifacts/t1/windows/matlabTestResults.json index b0da2dcb..69200384 100644 --- a/src/test/resources/testArtifacts/t1/matlabTestResults.json +++ b/src/test/resources/testArtifacts/t1/windows/matlabTestResults.json @@ -68,6 +68,6 @@ "Failed": false, "Incomplete": false }, - "BaseFolder": "C:\\workspace\\visualization\\duplicate tests" + "BaseFolder": "C:\\workspace\\visualization\\duplicate_tests" } ] \ No newline at end of file From 2d81d415af79479ff7b421fb063f18fd39f555c3 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 15 Oct 2024 13:51:52 +0530 Subject: [PATCH 24/33] update test data --- .../ci/TestResultsViewActionTest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java index 619ce29e..178f1064 100644 --- a/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/TestResultsViewActionTest.java @@ -81,7 +81,7 @@ public void verifyAllTestsReturned() throws ExecutionException, InterruptedExcep final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); int actualTestSessions = ta.size(); @@ -108,7 +108,7 @@ public void verifyTotalTestsCount() throws ExecutionException, InterruptedExcept final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getTotalCount(); Assert.assertEquals("Incorrect total tests count",4,actualCount); @@ -126,7 +126,7 @@ public void verifyPassedTestsCount() throws ExecutionException, InterruptedExcep final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getPassedCount(); Assert.assertEquals("Incorrect passed tests count",2,actualCount); @@ -144,7 +144,7 @@ public void verifyFailedTestsCount() throws ExecutionException, InterruptedExcep final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getFailedCount(); Assert.assertEquals("Incorrect failed tests count",1,actualCount); @@ -162,7 +162,7 @@ public void verifyIncompleteTestsCount() throws ExecutionException, InterruptedE final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getIncompleteCount(); Assert.assertEquals("Incorrect incomplete tests count",0,actualCount); @@ -180,7 +180,7 @@ public void verifyNotRunTestsCount() throws ExecutionException, InterruptedExcep final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); int actualCount = ac.getNotRunCount(); Assert.assertEquals("Incorrect not run tests count",1,actualCount); @@ -240,7 +240,7 @@ public void verifyTestFileName() throws ExecutionException, InterruptedException final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); String actualName1 = ta.get(0).get(0).getName(); @@ -261,7 +261,7 @@ public void verifyTestFileDuration() throws ExecutionException, InterruptedExcep final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); Double actualDuration1 = ta.get(0).get(0).getDuration(); @@ -282,7 +282,7 @@ public void verifyTestFileStatus() throws ExecutionException, InterruptedExcepti final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); String actualStatus1 = ta.get(0).get(0).getStatus(); @@ -303,7 +303,7 @@ public void verifyTestCaseName() throws ExecutionException, InterruptedException final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); String actualName1_1 = ta.get(0).get(0).getTestCases().get(0).getName(); @@ -328,7 +328,7 @@ public void verifyTestCaseStatus() throws ExecutionException, InterruptedExcepti final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); String actualStatus1_1 = ta.get(0).get(0).getTestCases().get(0).getStatus(); @@ -353,7 +353,7 @@ public void verifyTestCaseDuration() throws ExecutionException, InterruptedExcep final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); Double actualDuration1_1 = ta.get(0).get(0).getTestCases().get(0).getDuration(); @@ -378,7 +378,7 @@ public void verifyTestCaseDiagnostics() throws ExecutionException, InterruptedEx final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); List> ta = ac.getTestResults(); TestDiagnostics diagnostics = ta.get(0).get(0).getTestCases().get(1).getDiagnostics().get(0); @@ -400,7 +400,7 @@ public void verifyActionID() throws ExecutionException, InterruptedException, UR final String actionID = "abc123"; final String targetFile = MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + actionID + ".json"; FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("testArtifacts/t1/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); + copyFileInWorkspace("testArtifacts/t1/windows/" + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + ".json",targetFile,artifactRoot); TestResultsViewAction ac = new TestResultsViewAction(build, workspace, actionID); String actualActionID = ac.getActionID(); Assert.assertEquals("Incorrect action ID",actionID,actualActionID); From 06b2d12c03f0c92ab63098ba8f111b42e216778f Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 15 Oct 2024 14:47:58 +0530 Subject: [PATCH 25/33] Specify java version in yml --- azure-pipelines.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 30ae949c..afd10b7a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -19,6 +19,12 @@ trigger: - master steps: + - task: JavaToolInstaller@0 + inputs: + versionSpec: '11' + jdkArchitectureOption: 'x64' + jdkSourceOption: 'PreInstalled' + - task: Maven@4 inputs: mavenPomFile: 'pom.xml' From c15e013e3803b44fa1b0eff1dc97a1870d1ded22 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 22 Oct 2024 11:01:51 +0530 Subject: [PATCH 26/33] update slave label --- .../integ/com/mathworks/ci/RunMatlabBuildStepTest.java | 5 ++++- .../integ/com/mathworks/ci/RunMatlabCommandStepTest.java | 5 ++++- .../integ/com/mathworks/ci/RunMatlabTestsStepTest.java | 8 ++++++-- .../mathworks/ci/actions/RunMatlabBuildActionTest.java | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java index 8deb0ca0..3b86ef2a 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java @@ -77,13 +77,16 @@ public void verifyMATLABstartsInWorkspace() throws Exception { @Test public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); +// s.setLabelString("slave0"); + project.setDefinition(new CpsFlowDefinition( - "node('!master') { runMATLABBuild() }", true)); + "node('!built-in') { runMATLABBuild() }", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("Running on Jenkins", build); + j.assertLogContains("Running on " + s.getNodeName(), build); } /* diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java index 66c8e834..4144d84d 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -80,13 +80,16 @@ public void verifyMATLABstartsInWorkspace() throws Exception { @Test public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); + s.setLabelString("slave0"); + project.setDefinition(new CpsFlowDefinition( - "node('!master') { runMATLABCommand(command: 'pwd')}", true)); + "node('slave0') { runMATLABCommand(command: 'pwd')}", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("Running on Jenkins", build); + j.assertLogContains("Running on " + s.getNodeName(), build); } /* diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java index 0c49d86f..64ccb32b 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -65,12 +65,16 @@ public void verifyMATLABPathSet() throws Exception { @Test public void verifyOnslave() throws Exception { DumbSlave s = j.createOnlineSlave(); + s.setLabelString("slave0"); + project.setDefinition(new CpsFlowDefinition( - "node('!master') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); - s.getWorkspaceFor(project); + "node('slave0') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); + + s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("Running on Jenkins", build); + j.assertLogContains("Running on " + s.getNodeName(), build); } /* diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java index bfd66117..caa3b7cb 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java @@ -55,7 +55,7 @@ public void init() { when(params.getTaskListener()).thenReturn(listener); when(listener.getLogger()).thenReturn(out); - when(params.getBuild()).thenReturn(build); + lenient().when(params.getBuild()).thenReturn(build); } } From 40a7af4cbeeb45ccaef1a2f2d00bf949d76db0cb Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 22 Oct 2024 12:30:36 +0530 Subject: [PATCH 27/33] add null checks --- .../ci/UseMatlabVersionBuildWrapper.java | 15 +++++++++++++-- .../ci/utilities/MatlabCommandRunner.java | 17 +++++++++++++---- .../mathworks/ci/RunMatlabBuildStepTest.java | 5 +---- .../mathworks/ci/RunMatlabCommandStepTest.java | 7 ++----- .../mathworks/ci/RunMatlabTestsStepTest.java | 9 +++------ 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index eb8f0399..e72f621a 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -188,14 +188,25 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher // Set Environment variable setEnv(initialEnvironment); + String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener); + if (nodeSpecificMatlab == null) { + throw new IOException("Failed to get node-specific MATLAB path"); + } + + String nodeSpecificExecutable = getNodeSpecificExecutable(launcher); + if (nodeSpecificExecutable == null) { + throw new IOException("Failed to get node-specific MATLAB executable"); + } + FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), - getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher)); + nodeSpecificMatlab + nodeSpecificExecutable); if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } + // Add "matlabroot" without bin as env variable which will be available across the build. - context.env("matlabroot", getNodeSpecificMatlab(Computer.currentComputer(), listener)); + context.env("matlabroot", nodeSpecificMatlab); // Add matlab bin to path to invoke MATLAB directly on command line. context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote()); // Specify which MATLAB was added to path. diff --git a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java index a69f9559..776c91fa 100644 --- a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java +++ b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java @@ -34,20 +34,29 @@ public class MatlabCommandRunner { public MatlabCommandRunner(MatlabActionParameters params) throws IOException, InterruptedException { this.params = params; this.additionalEnvVars = new HashMap(); - + FilePath workspace = params.getWorkspace(); - + if (workspace == null) { + throw new IllegalArgumentException("Workspace in MatlabActionParameters cannot be null"); + } + // Handle case where workspace doesn't exist if (!workspace.exists()) { workspace.mkdirs(); } - + // Create MATLAB folder FilePath tmpRoot = WorkspaceList.tempDir(workspace); + if (tmpRoot == null) { + throw new IOException("Failed to create temporary directory"); + } tmpRoot.mkdirs(); - + // Create temp folder this.tempFolder = tmpRoot.createTempDir("matlab", null); + if (this.tempFolder == null) { + throw new IOException("Failed to create MATLAB temporary directory"); + } } /** diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java index 3b86ef2a..88072661 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java @@ -51,7 +51,7 @@ public void verifyMATLABPathNotSet() throws Exception { public void verifyMATLABstartsInWorkspace() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition( - new CpsFlowDefinition("node('!master') { runMATLABBuild() }", true)); + new CpsFlowDefinition("node('!built-in') { runMATLABBuild() }", true)); FilePath workspace = s.getWorkspaceFor(project); String workspaceName = workspace.getName(); @@ -77,8 +77,6 @@ public void verifyMATLABstartsInWorkspace() throws Exception { @Test public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); -// s.setLabelString("slave0"); - project.setDefinition(new CpsFlowDefinition( "node('!built-in') { runMATLABBuild() }", true)); @@ -86,7 +84,6 @@ public void verifyPipelineOnSlave() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("Running on Jenkins", build); - j.assertLogContains("Running on " + s.getNodeName(), build); } /* diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java index 4144d84d..f4b37d2a 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -50,7 +50,7 @@ public void verifyMATLABPathNotSet() throws Exception { public void verifyMATLABstartsInWorkspace() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition( - new CpsFlowDefinition("node('!master') { runMATLABCommand(command: 'pwd')}", true)); + new CpsFlowDefinition("node('!built-in') { runMATLABCommand(command: 'pwd')}", true)); FilePath workspace = s.getWorkspaceFor(project); String workspaceName = workspace.getName(); @@ -80,16 +80,13 @@ public void verifyMATLABstartsInWorkspace() throws Exception { @Test public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); - s.setLabelString("slave0"); - project.setDefinition(new CpsFlowDefinition( - "node('slave0') { runMATLABCommand(command: 'pwd')}", true)); + "node('!built-in') { runMATLABCommand(command: 'pwd')}", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("Running on Jenkins", build); - j.assertLogContains("Running on " + s.getNodeName(), build); } /* diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java index 64ccb32b..5f864a3c 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -65,16 +65,13 @@ public void verifyMATLABPathSet() throws Exception { @Test public void verifyOnslave() throws Exception { DumbSlave s = j.createOnlineSlave(); - s.setLabelString("slave0"); - project.setDefinition(new CpsFlowDefinition( - "node('slave0') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); - - s.getWorkspaceFor(project); + "node('!built-in') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); + + s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("Running on Jenkins", build); - j.assertLogContains("Running on " + s.getNodeName(), build); } /* From 35178030b7310d91b1f25da2c3c59f539cc60272 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 22 Oct 2024 14:05:32 +0530 Subject: [PATCH 28/33] add null check --- .../com/mathworks/ci/UseMatlabVersionBuildWrapper.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index e72f621a..b4e31ce3 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -204,13 +204,18 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } + + FilePath matlabBinPath = matlabExecutablePath.getParent(); + if (matlabBinPath == null) { + throw new IOException("Failed to get MATLAB bin directory"); + } // Add "matlabroot" without bin as env variable which will be available across the build. context.env("matlabroot", nodeSpecificMatlab); // Add matlab bin to path to invoke MATLAB directly on command line. - context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote()); + context.env("PATH+matlabroot", matlabBinPath.getRemote()); // Specify which MATLAB was added to path. - listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath.getParent().getRemote()) + "\n"); + listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabBinPath.getRemote()) + "\n"); } private String getNodeSpecificExecutable(Launcher launcher) { From 34c1a5bebc919e21d91c0e946b811f1800355a74 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Tue, 5 Nov 2024 15:29:46 +0530 Subject: [PATCH 29/33] Update as per review comments --- .../mathworks/ci/MatlabBuilderConstants.java | 6 + .../ci/{TestCase.java => MatlabTestCase.java} | 42 +++--- ...ostics.java => MatlabTestDiagnostics.java} | 14 +- .../java/com/mathworks/ci/MatlabTestFile.java | 95 +++++++++++++ src/main/java/com/mathworks/ci/TestFile.java | 94 ------------ .../mathworks/ci/TestResultsViewAction.java | 134 +++++++++--------- .../ci/utilities/MatlabCommandRunner.java | 6 +- .../ci/TestResultsViewAction/index.jelly | 98 ++++++------- .../ci/TestResultsViewActionTest.java | 104 +++++++------- .../t1/linux/matlabTestResults.json | 29 +++- .../t1/mac/matlabTestResults.json | 29 +++- .../t1/windows/matlabTestResults.json | 29 +++- 12 files changed, 374 insertions(+), 306 deletions(-) rename src/main/java/com/mathworks/ci/{TestCase.java => MatlabTestCase.java} (59%) rename src/main/java/com/mathworks/ci/{TestDiagnostics.java => MatlabTestDiagnostics.java} (63%) create mode 100644 src/main/java/com/mathworks/ci/MatlabTestFile.java delete mode 100644 src/main/java/com/mathworks/ci/TestFile.java diff --git a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java index 8ec055a7..0cb374d3 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java +++ b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java @@ -43,6 +43,12 @@ public class MatlabBuilderConstants { public static final String TEST_RESULTS_VIEW_ARTIFACT = "matlabTestResults"; public static final String BUILD_ARTIFACT = "buildArtifact"; + + // MATLAB Test Result Statuses + public static final String PASSED = "Passed"; + public static final String FAILED = "Failed"; + public static final String INCOMPLETE = "Incomplete"; + public static final String NOT_RUN = "NotRun"; public static final String NEW_LINE = System.getProperty("line.separator"); diff --git a/src/main/java/com/mathworks/ci/TestCase.java b/src/main/java/com/mathworks/ci/MatlabTestCase.java similarity index 59% rename from src/main/java/com/mathworks/ci/TestCase.java rename to src/main/java/com/mathworks/ci/MatlabTestCase.java index d82f6e6c..939f309b 100644 --- a/src/main/java/com/mathworks/ci/TestCase.java +++ b/src/main/java/com/mathworks/ci/MatlabTestCase.java @@ -3,6 +3,8 @@ /** * Copyright 2024, The MathWorks Inc. * + * Class to store MATLAB test case information + * */ import java.util.List; @@ -10,9 +12,9 @@ import org.apache.commons.lang.RandomStringUtils; -public class TestCase { +public class MatlabTestCase { private String name; - private List diagnostics; + private List diagnostics; private boolean passed; private boolean failed; private boolean incomplete; @@ -20,26 +22,26 @@ public class TestCase { private Double duration; private String id; - public TestCase() { - name = ""; - diagnostics = new ArrayList(); - passed = false; - failed = false; - incomplete = false; - status = "NotRun"; - duration = 0.0; - id = RandomStringUtils.randomAlphanumeric(8); + public MatlabTestCase() { + this.name = ""; + this.diagnostics = new ArrayList(); + this.passed = false; + this.failed = false; + this.incomplete = false; + this.status = MatlabBuilderConstants.NOT_RUN; + this.duration = 0.0; + this.id = RandomStringUtils.randomAlphanumeric(8); } public void updateStatus() { - if (failed){ - status = "Failed"; + if (this.failed){ + this.status = MatlabBuilderConstants.FAILED; } - else if (incomplete) { - status = "Incomplete"; + else if (this.incomplete) { + this.status = MatlabBuilderConstants.INCOMPLETE; } - else if(passed) { - status = "Passed"; + else if(this.passed) { + this.status = MatlabBuilderConstants.PASSED; } } @@ -51,11 +53,11 @@ public void setName(String name) { this.name = name; } - public List getDiagnostics() { + public List getDiagnostics() { return this.diagnostics; } - public void setDiagnostics(List diagnostics) { + public void setDiagnostics(List diagnostics) { this.diagnostics = diagnostics; } @@ -100,6 +102,6 @@ public void setDuration(Double duration) { } public String getId() { - return id; + return this.id; } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/TestDiagnostics.java b/src/main/java/com/mathworks/ci/MatlabTestDiagnostics.java similarity index 63% rename from src/main/java/com/mathworks/ci/TestDiagnostics.java rename to src/main/java/com/mathworks/ci/MatlabTestDiagnostics.java index 6df882a7..6cf748e3 100644 --- a/src/main/java/com/mathworks/ci/TestDiagnostics.java +++ b/src/main/java/com/mathworks/ci/MatlabTestDiagnostics.java @@ -3,19 +3,21 @@ /** * Copyright 2024, The MathWorks Inc. * + * Class to store MATLAB test diagnostics information + * */ import org.apache.commons.lang.RandomStringUtils; -public class TestDiagnostics { +public class MatlabTestDiagnostics { private String event; private String report; private String id; - public TestDiagnostics() { - event = ""; - report = ""; - id = RandomStringUtils.randomAlphanumeric(8); + public MatlabTestDiagnostics() { + this.event = ""; + this.report = ""; + this.id = RandomStringUtils.randomAlphanumeric(8); } public String getEvent() { @@ -35,6 +37,6 @@ public void setReport(String report) { } public String getId() { - return id; + return this.id; } } diff --git a/src/main/java/com/mathworks/ci/MatlabTestFile.java b/src/main/java/com/mathworks/ci/MatlabTestFile.java new file mode 100644 index 00000000..7b3747b7 --- /dev/null +++ b/src/main/java/com/mathworks/ci/MatlabTestFile.java @@ -0,0 +1,95 @@ +package com.mathworks.ci; + +/** + * Copyright 2024, The MathWorks Inc. + * + * Class to store MATLAB test file information + * + */ + +import java.util.List; +import java.util.ArrayList; + +import org.apache.commons.lang.RandomStringUtils; + +public class MatlabTestFile { + private String path; + private String name; + private Double duration; + private String status; + private List matlabTestCases; + private String id; + + public MatlabTestFile() { + this.path = ""; + this.name = ""; + this.duration = 0.0; + this.status = MatlabBuilderConstants.NOT_RUN; + this.matlabTestCases = new ArrayList(); + this.id = RandomStringUtils.randomAlphanumeric(8); + } + + public void incrementDuration(Double matlabTestCaseDuration) { + this.duration += matlabTestCaseDuration; + } + + public void updateStatus(MatlabTestCase matlabTestCase) { + if (!this.status.equals(MatlabBuilderConstants.FAILED)) { + if (matlabTestCase.getFailed()){ + this.status = MatlabBuilderConstants.FAILED; + } + else if (!this.status.equals(MatlabBuilderConstants.INCOMPLETE)){ + if (matlabTestCase.getIncomplete()){ + this.status = MatlabBuilderConstants.INCOMPLETE; + } + else if (matlabTestCase.getPassed()){ + this.status = MatlabBuilderConstants.PASSED; + } + } + } + } + + public String getPath() { + return this.path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getDuration() { + return this.duration; + } + + public void setDuration(Double duration) { + this.duration = duration; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(String status) { + this.status = status; + } + + public List getMatlabTestCases() { + return this.matlabTestCases; + } + + public void setMatlabTestCases(List matlabTestCases) { + this.matlabTestCases = matlabTestCases; + } + + public String getId() { + return this.id; + } +} diff --git a/src/main/java/com/mathworks/ci/TestFile.java b/src/main/java/com/mathworks/ci/TestFile.java deleted file mode 100644 index b4453dc0..00000000 --- a/src/main/java/com/mathworks/ci/TestFile.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.mathworks.ci; - -/** - * Copyright 2024, The MathWorks Inc. - * - */ - -import java.util.List; -import java.util.ArrayList; - -import org.apache.commons.lang.RandomStringUtils; - -public class TestFile { - private String filePath; - private String name; - private Double duration; - private String status; - private List testCases; - private String id; - - public TestFile() { - filePath = ""; - name = ""; - duration = 0.0; - status = "NotRun"; - testCases = new ArrayList(); - - id = RandomStringUtils.randomAlphanumeric(8); - } - - public void incrementDuration(Double testCaseDuration) { - this.duration += testCaseDuration; - } - - public void updateStatus(TestCase testCase) { - if (!status.equals("Failed")){ - if (testCase.getFailed()){ - status = "Failed"; - } - else if (!status.equals("Incomplete")){ - if (testCase.getIncomplete()){ - status = "Incomplete"; - } - else if (testCase.getPassed()){ - status = "Passed"; - } - } - } - } - - public String getFilePath() { - return this.filePath; - } - - public void setFilePath(String filePath) { - this.filePath = filePath; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public Double getDuration() { - return this.duration; - } - - public void setDuration(Double duration) { - this.duration = duration; - } - - public String getStatus() { - return this.status; - } - - public void setStatus(String status) { - this.status = status; - } - - public List getTestCases() { - return this.testCases; - } - - public void setTestCases(List testCases) { - this.testCases = testCases; - } - - public String getId() { - return id; - } -} diff --git a/src/main/java/com/mathworks/ci/TestResultsViewAction.java b/src/main/java/com/mathworks/ci/TestResultsViewAction.java index 4f5a3dfa..eb5e1286 100644 --- a/src/main/java/com/mathworks/ci/TestResultsViewAction.java +++ b/src/main/java/com/mathworks/ci/TestResultsViewAction.java @@ -45,32 +45,31 @@ public TestResultsViewAction(Run build, FilePath workspace, String actionI this.workspace = workspace; this.actionID = actionID; - totalCount = 0; - passedCount = 0; - failedCount = 0; - incompleteCount = 0; - notRunCount = 0; + this.totalCount = 0; + this.passedCount = 0; + this.failedCount = 0; + this.incompleteCount = 0; + this.notRunCount = 0; try{ // Set test results counts getTestResults(); } catch (InterruptedException | IOException e) { - e.printStackTrace(); throw e; } catch (ParseException e) { e.printStackTrace(); } } - public List> getTestResults() throws ParseException, InterruptedException, IOException { - List> testResults = new ArrayList<>(); + public List> getTestResults() throws ParseException, InterruptedException, IOException { + List> testResults = new ArrayList<>(); FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json")); try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(Paths.get(fl.toURI())), StandardCharsets.UTF_8)) { - totalCount = 0; - passedCount = 0; - failedCount = 0; - incompleteCount = 0; - notRunCount = totalCount; + this.totalCount = 0; + this.passedCount = 0; + this.failedCount = 0; + this.incompleteCount = 0; + this.notRunCount = totalCount; JSONArray testArtifact = (JSONArray) new JSONParser().parse(reader); Iterator testArtifactIterator = testArtifact.iterator(); @@ -78,8 +77,8 @@ public List> getTestResults() throws ParseException, InterruptedE while(testArtifactIterator.hasNext()){ Object jsonTestSessionResults = testArtifactIterator.next(); - List testSessionResults = new ArrayList<>(); - Map map = new HashMap<>(); + List testSessionResults = new ArrayList<>(); + Map map = new HashMap<>(); if(jsonTestSessionResults instanceof JSONArray){ JSONArray jsonTestSessionResultsArray = (JSONArray) jsonTestSessionResults; @@ -105,81 +104,82 @@ else if(jsonTestSessionResults instanceof JSONObject) { return testResults; } - private void getTestSessionResults(List testSessionResults, JSONObject jsonTestCase, Map map) throws IOException, InterruptedException { + private void getTestSessionResults(List testSessionResults, JSONObject jsonTestCase, Map map) throws IOException, InterruptedException { FilePath baseFolder = new FilePath(new File(jsonTestCase.get("BaseFolder").toString())); - JSONObject testCaseResult = (JSONObject) jsonTestCase.get("TestResult"); + JSONObject matlabTestCaseResult = (JSONObject) jsonTestCase.get("TestResult"); // Not OS dependent - String[] testNameSplit = testCaseResult.get("Name").toString().split("/"); - String testFileName = testNameSplit[0]; - String testCaseName = testNameSplit[1]; - - TestFile testFile = map.get(baseFolder + File.separator + testFileName); - if(testFile == null) { - testFile = new TestFile(); - testFile.setName(testFileName); - - map.put(baseFolder + File.separator + testFileName, testFile); - testSessionResults.add(testFile); + String[] testNameSplit = matlabTestCaseResult.get("Name").toString().split("/"); + String matlabTestFileName = testNameSplit[0]; + String matlabTestCaseName = testNameSplit[1]; + + // Check if test's file was known or not + MatlabTestFile matlabTestFile = map.get(baseFolder + File.separator + matlabTestFileName); + if(matlabTestFile == null) { + matlabTestFile = new MatlabTestFile(); + matlabTestFile.setName(matlabTestFileName); + + map.put(baseFolder + File.separator + matlabTestFileName, matlabTestFile); + testSessionResults.add(matlabTestFile); } // Calculate the relative path Path path1 = Paths.get(baseFolder.toURI()); Path path2 = Paths.get(this.workspace.toURI()); - Path filePath = path2.relativize(path1); - - testFile.setFilePath(this.workspace.getName() + File.separator + filePath.toString()); - - TestCase testCase = new TestCase(); - testCase.setName(testCaseName); - testCase.setPassed((boolean) testCaseResult.get("Passed")); - testCase.setFailed((boolean) testCaseResult.get("Failed")); - testCase.setIncomplete((boolean) testCaseResult.get("Incomplete")); - if (testCaseResult.get("Duration") instanceof Long) { - testCase.setDuration(((Long) testCaseResult.get("Duration")).doubleValue()); - } else if (testCaseResult.get("Duration") instanceof Double) { - testCase.setDuration(((Double) testCaseResult.get("Duration"))); + Path relPath = path2.relativize(path1); + + matlabTestFile.setPath(this.workspace.getName() + File.separator + relPath.toString()); + + MatlabTestCase matlabTestCase = new MatlabTestCase(); + matlabTestCase.setName(matlabTestCaseName); + matlabTestCase.setPassed((boolean) matlabTestCaseResult.get("Passed")); + matlabTestCase.setFailed((boolean) matlabTestCaseResult.get("Failed")); + matlabTestCase.setIncomplete((boolean) matlabTestCaseResult.get("Incomplete")); + if (matlabTestCaseResult.get("Duration") instanceof Long) { + matlabTestCase.setDuration(((Long) matlabTestCaseResult.get("Duration")).doubleValue()); + } else if (matlabTestCaseResult.get("Duration") instanceof Double) { + matlabTestCase.setDuration(((Double) matlabTestCaseResult.get("Duration"))); } - testCase.updateStatus(); + matlabTestCase.updateStatus(); - Object diagnostics = ((JSONObject)testCaseResult.get("Details")).get("DiagnosticRecord"); + Object diagnostics = ((JSONObject)matlabTestCaseResult.get("Details")).get("DiagnosticRecord"); if(diagnostics instanceof JSONObject) { - TestDiagnostics testDiagnostics = new TestDiagnostics(); - testDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); - testDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); - testCase.getDiagnostics().add(testDiagnostics); + MatlabTestDiagnostics matlabTestDiagnostics = new MatlabTestDiagnostics(); + matlabTestDiagnostics.setEvent(((JSONObject)diagnostics).get("Event").toString()); + matlabTestDiagnostics.setReport(((JSONObject)diagnostics).get("Report").toString()); + matlabTestCase.getDiagnostics().add(matlabTestDiagnostics); } else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0) { Iterator diagnosticsIterator = ((JSONArray)diagnostics).iterator(); while(diagnosticsIterator.hasNext()) { JSONObject diagnosticItem = diagnosticsIterator.next(); - TestDiagnostics testDiagnostics = new TestDiagnostics(); - testDiagnostics.setEvent(diagnosticItem.get("Event").toString()); - testDiagnostics.setReport(diagnosticItem.get("Report").toString()); - testCase.getDiagnostics().add(testDiagnostics); + MatlabTestDiagnostics matlabTestDiagnostics = new MatlabTestDiagnostics(); + matlabTestDiagnostics.setEvent(diagnosticItem.get("Event").toString()); + matlabTestDiagnostics.setReport(diagnosticItem.get("Report").toString()); + matlabTestCase.getDiagnostics().add(matlabTestDiagnostics); } } - testFile.incrementDuration(testCase.getDuration()); - testFile.updateStatus(testCase); - testFile.getTestCases().add(testCase); - updateCount(testCase); + matlabTestFile.incrementDuration(matlabTestCase.getDuration()); + matlabTestFile.updateStatus(matlabTestCase); + matlabTestFile.getMatlabTestCases().add(matlabTestCase); + updateCount(matlabTestCase); } - private void updateCount(TestCase testCase) { - totalCount += 1; - if (testCase.getStatus().equals("NotRun")) { - notRunCount += 1; + private void updateCount(MatlabTestCase matlabTestCase) { + this.totalCount += 1; + if (matlabTestCase.getStatus().equals(MatlabBuilderConstants.NOT_RUN)) { + this.notRunCount += 1; } - else if (testCase.getPassed()) { - passedCount += 1; + else if (matlabTestCase.getPassed()) { + this.passedCount += 1; } - else if (testCase.getFailed()) { - failedCount += 1; + else if (matlabTestCase.getFailed()) { + this.failedCount += 1; } - else if (testCase.getIncomplete()) { - incompleteCount += 1; + else if (matlabTestCase.getIncomplete()) { + this.incompleteCount += 1; } } @@ -194,7 +194,7 @@ public void onLoad(Run run) { } public Run getBuild() { - return build; + return this.build; } @CheckForNull @@ -220,7 +220,7 @@ public FilePath getWorkspace() { } public String getActionID() { - return actionID; + return this.actionID; } public void setTotalCount(int totalCount) { diff --git a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java index 776c91fa..099210f2 100644 --- a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java +++ b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java @@ -37,7 +37,7 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In FilePath workspace = params.getWorkspace(); if (workspace == null) { - throw new IllegalArgumentException("Workspace in MatlabActionParameters cannot be null"); + throw new IllegalArgumentException("Workspace cannot be null"); } // Handle case where workspace doesn't exist @@ -48,14 +48,14 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In // Create MATLAB folder FilePath tmpRoot = WorkspaceList.tempDir(workspace); if (tmpRoot == null) { - throw new IOException("Failed to create temporary directory"); + throw new IOException("Failed to locate temporary directory"); } tmpRoot.mkdirs(); // Create temp folder this.tempFolder = tmpRoot.createTempDir("matlab", null); if (this.tempFolder == null) { - throw new IOException("Failed to create MATLAB temporary directory"); + throw new IOException("Failed to create a temporary MATLAB directory"); } } diff --git a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly index ca7ce93d..0ca5d95a 100644 --- a/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly +++ b/src/main/resources/com/mathworks/ci/TestResultsViewAction/index.jelly @@ -7,7 +7,7 @@ - + @@ -33,7 +33,7 @@


Incomplete

-