Skip to content
Snippets Groups Projects
Commit 258e54ff authored by Omar ALQAWASMEH's avatar Omar ALQAWASMEH
Browse files

deleted TestSuites classes

parent d57658b0
No related branches found
No related tags found
No related merge requests found
/**
*
*/
package org.etsi.saref.server.outputformatter;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Omar Qawasmeh
*
*
*/
@XmlRootElement
public class Property {
}
/**
*
*/
package org.etsi.saref.server.outputformatter;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.jena.sparql.expr.nodevalue.NodeValueString;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
/**
* @author Omar Qawasmeh
*
*
*/
@XmlRootElement(name = "testcase")
@XmlType(propOrder = { "systemErr", "systemOut", "info" })
public class TestCase {
public enum Status {
SUCCESS, WARNING, DANGER, UNKNOWN;
}
private String name;
private String className;
private String systemErr;
private String systemOut;
private String status; // either pass or failure
private String info;
private Status statusObj;
/**
* @return the status
*/
@XmlAttribute
public String getStatus() {
return status;
}
/**
* @param status
* the status to set
*/
public void setStatus(String status) {
this.status = status;
}
public boolean isSuccess() {
return statusObj == Status.SUCCESS;
}
public boolean isDanger() {
return statusObj == Status.DANGER;
}
public boolean isWarning() {
return statusObj == Status.WARNING;
}
public boolean isUnknown() {
return statusObj == Status.UNKNOWN;
}
/**
* @param status
* the status to set
*/
public void setStatusFlag(String status) {
switch (status) {
case "danger":
this.statusObj = Status.DANGER;
break;
case "success":
this.statusObj = Status.SUCCESS;
break;
case "warning":
this.statusObj = Status.WARNING;
break;
default:
this.statusObj = Status.UNKNOWN;
}
}
@XmlAttribute
public String getClassName() {
return className;
}
/**
* @param className
* the className to set
*/
public void setClassName(String className) {
this.className = className;
}
@XmlAttribute
public String getName() {
if(name != null) {
Parser parser = Parser.builder().build();
Node document = parser.parse(name);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
return null;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the systemErr
*/
public String getSystemErr() {
return systemErr;
}
/**
* @param systemErr
* the systemErr to set
*/
public void setSystemErr(String systemErr) {
this.systemErr = systemErr;
}
/**
* @return the systemOut
*/
public String getSystemOut() {
return systemOut;
}
/**
* @param systemOut
* the systemOut to set
*/
public void setSystemOut(String systemOut) {
this.systemOut = systemOut;
}
/**
* @return the info
*/
public String getInfo() {
if(info != null) {
Parser parser = Parser.builder().build();
Node document = parser.parse(info);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
return null;
}
/**
* @param info
* the info to set
*/
public void setInfo(String info) {
this.info = info;
}
}
/**
*
*/
package org.etsi.saref.server.outputformatter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Omar Qawasmeh
*
*
*/
@XmlRootElement(name = "testsuite")
@XmlType(propOrder = { "disabled", "time", "name", "testcase" })
public class TestSuite implements Serializable {
private int tests;
private boolean disabled;
private float time;
private String name;
private TestCase[] testCase;
private int nbWarning=-1, nbDanger=-1;
public TestCase[] getTestcase() {
return testCase;
}
public void setTestcase(TestCase[] testCase) {
this.testCase = testCase;
}
@XmlAttribute
public int getTests() {
return tests;
}
public void setTests(int tests) {
this.tests = tests;
}
public int getNbDanger() {
if(nbDanger == -1) {
nbDanger = 0;
for (int i = 0; i < testCase.length; i++) {
if(testCase[i].isDanger()) {
nbDanger++;
};
}
}
return nbDanger;
}
public int getNbWarning() {
if(nbWarning == -1) {
nbWarning = 0;
for (int i = 0; i < testCase.length; i++) {
if(testCase[i].isWarning()) {
nbWarning++;
};
}
}
return nbWarning;
}
@XmlAttribute
public boolean getDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
@XmlAttribute
public float getTime() {
return time;
}
public void setTime(float time) {
this.time = time;
}
@XmlAttribute
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void jaxbObjectToXML(TestSuite ts) {
try {
// Create JAXB Context
JAXBContext jaxbContext = JAXBContext.newInstance(TestSuite.class);
// Create Marshaller
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// Required formatting??
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// Store XML to File
File file = new File("report_output.xml");
// Writes XML file to file-system
jaxbMarshaller.marshal(ts, file);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
*
*/
package org.etsi.saref.server.resources;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.etsi.saref.server.outputformatter.TestCase;
import org.etsi.saref.server.outputformatter.TestSuite;
import org.glassfish.jersey.server.mvc.Template;
/**
* @author Omar Qawasmeh
*
*
*/
@Path("/report.html")
public class Report {
@GET
@Produces(MediaType.TEXT_HTML)
@Template(name = "/report")
public TestSuite fillReportPage(@QueryParam("q") String url)
throws WebApplicationException, JAXBException, IOException {
// url=getRedirectedLink(url).replaceAll("https://gitlab.emse.fr/saref/",
// "http://saref.gitlab.emse.fr/-/");
// url=url.replaceAll("/file/", "/");
System.out.println("omaaar .... " + url);
// To access the repository
// https://gitlab.emse.fr/saref/saref4abcd/-/jobs/artifacts/master/browse?job=checkshacl
// To access the xml file directly
// https://gitlab.emse.fr/saref/saref4abcd/-/jobs/artifacts/master/file/report_output.xml?job=checkshacl
JAXBContext jaxbContext;
jaxbContext = JAXBContext.newInstance(TestSuite.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TestSuite tstSuite = (TestSuite) jaxbUnmarshaller.unmarshal(new URL(url));
TestCase[] tstCase = tstSuite.getTestcase();
for (int i = 0; i < tstCase.length; i++) {
tstCase[i].setStatusFlag(tstCase[i].getStatus());
}
return tstSuite;
}
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_XML)
@Template(name = "/report")
public TestSuite fillReportPageForPost(TestSuite tstSuite)
throws WebApplicationException, JAXBException, IOException {
if(tstSuite == null) {
throw new ServerErrorException(Status.BAD_REQUEST);
}
TestCase[] tstCase = tstSuite.getTestcase();
for (int i = 0; i < tstCase.length; i++) {
tstCase[i].setStatusFlag(tstCase[i].getStatus());
}
return tstSuite;
}
public static String getRedirectedLink(String URL) throws MalformedURLException, IOException {
String url = URL;
java.net.HttpURLConnection con = (java.net.HttpURLConnection) new java.net.URL(url).openConnection();
con.setInstanceFollowRedirects(false);
con.connect();
String realURL = con.getHeaderField("Location");
System.out.println(realURL);
return realURL;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment