1 17 18 package org.apache.geronimo.naming.geronimo; 19 20 import java.util.Set ; 21 import javax.naming.Context ; 22 import javax.naming.NamingException ; 23 24 import junit.framework.TestCase; 25 26 32 public class GeronimoContextTest extends TestCase { 33 private GeronimoContext context; 34 35 protected void setUp() throws Exception { 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 { 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 { 53 Context context = (Context ) 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 ) this.context.lookup("thing"); 58 assertEquals(context.lookup("one"), "uno"); 59 assertEquals(context.lookup("two"), "doz"); 60 } 61 62 public void testUnbind() throws Exception { 63 assertEquals(1, context.internalUnbind("one").size()); 64 try { 65 context.lookup("one"); 66 fail(); 67 } catch (NamingException 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 e) { 74 } 75 context.lookup("this/is"); 76 Set 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 e) { 83 } 84 } 85 } 86 | Popular Tags |