KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > namespaces > NamespaceRegistryTest


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5
6 package org.exoplatform.services.jcr.api.namespaces;
7
8
9 import javax.jcr.NamespaceRegistry;
10 import javax.jcr.RepositoryException;
11 import javax.jcr.NamespaceException;
12
13 import org.apache.commons.lang.ArrayUtils;
14 import org.exoplatform.services.jcr.BaseTest;
15
16 /**
17  * Created y the eXo platform team
18  * User: Benjamin Mestrallet
19  * Date: 14 aout 2004
20  */

21 public class NamespaceRegistryTest extends BaseTest{
22
23   private NamespaceRegistry namespaceRegistry;
24
25   public void init() throws Exception JavaDoc {
26     workspace = ticket.getWorkspace();
27     namespaceRegistry = workspace.getNamespaceRegistry();
28   }
29
30   public void testSetMapping() throws RepositoryException {
31     try {
32       namespaceRegistry.setMapping("jcr", null);
33       fail("exception should have been thrown");
34     } catch (NamespaceException e) {
35     }
36     try {
37       namespaceRegistry.setMapping("nt", null);
38       fail("exception should have been thrown");
39     } catch (NamespaceException e) {
40     }
41     try {
42       namespaceRegistry.setMapping("mix", null);
43       fail("exception should have been thrown");
44     } catch (NamespaceException e) {
45     }
46     try {
47       namespaceRegistry.setMapping("pt", null);
48       fail("exception should have been thrown");
49     } catch (NamespaceException e) {
50     }
51     try {
52       namespaceRegistry.setMapping("sv", null);
53       fail("exception should have been thrown");
54     } catch (NamespaceException e) {
55     }
56
57     try {
58       namespaceRegistry.setMapping("jcr", "http://dumb.uri/jcr");
59       fail("exception should have been thrown");
60     } catch (NamespaceException e) {
61     }
62
63     namespaceRegistry.setMapping("newMapping", null);
64     namespaceRegistry.setMapping("newMapping", "http://dumb.uri/jcr");
65     assertNotNull(namespaceRegistry.getURI("newMapping"));
66     assertEquals("http://dumb.uri/jcr", namespaceRegistry.getURI("newMapping"));
67     namespaceRegistry.setMapping("newMapping", null);
68     assertNull(namespaceRegistry.getURI("newMapping"));
69
70     namespaceRegistry.setMapping("newMapping", "http://dumb.uri/jcr");
71     namespaceRegistry.setMapping("newMapping2", "http://dumb.uri/jcr");
72     assertNull(namespaceRegistry.getURI("newMapping"));
73     assertNotNull(namespaceRegistry.getURI("newMapping2"));
74     assertEquals("http://dumb.uri/jcr", namespaceRegistry.getURI("newMapping2"));
75   }
76
77   public void testGetPrefixes() throws RepositoryException {
78     namespaceRegistry.setMapping("newMapping", "http://dumb.uri/jcr");
79     String JavaDoc[] namespaces = {"jcr", "nt", "mix","pt", "sv", "exo", "newMapping"};
80
81     String JavaDoc[] prefixes = namespaceRegistry.getPrefixes();
82     for (int i = 0; i < prefixes.length; i++) {
83       String JavaDoc prefix = prefixes[i];
84       assertTrue(ArrayUtils.contains(namespaces, prefix));
85     }
86     assertEquals(7, prefixes.length);
87   }
88
89   public void testGetURIs() throws RepositoryException {
90     namespaceRegistry.setMapping("newMapping", "http://dumb.uri/jcr");
91     String JavaDoc[] namespacesURIs = {"http://www.jcp.org/jcr/1.0", "http://www.jcp.org/jcr/nt/1.0",
92                                "http://www.jcp.org/jcr/mix/1.0", "http://www.jcp.org/jcr/pt/1.0",
93                                "http://www.jcp.org/jcr/sv/1.0", "http://www.exoplatform.com/jcr/exo/1.0",
94                                "http://dumb.uri/jcr"};
95
96     String JavaDoc[] uris = namespaceRegistry.getURIs();
97     for (int i = 0; i < uris.length; i++) {
98       String JavaDoc uri = uris[i];
99       assertTrue(ArrayUtils.contains(namespacesURIs, uri));
100     }
101     assertEquals(7, uris.length);
102   }
103
104   public void testGetURI() throws RepositoryException {
105     namespaceRegistry.setMapping("newMapping", "http://dumb.uri/jcr");
106
107     assertNotNull(namespaceRegistry.getURI("mix"));
108     assertNotNull(namespaceRegistry.getURI("newMapping"));
109   }
110
111   public void testGetPrefix() throws RepositoryException {
112     namespaceRegistry.setMapping("newMapping", "http://dumb.uri/jcr");
113
114     assertNotNull(namespaceRegistry.getPrefix("http://www.jcp.org/jcr/mix/1.0"));
115     assertNotNull(namespaceRegistry.getPrefix("http://dumb.uri/jcr"));
116
117     try {
118       namespaceRegistry.getPrefix("http://dumb.uri/jcr2");
119       fail("exception should have been thrown");
120     } catch (RepositoryException e) {
121     }
122   }
123
124 }
125
Popular Tags