1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
27
28
29
30
31
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
43
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
60
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
78
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
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
102
103
104
105