Commit 95b2eae4 authored by lefranois's avatar lefranois

Merge branch 'SalvaBranch2' into 'master'

Solved Themis and OOPS problems

See merge request saref/saref-pipeline!9
parents 30af40b3 075edb44
......@@ -26,6 +26,8 @@
package fr.emse.gitlab.saref.checkers;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......@@ -129,9 +131,10 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
onto = out.toString().replaceAll("]]", "] ]");
String xmlRequest = "<?xml version='1.0' encoding='UTF-8'?>" + "<OOPSRequest>" + "<OntologyURI></OntologyURI>"
+ "<OntologyContent><![CDATA[" + onto + "]]></OntologyContent>" + "<Pitfalls>10</Pitfalls>"
+ "<OntologyContent><![CDATA[" + onto + "]]></OntologyContent>" + "<Pitfalls></Pitfalls>"
+ "<OutputFormat>RDF/XML</OutputFormat>" + "</OOPSRequest>";
Object[] arrayData = new Object[0];
try {
......@@ -153,13 +156,10 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
String result = response.body().string();
String[] results = result.split("\\n");
List<String> pureData = new ArrayList<String>();
for (int i = 0; i < results.length; i++) {
if (results[i].startsWith("<")) {
for (int j = i; j < results.length; j++) {
pureData.add(results[j]);
}
}
pureData.add(results[i]);
}
arrayData = pureData.toArray(); // response into array
......@@ -174,10 +174,11 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
int s = 0;
ArrayList<String> results = new ArrayList<String>();
while (s < count) {
String data = result.get(0).get(s) + result.get(1).get(s) + result.get(2).get(s);
String data = result.get(0).get(s).concat("-") + result.get(1).get(s).concat(".") + result.get(2).get(s) + "Affected Elements: " + result.get(3).get(s);
results.add(data);
s++;
}
......
......@@ -25,11 +25,7 @@
*/
package fr.emse.gitlab.saref.checkers;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
......@@ -64,7 +60,7 @@ import okhttp3.Response;
/**
* Checks TS 103 673 Clause 9.5: Ontology tests
*
*
*/
public class Clause_9_5_Checker extends AbstractClauseChecker {
......@@ -140,6 +136,7 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
StringWriter requirementsRDFXML = new StringWriter();
version.getRequirements().write(requirementsRDFXML);
OkHttpClient httpClient = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
String jsonRequest = "{\"ontologiesCode\":[\""
......@@ -147,9 +144,11 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
+ "\"]," + "\"testfile\":[\"" + requirementsRDFXML.toString().replaceAll("\\\"", "\\\\\"")
.replaceAll("\"", "\\\"").replaceAll("\t", " ")
+ "\"]," + "\"format\":\"junit\"}";
RequestBody body = RequestBody.create(jsonRequest, mediaType);
Request request = new Request.Builder().url("http://themis.linkeddata.es/rest/api/results").method("POST", body)
.addHeader("accept", "application/json").addHeader("Content-Type", "application/json").build();
try {
Response response = httpClient.newCall(request).execute();
if (response.code() != 200) {
......@@ -164,12 +163,13 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
org.w3c.dom.Node node = nodeList.item(temp);
if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
Element element = (Element) node;
String id = element.getAttributeNode("id").toString();
String name = element.getAttributeNode("name").toString();
String message = ((Element) node).getElementsByTagName("error").item(0).getAttributes()
.getNamedItem("message").toString();
String themisError = String.format("%s, %s, %s", id, name, message);
themisErrors.add(themisError);
if (((Element) node).getElementsByTagName("error").item(0) != null) {
String id = element.getAttributeNode("id").toString();
String name = element.getAttributeNode("name").toString();
String message = ((Element) node).getElementsByTagName("error").item(0).getAttributes().getNamedItem("message").toString();
String themisError = String.format("%s, %s, %s", id, name, message);
themisErrors.add(themisError);
}
}
}
if (!themisErrors.isEmpty()) {
......
......@@ -33,13 +33,20 @@ public class OopsManager {
ArrayList<String> getID = new ArrayList<String>();
ArrayList<String> getName = new ArrayList<String>();
ArrayList<String> getInfo = new ArrayList<String>();
ArrayList<String> affectedElements = new ArrayList<String>();
ArrayList<ArrayList<String>> elements = new ArrayList<ArrayList<String>>();
elements.add(getID);
elements.add(getName);
elements.add(getInfo);
elements.add(affectedElements);
String affected = "";
for (int i = 0; i < data.length; i++) {
String data2 = data[i].toString().replaceAll(" ", "");
if (data2.startsWith("<oops:hasCode")) {
String[] data3 = data2.split("(<|>)");
getID.add(data3[2]);
......@@ -53,6 +60,30 @@ public class OopsManager {
getInfo.add(data3[2]);
elements.set(2, getInfo);
}
if (i>0 && i < data.length-1) {
String prove = data[i - 1].toString().replaceAll(" ", "");
String prove2 = data[i + 1].toString().replaceAll(" ", "");
if (data2.startsWith("<oops:hasAffectedElement")) {
if (!prove.startsWith("<oops:hasAffectedElement")) {
String[] data3 = data2.split("(<|>)");
affected += data3[2];
}
else if (!prove2.startsWith("<oops:hasAffectedElement")){
String[] data3 = data2.split("(<|>)");
affected += ", " + data3[2];
affectedElements.add(affected);
elements.set(3, affectedElements);
affected = "";
}
else{
String[] data3 = data2.split("(<|>)");
affected += ", " + data3[2];
}
}
}
}
return elements;
......
missing=The `tests` directory should contain a file `tests.csv`. This file shall conform to the requirements specification as defined in clause 9.5.2 in TS 103 673.
line=The `tests` specification shall be a CSV (Comma-Separated Values) file encoded in UTF-8. The first line of the file shall be the following: `Id;Requirement;Category;Test`
ioexception=Error while checking the `tests` directory
themis=OOPS found some problems. Violations are: %s
themis=Themis found some problems. Violations are: %s
themisError=Themis error. The service may be under maintenance.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment