1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package test.wsmo4j.ontology;
19
20 import org.omwg.ontology.Concept;
21 import org.omwg.ontology.Ontology;
22
23 import test.wsmo4j.Wsmo4jTestCase;
24
25
26
27
28
29
30
31
32
33 public class OntologyTest extends Wsmo4jTestCase {
34
35 protected Ontology ontology;
36
37 private String ns = "http://example.org";
38
39 public void setUp() throws Exception {
40 super.setUp();
41 ontology = factory.createOntology(createIRI(ns+"ontology"));
42 }
43
44 public void testOntologyAndOntologyElement() throws Exception {
45 Concept concept1 = factory.createConcept(createIRI(ns+"concept1"));
46 Concept concept2 = factory.createConcept(createIRI(ns+"concept2"));
47 ontology.addConcept(concept1);
48 concept2.setOntology(ontology);
49
50 assertEquals("Ontology element is not added correctly to the ontology",
51 concept1.getOntology(), ontology);
52 assertEquals("Ontology element is not added correctly to the ontology",
53 concept2.getOntology(), ontology);
54 assertEquals("Ontology element is not added correctly to the ontology",
55 ontology.findConcept(createIRI(ns+"concept1")), concept1);
56 assertEquals("Ontology element is not added correctly to the ontology",
57 ontology.findConcept(createIRI(ns+"concept2")), concept2);
58 assertEquals("Ontology count is not incremented",
59 ontology.listConcepts().size(), 2);
60
61
62
63 ontology.removeConcept(concept2);
64
65 assertFalse("Ontology element is not removed properly",
66 ontology.listConcepts().contains(concept2));
67 assertNull("Ontology element is not removed properly", concept2.getOntology());
68
69
70 ontology.addConcept(concept2);
71
72 assertEquals("Ontology element is not added correctly to the ontology",
73 concept2.getOntology(), ontology);
74 assertEquals("Ontology element is not added correctly to the ontology",
75 ontology.findConcept(createIRI(ns+"concept2")), concept2);
76
77
78 ontology.removeConcept(concept2.getIdentifier());
79
80 assertFalse("Ontology element is not removed",
81 ontology.listConcepts().contains(concept2));
82 assertNull("Ontology element is not removed", concept2.getOntology());
83
84
85 concept1.setOntology(null);
86
87 assertFalse("Ontology element is not removed",
88 ontology.listConcepts().contains(concept1));
89 assertNull("Ontology element is not removed", concept1.getOntology());
90
91
92 ontology.addConcept(concept1);
93
94 assertEquals("Ontology element is not added to the ontology",
95 concept1.getOntology(), ontology);
96 assertEquals("Ontology element is not added to the ontology",
97 ontology.findConcept(createIRI(ns+"concept1")), concept1);
98
99
100 Ontology anotherOntology = factory.createOntology(createIRI(ns+"anotherOntology"));
101 concept1.setOntology(anotherOntology);
102
103 assertFalse("Ontology element is not removed",
104 ontology.listConcepts().contains(concept1));
105 assertEquals("Ontology element is not removed", concept1.getOntology(),
106 anotherOntology);
107 assertTrue("Ontology element is not removed",
108 anotherOntology.listConcepts().contains(concept1));
109 }
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123