KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > registry > jndi > NamingContextImplTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: NamingContextImplTest.java 11:11:06 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.kernel.registry.jndi;
23
24 import java.util.Hashtable JavaDoc;
25
26 import javax.naming.CompositeName JavaDoc;
27 import javax.naming.InvalidNameException JavaDoc;
28 import javax.naming.Name JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30
31 import org.objectweb.petals.kernel.registry.jndi.mock.MockJNDIConnection;
32
33 import junit.framework.TestCase;
34
35 /**
36  * Tests of the NamingContextImpl
37  *
38  * @author ddesjardins - eBMWebsourcing
39  */

40 public class NamingContextImplTest extends TestCase {
41
42     protected NamingContextImpl namingContextImpl;
43
44     protected MockJNDIConnection connection;
45
46     public void setUp() {
47         connection = new MockJNDIConnection(9999, "127.0.0.1");
48         namingContextImpl = new NamingContextImpl(
49             new Hashtable JavaDoc<String JavaDoc, Object JavaDoc>(), connection, "test");
50     }
51
52     public void testAddToEnvironment() throws NamingException JavaDoc {
53         namingContextImpl.addToEnvironment("key", "value");
54         assertEquals(namingContextImpl.env.get("key"), "value");
55     }
56
57     public void testBindName() throws InvalidNameException JavaDoc, NamingException JavaDoc {
58         namingContextImpl.bind(new CompositeName JavaDoc("foo"), "bar");
59         assertTrue(connection.isBind());
60     }
61
62     public void testBindString() throws NamingException JavaDoc {
63         namingContextImpl.bind("foo", "bar");
64         assertTrue(connection.isBind());
65     }
66
67     public void testClose() throws NamingException JavaDoc {
68         namingContextImpl.close();
69         assertNull(namingContextImpl.jndiConnection);
70     }
71
72     public void testComposeNameName() throws InvalidNameException JavaDoc,
73         NamingException JavaDoc {
74         Name JavaDoc name = namingContextImpl.composeName(new CompositeName JavaDoc("foo"),
75             new CompositeName JavaDoc("bar"));
76         assertEquals(name, new CompositeName JavaDoc("barfoo"));
77     }
78
79     public void testComposeNameNameException() throws InvalidNameException JavaDoc,
80         NamingException JavaDoc {
81         try {
82             namingContextImpl.composeName((CompositeName JavaDoc) null, null);
83             fail();
84         } catch (Exception JavaDoc e) {
85             // do nothing
86
}
87     }
88
89     public void testComposeNameNameException1() throws InvalidNameException JavaDoc,
90         NamingException JavaDoc {
91         try {
92             namingContextImpl.composeName(new CompositeName JavaDoc("foo"), null);
93             fail();
94         } catch (Exception JavaDoc e) {
95             // do nothing
96
}
97     }
98
99     public void testComposeNameString() throws InvalidNameException JavaDoc,
100         NamingException JavaDoc {
101         String JavaDoc name = namingContextImpl.composeName("foo", "/bar/");
102         assertEquals(name, "/bar/foo");
103     }
104
105     public void testComposeNameStringException() throws InvalidNameException JavaDoc,
106         NamingException JavaDoc {
107         try {
108             namingContextImpl.composeName((String JavaDoc) null, null);
109             fail();
110         } catch (Exception JavaDoc e) {
111             // do nothing
112
}
113     }
114
115     public void testComposeNameStringException1() throws InvalidNameException JavaDoc,
116         NamingException JavaDoc {
117         try {
118             namingContextImpl.composeName("foo", null);
119             fail();
120         } catch (Exception JavaDoc e) {
121             // do nothing
122
}
123     }
124
125     public void testCreateSubcontextName() throws InvalidNameException JavaDoc,
126         NamingException JavaDoc {
127         namingContextImpl.createSubcontext(new CompositeName JavaDoc("test"));
128         assertTrue(connection.isCreateSubcontext());
129     }
130
131     public void testCreateSubcontextString() throws InvalidNameException JavaDoc,
132         NamingException JavaDoc {
133         namingContextImpl.createSubcontext("test");
134         assertTrue(connection.isCreateSubcontext());
135     }
136
137     public void testDestroySubcontextName() throws InvalidNameException JavaDoc,
138         NamingException JavaDoc {
139         namingContextImpl.destroySubcontext(new CompositeName JavaDoc("test"));
140         assertTrue(connection.isDestroySubcontext());
141     }
142
143     public void testDestroySubcontextString() throws InvalidNameException JavaDoc,
144         NamingException JavaDoc {
145         namingContextImpl.destroySubcontext("test");
146         assertTrue(connection.isDestroySubcontext());
147     }
148
149     public void testGetEnvironment() throws NamingException JavaDoc {
150         assertEquals(namingContextImpl.getEnvironment().size(), 0);
151     }
152
153     public void testGetNameInNamespace() throws NamingException JavaDoc {
154         assertEquals(namingContextImpl.getNameInNamespace(), "test");
155     }
156
157     public void testGetNameParserName() throws InvalidNameException JavaDoc,
158         NamingException JavaDoc {
159         assertNotNull(namingContextImpl
160             .getNameParser(new CompositeName JavaDoc("test")));
161     }
162
163     public void testGetNameParserString() throws InvalidNameException JavaDoc,
164         NamingException JavaDoc {
165         assertNotNull(namingContextImpl.getNameParser("test"));
166     }
167
168     public void testListName() throws InvalidNameException JavaDoc, NamingException JavaDoc {
169         namingContextImpl.list(new CompositeName JavaDoc("test"));
170         assertTrue(connection.isList());
171     }
172
173     public void testListString() throws InvalidNameException JavaDoc, NamingException JavaDoc {
174         namingContextImpl.list("test");
175         assertTrue(connection.isList());
176     }
177
178     public void testListBindingsName() throws InvalidNameException JavaDoc,
179         NamingException JavaDoc {
180         namingContextImpl.listBindings(new CompositeName JavaDoc("test"));
181         assertTrue(connection.isListBindings());
182     }
183
184     public void testListBindingsString() throws InvalidNameException JavaDoc,
185         NamingException JavaDoc {
186         namingContextImpl.listBindings("test");
187         assertTrue(connection.isListBindings());
188     }
189
190     public void testLookupName() throws InvalidNameException JavaDoc, NamingException JavaDoc {
191         namingContextImpl.lookup(new CompositeName JavaDoc("test"));
192         assertTrue(connection.isLookup());
193     }
194
195     public void testLookupString() throws InvalidNameException JavaDoc, NamingException JavaDoc {
196         namingContextImpl.lookup("test");
197         assertTrue(connection.isLookup());
198     }
199
200     public void testLookupLinkName() throws InvalidNameException JavaDoc,
201         NamingException JavaDoc {
202         namingContextImpl.lookupLink(new CompositeName JavaDoc("test"));
203         assertTrue(connection.isLookupLink());
204     }
205
206     public void testLookupLinkString() throws InvalidNameException JavaDoc,
207         NamingException JavaDoc {
208         namingContextImpl.lookupLink("test");
209         assertTrue(connection.isLookupLink());
210     }
211
212     public void testRebindName() throws InvalidNameException JavaDoc, NamingException JavaDoc {
213         namingContextImpl.rebind(new CompositeName JavaDoc("test"), "foo");
214         assertTrue(connection.isRebind());
215     }
216
217     public void testRebindString() throws InvalidNameException JavaDoc, NamingException JavaDoc {
218         namingContextImpl.rebind("test", "foo");
219         assertTrue(connection.isRebind());
220     }
221
222     public void testRemoveFromEnvironment() throws InvalidNameException JavaDoc,
223         NamingException JavaDoc {
224         namingContextImpl.env.put("key", "test");
225         namingContextImpl.removeFromEnvironment("key");
226         assertNull(namingContextImpl.env.get("key"));
227     }
228
229     public void testRenameName() throws InvalidNameException JavaDoc, NamingException JavaDoc {
230         namingContextImpl.rename(new CompositeName JavaDoc("test"), new CompositeName JavaDoc(
231             "test1"));
232         assertTrue(connection.isRename());
233     }
234
235     public void testRenameString() throws InvalidNameException JavaDoc, NamingException JavaDoc {
236         namingContextImpl.rename("test", "test1");
237         assertTrue(connection.isRename());
238     }
239
240     public void testUnbindName() throws InvalidNameException JavaDoc, NamingException JavaDoc {
241         namingContextImpl.unbind(new CompositeName JavaDoc("test"));
242         assertTrue(connection.isUnbind());
243     }
244
245     public void testUnbindString() throws InvalidNameException JavaDoc, NamingException JavaDoc {
246         namingContextImpl.unbind(new CompositeName JavaDoc("test"));
247         assertTrue(connection.isUnbind());
248     }
249
250 }
251
Popular Tags