1 | package tudelft.healthpsychology.traumaontologies.owltree;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.mockito.Matchers.any;
|
---|
5 | import static org.mockito.Mockito.mock;
|
---|
6 | import static org.mockito.Mockito.when;
|
---|
7 |
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.util.Arrays;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import org.junit.Before;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.semanticweb.owlapi.model.IRI;
|
---|
15 | import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
|
---|
16 |
|
---|
17 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
18 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
19 |
|
---|
20 | import tudelft.healthpsychology.traumaontologies.answerstate.Property;
|
---|
21 | import tudelft.healthpsychology.traumaontologies.questiontypes.TypedQuestion;
|
---|
22 | import tudelft.utilities.junit.GeneralTests;
|
---|
23 | import uk.ac.manchester.cs.owl.owlapi.OWLDataPropertyImpl;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * NOTICE this is a junit test so we do NOT test if
|
---|
27 | * {@link OWLDataPropertyDomainAxiom} properly implements equals.
|
---|
28 | */
|
---|
29 | public class OwlPropertyTest extends GeneralTests<OwlProperty> {
|
---|
30 |
|
---|
31 | private static final String STRING = "http://www.w3.org/2001/XMLSchema#string";
|
---|
32 | private OwlProperty prop1, prop1a, prop2, prop3;
|
---|
33 | private final OWLDataPropertyDomainAxiom dp1 = mock(
|
---|
34 | OWLDataPropertyDomainAxiom.class);
|
---|
35 | private final OWLDataPropertyDomainAxiom dp2 = mock(
|
---|
36 | OWLDataPropertyDomainAxiom.class);
|
---|
37 | private final OWLDataPropertyDomainAxiom dp3 = mock(
|
---|
38 | OWLDataPropertyDomainAxiom.class);
|
---|
39 |
|
---|
40 | private final OwlTreeReasoner r = mock(OwlTreeReasoner.class);
|
---|
41 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
42 | private final String SERIALIZED = "{\"OwlProperty\":{\"range\":\"range\",\"comment\":\"comment\",\"id\":\"node\"}}";
|
---|
43 |
|
---|
44 | @Before
|
---|
45 | public void before() {
|
---|
46 |
|
---|
47 | when(r.getRange(any())).thenReturn(STRING);
|
---|
48 |
|
---|
49 | OWLDataPropertyImpl odpi = mockDataPropImpl("id1");
|
---|
50 | when(dp1.getProperty()).thenReturn(odpi);
|
---|
51 | odpi = mockDataPropImpl("id2");
|
---|
52 | when(dp2.getProperty()).thenReturn(odpi);
|
---|
53 | odpi = mockDataPropImpl("id3");
|
---|
54 | when(dp3.getProperty()).thenReturn(odpi);
|
---|
55 |
|
---|
56 | when(r.getComment(dp1)).thenReturn("comment1");
|
---|
57 | when(r.getComment(dp2)).thenReturn("comment2");
|
---|
58 | when(r.getComment(dp3)).thenReturn("comment3");
|
---|
59 |
|
---|
60 | prop1 = new OwlProperty(dp1, r);
|
---|
61 | prop1a = new OwlProperty(dp1, r);
|
---|
62 | prop2 = new OwlProperty(dp2, r);
|
---|
63 | prop3 = new OwlProperty(dp3, r);
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | private OWLDataPropertyImpl mockDataPropImpl(String id) {
|
---|
68 | OWLDataPropertyImpl odp1 = mock(OWLDataPropertyImpl.class);
|
---|
69 | when(odp1.getIRI()).thenReturn(IRI.create(id));
|
---|
70 | return odp1;
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public List<List<OwlProperty>> getGeneralTestData() {
|
---|
76 | return Arrays.asList(Arrays.asList(prop1, prop1a), Arrays.asList(prop2),
|
---|
77 | Arrays.asList(prop3));
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public List<String> getGeneralTestStrings() {
|
---|
82 | return Arrays.asList("OWLProperty\\[id1,comment1\\]",
|
---|
83 | "OWLProperty\\[id2,comment2\\]",
|
---|
84 | "OWLProperty\\[id3,comment3\\]");
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Test
|
---|
88 | public void getAnswerTypeTest() {
|
---|
89 | OwlProperty prop = new OwlProperty(dp1, r);
|
---|
90 | TypedQuestion atype = prop.getQuestionType();
|
---|
91 | assertEquals("comment1", atype.getQuestion());
|
---|
92 | }
|
---|
93 |
|
---|
94 | @Test
|
---|
95 | public void testSerialize() throws JsonProcessingException {
|
---|
96 | OwlProperty prop = new OwlProperty("range", "comment", "node");
|
---|
97 | assertEquals(SERIALIZED, jackson.writeValueAsString(prop));
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Test
|
---|
101 | public void testDeserialize() throws IOException {
|
---|
102 | OwlProperty prop = new OwlProperty("range", "comment", "node");
|
---|
103 | assertEquals(prop, jackson.readValue(SERIALIZED, Property.class));
|
---|
104 | }
|
---|
105 |
|
---|
106 | }
|
---|