KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > namespace > DynamicNameSpaceResolverTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.service.namespace;
18
19 import junit.framework.TestCase;
20
21 public class DynamicNameSpaceResolverTest extends TestCase
22 {
23
24     public DynamicNameSpaceResolverTest()
25     {
26         super();
27     }
28     
29     public void testOne()
30     {
31         DynamicNamespacePrefixResolver dnpr = new DynamicNamespacePrefixResolver(null);
32         dnpr.registerNamespace("one", "http:/namespace/one");
33         dnpr.registerNamespace("two", "http:/namespace/two");
34         dnpr.registerNamespace("three", "http:/namespace/three");
35         dnpr.registerNamespace("oneagain", "http:/namespace/one");
36         dnpr.registerNamespace("four", "http:/namespace/one");
37         dnpr.registerNamespace("four", "http:/namespace/four");
38         
39         assertEquals("http:/namespace/one", dnpr.getNamespaceURI("one"));
40         assertEquals("http:/namespace/two", dnpr.getNamespaceURI("two"));
41         assertEquals("http:/namespace/three", dnpr.getNamespaceURI("three"));
42         assertEquals("http:/namespace/one", dnpr.getNamespaceURI("oneagain"));
43         assertEquals("http:/namespace/four", dnpr.getNamespaceURI("four"));
44         assertEquals(null, dnpr.getNamespaceURI("five"));
45         
46         dnpr.unregisterNamespace("four");
47         assertEquals(null, dnpr.getNamespaceURI("four"));
48         
49         assertEquals(0, dnpr.getPrefixes("http:/namespace/four").size());
50         assertEquals(1, dnpr.getPrefixes("http:/namespace/two").size());
51         assertEquals(2, dnpr.getPrefixes("http:/namespace/one").size());
52         
53         
54     }
55     
56     
57     public void testTwo()
58     {
59         DynamicNamespacePrefixResolver dnpr1 = new DynamicNamespacePrefixResolver(null);
60         dnpr1.registerNamespace("one", "http:/namespace/one");
61         dnpr1.registerNamespace("two", "http:/namespace/two");
62         dnpr1.registerNamespace("three", "http:/namespace/three");
63         dnpr1.registerNamespace("oneagain", "http:/namespace/one");
64         dnpr1.registerNamespace("four", "http:/namespace/one");
65         dnpr1.registerNamespace("four", "http:/namespace/four");
66         dnpr1.registerNamespace("five", "http:/namespace/five");
67         dnpr1.registerNamespace("six", "http:/namespace/six");
68         
69         DynamicNamespacePrefixResolver dnpr2 = new DynamicNamespacePrefixResolver(dnpr1);
70         dnpr2.registerNamespace("a", "http:/namespace/one");
71         dnpr2.registerNamespace("b", "http:/namespace/two");
72         dnpr2.registerNamespace("c", "http:/namespace/three");
73         dnpr2.registerNamespace("d", "http:/namespace/one");
74         dnpr2.registerNamespace("e", "http:/namespace/one");
75         dnpr2.registerNamespace("f", "http:/namespace/four");
76         dnpr2.registerNamespace("five", "http:/namespace/one");
77         dnpr2.registerNamespace("six", "http:/namespace/seven");
78         
79         assertEquals("http:/namespace/one", dnpr2.getNamespaceURI("one"));
80         assertEquals("http:/namespace/two", dnpr2.getNamespaceURI("two"));
81         assertEquals("http:/namespace/three", dnpr2.getNamespaceURI("three"));
82         assertEquals("http:/namespace/one", dnpr2.getNamespaceURI("oneagain"));
83         assertEquals("http:/namespace/four", dnpr2.getNamespaceURI("four"));
84         assertEquals("http:/namespace/one", dnpr2.getNamespaceURI("five"));
85         dnpr2.unregisterNamespace("five");
86         
87         assertEquals("http:/namespace/five", dnpr2.getNamespaceURI("five"));
88         assertEquals("http:/namespace/one", dnpr2.getNamespaceURI("a"));
89         assertEquals("http:/namespace/two", dnpr2.getNamespaceURI("b"));
90         assertEquals("http:/namespace/three", dnpr2.getNamespaceURI("c"));
91         assertEquals("http:/namespace/one", dnpr2.getNamespaceURI("d"));
92         assertEquals("http:/namespace/one", dnpr2.getNamespaceURI("e"));
93         assertEquals("http:/namespace/four", dnpr2.getNamespaceURI("f"));
94         
95         assertEquals(5, dnpr2.getPrefixes("http:/namespace/one").size());
96         assertEquals(2, dnpr2.getPrefixes("http:/namespace/two").size());
97         assertEquals(2, dnpr2.getPrefixes("http:/namespace/three").size());
98         assertEquals(2, dnpr2.getPrefixes("http:/namespace/four").size());
99         assertEquals(1, dnpr2.getPrefixes("http:/namespace/five").size());
100         assertEquals(0, dnpr2.getPrefixes("http:/namespace/six").size());
101         assertEquals(1, dnpr2.getPrefixes("http:/namespace/seven").size());
102     }
103
104 }
105
Popular Tags