1 22 package org.objectweb.petals.util; 23 24 import javax.naming.Context ; 25 import javax.naming.Name ; 26 import javax.naming.NameClassPair ; 27 import javax.naming.NamingException ; 28 29 import junit.framework.TestCase; 30 31 import org.easymock.classextension.EasyMock; 32 import org.objectweb.petals.util.mock.NamingEnumerationImpl; 33 34 39 public class JNDIUtilTest extends TestCase { 40 41 public void testIsBoundNameString() throws SecurityException , 42 NoSuchMethodException , NamingException { 43 Context context = EasyMock.createMock(Context .class); 44 Name name = EasyMock.createMock(Name .class); 45 NamingEnumerationImpl<NameClassPair > namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair >( 46 new NameClassPair [] {}); 47 48 EasyMock.expect(context.list(name.toString())).andReturn( 49 namingEnumerationImpl); 50 51 EasyMock.replay(context); 52 EasyMock.replay(name); 53 54 assertFalse(JNDIUtil.isBound(context, name, "name")); 55 } 56 57 public void testIsBoundNameName() throws SecurityException , 58 NoSuchMethodException , NamingException { 59 Context context = EasyMock.createMock(Context .class); 60 Name name = EasyMock.createMock(Name .class); 61 Name name1 = EasyMock.createMock(Name .class); 62 NamingEnumerationImpl<NameClassPair > namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair >( 63 new NameClassPair [] {}); 64 65 EasyMock.expect(context.list(name.toString())).andReturn( 66 namingEnumerationImpl); 67 68 EasyMock.replay(context); 69 EasyMock.replay(name); 70 EasyMock.replay(name1); 71 72 assertFalse(JNDIUtil.isBound(context, name, name1)); 73 } 74 75 public void testIsBoundStringName() throws SecurityException , 76 NoSuchMethodException , NamingException { 77 Context context = EasyMock.createMock(Context .class); 78 Name name1 = EasyMock.createMock(Name .class); 79 NamingEnumerationImpl<NameClassPair > namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair >( 80 new NameClassPair [] {}); 81 82 EasyMock.expect(context.list("name")).andReturn(namingEnumerationImpl); 83 84 EasyMock.replay(context); 85 EasyMock.replay(name1); 86 87 assertFalse(JNDIUtil.isBound(context, "name", name1)); 88 } 89 90 public void testIsBoundStringString() throws SecurityException , 91 NoSuchMethodException , NamingException { 92 Context context = EasyMock.createMock(Context .class); 93 NamingEnumerationImpl<NameClassPair > namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair >( 94 new NameClassPair [] {new NameClassPair ("name1", "foo")}); 95 96 EasyMock.expect(context.list("name")).andReturn(namingEnumerationImpl); 97 98 EasyMock.replay(context); 99 100 assertTrue(JNDIUtil.isBound(context, "name", "name1")); 101 } 102 103 public void testIsBoundStringStringException() throws SecurityException , 104 NoSuchMethodException , NamingException { 105 Context context = EasyMock.createMock(Context .class); 106 107 EasyMock.expect(context.list("name")).andThrow(new NamingException ()); 108 109 EasyMock.replay(context); 110 111 assertFalse(JNDIUtil.isBound(context, "name", "name1")); 112 } 113 } 114 | Popular Tags |