6016e2b3e041e75b7c461994086dc0738dc54c6a
[utils] /
1 package org.wamblee.support.jndi;
2
3 import static junit.framework.Assert.assertEquals;
4
5 import javax.naming.InitialContext;
6 import javax.naming.NamingException;
7
8 import org.junit.After;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.wamblee.support.jndi.StubInitialContextFactory;
12
13 public class StubInitiaContextFactoryTest {
14
15         @Before
16         @After
17         public void setUp() { 
18                 StubInitialContextFactory.unregister();
19         }
20
21         
22         @Test(expected = NamingException.class)
23         public void testLookupNotRegistered() throws Exception { 
24                 InitialContext ctx = new InitialContext();
25                 ctx.bind("a/b", "hallo");
26         }
27         
28         @Test
29         public void testLookup() throws Exception {
30             StubInitialContextFactory.register();
31             
32                 InitialContext ctx = new InitialContext();
33                 ctx.bind("a/b", "hallo");
34                 
35                 ctx = new InitialContext(); 
36                 Object obj = ctx.lookup("a/b");
37                 
38                 assertEquals("hallo", obj);
39         }
40         
41 }