KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > geronimo > GeronimoContextTest


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.naming.geronimo;
19
20 import java.util.Set JavaDoc;
21 import javax.naming.Context JavaDoc;
22 import javax.naming.NamingException JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  *
28  *
29  * @version $Rev: 47116 $ $Date: 2004-09-23 13:35:58 -0700 (Thu, 23 Sep 2004) $
30  *
31  * */

32 public class GeronimoContextTest extends TestCase {
33     private GeronimoContext context;
34
35     protected void setUp() throws Exception JavaDoc {
36         context = new GeronimoContext();
37         context.internalBind("one", "one");
38         context.internalBind("this/is/a/compound/name", "two");
39         context.internalBind("this/is/another/compound/name", "three");
40         context.internalBind("thing/one", "uno");
41         context.internalBind("thing/two", "doz");
42     }
43
44     public void testLookup() throws Exception JavaDoc {
45         assertEquals(context.lookup("one"), "one");
46         assertEquals(context.lookup("this/is/a/compound/name"), "two");
47         assertEquals(context.lookup("this/is/another/compound/name"), "three");
48         assertEquals(context.lookup("thing/one"), "uno");
49         assertEquals(context.lookup("thing/two"), "doz");
50     }
51
52     public void testLookupSubContext() throws Exception JavaDoc {
53         Context JavaDoc context = (Context JavaDoc) this.context.lookup("this/is");
54         assertEquals(context.lookup("a/compound/name"), "two");
55         assertEquals(context.lookup("another/compound/name"), "three");
56
57         context = (Context JavaDoc) this.context.lookup("thing");
58         assertEquals(context.lookup("one"), "uno");
59         assertEquals(context.lookup("two"), "doz");
60     }
61
62     public void testUnbind() throws Exception JavaDoc {
63         assertEquals(1, context.internalUnbind("one").size());
64         try {
65             context.lookup("one");
66             fail();
67         } catch (NamingException JavaDoc e) {
68         }
69         assertEquals(3, context.internalUnbind("this/is/a/compound/name").size());
70         try {
71             context.lookup("this/is/a/compound/name");
72             fail();
73         } catch (NamingException JavaDoc e) {
74         }
75         context.lookup("this/is");
76         Set JavaDoc set = context.internalUnbind("this/is/another/compound/name");
77         int actual = set.size();
78         assertEquals(5, actual);
79         try {
80             context.lookup("this/is");
81             fail();
82         } catch (NamingException JavaDoc e) {
83         }
84     }
85 }
86
Popular Tags