diff --git a/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/ApplyCommandTest.java b/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/ApplyCommandTest.java
index 5b432c3..340ec61 100644
--- a/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/ApplyCommandTest.java
+++ b/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/ApplyCommandTest.java
@@ -22,13 +22,8 @@
import java.io.IOException;
import org.apache.commons.io.FileUtils;
-import org.geneontology.owl.differ.Differ;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.obolibrary.robot.CommandManager;
-import org.semanticweb.owlapi.apibinding.OWLManager;
-import org.semanticweb.owlapi.model.OWLOntology;
-import org.semanticweb.owlapi.model.OWLOntologyCreationException;
public class ApplyCommandTest {
@@ -120,65 +115,8 @@ void testCreateNewOntology() {
"create relation EX:0101 'object property 1'", "--kgcl", "create edge EX:0001 EX:0101 EX:0002");
}
- /*
- * Try running a KGCL-Apply command and check that the output ontology matches
- * what we expect.
- *
- * inputFile: the input ontology (filename relative to
- * {,../core}/src/test/resources). outputFile: expected output file (likewise);
- * if null, ignore the output.
- */
private void runCommand(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-apply";
- 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.main(args);
-
- if ( outputFile != null ) {
- compareOntologies(expectedOutput, actualOutput);
- } else if ( actualOutput.exists() ) {
- actualOutput.delete();
- }
- }
-
- private 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);
- }
+ TestUtils.runCommand("apply", inputFile, outputFile, extra);
}
private void checkOutput(String expectedFile, String actualFile) {
diff --git a/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/MintCommandTest.java b/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/MintCommandTest.java
new file mode 100644
index 0000000..47700d5
--- /dev/null
+++ b/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/MintCommandTest.java
@@ -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 .
+ */
+
+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);
+ }
+}
diff --git a/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/TestUtils.java b/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/TestUtils.java
new file mode 100644
index 0000000..f3d14db
--- /dev/null
+++ b/robot/src/test/java/org/incenp/obofoundry/kgcl/robot/TestUtils.java
@@ -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 .
+ */
+
+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);
+ }
+ }
+}
diff --git a/robot/src/test/resources/reallocated-ids-keep-deprecated.ofn b/robot/src/test/resources/reallocated-ids-keep-deprecated.ofn
new file mode 100644
index 0000000..e136b2c
--- /dev/null
+++ b/robot/src/test/resources/reallocated-ids-keep-deprecated.ofn
@@ -0,0 +1,34 @@
+Prefix(owl:=)
+Prefix(rdf:=)
+Prefix(xml:=)
+Prefix(xsd:=)
+Prefix(rdfs:=)
+
+
+Ontology(
+Declaration(Class())
+Declaration(Class())
+Declaration(Class())
+Declaration(AnnotationProperty())
+
+
+############################
+# Classes
+############################
+
+# Class: (obsolete class 2)
+
+AnnotationAssertion( )
+AnnotationAssertion(rdfs:label "obsolete class 2")
+AnnotationAssertion(owl:deprecated "true"^^xsd:boolean)
+
+# Class: (class 1)
+
+AnnotationAssertion(rdfs:label "class 1")
+
+# Class: (class 2)
+
+AnnotationAssertion(rdfs:label "class 2")
+
+
+)
diff --git a/robot/src/test/resources/reallocated-ids-minted-from.ofn b/robot/src/test/resources/reallocated-ids-minted-from.ofn
new file mode 100644
index 0000000..bfe3dd8
--- /dev/null
+++ b/robot/src/test/resources/reallocated-ids-minted-from.ofn
@@ -0,0 +1,28 @@
+Prefix(owl:=)
+Prefix(rdf:=)
+Prefix(xml:=)
+Prefix(xsd:=)
+Prefix(rdfs:=)
+
+
+Ontology(
+Declaration(Class())
+Declaration(Class())
+Declaration(AnnotationProperty())
+
+
+############################
+# Classes
+############################
+
+# Class: (class 1)
+
+AnnotationAssertion(rdfs:label "class 1")
+
+# Class: (class 2)
+
+AnnotationAssertion(rdfs:label "class 2")
+AnnotationAssertion( )
+
+
+)
diff --git a/robot/src/test/resources/reallocated-ids.ofn b/robot/src/test/resources/reallocated-ids.ofn
new file mode 100644
index 0000000..3e06b2b
--- /dev/null
+++ b/robot/src/test/resources/reallocated-ids.ofn
@@ -0,0 +1,26 @@
+Prefix(owl:=)
+Prefix(rdf:=)
+Prefix(xml:=)
+Prefix(xsd:=)
+Prefix(rdfs:=)
+
+
+Ontology(
+Declaration(Class())
+Declaration(Class())
+
+
+############################
+# Classes
+############################
+
+# Class: (class 1)
+
+AnnotationAssertion(rdfs:label "class 1")
+
+# Class: (class 2)
+
+AnnotationAssertion(rdfs:label "class 2")
+
+
+)
diff --git a/robot/src/test/resources/temporary-ids.ofn b/robot/src/test/resources/temporary-ids.ofn
new file mode 100644
index 0000000..d7a9468
--- /dev/null
+++ b/robot/src/test/resources/temporary-ids.ofn
@@ -0,0 +1,26 @@
+Prefix(owl:=)
+Prefix(rdf:=)
+Prefix(xml:=)
+Prefix(xsd:=)
+Prefix(rdfs:=)
+
+
+Ontology(
+Declaration(Class())
+Declaration(Class())
+
+
+############################
+# Classes
+############################
+
+# Class (class 1)
+
+AnnotationAssertion(rdfs:label "class 1")
+
+# Class: (class 2)
+
+AnnotationAssertion(rdfs:label "class 2")
+
+
+)