Skip to content

Commit

Permalink
- Improved print - input file command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-asprino committed Sep 3, 2021
1 parent 2885c95 commit 247ff0c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ The jar can be executed as follows:
usage: java -jar OWLUnit-<VERSION>.jar [ARGS]
-c,--test-case <URI> The URI of the test case to
execute.
-f,--filepath <path> The filepath leading to the
file defining the test case
or test suite to be
executed.
-m,--iri-mappings <A list of pairs of IRIs> A list of pairs IRIs
separated by a white space.
The first IRI of the pair
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/it/cnr/istc/stlab/owlunit/OWLUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class OWLUnit {
private static final String TEST_SUITE = "s";
private static final String TEST_CASE = "c";
private static final String IRI_MAPPING = "m";
private static final String FILE = "f";
private static final Logger logger = LoggerFactory.getLogger(OWLUnit.class);

public static void main(String[] args) throws OWLUnitException {
Expand All @@ -41,6 +42,10 @@ public static void main(String[] args) throws OWLUnitException {
options.addOption(Option.builder(TEST_CASE).argName("URI").hasArg().required(false)
.desc("The URI of the test case to execute.").longOpt("test-case").build());

options.addOption(Option.builder(FILE).argName("path").hasArg().required(false)
.desc("The filepath leading to the file defining the test case or test suite to be executed.")
.longOpt("filepath").build());

Option o = Option.builder(IRI_MAPPING).argName("A list of pairs of IRIs").required(false).desc(
"A list of pairs IRIs separated by a white space. The first IRI of the pair will be resolved on the second of the pair.")
.longOpt("iri-mappings").build();
Expand Down Expand Up @@ -71,13 +76,33 @@ public static void main(String[] args) throws OWLUnitException {
logger.info("Test suite URI {}", commandLine.getOptionValue(TEST_SUITE));

TestSuiteExecutor tse = new TestSuiteExecutor(commandLine.getOptionValue(TEST_SUITE));

if (commandLine.hasOption(FILE)) {
tse.setFileIn(commandLine.getOptionValue(FILE));
}

tse.runTestSuite();

}

if (commandLine.hasOption(TEST_CASE)) {
logger.info("Test case URI {}", commandLine.getOptionValue(TEST_CASE));

for (TestWorker tw : TestWorkerBase.guessTestClass(commandLine.getOptionValue(TEST_CASE), mappers)) {
List<TestWorker> workers;

if (commandLine.hasOption(FILE)) {
workers = TestWorkerBase.guessTestClass(commandLine.getOptionValue(TEST_CASE),
commandLine.getOptionValue(FILE), mappers);
} else {
workers = TestWorkerBase.guessTestClass(commandLine.getOptionValue(TEST_CASE),
commandLine.getOptionValue(TEST_CASE), mappers);
}

if (workers.size() == 0) {
logger.info("{} doesn't define any test case.", commandLine.getOptionValue(TEST_CASE));
}

for (TestWorker tw : workers) {
if (tw.getClass().equals(CompetencyQuestionVerificationExecutor.class)) {
System.out.print("CQ Verification test ");
}
Expand All @@ -90,6 +115,10 @@ public static void main(String[] args) throws OWLUnitException {
System.out.print("Inference Verification test ");
}

if (commandLine.hasOption(FILE)) {
tw.setFileIn(commandLine.getOptionValue(FILE));
}

if (tw.runTest()) {
System.out.println("PASSED");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public boolean runTest() throws OWLUnitException {
logger.trace("Actual " + baos.toString());
logger.trace("Expected " + expectedResult);
String expectedJSON = expectedResult.toString().replaceAll("\\\\\"", "\"");
logger.trace("Expected clean " + expectedJSON);
JsonElement expected = JsonParser.parseString(expectedJSON);
JsonElement actual = JsonParser.parseString(baos.toString());
return expected.equals(actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ public class TestSuiteExecutor {

private String iri;

private String filepath;

public TestSuiteExecutor(String iri) {
this.iri = iri;
}

public void setFileIn(String path) {
this.filepath = path;
}

public int runTestSuite() {
Model m = ModelFactory.createDefaultModel();
String location = iri;

String location = filepath == null ? iri : filepath;

logger.trace("Location {}", location);

RDFDataMgr.read(m, location);
logger.trace("IRI Executor model size {}", m.size());
StmtIterator it = m.listStatements(m.getResource(location), m.getProperty(Constants.HASTESTCASE),
StmtIterator it = m.listStatements(m.getResource(iri), m.getProperty(Constants.HASTESTCASE),
(RDFNode) null);
// logger.trace("Number of test cases {}", it.toModel().size());
// m.write(System.out, "NT");
Expand Down Expand Up @@ -76,7 +83,7 @@ private boolean runTestByClass(Resource iriTestCase, Resource klass) throws OWLU
} else if (klass.getURI().equals(Constants.INFERENCEVERIFICATION)) {
InferenceVerificationTestExecutor te = new InferenceVerificationTestExecutor(iriTestCase.getURI());
return te.runTest();
}else if (klass.getURI().equals(Constants.ANNOTATIONVERIFICATION)) {
} else if (klass.getURI().equals(Constants.ANNOTATIONVERIFICATION)) {
AnnotationVerificationExecutor te = new AnnotationVerificationExecutor(iriTestCase.getURI());
return te.runTest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public interface TestWorker {

public boolean runTest() throws OWLUnitException;

public void setFileIn(String fi);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ protected Query getSPARQLQuery() throws OWLUnitException {

String sparqlQuery = ni.next().asLiteral().getString();

logger.trace("SPARQL query {}", sparqlQuery);

Query q = QueryFactory.create(sparqlQuery);

return q;
Expand Down Expand Up @@ -233,10 +235,10 @@ protected Object getExpectedResult() throws OWLUnitException {

}

public static List<TestWorker> guessTestClass(String iri, List<OWLOntologyIRIMapper> mappers)
public static List<TestWorker> guessTestClass(String iri, String uriTest, List<OWLOntologyIRIMapper> mappers)
throws OWLUnitException {
Model model = ModelFactory.createDefaultModel();
RDFDataMgr.read(model, iri);
RDFDataMgr.read(model, uriTest);

List<TestWorker> result = new ArrayList<>();

Expand Down

0 comments on commit 247ff0c

Please sign in to comment.