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.wsmo.common.Namespace;
21  import org.wsmo.common.TopEntity;
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 NamespaceTest extends Wsmo4jTestCase {
34      
35      private String ontologyIri = "http://default#ontology";
36      private String defaultNsIri = "http://default";
37      private String defaultNsPrefix = "default";
38      private String testNsIri = "http://test";
39      private String testNsPrefix = "test";
40      
41      /**
42       * Tests the preconditions to create namespace
43       * @throws Exception
44       */
45      public void atestCreateNamespace() throws Exception {
46          try {
47              factory.createNamespace(null, createIRI(defaultNsIri));
48              fail("Precondtions not checked");
49          }
50          catch (IllegalArgumentException e) {}
51          try {
52              factory.createNamespace(defaultNsPrefix, null);
53              fail("Precondtions not checked");
54          }
55          catch (IllegalArgumentException e) {}
56      }
57      
58      /**
59       * Test probes if addNamespace / removeNamespace / findNamespace works correctly
60       * @throws Exception
61       */
62      public void atestAddRemoveNamespaces() throws Exception {
63          TopEntity entity = factory.createOntology(createIRI(ontologyIri));
64          Namespace ns1 = factory.createNamespace(testNsPrefix, createIRI(testNsIri));
65         
66          entity.addNamespace(ns1);
67          assertEquals("The namespace count is invalid", entity.listNamespaces().size(), 1);
68          assertEquals("Unable to found by prefix", entity.findNamespace(testNsPrefix), ns1);
69          entity.removeNamespace(ns1);
70          assertEquals("Namespace is not removed by handle", entity.listNamespaces().size(), 0);
71          entity.addNamespace(ns1);
72          entity.removeNamespace(ns1.getPrefix());
73          assertEquals("Namespace is not removed by prefix", entity.listNamespaces().size(), 0);
74      }
75      
76      /**
77       * Test probes if the set of the default namespace works correctly
78       * @throws Exception
79       */
80      public void testDefaultNamespace() throws Exception {
81          TopEntity entity = factory.createOntology(createIRI(ontologyIri));
82          Namespace ns1 = factory.createNamespace(defaultNsPrefix, createIRI(defaultNsIri));
83          entity.setDefaultNamespace(ns1);
84          Namespace ns2 = factory.createNamespace(testNsPrefix, createIRI(testNsIri));
85          entity.addNamespace(ns2);
86          assertEquals("Default namespace is not set!", ns1, entity.getDefaultNamespace());
87          
88          // setDefaultNamespace appends # if the current IRI do not ends with '#' or '/'
89          entity.setDefaultNamespace(createIRI(defaultNsIri));
90          assertEquals("Default namespace iri is not appended with #",
91                  entity.getDefaultNamespace().getIRI(),
92                  createIRI(defaultNsIri + "#"));
93          entity.setDefaultNamespace(createIRI(defaultNsIri + "/"));
94          assertEquals("Default namespace iri is not appended with #",
95                  entity.getDefaultNamespace().getIRI(),
96                  createIRI(defaultNsIri + "/"));
97      }
98  }
99  
100 /*
101  * $Log$
102  * Revision 1.2  2005/09/12 14:41:17  vassil_momtchev
103  * log added
104  *
105  */