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.common;
19  
20  import org.omwg.ontology.*;
21  import org.wsmo.common.*;
22  import org.wsmo.common.exception.*;
23  import org.wsmo.factory.*;
24  import org.wsmo.wsml.*;
25  
26  import test.wsmo4j.Wsmo4jTestCase;
27  
28  /**
29   * <p>Title: WSMO4J</p>
30   * <p>Description: WSMO API and a Reference Implementation</p>
31   * <p>Copyright:  Copyright (c) 2004-2005</p>
32   * <p>Company: OntoText Lab. / SIRMA </p>
33   * @author not attributable
34   * @version 1.0
35   */
36  public class IDReferenceTest extends Wsmo4jTestCase {
37      
38      private static final String DEFAULT_NS = "http://ex.org#";
39      
40      private Parser parser = Factory.createParser(null);
41      
42      public void testIDReference() throws Exception {
43          String test = "namespace _\"http://ex.org#\" \n" +
44          "ontology ont"+System.currentTimeMillis()+" \n" +
45          "concept car subConceptOf vehicle \n"+
46          "concept vehicle \n" +
47          " \n ";
48          Ontology o = (Ontology)parser.parse(new StringBuffer(test))[0];
49          Concept airplaine =
50              o.findConcept(factory.createIRI(DEFAULT_NS+"vehicle"));
51          assertEquals(1,airplaine.listSubConcepts().size());
52      }
53      
54      
55      Relation relation = null;
56      
57      /**
58       * Tries to create multiple objects with the same IRI (see the test below as suite)
59       * @throws Exception
60       */
61      public void testMetaModeling() throws Exception {
62          IRI duplicatedIRI = factory.createIRI("http://duplicated/iri");
63          
64          // create object with no strong references to it (should disappear)
65          Concept concept = factory.createConcept(duplicatedIRI);
66          // create object with strong references (should NOT disappear)
67          relation = factory.createRelation(duplicatedIRI);
68          
69          assertEquals("Duplicated IRI fails!", concept, factory.getConcept(duplicatedIRI));
70          assertEquals("Duplicated IRI fails!", relation, factory.getRelation(duplicatedIRI));
71      }
72      
73      /**
74       * The test is seuqnece of the test above and it's not guarantee to work on all JVM, 
75       * because System.gc() may not performed!
76       * @throws Exception
77       */
78      public void testWSMOObjectRemoval() throws Exception {
79          System.gc();
80          IRI duplicatedIRI = factory.createIRI("http://duplicated/iri");
81          
82          try {
83              Relation relation = factory.getRelation(duplicatedIRI);
84              relation.listRelationInstances();
85          }
86          catch (SynchronisationException e) {
87              e.printStackTrace();
88              fail("Object was removed!");
89          }
90          
91          try {
92              // check if it's a proxy or real implementation by calling createAttribute
93              factory.getConcept(duplicatedIRI).createAttribute(duplicatedIRI);
94              fail("Removal test fails");
95          }
96          catch (SynchronisationException e) {
97              assertTrue("Object is removed!", true);
98          }
99      }
100     
101     public void testMetaModelling2() throws Exception{
102         IRI aircraft = factory.createIRI("http://ex.org#aircraft");
103         IRI boing747 = factory.createIRI("http://ex.org#boing747");
104         IRI af1 = factory.createIRI("http://ex.org#airforceone");
105         Concept C_aircraft = factory.getConcept(aircraft);
106         Instance I_boing747 = factory.createInstance(boing747);
107         Concept C_boing747 = factory.getConcept(boing747);
108         Instance I_af1 = factory.createInstance(af1);
109         I_boing747.addConcept(C_aircraft);
110         I_af1.addConcept(C_boing747);
111     }
112 }
113 
114 /*
115  * $Log$
116  * Revision 1.3  2005/10/18 10:22:15  holgerlausen
117  * additional tests for meta modelling
118  *
119  * Revision 1.2  2005/10/18 08:57:52  vassil_momtchev
120  * metamodeling unit tests added; test for the object removal after System.gc() added
121  *
122  * Revision 1.1  2005/09/26 12:46:07  vassil_momtchev
123  * test for the correctness of the proxy invoke cache
124  *
125 */