@@ -92,7 +92,7 @@
Diagnostics
@@ -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 @@
Open in MATLAB Online
-
+
@@ -33,7 +33,7 @@
Incomplete
-
+
${it.notRunCount}
Not Run
@@ -44,94 +44,94 @@
-
-
-
-
+
+
+
+
-
+
-
+
-
+
-
-
${testFile.name}
+
+ ${matlabTestFile.name}
-
+
-
+
-
+
-
-
-
+
+
+
-
+
-
+
-
+
-
+
- ${testCase.name}
+ ${matlabTestCase.name}
-
+
${diagnostic.event}
-
+
-
+
-
-
- ${testCase.duration}
+
+ ${matlabTestCase.duration}
@@ -139,8 +139,8 @@
-
- ${testFile.duration}
+
+ ${matlabTestFile.duration}
@@ -151,21 +151,21 @@