-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for AddEdge and RemoveEdge serialization
- Loading branch information
1 parent
c41bca8
commit 25965ae
Showing
5 changed files
with
126 additions
and
0 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
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
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
55 changes: 55 additions & 0 deletions
55
src/test/java/edu/stanford/protege/webprotege/hierarchy/AddEdge_Serialization_Test.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,55 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import edu.stanford.protege.webprotege.MockingUtils; | ||
import edu.stanford.protege.webprotege.entity.EntityNode; | ||
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.AutoConfigureJsonTesters; | ||
import org.springframework.boot.test.autoconfigure.json.JsonTest; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@JsonTest | ||
@AutoConfigureJsonTesters | ||
class AddEdge_Serialization_Test { | ||
|
||
@Autowired | ||
JacksonTester<GraphModelChange<EntityNode>> tester; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@BeforeEach | ||
void setUp() throws JsonProcessingException { | ||
} | ||
|
||
@Test | ||
void shouldSerializeAsJson() throws IOException { | ||
var written = tester.write(new AddEdge<>( | ||
new GraphEdge<>( | ||
GraphNode.getForEntityNode(MockingUtils.mockOWLClassNode(), | ||
false), | ||
GraphNode.getForEntityNode(MockingUtils.mockOWLClassNode(), | ||
false) | ||
) | ||
)); | ||
assertThat(written).hasJsonPathStringValue("type", "webprotege.events.graph.AddEdge"); | ||
assertThat(written).hasJsonPath("edge"); | ||
} | ||
|
||
@Test | ||
void shouldDeserializeFromJson() throws IOException { | ||
var json = """ | ||
{"type":"webprotege.events.graph.AddEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"<http://stuff.com/I0>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"<http://stuff.com/I1>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false}}} | ||
"""; | ||
var read = tester.readObject(new StringReader(json)); | ||
assertThat(read).isInstanceOf(AddEdge.class); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/edu/stanford/protege/webprotege/hierarchy/RemoveEdge_Serialization_Test.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,60 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import edu.stanford.protege.webprotege.MockingUtils; | ||
import edu.stanford.protege.webprotege.entity.EntityNode; | ||
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.AutoConfigureJsonTesters; | ||
import org.springframework.boot.test.autoconfigure.json.JsonTest; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 2024-04-18 | ||
*/ | ||
@JsonTest | ||
@AutoConfigureJsonTesters | ||
class RemoveEdge_Serialization_Test { | ||
|
||
@Autowired | ||
JacksonTester<GraphModelChange<EntityNode>> tester; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@BeforeEach | ||
void setUp() throws JsonProcessingException { | ||
} | ||
|
||
@Test | ||
void shouldSerializeAsJson() throws IOException { | ||
var written = tester.write(new RemoveEdge<>( | ||
new GraphEdge<>( | ||
GraphNode.getForEntityNode(MockingUtils.mockOWLClassNode(), | ||
false), | ||
GraphNode.getForEntityNode(MockingUtils.mockOWLClassNode(), | ||
false) | ||
) | ||
)); | ||
assertThat(written).hasJsonPathStringValue("type", "webprotege.events.graph.RemoveEdge"); | ||
assertThat(written).hasJsonPath("edge"); | ||
} | ||
|
||
@Test | ||
void shouldDeserializeFromJson() throws IOException { | ||
var json = """ | ||
{"type":"webprotege.events.graph.RemoveEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"<http://stuff.com/I0>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"<http://stuff.com/I1>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false}}} | ||
"""; | ||
var read = tester.readObject(new StringReader(json)); | ||
assertThat(read).isInstanceOf(RemoveEdge.class); | ||
} | ||
} |