KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > JNDIUtilTest


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: JNDIUtilTest.java 9:19:04 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 import javax.naming.Context JavaDoc;
25 import javax.naming.Name JavaDoc;
26 import javax.naming.NameClassPair JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 import junit.framework.TestCase;
30
31 import org.easymock.classextension.EasyMock;
32 import org.objectweb.petals.util.mock.NamingEnumerationImpl;
33
34 /**
35  * Test of the JNDIUtil
36  *
37  * @author ddesjardins - eBMWebsourcing
38  */

39 public class JNDIUtilTest extends TestCase {
40
41     public void testIsBoundNameString() throws SecurityException JavaDoc,
42         NoSuchMethodException JavaDoc, NamingException JavaDoc {
43         Context JavaDoc context = EasyMock.createMock(Context JavaDoc.class);
44         Name JavaDoc name = EasyMock.createMock(Name JavaDoc.class);
45         NamingEnumerationImpl<NameClassPair JavaDoc> namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair JavaDoc>(
46             new NameClassPair JavaDoc[] {});
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 JavaDoc,
58         NoSuchMethodException JavaDoc, NamingException JavaDoc {
59         Context JavaDoc context = EasyMock.createMock(Context JavaDoc.class);
60         Name JavaDoc name = EasyMock.createMock(Name JavaDoc.class);
61         Name JavaDoc name1 = EasyMock.createMock(Name JavaDoc.class);
62         NamingEnumerationImpl<NameClassPair JavaDoc> namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair JavaDoc>(
63             new NameClassPair JavaDoc[] {});
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 JavaDoc,
76         NoSuchMethodException JavaDoc, NamingException JavaDoc {
77         Context JavaDoc context = EasyMock.createMock(Context JavaDoc.class);
78         Name JavaDoc name1 = EasyMock.createMock(Name JavaDoc.class);
79         NamingEnumerationImpl<NameClassPair JavaDoc> namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair JavaDoc>(
80             new NameClassPair JavaDoc[] {});
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 JavaDoc,
91         NoSuchMethodException JavaDoc, NamingException JavaDoc {
92         Context JavaDoc context = EasyMock.createMock(Context JavaDoc.class);
93         NamingEnumerationImpl<NameClassPair JavaDoc> namingEnumerationImpl = new NamingEnumerationImpl<NameClassPair JavaDoc>(
94             new NameClassPair JavaDoc[] {new NameClassPair JavaDoc("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 JavaDoc,
104         NoSuchMethodException JavaDoc, NamingException JavaDoc {
105         Context JavaDoc context = EasyMock.createMock(Context JavaDoc.class);
106
107         EasyMock.expect(context.list("name")).andThrow(new NamingException JavaDoc());
108
109         EasyMock.replay(context);
110
111         assertFalse(JNDIUtil.isBound(context, "name", "name1"));
112     }
113 }
114
Popular Tags