1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3   
4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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   * <p>Title: WSMO4J</p>
27   * <p>Description: WSMO API and a Reference Implementation</p>
28   * <p>Copyright:  Copyright (c) 2004-2005</p>
29   * <p>Company: OntoText Lab. / SIRMA </p>
30   * @author not attributable
31   * @version 1.0
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          // test if removeXXX(OntologyElement) works
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          // restore back the state of the ontology
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          // test if removeXXX(IRI) works
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          // test if OntologyElement.setOntology = null removes it also
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          // restore back the state of ontology
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          // test if OntologyElement.setOntology = anotherOntology removes/adds from the ontologies
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  * $Log$
114  * Revision 1.7  2005/11/04 06:14:26  holgerlausen
115  * fixed unit tests relying on relative iris
116  *
117  * Revision 1.6  2005/09/15 08:40:34  vassil_momtchev
118  * test extended for OntologyElement.setOntology(Ontology)
119  *
120  * Revision 1.5  2005/09/12 14:29:03  vassil_momtchev
121  * Ontology unit test
122  *
123  */