feature: Create test script json file This is for creating a json file that will be able to be sent by REST to an OSEE database. Change-Id: I9e037c23dabb0cdf916bc53f92448614ccc52aa5
diff --git a/org.eclipse.osee.ote.core.test/data/attribute.json b/org.eclipse.osee.ote.core.test/data/attribute.json new file mode 100644 index 0000000..1761f22 --- /dev/null +++ b/org.eclipse.osee.ote.core.test/data/attribute.json
@@ -0,0 +1 @@ +{"typeName":"Outfile URL","value":"TBD"} \ No newline at end of file
diff --git a/org.eclipse.osee.ote.core.test/data/createArtifacts.json b/org.eclipse.osee.ote.core.test/data/createArtifacts.json new file mode 100644 index 0000000..c3f90e7 --- /dev/null +++ b/org.eclipse.osee.ote.core.test/data/createArtifacts.json
@@ -0,0 +1 @@ +{"typeName":"TestRun","scriptName":"TBD","attribute":[{"typeName":"Outfile URL","value":"TBD"},{"typeName":"ElapsedDate","value":"0:08:15"}]} \ No newline at end of file
diff --git a/org.eclipse.osee.ote.core.test/data/testRunTransactionEndpoint.json b/org.eclipse.osee.ote.core.test/data/testRunTransactionEndpoint.json new file mode 100644 index 0000000..c64da72 --- /dev/null +++ b/org.eclipse.osee.ote.core.test/data/testRunTransactionEndpoint.json
@@ -0,0 +1 @@ +{"branch":"testRunBranch","txComment":"Created by ScriptJsonOutLogHandler","createArtifacts":{"typeName":"TestRun","scriptName":"TBD","attribute":[{"typeName":"Outfile URL","value":"TBD"},{"typeName":"ElapsedDate","value":"0:08:15"}]}} \ No newline at end of file
diff --git a/org.eclipse.osee.ote.core.test/data/testRunTransactionEndpointPublisher.json b/org.eclipse.osee.ote.core.test/data/testRunTransactionEndpointPublisher.json new file mode 100644 index 0000000..51f4a2c --- /dev/null +++ b/org.eclipse.osee.ote.core.test/data/testRunTransactionEndpointPublisher.json
@@ -0,0 +1 @@ +{"branch":"ote_test_run_transaction_endpoint_HARDCODED","txComment":"Created by TestRunTransactionEndpointPublisher","createArtifacts":{"typeName":"TestRun","scriptName":"org.eclipse.ote.simple.test.script.SimpleTestScript","attribute":[{"typeName":"Elapsed Date","value":"0:01:48"},{"typeName":"End Date","value":"Thu May 19 16:58:44 MST 2022"},{"typeName":"Start Date","value":"Thu May 19 16:56:55 MST 2022"},{"typeName":"Passed","value":"1"},{"typeName":"Failed","value":"0"},{"typeName":"Script Aborted","value":"true"},{"typeName":"Total Test Points","value":"1"},{"typeName":"OS Name","value":"Windows 10"},{"typeName":"OS Architecture","value":"amd64"},{"typeName":"OS Version","value":"10.0"},{"typeName":"OSEE Version","value":"1.0.0.v202202031707-DEV"},{"typeName":"OSEE Server Title","value":"OTE_CI"}]}} \ No newline at end of file
diff --git a/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/AttributeJsonPojoTest.java b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/AttributeJsonPojoTest.java new file mode 100644 index 0000000..2d9edfb --- /dev/null +++ b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/AttributeJsonPojoTest.java
@@ -0,0 +1,42 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.Test; + +/** + * @author Andy Jury + */ +public class AttributeJsonPojoTest { + + @Test + public void testAttributeJsonPojoTest() throws Exception { + + String path = "data/attribute.json"; + String jsonFileString = new String(Files.readAllBytes(Paths.get(path))); + + AttributeJsonPojo attribute = new AttributeJsonPojo(); + attribute.setTypeName("Outfile URL"); + attribute.setValue("TBD"); + + ObjectMapper objectMapper = new ObjectMapper(); + String inputJson = objectMapper.writeValueAsString(attribute); + + assertEquals(jsonFileString, inputJson); + } +}
diff --git a/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/CreateArtifactsJsonPojoTest.java b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/CreateArtifactsJsonPojoTest.java new file mode 100644 index 0000000..4a16c9a --- /dev/null +++ b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/CreateArtifactsJsonPojoTest.java
@@ -0,0 +1,53 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.Test; + +/** + * @author Andy Jury + */ +public class CreateArtifactsJsonPojoTest { + + @Test + public void testCreateArtifactsJsonPojoTest() throws Exception { + + String path = "data/createArtifacts.json"; + String jsonFileString = new String(Files.readAllBytes(Paths.get(path))); + + CreateArtifactsJsonPojo createArtifacts = new CreateArtifactsJsonPojo(); + createArtifacts.setTypeName("TestRun"); + createArtifacts.setScriptName("TBD"); + + AttributeJsonPojo attribute1 = new AttributeJsonPojo(); + attribute1.setTypeName("Outfile URL"); + attribute1.setValue("TBD"); + + AttributeJsonPojo attribute2 = new AttributeJsonPojo(); + attribute2.setTypeName("ElapsedDate"); + attribute2.setValue("0:08:15"); + + createArtifacts.addAttribute(attribute1); + createArtifacts.addAttribute(attribute2); + + ObjectMapper objectMapper = new ObjectMapper(); + String inputJson = objectMapper.writeValueAsString(createArtifacts); + + assertEquals(jsonFileString, inputJson); + } +}
diff --git a/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointJsonPojoTest.java b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointJsonPojoTest.java new file mode 100644 index 0000000..ca8a5a0 --- /dev/null +++ b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointJsonPojoTest.java
@@ -0,0 +1,60 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.Test; + +/** + * @author Andy Jury + */ +public class TestRunTransactionEndpointJsonPojoTest { + + @Test + public void testTestRunTransactionEndpointsJsonPojoTest() throws Exception { + + String path = "data/testRunTransactionEndpoint.json"; + String jsonFileString = new String(Files.readAllBytes(Paths.get(path))); + + TestRunTransactionEndpointJsonPojo testRunTransactionEndpoint = new TestRunTransactionEndpointJsonPojo(); + + testRunTransactionEndpoint.setBranch("testRunBranch"); + testRunTransactionEndpoint.setTxComment("Created by ScriptJsonOutLogHandler"); + + CreateArtifactsJsonPojo createArtifacts = new CreateArtifactsJsonPojo(); + createArtifacts.setTypeName("TestRun"); + createArtifacts.setScriptName("TBD"); + + AttributeJsonPojo attribute1 = new AttributeJsonPojo(); + attribute1.setTypeName("Outfile URL"); + attribute1.setValue("TBD"); + + AttributeJsonPojo attribute2 = new AttributeJsonPojo(); + attribute2.setTypeName("ElapsedDate"); + attribute2.setValue("0:08:15"); + + createArtifacts.addAttribute(attribute1); + createArtifacts.addAttribute(attribute2); + + testRunTransactionEndpoint.setCreateArtifacts(createArtifacts); + + ObjectMapper objectMapper = new ObjectMapper(); + String inputJson = objectMapper.writeValueAsString(testRunTransactionEndpoint); + + assertEquals(jsonFileString, inputJson); + } +}
diff --git a/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointPublisherTest.java b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointPublisherTest.java new file mode 100644 index 0000000..0d6017b --- /dev/null +++ b/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointPublisherTest.java
@@ -0,0 +1,111 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.Test; + +/** + * @author Andy Jury + */ +public class TestRunTransactionEndpointPublisherTest { + + @Test + public void testTestRunTransactionEndpointPublisher() throws IOException { + + String path = "data/testRunTransactionEndpointPublisher.json"; + String jsonFileString = new String(Files.readAllBytes(Paths.get(path))); + + TestRunTransactionEndpointJsonPojo testRunTransactionEndpoint = new TestRunTransactionEndpointJsonPojo(); + + testRunTransactionEndpoint.setBranch("ote_test_run_transaction_endpoint_HARDCODED"); + testRunTransactionEndpoint.setTxComment("Created by TestRunTransactionEndpointPublisher"); + + CreateArtifactsJsonPojo createArtifacts = new CreateArtifactsJsonPojo(); + createArtifacts.setTypeName("TestRun"); + createArtifacts.setScriptName("org.eclipse.ote.simple.test.script.SimpleTestScript"); + + AttributeJsonPojo attribute1 = new AttributeJsonPojo(); + attribute1.setTypeName("Elapsed Date"); + attribute1.setValue("0:01:48"); + createArtifacts.addAttribute(attribute1); + + AttributeJsonPojo attribute2 = new AttributeJsonPojo(); + attribute2.setTypeName("End Date"); + attribute2.setValue("Thu May 19 16:58:44 MST 2022"); + createArtifacts.addAttribute(attribute2); + + AttributeJsonPojo attribute3 = new AttributeJsonPojo(); + attribute3.setTypeName("Start Date"); + attribute3.setValue("Thu May 19 16:56:55 MST 2022"); + createArtifacts.addAttribute(attribute3); + + AttributeJsonPojo attribute4 = new AttributeJsonPojo(); + attribute4.setTypeName("Passed"); + attribute4.setValue("1"); + createArtifacts.addAttribute(attribute4); + + AttributeJsonPojo attribute5 = new AttributeJsonPojo(); + attribute5.setTypeName("Failed"); + attribute5.setValue("0"); + createArtifacts.addAttribute(attribute5); + + AttributeJsonPojo attribute6 = new AttributeJsonPojo(); + attribute6.setTypeName("Script Aborted"); + attribute6.setValue("true"); + createArtifacts.addAttribute(attribute6); + + AttributeJsonPojo attribute7 = new AttributeJsonPojo(); + attribute7.setTypeName("Total Test Points"); + attribute7.setValue("1"); + createArtifacts.addAttribute(attribute7); + + AttributeJsonPojo attribute8 = new AttributeJsonPojo(); + attribute8.setTypeName("OS Name"); + attribute8.setValue("Windows 10"); + createArtifacts.addAttribute(attribute8); + + AttributeJsonPojo attribute9 = new AttributeJsonPojo(); + attribute9.setTypeName("OS Architecture"); + attribute9.setValue("amd64"); + createArtifacts.addAttribute(attribute9); + + AttributeJsonPojo attribute10 = new AttributeJsonPojo(); + attribute10.setTypeName("OS Version"); + attribute10.setValue("10.0"); + createArtifacts.addAttribute(attribute10); + + AttributeJsonPojo attribute11 = new AttributeJsonPojo(); + attribute11.setTypeName("OSEE Version"); + attribute11.setValue("1.0.0.v202202031707-DEV"); + createArtifacts.addAttribute(attribute11); + + AttributeJsonPojo attribute12 = new AttributeJsonPojo(); + attribute12.setTypeName("OSEE Server Title"); + attribute12.setValue("OTE_CI"); + createArtifacts.addAttribute(attribute12); + + testRunTransactionEndpoint.setCreateArtifacts(createArtifacts); + + ObjectMapper objectMapper = new ObjectMapper(); + String inputJson = objectMapper.writeValueAsString(testRunTransactionEndpoint); + + assertEquals(jsonFileString, inputJson); + } + +}
diff --git a/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF b/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF index 7985420..19183f3 100644 --- a/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF +++ b/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF
@@ -74,6 +74,7 @@ com.fasterxml.jackson.databind;version="2.9.2", com.fasterxml.jackson.databind.jsontype;version="2.9.2", com.fasterxml.jackson.databind.module;version="2.9.2", + javax.ws.rs.client, javax.xml.parsers, org.apache.xml.serialize, org.eclipse.osee.framework.core.data,
diff --git a/org.eclipse.osee.ote.core/plugin.xml b/org.eclipse.osee.ote.core/plugin.xml index 56d6721..d66628a 100644 --- a/org.eclipse.osee.ote.core/plugin.xml +++ b/org.eclipse.osee.ote.core/plugin.xml
@@ -20,10 +20,10 @@ point="org.eclipse.core.runtime.products"> <product application="org.eclipse.osee.ote.core.server" - name="OteTestServer"> + name="F18OteCiTestServer"> <property name="appName" - value="OteTestServer"> + value="F18OteCiTestServer"> </property> </product> </extension>
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/AttributeJsonPojo.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/AttributeJsonPojo.java new file mode 100644 index 0000000..5032dff --- /dev/null +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/AttributeJsonPojo.java
@@ -0,0 +1,40 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +/** + * @author Andy Jury + */ +public class AttributeJsonPojo { + + private String typeName; + private String value; + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +}
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/CreateArtifactsJsonPojo.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/CreateArtifactsJsonPojo.java new file mode 100644 index 0000000..214ea0b --- /dev/null +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/CreateArtifactsJsonPojo.java
@@ -0,0 +1,55 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; + +/** + * @author Andy Jury + */ +public class CreateArtifactsJsonPojo { + + private String typeName; + private String scriptName; + private ArrayList<AttributeJsonPojo> attribute; + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + + @JsonProperty("attribute") + public ArrayList<AttributeJsonPojo> getAttributes() { + return attribute; + } + + public void addAttribute(AttributeJsonPojo attribute1) { + if (attribute == null) { + attribute = new ArrayList<AttributeJsonPojo>(); + } + this.attribute.add(attribute1); + } +}
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/MinimumPublisher.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/MinimumPublisher.java new file mode 100644 index 0000000..52c59f9 --- /dev/null +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/MinimumPublisher.java
@@ -0,0 +1,127 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.LogRecord; +import org.eclipse.osee.framework.jdk.core.persistence.XmlizableStream; +import org.eclipse.osee.ote.core.environment.interfaces.ITestPoint; +import org.eclipse.osee.ote.core.framework.outfile.xml.TestPointResults; +import org.eclipse.osee.ote.core.framework.outfile.xml.TimeSummary; +import org.eclipse.osee.ote.core.log.record.ScriptResultRecord; +import org.eclipse.osee.ote.core.log.record.TestPointRecord; +import org.eclipse.osee.ote.core.testPoint.CheckGroup; +import org.eclipse.osee.ote.core.testPoint.CheckPoint; +import org.eclipse.osee.ote.core.testPoint.Operation; + +/** + * @author Andy Jury + */ +public class MinimumPublisher { + + private final Map<String, Object> minimum; + + public MinimumPublisher(Map<String, Object> minimum) { + this.minimum = minimum; + } + + void publish(LogRecord logRecord) { + try { + minimum.put("machineName", InetAddress.getLocalHost().getHostName()); + } catch (UnknownHostException ex) { + logError(ex, "Unable to determine machine name"); + } + if (logRecord instanceof ScriptResultRecord) { + ScriptResultRecord srr = (ScriptResultRecord) logRecord; + minimum.put("ScriptName", logRecord.getMessage()); + for (XmlizableStream rec : srr.getResults()) { + if (rec instanceof TimeSummary) { + TimeSummary ts = (TimeSummary) rec; + minimum.put("elapsedTime", ts.getElapsedTime()); + minimum.put("startTime", ts.getStartTime()); + minimum.put("endTime", ts.getEndTime()); + } else if (rec instanceof TestPointResults) { + Map<String, Object> results = new HashMap<String, Object>(); + results.put("passes", ((TestPointResults) rec).getPasses()); + results.put("fails", ((TestPointResults) rec).getFails()); + results.put("interactives", ((TestPointResults) rec).getInteractives()); + results.put("aborted", ((TestPointResults) rec).isAborted()); + results.put("total", ((TestPointResults) rec).getTotal()); + minimum.put("results", results); + } + } + } else if (logRecord instanceof TestPointRecord) { + @SuppressWarnings("unchecked") + List<Object> testPoints = (List<Object>) minimum.get("testPoints"); + if (testPoints == null) { + testPoints = new ArrayList<Object>(); + minimum.put("testPoints", testPoints); + } + ITestPoint testPoint = ((TestPointRecord) logRecord).getTestPoint(); + int number = ((TestPointRecord) logRecord).getNumber(); + boolean overall = testPoint.isPass(); + handleTestPoint(testPoint, testPoints, number, "", overall, String.valueOf(number)); + } + } + + private void handleTestPoint(ITestPoint testPoint, List<Object> testPoints, int number, String groupName, boolean overallPass, String levelNum) { + if (testPoint instanceof CheckPoint) { + Map<String, Object> point = + convertCheckPoint((CheckPoint) testPoint, number, groupName, overallPass, levelNum); + testPoints.add(point); + } else if (testPoint instanceof CheckGroup) { + CheckGroup group = (CheckGroup) testPoint; + ArrayList<ITestPoint> groupPoints = group.getTestPoints(); + Operation op = group.getOperation(); + String curGroupName = group.getGroupName() + " [" + op.getName() + "]"; + for (int i = 0; i < groupPoints.size(); i++) { + ITestPoint tp = groupPoints.get(i); + handleTestPoint(tp, testPoints, number, curGroupName, overallPass, levelNum + "." + (i + 1)); + } + } + } + + private Map<String, Object> convertCheckPoint(CheckPoint checkPoint, int number, String groupName, boolean overallPass, String levelNum) { + Map<String, Object> tpMap = new HashMap<String, Object>(); + tpMap.put("name", checkPoint.getTestPointName()); + tpMap.put("expected", checkPoint.getExpected()); + tpMap.put("actual", checkPoint.getActual()); + tpMap.put("pass", checkPoint.isPass()); + tpMap.put("isInteractive", checkPoint.isInteractive()); + tpMap.put("number", number); + tpMap.put("overall", overallPass); + if (!groupName.isEmpty()) { + tpMap.put("groupName", groupName); + } + tpMap.put("tpLevel", levelNum); + return tpMap; + } + + private void logError(final Exception ex, final String message) { + if (message != null && message.trim().length() > 0) { + System.err.println(message); + } + if (ex != null) { + ex.printStackTrace(); + } else { + Throwable throwable = new Throwable(); + throwable.printStackTrace(); + } + } +}
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/ScriptJsonOutLogHandler.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/ScriptJsonOutLogHandler.java index 0001686..f0a696c 100644 --- a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/ScriptJsonOutLogHandler.java +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/ScriptJsonOutLogHandler.java
@@ -27,41 +27,34 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import org.eclipse.osee.framework.jdk.core.persistence.XmlizableStream; -import org.eclipse.osee.ote.core.environment.interfaces.ITestPoint; -import org.eclipse.osee.ote.core.framework.outfile.xml.TestPointResults; -import org.eclipse.osee.ote.core.framework.outfile.xml.TimeSummary; import org.eclipse.osee.ote.core.log.record.ScriptResultRecord; -import org.eclipse.osee.ote.core.log.record.TestPointRecord; import org.eclipse.osee.ote.core.log.record.json.LogRecordModule; -import org.eclipse.osee.ote.core.testPoint.CheckGroup; -import org.eclipse.osee.ote.core.testPoint.CheckPoint; -import org.eclipse.osee.ote.core.testPoint.Operation; /** * @author Andy Jury */ public class ScriptJsonOutLogHandler extends Handler { private final Map<String, Object> minimum = new HashMap<String, Object>(); + private final MinimumPublisher minimumPublisher; private final ObjectMapper mapper = new ObjectMapper(); private final File outfile; private ZipOutputStream zip; private final String distrStatement; + private final StringBuilder testRunTransactionEndpointJson = new StringBuilder(); + private final TestRunTransactionEndpointPublisher testRunTransactionEndpointPublisher; public ScriptJsonOutLogHandler(final File outFile, final String distributionStatement) { super(); outfile = outFile; distrStatement = distributionStatement; + this.minimumPublisher = new MinimumPublisher(minimum); + this.testRunTransactionEndpointPublisher = new TestRunTransactionEndpointPublisher(); } public ScriptJsonOutLogHandler(File outFile) { @@ -72,84 +65,16 @@ public synchronized void publish(final LogRecord logRecord) { if (isLoggable(logRecord)) { try { - publisihMinimum(logRecord); - } catch (Exception ex) { - logError(ex); - } - } - } - - private void publisihMinimum(LogRecord logRecord) { - try { - minimum.put("machineName", InetAddress.getLocalHost().getHostName()); - } catch (UnknownHostException ex) { - logError(ex, "Unable to determine machine name"); - } - if (logRecord instanceof ScriptResultRecord) { - ScriptResultRecord srr = (ScriptResultRecord) logRecord; - minimum.put("ScriptName", logRecord.getMessage()); - for (XmlizableStream rec : srr.getResults()) { - if (rec instanceof TimeSummary) { - TimeSummary ts = (TimeSummary) rec; - minimum.put("elapsedTime", ts.getElapsedTime()); - minimum.put("startTime", ts.getStartTime()); - minimum.put("endTime", ts.getEndTime()); - } else if (rec instanceof TestPointResults) { - Map<String, Object> results = new HashMap<String, Object>(); - results.put("passes", ((TestPointResults) rec).getPasses()); - results.put("fails", ((TestPointResults) rec).getFails()); - results.put("interactives", ((TestPointResults) rec).getInteractives()); - results.put("aborted", ((TestPointResults) rec).isAborted()); - results.put("total", ((TestPointResults) rec).getTotal()); - minimum.put("results", results); + minimumPublisher.publish(logRecord); + if (logRecord instanceof ScriptResultRecord) { + testRunTransactionEndpointJson.append(testRunTransactionEndpointPublisher.publish(logRecord)); } - } - } else if (logRecord instanceof TestPointRecord) { - @SuppressWarnings("unchecked") - List<Object> testPoints = (List<Object>) minimum.get("testPoints"); - if (testPoints == null) { - testPoints = new ArrayList<Object>(); - minimum.put("testPoints", testPoints); - } - ITestPoint testPoint = ((TestPointRecord) logRecord).getTestPoint(); - int number = ((TestPointRecord) logRecord).getNumber(); - boolean overall = testPoint.isPass(); - handleTestPoint(testPoint, testPoints, number, "", overall, String.valueOf(number)); - } - } - - private void handleTestPoint(ITestPoint testPoint, List<Object> testPoints, int number, String groupName, boolean overallPass, String levelNum) { - if (testPoint instanceof CheckPoint) { - Map<String, Object> point = convertCheckPoint((CheckPoint) testPoint, number, groupName, overallPass, levelNum); - testPoints.add(point); - } else if (testPoint instanceof CheckGroup) { - CheckGroup group = (CheckGroup) testPoint; - ArrayList<ITestPoint> groupPoints = group.getTestPoints(); - Operation op = group.getOperation(); - String curGroupName = group.getGroupName() + " [" + op.getName() + "]"; - for (int i = 0; i < groupPoints.size(); i++) { - ITestPoint tp = groupPoints.get(i); - handleTestPoint(tp, testPoints, number, curGroupName, overallPass, levelNum + "." + (i + 1)); + } catch (Exception ex) { + logError(ex, "Exception publishing items from outfile to json entries!"); } } } - private Map<String, Object> convertCheckPoint(CheckPoint checkPoint, int number, String groupName, boolean overallPass, String levelNum) { - Map<String, Object> tpMap = new HashMap<String, Object>(); - tpMap.put("name", checkPoint.getTestPointName()); - tpMap.put("expected", checkPoint.getExpected()); - tpMap.put("actual", checkPoint.getActual()); - tpMap.put("pass", checkPoint.isPass()); - tpMap.put("isInteractive", checkPoint.isInteractive()); - tpMap.put("number", number); - tpMap.put("overall", overallPass); - if (!groupName.isEmpty()) { - tpMap.put("groupName", groupName); - } - tpMap.put("tpLevel", levelNum); - return tpMap; - } - private boolean prepareToFlush() { setupJson(); return setupOutputFile(); @@ -187,7 +112,7 @@ result = false; } } catch (IOException ex) { - logError(ex, "Failed to get canaonical path from outFile"); + logError(ex, "Failed to get canonical path from outFile"); result = false; } return result; @@ -197,6 +122,19 @@ if (prepareToFlush()) { writeZipEntry("Minimum", minimum); writeZipEntry("DistributionStatement", distrStatement); + writeZipEntrySB("TestRunTransactionEndpoint", testRunTransactionEndpointJson); + } + } + + private void writeZipEntrySB(String basename, StringBuilder testRunTransactionEndpointJson2) { + try { + ZipEntry entry = new ZipEntry(basename + ".json"); + zip.putNextEntry(entry); + + byte[] data = testRunTransactionEndpointJson2.toString().getBytes(); + zip.write(data, 0, data.length); + } catch (IOException ex) { + logError(ex, "Exception generating zip archive with json files in it!"); } } @@ -215,11 +153,11 @@ input.close(); temp.delete(); } catch (JsonGenerationException ex) { - logError(ex); + logError(ex, "Exception generating json!"); } catch (JsonMappingException ex) { - logError(ex); + logError(ex, "Exception mapping json!"); } catch (IOException ex) { - logError(ex); + logError(ex, "Exception generating zip archive with json files in it!"); } } @@ -228,7 +166,7 @@ try { zip.close(); } catch (Exception ex) { - logError(ex); + logError(ex, "Exception closing zip archive!"); } } @@ -237,10 +175,6 @@ // don't call this method } - private void logError(final Exception ex) { - logError(ex); - } - private void logError(final Exception ex, final String message) { if (message != null && message.trim().length() > 0) { System.err.println(message);
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointJsonPojo.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointJsonPojo.java new file mode 100644 index 0000000..131616f --- /dev/null +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointJsonPojo.java
@@ -0,0 +1,49 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +/** + * @author Andy Jury + */ +public class TestRunTransactionEndpointJsonPojo { + + private String branch; + private String txComment; + + private CreateArtifactsJsonPojo createArtifacts; + + public String getBranch() { + return branch; + } + + public void setBranch(String branch) { + this.branch = branch; + } + + public String getTxComment() { + return txComment; + } + + public void setTxComment(String txComment) { + this.txComment = txComment; + } + + public CreateArtifactsJsonPojo getCreateArtifacts() { + return createArtifacts; + } + + public void setCreateArtifacts(CreateArtifactsJsonPojo createArtifacts) { + this.createArtifacts = createArtifacts; + } +}
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointPublisher.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointPublisher.java new file mode 100644 index 0000000..8737bc5 --- /dev/null +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/TestRunTransactionEndpointPublisher.java
@@ -0,0 +1,86 @@ +/********************************************************************* + * Copyright (c) 2022 Boeing + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Boeing - initial API and implementation + **********************************************************************/ + +package org.eclipse.osee.ote.core.framework.outfile; + +import java.util.logging.LogRecord; +import org.eclipse.osee.framework.core.util.JsonUtil; +import org.eclipse.osee.framework.jdk.core.persistence.XmlizableStream; +import org.eclipse.osee.ote.core.framework.outfile.xml.SystemInfo; +import org.eclipse.osee.ote.core.framework.outfile.xml.TestPointResults; +import org.eclipse.osee.ote.core.framework.outfile.xml.TimeSummary; +import org.eclipse.osee.ote.core.log.record.ScriptResultRecord; + +/** + * @author Andy Jury + */ +public class TestRunTransactionEndpointPublisher { + + private final TestRunTransactionEndpointJsonPojo testRunTransactionEndpointJsonPojo = + new TestRunTransactionEndpointJsonPojo(); + private String testRunTransactionEndpointJson = new String(); + private final String branchName = "ote_test_run_transaction_endpoint_HARDCODED"; //This should be connected to user supplied branch in future + private final CreateArtifactsJsonPojo createArtifacts = new CreateArtifactsJsonPojo(); + + public String publish(LogRecord logRecord) { + + testRunTransactionEndpointJsonPojo.setBranch(branchName); + testRunTransactionEndpointJsonPojo.setTxComment("Created by TestRunTransactionEndpointPublisher"); + + createArtifacts.setTypeName("TestRun"); + + if (logRecord instanceof ScriptResultRecord) { + ScriptResultRecord srr = (ScriptResultRecord) logRecord; + createArtifacts.setScriptName(logRecord.getMessage()); + AttributeJsonPojo attribute = new AttributeJsonPojo(); + + for (XmlizableStream rec : srr.getResults()) { + if (rec instanceof TimeSummary) { + TimeSummary timeSummary = (TimeSummary) rec; + addAttributeToCreateArtifacts("Elapsed Date", timeSummary.getElapsed()); + addAttributeToCreateArtifacts("End Date", timeSummary.getEndTime().toString()); + addAttributeToCreateArtifacts("Start Date", timeSummary.getStartTime().toString()); + } else if (rec instanceof TestPointResults) { + TestPointResults testPointResults = (TestPointResults) rec; + + addAttributeToCreateArtifacts("Passed", Integer.toString(testPointResults.getPasses())); + addAttributeToCreateArtifacts("Failed", Integer.toString(testPointResults.getFails())); + addAttributeToCreateArtifacts("Script Aborted", Boolean.toString(testPointResults.isAborted())); + addAttributeToCreateArtifacts("Total Test Points", Integer.toString(testPointResults.getTotal())); + } else if (rec instanceof SystemInfo) { + SystemInfo systemInfo = (SystemInfo) rec; + + addAttributeToCreateArtifacts("OS Name", (systemInfo.getOperatingSystemName())); + addAttributeToCreateArtifacts("OS Architecture", (systemInfo.getOperatingSystemArchitecture())); + addAttributeToCreateArtifacts("OS Version", (systemInfo.getOperatingSystemVersion())); + addAttributeToCreateArtifacts("OSEE Version", (systemInfo.getOseeCodeVersion())); + addAttributeToCreateArtifacts("OSEE Server Title", (systemInfo.getOteServerTitle())); + } + + } + } + + testRunTransactionEndpointJsonPojo.setCreateArtifacts(createArtifacts); + + testRunTransactionEndpointJson = JsonUtil.toJson(testRunTransactionEndpointJsonPojo); + return testRunTransactionEndpointJson; + } + + private void addAttributeToCreateArtifacts(String typeName, String value) { + AttributeJsonPojo attribute = new AttributeJsonPojo(); + attribute.setTypeName(typeName); + attribute.setValue(value); + createArtifacts.addAttribute(attribute); + + } +}
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/xml/SystemInfo.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/xml/SystemInfo.java index d21bec9..4f5cef5 100644 --- a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/xml/SystemInfo.java +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/outfile/xml/SystemInfo.java
@@ -13,10 +13,9 @@ package org.eclipse.osee.ote.core.framework.outfile.xml; +import com.fasterxml.jackson.annotation.JsonProperty; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; - -import com.fasterxml.jackson.annotation.JsonProperty; import org.eclipse.osee.framework.core.data.OseeCodeVersion; import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; import org.eclipse.osee.framework.jdk.core.persistence.XmlizableStream; @@ -59,7 +58,7 @@ } @JsonProperty - public String getOperatingSystem() { + public String getOperatingSystemName() { return System.getProperty("os.name"); } @@ -69,7 +68,7 @@ } @JsonProperty - public String getArchitecture() { + public String getOperatingSystemArchitecture() { return System.getProperty("os.arch"); }
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/ScriptLogHandler.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/ScriptLogHandler.java index c1a8cf5..dfeba15 100644 --- a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/ScriptLogHandler.java +++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/ScriptLogHandler.java
@@ -58,7 +58,7 @@ /** * ScriptLogHandler Constructor. Sets the outfile to log to and the test script that will be logged. It also * establishes the xml format to be used. - * + * * @param outFile Reference to the outfile that will be used to output the log. */ public ScriptLogHandler(File outFile, TestEnvironment testEnvironment) { @@ -74,13 +74,12 @@ OseeLog.log(TestEnvironment.class, Level.SEVERE, ex); } - ProcessingInstruction processingInstruction = - document.createProcessingInstruction("xml-stylesheet", - "type=\"text/xsl\" href=\"" + getXSLTransformName() + "\""); + ProcessingInstruction processingInstruction = document.createProcessingInstruction("xml-stylesheet", + "type=\"text/xsl\" href=\"" + getXSLTransformName() + "\""); document.appendChild(processingInstruction); records = new ArrayList<>(); - document.appendChild(document.createComment("OUTFILE_COMMNET")); + document.appendChild(document.createComment("OUTFILE_COMMENT")); this.testScriptElement = document.createElement("TestScript"); this.scriptInitElement = document.createElement("ScriptInit");