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