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 public class JndiContainerContextTestCase extends AbstractContainerContextTestCase
28 {
29 JndiContainerContext context;
30
31
32
33
34
35
36 public UMOContainerContext getContainerContext()
37 {
38 return context;
39 }
40
41
42
43
44
45
46 protected void doSetUp() throws Exception
47 {
48 context = new JndiContainerContext();
49 Map env = new HashMap();
50 env.put(Context.INITIAL_CONTEXT_FACTORY, MuleInitialContextFactory.class.getName());
51 context.setEnvironment(env);
52 context.initialise();
53 Context ic = context.getContext();
54 ic.bind(FruitBowl.class.getName(), new FruitBowl(new Apple(), new Banana()));
55 ic.bind(Apple.class.getName(), new Apple());
56 }
57
58 public void testExternalUMOReference() throws Exception
59 {
60 UMOContainerContext ctx = getContainerContext();
61 assertNotNull(ctx);
62
63 UMODescriptor descriptor = getTestDescriptor("fruit Bowl", "org.mule.tck.testmodels.fruit.FruitBowl");
64 FruitBowl fruitBowl = (FruitBowl)ctx.getComponent(descriptor.getImplementation());
65
66 assertNotNull(fruitBowl);
67 }
68
69
70
71
72
73 public void testDefaultInitialContext() throws Exception
74 {
75 Context icEnv = context.getContext();
76 assertNotNull(icEnv);
77
78
79 context.setEnvironment(null);
80 context.setContext(null);
81 context.initialise();
82 Context icDefault = context.getContext();
83 assertNotNull(icDefault);
84 assertNotSame(icEnv, icDefault);
85
86
87 context.setEnvironment(Collections.EMPTY_MAP);
88 context.setContext(null);
89 context.initialise();
90 icDefault = context.getContext();
91 assertNotNull(icDefault);
92
93 assertNotSame(icEnv, icDefault);
94 }
95 }