1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl.container;
12
13 import org.mule.impl.jndi.MuleInitialContextFactory;
14 import org.mule.tck.model.AbstractContainerContextTestCase;
15 import org.mule.tck.testmodels.fruit.Apple;
16 import org.mule.tck.testmodels.fruit.Banana;
17 import org.mule.tck.testmodels.fruit.FruitBowl;
18 import org.mule.umo.UMODescriptor;
19 import org.mule.umo.manager.UMOContainerContext;
20
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import javax.naming.Context;
26
27
28
29
30
31 public class JndiContainerContextTestCase extends AbstractContainerContextTestCase
32 {
33 JndiContainerContext context;
34
35
36
37
38
39
40 public UMOContainerContext getContainerContext()
41 {
42 return context;
43 }
44
45
46
47
48
49
50 protected void doSetUp() throws Exception
51 {
52 context = new JndiContainerContext();
53 Map env = new HashMap();
54 env.put(Context.INITIAL_CONTEXT_FACTORY, MuleInitialContextFactory.class.getName());
55 context.setEnvironment(env);
56 context.initialise();
57 Context ic = context.getContext();
58 ic.bind(FruitBowl.class.getName(), new FruitBowl(new Apple(), new Banana()));
59 ic.bind(Apple.class.getName(), new Apple());
60 }
61
62 public void testExternalUMOReference() throws Exception
63 {
64 UMOContainerContext ctx = getContainerContext();
65 assertNotNull(ctx);
66
67 UMODescriptor descriptor = getTestDescriptor("fruit Bowl", "org.mule.tck.testmodels.fruit.FruitBowl");
68 FruitBowl fruitBowl = (FruitBowl)ctx.getComponent(descriptor.getImplementation());
69
70 assertNotNull(fruitBowl);
71 }
72
73
74
75
76
77 public void testDefaultInitialContext() throws Exception
78 {
79 Context icEnv = context.getContext();
80 assertNotNull(icEnv);
81
82
83 context.setEnvironment(null);
84 context.setContext(null);
85 context.initialise();
86 Context icDefault = context.getContext();
87 assertNotNull(icDefault);
88 assertNotSame(icEnv, icDefault);
89
90
91 context.setEnvironment(Collections.EMPTY_MAP);
92 context.setContext(null);
93 context.initialise();
94 icDefault = context.getContext();
95 assertNotNull(icDefault);
96
97 assertNotSame(icEnv, icDefault);
98 }
99 }