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.umo.UMODescriptor;
17 import org.mule.umo.manager.ObjectNotFoundException;
18 import org.mule.umo.manager.UMOContainerContext;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import javax.naming.Context;
24
25 public class EjbContainerContextTestCase extends AbstractContainerContextTestCase
26 {
27 public static final String EJB_NAME = "DummyEjb";
28
29 EjbContainerContext 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 EjbContainerContext();
49 Map env = new HashMap();
50 env.put(Context.INITIAL_CONTEXT_FACTORY, MuleInitialContextFactory.class.getName());
51 context.setEnvironment(env);
52
53 context.initialise();
54 Context ic = context.getContext();
55 ic.bind(EJB_NAME, new DummyEjbHomeProxy());
56 ic.bind(Apple.class.getName(), new Apple());
57 }
58
59 public void testContainerContext() throws Exception
60 {
61 UMOContainerContext container = getContainerContext();
62 assertNotNull(container);
63
64 Object result = null;
65
66 try
67 {
68 result = container.getComponent(null);
69 fail("Should throw ObjectNotFoundException for null key");
70 }
71 catch (ObjectNotFoundException e)
72 {
73
74 }
75
76 try
77 {
78 result = container.getComponent("abcdefg123456!£$%^n");
79 fail("Should throw ObjectNotFoundException for a key that doesn't exist");
80 }
81 catch (ObjectNotFoundException e)
82 {
83
84 }
85
86 try
87 {
88 result = container.getComponent(EJB_NAME);
89 assertNotNull("Component should exist in container", result);
90 }
91 catch (ObjectNotFoundException e)
92 {
93 fail("Component should exist in the container");
94 }
95 }
96
97
98
99
100
101
102
103 public void testExternalUMOReference() throws Exception
104 {
105 UMOContainerContext container = getContainerContext();
106 assertNotNull(container);
107 container.initialise();
108 UMODescriptor descriptor = getTestDescriptor("some Ejb service", EJB_NAME);
109 DummyEjbBean dummyEjbBean = (DummyEjbBean)container.getComponent(descriptor.getImplementation());
110
111 assertNotNull(dummyEjbBean);
112 }
113
114 public void testInvalidObjectLookup() throws Exception
115 {
116 UMOContainerContext container = getContainerContext();
117 container.initialise();
118 assertNotNull(container);
119
120 try
121 {
122 container.getComponent(Apple.class.getName());
123 fail("Should throw ObjectNotFoundException for non-ejb object");
124 }
125 catch (ObjectNotFoundException e)
126 {
127
128 }
129 }
130 }