1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.jca;
12
13 import org.mule.api.MuleEvent;
14 import org.mule.api.MuleException;
15 import org.mule.api.endpoint.ImmutableEndpoint;
16 import org.mule.api.service.Service;
17 import org.mule.model.resolvers.DefaultEntryPointResolverSet;
18 import org.mule.tck.AbstractMuleTestCase;
19
20 import java.lang.reflect.Method;
21
22 import javax.resource.ResourceException;
23 import javax.resource.spi.UnavailableException;
24 import javax.resource.spi.endpoint.MessageEndpoint;
25 import javax.resource.spi.endpoint.MessageEndpointFactory;
26 import javax.transaction.xa.XAResource;
27
28 public class JcaServiceTestCase extends AbstractMuleTestCase
29 {
30
31
32
33
34 private Service service;
35
36 private TestJCAWorkManager workManager;
37
38 protected void doSetUp() throws Exception
39 {
40
41 workManager = new TestJCAWorkManager();
42 JcaModel jcaModel = new JcaModel();
43 muleContext.getRegistry().registerModel(jcaModel);
44
45
46 String name = "JcaService#";
47 service = new JcaService();
48 service.setName(name);
49 service.setModel(jcaModel);
50 service.setComponent(new JcaComponent(new TestMessageEndpointFactory(), new DefaultEntryPointResolverSet(),
51 service, workManager));
52 muleContext.getRegistry().registerService(service);
53
54 assertNotNull(service);
55 }
56
57 protected void doTearDown() throws Exception
58 {
59 workManager = null;
60 service = null;
61 }
62
63 public void testSendEvent() throws Exception
64 {
65 service.start();
66 ImmutableEndpoint endpoint = getTestInboundEndpoint("jcaInFlowEndpoint");
67 MuleEvent event = getTestEvent("Message", endpoint);
68
69 try
70 {
71 service.sendEvent(event);
72 fail("Exception expected, JcaService does not support sendEvent()");
73 }
74 catch (Exception e)
75 {
76
77 }
78 }
79
80 public void testDispatchEvent() throws Exception
81 {
82 service.start();
83 ImmutableEndpoint endpoint = getTestInboundEndpoint("jcaInFlowEndpoint");
84 MuleEvent event = getTestEvent("Message", endpoint);
85
86 service.dispatchEvent(event);
87 assertEquals(1, workManager.getScheduledWorkList().size());
88 assertEquals(0, workManager.getStartWorkList().size());
89 assertEquals(0, workManager.getDoWorkList().size());
90 }
91
92 public void testPause()
93 {
94 try
95 {
96 service.pause();
97 fail("Exception expected, JcaService does not support pause()");
98 }
99 catch (MuleException e)
100 {
101
102 }
103 }
104
105 public void testResume()
106 {
107 try
108 {
109 service.resume();
110 fail("Exception expected, JcaService does not support resume()");
111 }
112 catch (MuleException e)
113 {
114
115 }
116 }
117
118 class TestMessageEndpointFactory implements MessageEndpointFactory
119 {
120
121 public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException
122 {
123 return null;
124 }
125
126 public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
127 {
128 return false;
129 }
130
131 }
132
133 class TestMessageEndoint implements MessageEndpoint
134 {
135
136 public void afterDelivery() throws ResourceException
137 {
138
139
140 }
141
142 public void beforeDelivery(Method method) throws NoSuchMethodException, ResourceException
143 {
144
145
146 }
147
148 public void release()
149 {
150
151
152 }
153
154 }
155
156 }