-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the kgcl:mint command.
Adds a text fixture for the `kgcl:mint` command. We test re-allocating IDs on a dummy ontology that contains only one entity with a temporary identifier, so that we don't run into reproducibility issue because we can't control the order in which entities are iterated over.
- Loading branch information
Showing
7 changed files
with
272 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
robot/src/test/java/org/incenp/obofoundry/kgcl/robot/MintCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* KGCL-Java - KGCL library for Java | ||
* Copyright © 2024 Damien Goutte-Gattat | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the Gnu General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.incenp.obofoundry.kgcl.robot; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class MintCommandTest { | ||
|
||
private final static String idRangeFile = "../core/src/test/resources/idranges.owl"; | ||
|
||
@Test | ||
void testReallocateWithExplicitRange() { | ||
runCommand("temporary-ids.ofn", "reallocated-ids.ofn", "--minted-id-prefix", "https://example.org/", | ||
"--pad-width", "4", "--min-id", "501"); | ||
} | ||
|
||
@Test | ||
void testReallocateWithIDRangePolicy() { | ||
runCommand("temporary-ids.ofn", "reallocated-ids.ofn", "--id-range-file", idRangeFile, "--id-range-name", | ||
"Bob"); | ||
} | ||
|
||
@Test | ||
void testKeepDeprecated() { | ||
runCommand("temporary-ids.ofn", "reallocated-ids-keep-deprecated.ofn", "--id-range-file", idRangeFile, | ||
"--id-range-name", "Bob", "--keep-deprecated"); | ||
} | ||
|
||
@Test | ||
void testMintedFrom() { | ||
runCommand("temporary-ids.ofn", "reallocated-ids-minted-from.ofn", "--id-range-file", idRangeFile, | ||
"--id-range-name", "Bob", "--minted-from-property", "https://example.org/properties#mintedFrom"); | ||
} | ||
|
||
private void runCommand(String inputFile, String outputFile, String... extra) { | ||
TestUtils.runCommand("mint", inputFile, outputFile, extra); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
robot/src/test/java/org/incenp/obofoundry/kgcl/robot/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* KGCL-Java - KGCL library for Java | ||
* Copyright © 2024 Damien Goutte-Gattat | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the Gnu General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.incenp.obofoundry.kgcl.robot; | ||
|
||
import java.io.File; | ||
|
||
import org.geneontology.owl.differ.Differ; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.obolibrary.robot.CommandManager; | ||
import org.semanticweb.owlapi.apibinding.OWLManager; | ||
import org.semanticweb.owlapi.model.OWLOntology; | ||
import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
|
||
/* | ||
* Helper methods to test the ROBOT commands. | ||
*/ | ||
public class TestUtils { | ||
|
||
/* | ||
* Tries running a command from the KGCL plugin and checks that the output | ||
* ontology matches what we expect. | ||
* | ||
* @param command The command to run ("apply", "mint"). | ||
* | ||
* @param inputFile The input ontology (as a filename relative to {@code | ||
* {,../core}/src/test/resources}. | ||
* | ||
* @param outputFile The expected output file (likewise). If {@code null}, the | ||
* output is ignored. | ||
* | ||
* @param extra Any extra arguments to pass to the command. | ||
*/ | ||
public static void runCommand(String command, String inputFile, String outputFile, String... extra) { | ||
File input = new File("src/test/resources/" + inputFile); | ||
if ( !input.exists() ) { | ||
input = new File("../core/src/test/resources/" + inputFile); | ||
} | ||
|
||
File expectedOutput = null; | ||
File actualOutput = null; | ||
if ( outputFile != null ) { | ||
expectedOutput = new File("src/test/resources/" + outputFile); | ||
if ( !expectedOutput.exists() ) { | ||
expectedOutput = new File("../core/src/test/resources/" + outputFile); | ||
} | ||
actualOutput = new File("src/test/resources/output-" + outputFile); | ||
} else { | ||
actualOutput = new File("dont-care.ofn"); | ||
} | ||
|
||
String[] args = new String[1 + 2 + 2 + extra.length]; | ||
args[0] = "kgcl-" + command; | ||
args[1] = "--input"; | ||
args[2] = input.getPath(); | ||
args[3] = "--output"; | ||
args[4] = actualOutput.getPath(); | ||
for ( int i = 0; i < extra.length; i++ ) { | ||
args[i + 5] = extra[i]; | ||
} | ||
|
||
CommandManager robot = new CommandManager(); | ||
robot.addCommand("kgcl-apply", new ApplyCommand()); | ||
robot.addCommand("kgcl-mint", new MintCommand()); | ||
robot.main(args); | ||
|
||
if ( outputFile != null ) { | ||
compareOntologies(expectedOutput, actualOutput); | ||
} else if ( actualOutput.exists() ) { | ||
actualOutput.delete(); | ||
} | ||
} | ||
|
||
private static void compareOntologies(File expected, File actual) { | ||
try { | ||
OWLOntology expectedOntology = OWLManager.createOWLOntologyManager() | ||
.loadOntologyFromOntologyDocument(expected); | ||
OWLOntology actualOntology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(actual); | ||
Differ.BasicDiff diff = Differ.diff(expectedOntology, actualOntology); | ||
Assertions.assertTrue(diff.isEmpty()); | ||
if ( diff.isEmpty() ) { | ||
actual.delete(); | ||
} | ||
} catch ( OWLOntologyCreationException e ) { | ||
Assertions.fail(e); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
robot/src/test/resources/reallocated-ids-keep-deprecated.ofn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Prefix(owl:=<http://www.w3.org/2002/07/owl#>) | ||
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) | ||
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) | ||
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) | ||
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) | ||
|
||
|
||
Ontology( | ||
Declaration(Class(<http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394>)) | ||
Declaration(Class(<https://example.org/0001>)) | ||
Declaration(Class(<https://example.org/0501>)) | ||
Declaration(AnnotationProperty(<http://purl.obolibrary.org/obo/IAO_0100001>)) | ||
|
||
|
||
############################ | ||
# Classes | ||
############################ | ||
|
||
# Class: <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394> (obsolete class 2) | ||
|
||
AnnotationAssertion(<http://purl.obolibrary.org/obo/IAO_0100001> <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394> <https://example.org/0501>) | ||
AnnotationAssertion(rdfs:label <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394> "obsolete class 2") | ||
AnnotationAssertion(owl:deprecated <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394> "true"^^xsd:boolean) | ||
|
||
# Class: <https://example.org/0001> (class 1) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0001> "class 1") | ||
|
||
# Class: <https://example.org/0501> (class 2) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0501> "class 2") | ||
|
||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Prefix(owl:=<http://www.w3.org/2002/07/owl#>) | ||
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) | ||
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) | ||
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) | ||
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) | ||
|
||
|
||
Ontology( | ||
Declaration(Class(<https://example.org/0001>)) | ||
Declaration(Class(<https://example.org/0501>)) | ||
Declaration(AnnotationProperty(<https://example.org/properties#mintedFrom>)) | ||
|
||
|
||
############################ | ||
# Classes | ||
############################ | ||
|
||
# Class: <https://example.org/0001> (class 1) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0001> "class 1") | ||
|
||
# Class: <https://example.org/0501> (class 2) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0501> "class 2") | ||
AnnotationAssertion(<https://example.org/properties#mintedFrom> <https://example.org/0501> <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394>) | ||
|
||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Prefix(owl:=<http://www.w3.org/2002/07/owl#>) | ||
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) | ||
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) | ||
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) | ||
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) | ||
|
||
|
||
Ontology( | ||
Declaration(Class(<https://example.org/0001>)) | ||
Declaration(Class(<https://example.org/0501>)) | ||
|
||
|
||
############################ | ||
# Classes | ||
############################ | ||
|
||
# Class: <https://example.org/0001> (class 1) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0001> "class 1") | ||
|
||
# Class: <https://example.org/0501> (class 2) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0501> "class 2") | ||
|
||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Prefix(owl:=<http://www.w3.org/2002/07/owl#>) | ||
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>) | ||
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>) | ||
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>) | ||
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>) | ||
|
||
|
||
Ontology( | ||
Declaration(Class(<https://example.org/0001>)) | ||
Declaration(Class(<http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394>)) | ||
|
||
|
||
############################ | ||
# Classes | ||
############################ | ||
|
||
# Class <https://example.org/0001> (class 1) | ||
|
||
AnnotationAssertion(rdfs:label <https://example.org/0001> "class 1") | ||
|
||
# Class: <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394> (class 2) | ||
|
||
AnnotationAssertion(rdfs:label <http://purl.obolibrary.org/temp#00819d24-4175-43d4-8405-3a1be211a394> "class 2") | ||
|
||
|
||
) |