diff --git a/pom.xml b/pom.xml
index 880398e..950ef61 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
edu.stanford.protege
webprotege-backend-api
- 1.0.27-WHO
+ 2.0.1-WHO
UTF-8
@@ -30,7 +30,7 @@
yyyyMMdd
0.11.0
8.5.2
- 16
+ 17
2020.0.3
@@ -248,9 +248,9 @@
maven-compiler-plugin
3.8.1
-
- 16
- 16
+
+ 17
+ 17
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptor.java
new file mode 100644
index 0000000..0abecf6
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptor.java
@@ -0,0 +1,22 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.semanticweb.owlapi.model.OWLAnnotationProperty;
+import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+import uk.ac.manchester.cs.owl.owlapi.OWLAnnotationPropertyImpl;
+import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl;
+
+import java.util.Set;
+
+@JsonTypeName("AnnotationPropertyHierarchyDescriptor")
+public record AnnotationPropertyHierarchyDescriptor(@JsonProperty("roots") Set roots) implements HierarchyDescriptor {
+
+ public AnnotationPropertyHierarchyDescriptor(@JsonProperty("roots") Set roots) {
+ this.roots = Set.copyOf(roots);
+ }
+
+ public static AnnotationPropertyHierarchyDescriptor create() {
+ return new AnnotationPropertyHierarchyDescriptor(Set.of());
+ }
+}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptor.java
new file mode 100644
index 0000000..ce5b874
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptor.java
@@ -0,0 +1,27 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;
+
+import java.util.Set;
+
+@JsonTypeName("ClassHierarchyDescriptor")
+public record ClassHierarchyDescriptor(@JsonProperty("roots") Set roots) implements HierarchyDescriptor {
+
+ public ClassHierarchyDescriptor(Set roots) {
+ this.roots = Set.copyOf(roots);
+ }
+
+ @JsonCreator
+ public static ClassHierarchyDescriptor create(@JsonProperty("roots") Set roots) {
+ return new ClassHierarchyDescriptor(roots);
+ }
+
+ public static ClassHierarchyDescriptor create() {
+ return create(Set.of(new OWLClassImpl(OWLRDFVocabulary.OWL_THING.getIRI())));
+ }
+}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptor.java
new file mode 100644
index 0000000..86bcf66
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptor.java
@@ -0,0 +1,22 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.semanticweb.owlapi.model.OWLDataProperty;
+import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+import uk.ac.manchester.cs.owl.owlapi.OWLDataPropertyImpl;
+import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl;
+
+import java.util.Set;
+
+@JsonTypeName("DataPropertyHierarchyDescriptor")
+public record DataPropertyHierarchyDescriptor(@JsonProperty("roots") Set roots) implements HierarchyDescriptor {
+
+ public DataPropertyHierarchyDescriptor(Set roots) {
+ this.roots = Set.copyOf(roots);
+ }
+
+ public static DataPropertyHierarchyDescriptor create() {
+ return new DataPropertyHierarchyDescriptor(Set.of(new OWLDataPropertyImpl(OWLRDFVocabulary.OWL_TOP_DATA_PROPERTY.getIRI())));
+ }
+}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEvent.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEvent.java
index 294cd10..40792cd 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEvent.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEvent.java
@@ -1,24 +1,34 @@
package edu.stanford.protege.webprotege.hierarchy;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.common.EventId;
import edu.stanford.protege.webprotege.common.ProjectEvent;
import edu.stanford.protege.webprotege.common.ProjectId;
import javax.annotation.Nonnull;
+import java.util.Objects;
/**
* Matthew Horridge Stanford Center for Biomedical Informatics Research 1 Dec 2017
*/
@JsonTypeName("webprotege.events.hierarchies.EntityHierarchyChanged")
-public record EntityHierarchyChangedEvent(@Nonnull EventId eventId,
- @Nonnull ProjectId projectId,
- @Nonnull HierarchyId hierarchyId,
- @Nonnull GraphModelChangedEvent changeEvent) implements ProjectEvent {
+public record EntityHierarchyChangedEvent(@JsonProperty("eventId") @Nonnull EventId eventId,
+ @JsonProperty("projectId") @Nonnull ProjectId projectId,
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor,
+ @JsonProperty("changeEvent") @Nonnull GraphModelChangedEvent changeEvent) implements ProjectEvent {
public static final String CHANNEL = "webprotege.events.hierarchies.EntityHierarchyChanged";
+ public EntityHierarchyChangedEvent(@JsonProperty("eventId") @Nonnull EventId eventId, @JsonProperty("projectId") @Nonnull ProjectId projectId, @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor, @JsonProperty("changeEvent") @Nonnull GraphModelChangedEvent changeEvent) {
+ this.eventId = Objects.requireNonNull(eventId);
+ this.projectId = Objects.requireNonNull(projectId);
+ this.hierarchyDescriptor = Objects.requireNonNull(hierarchyDescriptor);
+ this.changeEvent = Objects.requireNonNull(changeEvent);
+ }
+
@Override
public String getChannel() {
return CHANNEL;
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction.java
index 1fd3e00..9838b2c 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction.java
@@ -19,7 +19,7 @@
@JsonTypeName("webprotege.hierarchies.GetHierarchyChildren")
public record GetHierarchyChildrenAction(@JsonProperty("projectId") @Nonnull ProjectId projectId,
@JsonProperty("entity") @Nonnull OWLEntity entity,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId,
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor,
@JsonProperty("pageRequest") @Nonnull PageRequest pageRequest) implements ProjectAction {
public static final String CHANNEL = "webprotege.hierarchies.GetHierarchyChildren";
@@ -31,11 +31,11 @@ public String getChannel() {
public GetHierarchyChildrenAction(@JsonProperty("projectId") @Nonnull ProjectId projectId,
@JsonProperty("entity") @Nonnull OWLEntity entity,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId,
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor,
@JsonProperty("pageRequest") @Nonnull PageRequest pageRequest) {
this.projectId = checkNotNull(projectId);
this.entity = checkNotNull(entity);
- this.hierarchyId = checkNotNull(hierarchyId);
+ this.hierarchyDescriptor = checkNotNull(hierarchyDescriptor);
this.pageRequest = checkNotNull(pageRequest);
}
}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsAction.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsAction.java
index fd50506..da23dc9 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsAction.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsAction.java
@@ -13,12 +13,10 @@
/**
* Matthew Horridge Stanford Center for Biomedical Informatics Research 28 Nov 2017
*/
-
-
@JsonTypeName("webprotege.hierarchies.GetHierarchyParents")
public record GetHierarchyParentsAction(@JsonProperty("projectId") @Nonnull ProjectId projectId,
@JsonProperty("entity") @Nonnull OWLEntity entity,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId) implements ProjectAction {
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor) implements ProjectAction {
public static final String CHANNEL = "webprotege.hierarchies.GetHierarchyParents";
@@ -29,9 +27,9 @@ public String getChannel() {
public GetHierarchyParentsAction(@JsonProperty("projectId") @Nonnull ProjectId projectId,
@JsonProperty("entity") @Nonnull OWLEntity entity,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId) {
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor) {
this.projectId = checkNotNull(projectId);
this.entity = checkNotNull(entity);
- this.hierarchyId = checkNotNull(hierarchyId);
+ this.hierarchyDescriptor = checkNotNull(hierarchyDescriptor);
}
}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction.java
index 7fb7698..5fd7e67 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction.java
@@ -18,7 +18,7 @@
@JsonTypeName("webprotege.hierarchies.GetHierarchyPathsToRoot")
public record GetHierarchyPathsToRootAction(@JsonProperty("projectId") @Nonnull ProjectId projectId,
@JsonProperty("entity") @Nonnull OWLEntity entity,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId) implements ProjectAction {
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor) implements ProjectAction {
public static final String CHANNEL = "webprotege.hierarchies.GetHierarchyPathsToRoot";
@@ -29,9 +29,9 @@ public String getChannel() {
public GetHierarchyPathsToRootAction(@JsonProperty("projectId") @Nonnull ProjectId projectId,
@JsonProperty("entity") @Nonnull OWLEntity entity,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId) {
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor) {
this.projectId = checkNotNull(projectId);
this.entity = checkNotNull(entity);
- this.hierarchyId = checkNotNull(hierarchyId);
+ this.hierarchyDescriptor = checkNotNull(hierarchyDescriptor);
}
}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction.java
index 3d7d7f3..3eec5eb 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction.java
@@ -12,7 +12,7 @@
* Matthew Horridge Stanford Center for Biomedical Informatics Research 30 Nov 2017
*/
@JsonTypeName("webprotege.hierarchies.GetHierarchyRoots")
-public record GetHierarchyRootsAction(@Nonnull ProjectId projectId, @Nonnull HierarchyId hierarchyId) implements ProjectAction {
+public record GetHierarchyRootsAction(@Nonnull ProjectId projectId, @Nonnull HierarchyDescriptor hierarchyDescriptor) implements ProjectAction {
public static final String CHANNEL = "webprotege.hierarchies.GetHierarchyRoots";
@@ -21,8 +21,8 @@ public String getChannel() {
return CHANNEL;
}
- public GetHierarchyRootsAction(@Nonnull ProjectId projectId, @Nonnull HierarchyId hierarchyId) {
+ public GetHierarchyRootsAction(@Nonnull ProjectId projectId, @Nonnull HierarchyDescriptor hierarchyDescriptor) {
this.projectId = checkNotNull(projectId);
- this.hierarchyId = checkNotNull(hierarchyId);
+ this.hierarchyDescriptor = checkNotNull(hierarchyDescriptor);
}
}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsAction.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsAction.java
index 78def1b..78f84ed 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsAction.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsAction.java
@@ -17,7 +17,7 @@
@JsonTypeName("webprotege.hierarchies.GetHierarchySiblings")
public record GetHierarchySiblingsAction(@JsonProperty("projectId") ProjectId projectId,
@JsonProperty("entity") OWLEntity entity,
- @JsonProperty("hierarchyId") HierarchyId hierarchyId,
+ @JsonProperty("hierarchyDescriptor") HierarchyDescriptor hierarchyDescriptor,
@JsonProperty("pageRequest") PageRequest pageRequest) implements ProjectAction {
public static final String CHANNEL = "webprotege.hierarchies.GetHierarchySiblings";
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptor.java
new file mode 100644
index 0000000..0d6f826
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptor.java
@@ -0,0 +1,16 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import com.fasterxml.jackson.annotation.JsonSubTypes;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
+@JsonSubTypes({
+ @JsonSubTypes.Type(ClassHierarchyDescriptor.class),
+ @JsonSubTypes.Type(ObjectPropertyHierarchyDescriptor.class),
+ @JsonSubTypes.Type(DataPropertyHierarchyDescriptor.class),
+ @JsonSubTypes.Type(AnnotationPropertyHierarchyDescriptor.class)
+})
+public interface HierarchyDescriptor {
+
+
+}
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeAction.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeAction.java
index 292c57b..23b8e13 100644
--- a/src/main/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeAction.java
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeAction.java
@@ -18,7 +18,7 @@
@JsonTypeName("webprotege.hierarchies.MoveHierarchyNode")
public record MoveHierarchyNodeAction(@JsonProperty("changeRequestId") ChangeRequestId changeRequestId,
@JsonProperty("projectId") @Nonnull ProjectId projectId,
- @JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId,
+ @JsonProperty("hierarchyDescriptor") @Nonnull HierarchyDescriptor hierarchyDescriptor,
@JsonProperty("fromNodePath") @Nonnull Path fromNodePath,
@JsonProperty("toNodeParentPath") @Nonnull Path toNodeParentPath,
@JsonProperty("dropType") @Nonnull DropType dropType) implements ProjectAction, ContentChangeRequest {
diff --git a/src/main/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptor.java
new file mode 100644
index 0000000..1beb95d
--- /dev/null
+++ b/src/main/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptor.java
@@ -0,0 +1,21 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl;
+
+import java.util.Set;
+
+@JsonTypeName("ObjectPropertyHierarchyDescriptor")
+public record ObjectPropertyHierarchyDescriptor(@JsonProperty("roots") Set roots) implements HierarchyDescriptor {
+
+ public ObjectPropertyHierarchyDescriptor(Set roots) {
+ this.roots = Set.copyOf(roots);
+ }
+
+ public static ObjectPropertyHierarchyDescriptor create() {
+ return new ObjectPropertyHierarchyDescriptor(Set.of(new OWLObjectPropertyImpl(OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.getIRI())));
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptorJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptorJsonTest.java
new file mode 100644
index 0000000..70b39b6
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptorJsonTest.java
@@ -0,0 +1,64 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import org.junit.jupiter.api.Test;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
+
+@JsonTest
+class AnnotationPropertyHierarchyDescriptorJsonTest {
+
+
+ public static final String ROOT_IRI = "http://example.org/prop";
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeClassHierarchyDescriptor() throws Exception {
+ var prop = dataFactory.getOWLAnnotationProperty(IRI.create(ROOT_IRI));
+ var descriptor = new AnnotationPropertyHierarchyDescriptor(Set.of(prop));
+ var json = jacksonTester.write(descriptor);
+
+ // Check for the correct JSON structure
+ assertThat(json).hasJsonPathArrayValue("roots")
+ .extractingJsonPathStringValue("roots[0].iri")
+ .isEqualTo(ROOT_IRI);
+
+ // Assert that the @type is correct
+ assertThat(json).extractingJsonPathStringValue("['@type']")
+ .isEqualTo("AnnotationPropertyHierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeClassHierarchyDescriptor() throws Exception {
+ var json = """
+ {
+ "@type": "AnnotationPropertyHierarchyDescriptor",
+ "roots": [
+ {
+ "@type" : "AnnotationProperty",
+ "iri": "http://example.org/prop"
+ }
+ ]
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var descriptor = objectContent.getObject();
+
+ assertThat(descriptor).isNotNull();
+ assertThat(descriptor.roots()).hasSize(1);
+ var rootClass = descriptor.roots().iterator().next();
+ assertThat(rootClass.getIRI().toString()).isEqualTo(ROOT_IRI);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptorJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptorJsonTest.java
new file mode 100644
index 0000000..5c3a948
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptorJsonTest.java
@@ -0,0 +1,63 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import org.junit.jupiter.api.Test;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Set;
+
+@JsonTest
+public class ClassHierarchyDescriptorJsonTest {
+
+ public static final String ROOT_IRI = "http://example.org/A";
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeClassHierarchyDescriptor() throws Exception {
+ var cls = dataFactory.getOWLClass(IRI.create(ROOT_IRI));
+ var descriptor = new ClassHierarchyDescriptor(Set.of(cls));
+ var json = jacksonTester.write(descriptor);
+
+ // Check for the correct JSON structure
+ assertThat(json).hasJsonPathArrayValue("roots")
+ .extractingJsonPathStringValue("roots[0].iri")
+ .isEqualTo(ROOT_IRI);
+
+ // Assert that the @type is correct
+ assertThat(json).extractingJsonPathStringValue("['@type']")
+ .isEqualTo("ClassHierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeClassHierarchyDescriptor() throws Exception {
+ // Example JSON
+ var json = """
+ {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "@type" : "Class",
+ "iri": "http://example.org/A"
+ }
+ ]
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var descriptor = objectContent.getObject();
+
+ assertThat(descriptor).isNotNull();
+ assertThat(descriptor.roots()).hasSize(1);
+ var rootClass = descriptor.roots().iterator().next();
+ assertThat(rootClass.getIRI().toString()).isEqualTo(ROOT_IRI);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptorJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptorJsonTest.java
new file mode 100644
index 0000000..a218190
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptorJsonTest.java
@@ -0,0 +1,62 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import org.junit.jupiter.api.Test;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@JsonTest
+class DataPropertyHierarchyDescriptorJsonTest {
+
+ public static final String ROOT_IRI = "http://example.org/prop";
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeClassHierarchyDescriptor() throws Exception {
+ var prop = dataFactory.getOWLDataProperty(IRI.create(ROOT_IRI));
+ var descriptor = new DataPropertyHierarchyDescriptor(Set.of(prop));
+ var json = jacksonTester.write(descriptor);
+
+ // Check for the correct JSON structure
+ assertThat(json).hasJsonPathArrayValue("roots")
+ .extractingJsonPathStringValue("roots[0].iri")
+ .isEqualTo(ROOT_IRI);
+
+ // Assert that the @type is correct
+ assertThat(json).extractingJsonPathStringValue("['@type']")
+ .isEqualTo("DataPropertyHierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeClassHierarchyDescriptor() throws Exception {
+ var json = """
+ {
+ "@type": "DataPropertyHierarchyDescriptor",
+ "roots": [
+ {
+ "@type" : "DataProperty",
+ "iri": "http://example.org/prop"
+ }
+ ]
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var descriptor = objectContent.getObject();
+
+ assertThat(descriptor).isNotNull();
+ assertThat(descriptor.roots()).hasSize(1);
+ var rootClass = descriptor.roots().iterator().next();
+ assertThat(rootClass.getIRI().toString()).isEqualTo(ROOT_IRI);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEventJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEventJsonTest.java
new file mode 100644
index 0000000..2b12404
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEventJsonTest.java
@@ -0,0 +1,105 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+
+import com.google.common.collect.ImmutableList;
+import edu.stanford.protege.webprotege.common.EventId;
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+import org.springframework.boot.test.json.JsonContent;
+import org.springframework.boot.test.json.ObjectContent;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;
+import org.semanticweb.owlapi.model.OWLClass;
+
+import java.util.Set;
+
+@JsonTest
+public class EntityHierarchyChangedEventJsonTest {
+
+ public static final String PROJECT_ID = "00000000-1111-2222-3333-444444444444";
+
+ public static final String EVENT_ID = "event-id";
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Test
+ void testSerializeEntityHierarchyChangedEvent() throws Exception {
+ // Create sample objects
+ var eventId = new EventId(EVENT_ID);
+ var projectId = new ProjectId(PROJECT_ID);
+
+ // Sample HierarchyDescriptor (using ClassHierarchyDescriptor as an example)
+ OWLClass owlClass = new OWLClassImpl(OWLRDFVocabulary.OWL_THING.getIRI());
+ HierarchyDescriptor hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(owlClass));
+
+ // Sample GraphModelChangedEvent (you need to provide a concrete instance of this class)
+ var changeEvent = GraphModelChangedEvent.create(ImmutableList.of(new AddEdge<>(new GraphEdge<>(new GraphNode<>("A"), new GraphNode<>("B")))));
+
+ // Create an EntityHierarchyChangedEvent instance
+ EntityHierarchyChangedEvent event = new EntityHierarchyChangedEvent(eventId, projectId, hierarchyDescriptor, changeEvent);
+
+ // Serialize to JSON
+ JsonContent json = jacksonTester.write(event);
+
+ // Assert the JSON structure and values
+ assertThat(json).extractingJsonPathStringValue("$.eventId").isEqualTo(EVENT_ID);
+ assertThat(json).extractingJsonPathStringValue("$.projectId").isEqualTo(PROJECT_ID);
+
+ // Check hierarchyDescriptor and changeEvent fields
+ assertThat(json).hasJsonPathMapValue("$.hierarchyDescriptor");
+ assertThat(json).hasJsonPathMapValue("$.changeEvent");
+
+ // Check the channel
+ assertThat(json).extractingJsonPathStringValue("$.['@type']").isEqualTo(EntityHierarchyChangedEvent.CHANNEL);
+ }
+
+ @Test
+ void testDeserializeEntityHierarchyChangedEvent() throws Exception {
+ // Example JSON
+ String json = """
+ {
+
+ "@type": "webprotege.events.hierarchies.EntityHierarchyChanged",
+ "eventId": "event-id",
+ "projectId": "00000000-1111-2222-3333-444444444444",
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "changeEvent": {
+ "changes" : []
+ }
+ }
+ """;
+
+ // Deserialize from JSON
+ ObjectContent objectContent = jacksonTester.parse(json);
+
+ // Get the result
+ EntityHierarchyChangedEvent event = objectContent.getObject();
+
+ // Assert deserialized object
+ assertThat(event).isNotNull();
+ assertThat(event.eventId().id()).isEqualTo(EVENT_ID);
+ assertThat(event.projectId().id()).isEqualTo(PROJECT_ID);
+
+ // Assert HierarchyDescriptor
+ assertThat(event.hierarchyDescriptor()).isInstanceOf(ClassHierarchyDescriptor.class);
+
+ // Assert changeEvent
+ assertThat(event.changeEvent().getChanges()).isEmpty();
+
+ // Assert the channel
+ assertThat(event.getChannel()).isEqualTo(EntityHierarchyChangedEvent.CHANNEL);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEventTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEventTest.java
new file mode 100644
index 0000000..6b0c829
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEventTest.java
@@ -0,0 +1,55 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import com.google.common.collect.ImmutableList;
+import edu.stanford.protege.webprotege.common.EventId;
+import edu.stanford.protege.webprotege.common.ProjectId;
+import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+import org.springframework.context.annotation.Import;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
+
+@JsonTest
+@Import(WebProtegeJacksonApplication.class)
+class EntityHierarchyChangedEventTest {
+
+ @Autowired
+ private JacksonTester tester;
+
+ @BeforeEach
+ void setUp() throws IOException {
+
+ }
+
+ @Test
+ void shouldSerializeToJson() throws IOException {
+ var event = new EntityHierarchyChangedEvent(EventId.generate(),
+ ProjectId.generate(),
+ ClassHierarchyDescriptor.create(),
+ GraphModelChangedEvent.create(ImmutableList.of()));
+ var json = tester.write(event);
+ assertThat(json).hasJsonPathStringValue("projectId");
+ assertThat(json).hasJsonPathStringValue("eventId");
+ assertThat(json).hasJsonPathMapValue("hierarchyDescriptor");
+ }
+
+ @Test
+ void shouldDeserializeFromJson() throws IOException {
+ var json = """
+ {"@type":"webprotege.events.hierarchies.EntityHierarchyChanged","eventId":"08adfb16-60cf-49f9-b82b-689302d11e91","projectId":"bd6b3b60-735c-42ee-8aa9-df6fcca6b0ee","hierarchyDescriptor":{"@type":"ClassHierarchyDescriptor","roots":[{"@type":"Class","iri":"http://www.w3.org/2002/07/owl#Thing"}]},"changeEvent":{"changes":[]}}
+ """;
+ var obj = tester.read(new StringReader(json));
+ var event = obj.getObject();
+ assertThat(event.eventId().id()).isEqualTo("08adfb16-60cf-49f9-b82b-689302d11e91");
+ assertThat(event.projectId().id()).isEqualTo("bd6b3b60-735c-42ee-8aa9-df6fcca6b0ee");
+ assertThat(event.hierarchyDescriptor()).isNotNull();
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenActionJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenActionJsonTest.java
new file mode 100644
index 0000000..f4e470e
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenActionJsonTest.java
@@ -0,0 +1,80 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import edu.stanford.protege.webprotege.common.PageRequest;
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.semanticweb.owlapi.model.OWLDataFactory;
+
+import java.util.Set;
+
+@JsonTest
+public class GetHierarchyChildrenActionJsonTest {
+
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory; // Auto-wired OWLDataFactory
+
+ @Test
+ void testSerializeGetHierarchyChildrenAction() throws Exception {
+ var projectId = ProjectId.generate();
+ var owlClass = dataFactory.getOWLThing();
+ var hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(owlClass));
+ var pageRequest = PageRequest.requestFirstPage();
+
+ var action = new GetHierarchyChildrenAction(projectId, owlClass, hierarchyDescriptor, pageRequest);
+
+ var json = jacksonTester.write(action);
+
+ assertThat(json).hasJsonPath("$.projectId");
+ assertThat(json).hasJsonPath("$.entity.iri");
+ assertThat(json).hasJsonPath("$.hierarchyDescriptor");
+ assertThat(json).hasJsonPath("$.pageRequest");
+ }
+
+ @Test
+ void testDeserializeGetHierarchyChildrenAction() throws Exception {
+ var json = """
+ {
+ "projectId": "123e4567-e89b-12d3-a456-426614174000",
+ "entity": {
+ "iri": "http://www.w3.org/2002/07/owl#Thing",
+ "@type": "Class"
+ },
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "pageRequest": {
+ "pageNumber": 1,
+ "pageSize": 10
+ },
+ "@type": "webprotege.hierarchies.GetHierarchyChildren"
+ }
+ """;
+
+ // Deserialize from JSON
+ var objectContent = jacksonTester.parse(json);
+
+ var action = objectContent.getObject();
+
+ assertThat(action.projectId()).isNotNull();
+ assertThat(action.entity()).isNotNull();
+ assertThat(action.hierarchyDescriptor()).isNotNull();
+ assertThat(action.pageRequest()).isNotNull();
+ assertThat(action.getChannel()).isEqualTo(GetHierarchyChildrenAction.CHANNEL);
+ }
+}
+
+
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction_TestCase.java
index 831ac01..6aca2f4 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildrenAction_TestCase.java
@@ -8,7 +8,11 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLEntity;
+import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;
+
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -24,18 +28,17 @@ public class GetHierarchyChildrenAction_TestCase {
@Mock
private OWLEntity entity;
- @Mock
- private HierarchyId hierarchyId;
+ private HierarchyDescriptor hierarchyDescriptor = ClassHierarchyDescriptor.create();
@Before
public void setUp() {
- action = new GetHierarchyChildrenAction(projectId, entity, hierarchyId, PageRequest.requestFirstPage());
+ action = new GetHierarchyChildrenAction(projectId, entity, hierarchyDescriptor, PageRequest.requestFirstPage());
}
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_projectId_IsNull() {
- new GetHierarchyChildrenAction(null, entity, hierarchyId, PageRequest.requestFirstPage());
+ new GetHierarchyChildrenAction(null, entity, hierarchyDescriptor, PageRequest.requestFirstPage());
}
@Test
@@ -46,7 +49,7 @@ public void shouldReturnSupplied_projectId() {
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_entity_IsNull() {
- new GetHierarchyChildrenAction(projectId, null, hierarchyId, PageRequest.requestFirstPage());
+ new GetHierarchyChildrenAction(projectId, null, hierarchyDescriptor, PageRequest.requestFirstPage());
}
@Test
@@ -60,11 +63,6 @@ public void shouldThrowNullPointerExceptionIf_hierarchyId_IsNull() {
new GetHierarchyChildrenAction(projectId, entity, null, PageRequest.requestFirstPage());
}
- @Test
- public void shouldReturnSupplied_hierarchyId() {
- assertThat(action.hierarchyId(), is(this.hierarchyId));
- }
-
@Test
public void shouldBeEqualToSelf() {
assertThat(action, is(action));
@@ -78,27 +76,27 @@ public void shouldNotBeEqualToNull() {
@Test
public void shouldBeEqualToOther() {
- assertThat(action, is(new GetHierarchyChildrenAction(projectId, entity, hierarchyId, PageRequest.requestFirstPage())));
+ assertThat(action, is(new GetHierarchyChildrenAction(projectId, entity, hierarchyDescriptor, PageRequest.requestFirstPage())));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_projectId() {
- assertThat(action, is(not(new GetHierarchyChildrenAction(ProjectId.generate(), entity, hierarchyId, PageRequest.requestFirstPage()))));
+ assertThat(action, is(not(new GetHierarchyChildrenAction(ProjectId.generate(), entity, hierarchyDescriptor, PageRequest.requestFirstPage()))));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_entity() {
- assertThat(action, is(not(new GetHierarchyChildrenAction(projectId, mock(OWLEntity.class), hierarchyId, PageRequest.requestFirstPage()))));
+ assertThat(action, is(not(new GetHierarchyChildrenAction(projectId, mock(OWLEntity.class), hierarchyDescriptor, PageRequest.requestFirstPage()))));
}
@Test
- public void shouldNotBeEqualToOtherThatHasDifferent_hierarchyId() {
- assertThat(action, is(not(new GetHierarchyChildrenAction(projectId, entity, mock(HierarchyId.class), PageRequest.requestFirstPage()))));
+ public void shouldNotBeEqualToOtherThatHasDifferent_hierarchyDescriptor() {
+ assertThat(action, is(not(new GetHierarchyChildrenAction(projectId, entity, ClassHierarchyDescriptor.create(Set.of(new OWLClassImpl(IRI.create("http://example.org")))), PageRequest.requestFirstPage()))));
}
@Test
public void shouldBeEqualToOtherHashCode() {
- assertThat(action.hashCode(), is(new GetHierarchyChildrenAction(projectId, entity, hierarchyId, PageRequest.requestFirstPage()).hashCode()));
+ assertThat(action.hashCode(), is(new GetHierarchyChildrenAction(projectId, entity, hierarchyDescriptor, PageRequest.requestFirstPage()).hashCode()));
}
@Test
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildren_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildren_Serialization_TestCase.java
index 94ee15a..cb06142 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildren_Serialization_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyChildren_Serialization_TestCase.java
@@ -1,14 +1,18 @@
package edu.stanford.protege.webprotege.hierarchy;
+import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.protege.webprotege.common.Page;
import edu.stanford.protege.webprotege.common.PageRequest;
import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.Before;
import org.junit.Test;
+import org.springframework.boot.test.json.JacksonTester;
import java.io.IOException;
import static edu.stanford.protege.webprotege.MockingUtils.mockOWLClass;
import static edu.stanford.protege.webprotege.MockingUtils.mockOWLClassNode;
+import static org.mockito.Mockito.mock;
/**
* Matthew Horridge
@@ -17,11 +21,18 @@
*/
public class GetHierarchyChildren_Serialization_TestCase {
+ private JacksonTester tester;
+
+ @Before
+ public void setUp() throws Exception {
+ JacksonTester.initFields(this, ObjectMapper::new);
+ }
+
@Test
public void shouldSerializeAction() throws IOException {
var action = new GetHierarchyChildrenAction(ProjectId.generate(),
mockOWLClass(),
- HierarchyId.CLASS_HIERARCHY,
+ ClassHierarchyDescriptor.create(),
PageRequest.requestFirstPage());
}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionJsonTest.java
new file mode 100644
index 0000000..3463a58
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionJsonTest.java
@@ -0,0 +1,67 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.semanticweb.owlapi.model.OWLDataFactory;
+
+import java.util.Set;
+
+@JsonTest
+public class GetHierarchyParentsActionJsonTest {
+
+ @Autowired
+ private JacksonTester tester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeGetHierarchyParentsAction() throws Exception {
+ var projectId = ProjectId.generate();
+ var rootCls = dataFactory.getOWLThing();
+ var hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(rootCls));
+ var action = new GetHierarchyParentsAction(projectId, rootCls, hierarchyDescriptor);
+
+ var json = tester.write(action);
+
+ assertThat(json).hasJsonPathStringValue("$.projectId");
+ assertThat(json).hasJsonPathMapValue("$.entity");
+ assertThat(json).hasJsonPathMapValue("$.hierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeGetHierarchyParentsAction() throws Exception {
+ var json = """
+ {
+ "projectId": "123e4567-e89b-12d3-a456-426614174000",
+ "entity": {
+ "iri": "http://www.w3.org/2002/07/owl#Thing",
+ "@type": "Class"
+ },
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "@type": "webprotege.hierarchies.GetHierarchyParents"
+ }
+ """;
+
+ var objectContent = tester.parse(json);
+ var action = objectContent.getObject();
+
+ assertThat(action.projectId()).isNotNull();
+ assertThat(action.entity()).isNotNull();
+ assertThat(action.hierarchyDescriptor()).isNotNull();
+ assertThat(action.getChannel()).isEqualTo(GetHierarchyParentsAction.CHANNEL);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionTest.java
index d15fc9b..5527709 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionTest.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionTest.java
@@ -7,7 +7,11 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLEntity;
+import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;
+
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@ -26,12 +30,12 @@ class GetHierarchyParentsActionTest {
@Mock
private OWLEntity entity;
- @Mock
- private HierarchyId hierarchyId;
+ private HierarchyDescriptor hierarchyDescriptor;
@Before
public void setUp() {
- action = new GetHierarchyParentsAction(projectId, entity, hierarchyId);
+ hierarchyDescriptor = ClassHierarchyDescriptor.create();
+ action = new GetHierarchyParentsAction(projectId, entity, hierarchyDescriptor);
}
@AfterEach
@@ -41,7 +45,7 @@ void tearDown() {
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_projectId_IsNull() {
- new GetHierarchyParentsAction(null, entity, hierarchyId);
+ new GetHierarchyParentsAction(null, entity, hierarchyDescriptor);
}
@Test
@@ -52,7 +56,7 @@ public void shouldReturnSupplied_projectId() {
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_entity_IsNull() {
- new GetHierarchyParentsAction(projectId, null, hierarchyId);
+ new GetHierarchyParentsAction(projectId, null, hierarchyDescriptor);
}
@@ -70,27 +74,27 @@ public void shouldThrowNullPointerExceptionIf_hierarchyId_IsNull() {
@Test
public void shouldBeEqualToOther() {
- assertThat(action, is(new GetHierarchyParentsAction(projectId, entity, hierarchyId)));
+ assertThat(action, is(new GetHierarchyParentsAction(projectId, entity, hierarchyDescriptor)));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_projectId() {
- assertThat(action, is(not(new GetHierarchyParentsAction(ProjectId.generate(), entity, hierarchyId))));
+ assertThat(action, is(not(new GetHierarchyParentsAction(ProjectId.generate(), entity, hierarchyDescriptor))));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_entity() {
- assertThat(action, is(not(new GetHierarchyParentsAction(projectId, mock(OWLEntity.class), hierarchyId))));
+ assertThat(action, is(not(new GetHierarchyParentsAction(projectId, mock(OWLEntity.class), hierarchyDescriptor))));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_hierarchyId() {
- assertThat(action, is(not(new GetHierarchyParentsAction(projectId, entity, mock(HierarchyId.class)))));
+ assertThat(action, is(not(new GetHierarchyParentsAction(projectId, entity, ClassHierarchyDescriptor.create(Set.of(new OWLClassImpl(IRI.create("http://example.org/A"))))))));
}
@Test
public void shouldBeEqualToOtherHashCode() {
- assertThat(action.hashCode(), is(new GetHierarchyParentsAction(projectId, entity, hierarchyId).hashCode()));
+ assertThat(action.hashCode(), is(new GetHierarchyParentsAction(projectId, entity, hierarchyDescriptor).hashCode()));
}
@Test
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootActionJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootActionJsonTest.java
new file mode 100644
index 0000000..6c3efd4
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootActionJsonTest.java
@@ -0,0 +1,67 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.semanticweb.owlapi.model.OWLDataFactory;
+
+import java.util.Set;
+
+@JsonTest
+public class GetHierarchyPathsToRootActionJsonTest {
+
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeGetHierarchyPathsToRootAction() throws Exception {
+ var projectId = ProjectId.generate();
+ var rootCls = dataFactory.getOWLThing();
+ var hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(rootCls));
+ var action = new GetHierarchyPathsToRootAction(projectId, rootCls, hierarchyDescriptor);
+
+ var json = jacksonTester.write(action);
+
+ assertThat(json).hasJsonPathStringValue("$.projectId");
+ assertThat(json).hasJsonPathMapValue("$.entity");
+ assertThat(json).hasJsonPathMapValue("$.hierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeGetHierarchyPathsToRootAction() throws Exception {
+ var json = """
+ {
+ "projectId": "123e4567-e89b-12d3-a456-426614174000",
+ "entity": {
+ "iri": "http://www.w3.org/2002/07/owl#Thing",
+ "@type": "Class"
+ },
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "@type": "webprotege.hierarchies.GetHierarchyPathsToRoot"
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var action = objectContent.getObject();
+
+ assertThat(action.projectId()).isNotNull();
+ assertThat(action.entity()).isNotNull();
+ assertThat(action.hierarchyDescriptor()).isNotNull();
+ assertThat(action.getChannel()).isEqualTo(GetHierarchyPathsToRootAction.CHANNEL);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction_TestCase.java
index 705149d..42e35a2 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRootAction_TestCase.java
@@ -7,7 +7,11 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLEntity;
+import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;
+
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -23,18 +27,17 @@ public class GetHierarchyPathsToRootAction_TestCase {
@Mock
private OWLEntity entity;
- @Mock
- private HierarchyId hierarchyId;
+ private HierarchyDescriptor hierarchyDescriptor = ClassHierarchyDescriptor.create();
@Before
public void setUp() {
- action = new GetHierarchyPathsToRootAction(projectId, entity, hierarchyId);
+ action = new GetHierarchyPathsToRootAction(projectId, entity, hierarchyDescriptor);
}
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_projectId_IsNull() {
- new GetHierarchyPathsToRootAction(null, entity, hierarchyId);
+ new GetHierarchyPathsToRootAction(null, entity, hierarchyDescriptor);
}
@Test
@@ -45,7 +48,7 @@ public void shouldReturnSupplied_projectId() {
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_entity_IsNull() {
- new GetHierarchyPathsToRootAction(projectId, null, hierarchyId);
+ new GetHierarchyPathsToRootAction(projectId, null, hierarchyDescriptor);
}
@Test
@@ -59,11 +62,6 @@ public void shouldThrowNullPointerExceptionIf_hierarchyId_IsNull() {
new GetHierarchyPathsToRootAction(projectId, entity, null);
}
- @Test
- public void shouldReturnSupplied_hierarchyId() {
- assertThat(action.hierarchyId(), is(this.hierarchyId));
- }
-
@Test
public void shouldBeEqualToSelf() {
assertThat(action, is(action));
@@ -77,27 +75,27 @@ public void shouldNotBeEqualToNull() {
@Test
public void shouldBeEqualToOther() {
- assertThat(action, is(new GetHierarchyPathsToRootAction(projectId, entity, hierarchyId)));
+ assertThat(action, is(new GetHierarchyPathsToRootAction(projectId, entity, hierarchyDescriptor)));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_projectId() {
- assertThat(action, is(not(new GetHierarchyPathsToRootAction(ProjectId.generate(), entity, hierarchyId))));
+ assertThat(action, is(not(new GetHierarchyPathsToRootAction(ProjectId.generate(), entity, hierarchyDescriptor))));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_entity() {
- assertThat(action, is(not(new GetHierarchyPathsToRootAction(projectId, mock(OWLEntity.class), hierarchyId))));
+ assertThat(action, is(not(new GetHierarchyPathsToRootAction(projectId, mock(OWLEntity.class), hierarchyDescriptor))));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_hierarchyId() {
- assertThat(action, is(not(new GetHierarchyPathsToRootAction(projectId, entity, mock(HierarchyId.class)))));
+ assertThat(action, is(not(new GetHierarchyPathsToRootAction(projectId, entity, ClassHierarchyDescriptor.create(Set.of(new OWLClassImpl(IRI.create("http://example.org"))))))));
}
@Test
public void shouldBeEqualToOtherHashCode() {
- assertThat(action.hashCode(), is(new GetHierarchyPathsToRootAction(projectId, entity, hierarchyId).hashCode()));
+ assertThat(action.hashCode(), is(new GetHierarchyPathsToRootAction(projectId, entity, hierarchyDescriptor).hashCode()));
}
@Test
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRoot_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRoot_Serialization_TestCase.java
index 4f48c92..233ef12 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRoot_Serialization_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyPathsToRoot_Serialization_TestCase.java
@@ -19,7 +19,7 @@ public abstract class GetHierarchyPathsToRoot_Serialization_TestCase {
public void shouldSerializeAction() throws IOException {
var action = new GetHierarchyPathsToRootAction(ProjectId.generate(),
mockOWLClass(),
- HierarchyId.CLASS_HIERARCHY);
+ ClassHierarchyDescriptor.create());
}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsActionJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsActionJsonTest.java
new file mode 100644
index 0000000..f085aeb
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsActionJsonTest.java
@@ -0,0 +1,63 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+import org.springframework.boot.test.json.JsonContent;
+import org.springframework.boot.test.json.ObjectContent;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.semanticweb.owlapi.model.OWLDataFactory;
+
+import java.util.Set;
+
+@JsonTest
+public class GetHierarchyRootsActionJsonTest {
+
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeGetHierarchyRootsAction() throws Exception {
+ var projectId = ProjectId.generate();
+ var rootCls = dataFactory.getOWLThing();
+ var hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(rootCls));
+ var action = new GetHierarchyRootsAction(projectId, hierarchyDescriptor);
+
+ JsonContent json = jacksonTester.write(action);
+
+ assertThat(json).hasJsonPath("$.projectId");
+ assertThat(json).hasJsonPath("$.hierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeGetHierarchyRootsAction() throws Exception {
+ var json = """
+ {
+ "projectId": "123e4567-e89b-12d3-a456-426614174000",
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "@type": "webprotege.hierarchies.GetHierarchyRoots"
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var action = objectContent.getObject();
+
+ assertThat(action.projectId()).isNotNull();
+ assertThat(action.hierarchyDescriptor()).isNotNull();
+ assertThat(action.getChannel()).isEqualTo(GetHierarchyRootsAction.CHANNEL);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction_TestCase.java
index c690777..cb712c7 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRootsAction_TestCase.java
@@ -17,18 +17,17 @@ public class GetHierarchyRootsAction_TestCase {
private GetHierarchyRootsAction action;
private ProjectId projectId = ProjectId.generate();
- @Mock
- private HierarchyId hierarchyId;
+ private HierarchyDescriptor hierarchyDescriptor = ClassHierarchyDescriptor.create();
@Before
public void setUp() {
- action = new GetHierarchyRootsAction(projectId, hierarchyId);
+ action = new GetHierarchyRootsAction(projectId, hierarchyDescriptor);
}
@SuppressWarnings("ConstantConditions")
@Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_projectId_IsNull() {
- new GetHierarchyRootsAction(null, hierarchyId);
+ new GetHierarchyRootsAction(null, hierarchyDescriptor);
}
@Test
@@ -42,11 +41,6 @@ public void shouldThrowNullPointerExceptionIf_hierarchyId_IsNull() {
new GetHierarchyRootsAction(projectId, null);
}
- @Test
- public void shouldReturnSupplied_hierarchyId() {
- assertThat(action.hierarchyId(), is(this.hierarchyId));
- }
-
@Test
public void shouldBeEqualToSelf() {
assertThat(action, is(action));
@@ -60,22 +54,17 @@ public void shouldNotBeEqualToNull() {
@Test
public void shouldBeEqualToOther() {
- assertThat(action, is(new GetHierarchyRootsAction(projectId, hierarchyId)));
+ assertThat(action, is(new GetHierarchyRootsAction(projectId, hierarchyDescriptor)));
}
@Test
public void shouldNotBeEqualToOtherThatHasDifferent_projectId() {
- assertThat(action, is(not(new GetHierarchyRootsAction(ProjectId.generate(), hierarchyId))));
- }
-
- @Test
- public void shouldNotBeEqualToOtherThatHasDifferent_hierarchyId() {
- assertThat(action, is(not(new GetHierarchyRootsAction(projectId, mock(HierarchyId.class)))));
+ assertThat(action, is(not(new GetHierarchyRootsAction(ProjectId.generate(), hierarchyDescriptor))));
}
@Test
public void shouldBeEqualToOtherHashCode() {
- assertThat(action.hashCode(), is(new GetHierarchyRootsAction(projectId, hierarchyId).hashCode()));
+ assertThat(action.hashCode(), is(new GetHierarchyRootsAction(projectId, hierarchyDescriptor).hashCode()));
}
@Test
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRoots_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRoots_Serialization_TestCase.java
index 9280382..5f9afc6 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRoots_Serialization_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyRoots_Serialization_TestCase.java
@@ -16,7 +16,7 @@ public class GetHierarchyRoots_Serialization_TestCase {
@Test
public void shouldSerializeAction() throws IOException {
var action = new GetHierarchyRootsAction(ProjectId.generate(),
- HierarchyId.CLASS_HIERARCHY);
+ ClassHierarchyDescriptor.create());
}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsActionJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsActionJsonTest.java
new file mode 100644
index 0000000..01430f5
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblingsActionJsonTest.java
@@ -0,0 +1,74 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import edu.stanford.protege.webprotege.common.PageRequest;
+import edu.stanford.protege.webprotege.common.ProjectId;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+
+import java.util.Set;
+
+@JsonTest
+public class GetHierarchySiblingsActionJsonTest {
+
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeGetHierarchySiblingsAction() throws Exception {
+ var projectId = ProjectId.generate();
+ var rootCls = dataFactory.getOWLThing();
+ var hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(rootCls));
+ var pageRequest = PageRequest.requestFirstPage();
+ var action = new GetHierarchySiblingsAction(projectId, rootCls, hierarchyDescriptor, pageRequest);
+
+ var json = jacksonTester.write(action);
+
+ assertThat(json).hasJsonPathStringValue("$.projectId");
+ assertThat(json).hasJsonPathMapValue("$.entity");
+ assertThat(json).hasJsonPathMapValue("$.hierarchyDescriptor");
+ assertThat(json).hasJsonPathMapValue("$.pageRequest");
+ }
+
+ @Test
+ void testDeserializeGetHierarchySiblingsAction() throws Exception {
+ var json = """
+ {
+ "projectId": "123e4567-e89b-12d3-a456-426614174000",
+ "entity": {
+ "iri": "http://www.w3.org/2002/07/owl#Thing",
+ "@type": "Class"
+ },
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "pageRequest": {
+ "pageNumber": 1,
+ "pageSize": 10
+ },
+ "@type": "webprotege.hierarchies.GetHierarchySiblings"
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var action = objectContent.getObject();
+
+ assertThat(action.projectId()).isNotNull();
+ assertThat(action.entity()).isNotNull();
+ assertThat(action.hierarchyDescriptor()).isNotNull();
+ assertThat(action.pageRequest()).isNotNull();
+ assertThat(action.getChannel()).isEqualTo(GetHierarchySiblingsAction.CHANNEL);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblings_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblings_Serialization_TestCase.java
index 4287c34..a5abce4 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblings_Serialization_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchySiblings_Serialization_TestCase.java
@@ -20,7 +20,7 @@ public abstract class GetHierarchySiblings_Serialization_TestCase {
public void shouldSerializeAction() throws IOException {
var action = new GetHierarchySiblingsAction(ProjectId.generate(),
mockOWLClass(),
- HierarchyId.CLASS_HIERARCHY,
+ ClassHierarchyDescriptor.create(),
PageRequest.requestFirstPage());
}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptorTest.java
new file mode 100644
index 0000000..bfd2c07
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptorTest.java
@@ -0,0 +1,67 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import java.io.StringReader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@JsonTest
+public class HierarchyDescriptorTest {
+
+ @Autowired
+ private JacksonTester tester;
+
+ @Test
+ void testSerializeClassHierarchyDescriptor() throws Exception {
+ var classHierarchyDescriptor = ClassHierarchyDescriptor.create();
+
+ var json = tester.write(classHierarchyDescriptor);
+
+ assertThat(json).hasJsonPathStringValue("['@type']", "ClassHierarchyDescriptor");
+
+ // Deserialize and assert it becomes the correct class
+ var deserialized = tester.read(new StringReader(json.getJson()));
+ assertThat(deserialized).isInstanceOf(ClassHierarchyDescriptor.class);
+ }
+
+ @Test
+ void testSerializeObjectPropertyHierarchyDescriptor() throws Exception {
+ var objectPropertyDescriptor = ObjectPropertyHierarchyDescriptor.create();
+ var json = tester.write(objectPropertyDescriptor);
+
+ assertThat(json).hasJsonPathStringValue("['@type']", "ObjectPropertyHierarchyDescriptor");
+
+ // Deserialize and assert it becomes the correct class
+ var deserialized = tester.read(new StringReader(json.getJson()));
+ assertThat(deserialized).isInstanceOf(ObjectPropertyHierarchyDescriptor.class);
+ }
+
+ @Test
+ void testSerializeDataPropertyHierarchyDescriptor() throws Exception {
+ var dataPropertyDescriptor = DataPropertyHierarchyDescriptor.create();
+ // Initialize the object with appropriate fields
+ var json = tester.write(dataPropertyDescriptor);
+
+ assertThat(json).hasJsonPathStringValue("['@type']", "DataPropertyHierarchyDescriptor");
+
+ var deserialized = tester.read(new StringReader(json.getJson()));
+ assertThat(deserialized).isInstanceOf(DataPropertyHierarchyDescriptor.class);
+ }
+
+ @Test
+ void testSerializeAnnotationPropertyHierarchyDescriptor() throws Exception {
+ var annotationPropertyDescriptor = AnnotationPropertyHierarchyDescriptor.create();
+ var json = tester.write(annotationPropertyDescriptor);
+
+ assertThat(json).hasJsonPathStringValue("['@type']", "AnnotationPropertyHierarchyDescriptor");
+
+ // Deserialize and assert it becomes the correct class
+ var deserialized = tester.read(new StringReader(json.getJson()));
+ assertThat(deserialized).isInstanceOf(AnnotationPropertyHierarchyDescriptor.class);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeActionJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeActionJsonTest.java
new file mode 100644
index 0000000..53f7768
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNodeActionJsonTest.java
@@ -0,0 +1,84 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import edu.stanford.protege.webprotege.common.ChangeRequestId;
+import edu.stanford.protege.webprotege.common.ProjectId;
+import edu.stanford.protege.webprotege.entity.EntityNode;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+import org.springframework.boot.test.json.JsonContent;
+import org.springframework.boot.test.json.ObjectContent;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.semanticweb.owlapi.model.OWLDataFactory;
+
+import java.util.Set;
+
+@JsonTest
+public class MoveHierarchyNodeActionJsonTest {
+
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeMoveHierarchyNodeAction() throws Exception {
+ var changeRequestId = ChangeRequestId.generate();
+ var projectId = ProjectId.generate();
+ var owlClass = dataFactory.getOWLThing();
+ var hierarchyDescriptor = new ClassHierarchyDescriptor(Set.of(owlClass));
+ var fromNodePath = Path.emptyPath();
+ var toNodeParentPath = Path.emptyPath();
+ var dropType = DropType.MOVE;
+
+ var action = new MoveHierarchyNodeAction(
+ changeRequestId, projectId, hierarchyDescriptor, fromNodePath, toNodeParentPath, dropType
+ );
+
+ JsonContent json = jacksonTester.write(action);
+
+ assertThat(json).hasJsonPathStringValue("$.changeRequestId");
+ assertThat(json).hasJsonPathStringValue("$.projectId");
+ assertThat(json).hasJsonPathMapValue("$.hierarchyDescriptor");
+ assertThat(json).hasJsonPathArrayValue("$.fromNodePath");
+ assertThat(json).hasJsonPathArrayValue("$.toNodeParentPath");
+ assertThat(json).hasJsonPathStringValue("$.dropType");
+ }
+
+ @Test
+ void testDeserializeMoveHierarchyNodeAction() throws Exception {
+ var json = """
+ {
+ "changeRequestId": "123e4567-e89b-12d3-a456-426614174000",
+ "projectId": "123e4567-e89b-12d3-a456-426614174000",
+ "hierarchyDescriptor": {
+ "@type": "ClassHierarchyDescriptor",
+ "roots": [
+ {
+ "iri": "http://www.w3.org/2002/07/owl#Thing"
+ }
+ ]
+ },
+ "fromNodePath": [],
+ "toNodeParentPath": [],
+ "dropType": "MOVE",
+ "@type": "webprotege.hierarchies.MoveHierarchyNode"
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var action = objectContent.getObject();
+
+ assertThat(action.changeRequestId()).isNotNull();
+ assertThat(action.projectId()).isNotNull();
+ assertThat(action.hierarchyDescriptor()).isNotNull();
+ assertThat(action.fromNodePath()).isNotNull();
+ assertThat(action.toNodeParentPath()).isNotNull();
+ assertThat(action.dropType()).isNotNull();
+ assertThat(action.getChannel()).isEqualTo(MoveHierarchyNodeAction.CHANNEL);
+ }
+}
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNode_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNode_Serialization_TestCase.java
index d5e1725..0ab9ec8 100644
--- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNode_Serialization_TestCase.java
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/MoveHierarchyNode_Serialization_TestCase.java
@@ -20,7 +20,8 @@ public class MoveHierarchyNode_Serialization_TestCase {
@Test
public void shouldSerializeAction() throws IOException {
var action = new MoveHierarchyNodeAction(changeRequestId, mockProjectId(),
- HierarchyId.CLASS_HIERARCHY, Path.asPath(mockOWLClassNode()),
+ ClassHierarchyDescriptor.create(),
+ Path.asPath(mockOWLClassNode()),
Path.emptyPath(),
DropType.ADD);
diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptorJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptorJsonTest.java
new file mode 100644
index 0000000..140761f
--- /dev/null
+++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptorJsonTest.java
@@ -0,0 +1,63 @@
+package edu.stanford.protege.webprotege.hierarchy;
+
+import org.junit.jupiter.api.Test;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.json.JsonTest;
+import org.springframework.boot.test.json.JacksonTester;
+
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@JsonTest
+class ObjectPropertyHierarchyDescriptorJsonTest {
+
+ public static final String ROOT_IRI = "http://example.org/A";
+ @Autowired
+ private JacksonTester jacksonTester;
+
+ @Autowired
+ private OWLDataFactory dataFactory;
+
+ @Test
+ void testSerializeClassHierarchyDescriptor() throws Exception {
+ var prop = dataFactory.getOWLObjectProperty(IRI.create(ROOT_IRI));
+ var descriptor = new ObjectPropertyHierarchyDescriptor(Set.of(prop));
+ var json = jacksonTester.write(descriptor);
+
+ // Check for the correct JSON structure
+ assertThat(json).hasJsonPathArrayValue("roots")
+ .extractingJsonPathStringValue("roots[0].iri")
+ .isEqualTo(ROOT_IRI);
+
+ // Assert that the @type is correct
+ assertThat(json).extractingJsonPathStringValue("['@type']")
+ .isEqualTo("ObjectPropertyHierarchyDescriptor");
+ }
+
+ @Test
+ void testDeserializeClassHierarchyDescriptor() throws Exception {
+ // Example JSON
+ var json = """
+ {
+ "@type": "ObjectPropertyHierarchyDescriptor",
+ "roots": [
+ {
+ "@type" : "ObjectProperty",
+ "iri": "http://example.org/A"
+ }
+ ]
+ }
+ """;
+
+ var objectContent = jacksonTester.parse(json);
+ var descriptor = objectContent.getObject();
+
+ assertThat(descriptor).isNotNull();
+ assertThat(descriptor.roots()).hasSize(1);
+ var rootClass = descriptor.roots().iterator().next();
+ assertThat(rootClass.getIRI().toString()).isEqualTo(ROOT_IRI);
+ }
+}
\ No newline at end of file