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.AbstractServiceTestCase;
18 import org.mule.model.resolvers.DefaultEntryPointResolverSet;
19
20 import java.lang.reflect.Method;
21
22 import javax.resource.spi.UnavailableException;
23 import javax.resource.spi.endpoint.MessageEndpoint;
24 import javax.resource.spi.endpoint.MessageEndpointFactory;
25 import javax.transaction.xa.XAResource;
26
27 import org.junit.Test;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.fail;
31
32 public class JcaServiceTestCase extends AbstractServiceTestCase
33 {
34 private Service service;
35
36 protected void doSetUp() throws Exception
37 {
38
39 workManager = new TestJCAWorkManager();
40 JcaModel jcaModel = new JcaModel();
41 jcaModel.setMuleContext(muleContext);
42 jcaModel.initialise();
43
44 String name = "JcaService#";
45 service = new JcaService(muleContext);
46 service.setName(name);
47 service.setModel(jcaModel);
48 service.setComponent(new JcaComponent(new TestMessageEndpointFactory(), new DefaultEntryPointResolverSet(),
49 service, workManager));
50 }
51
52 @Override
53 protected Service getService()
54 {
55 return service;
56 }
57
58 private TestJCAWorkManager workManager;
59
60 protected void doTearDown() throws Exception
61 {
62 workManager = null;
63 service = null;
64 }
65
66 @Test
67 public void testSendEvent() throws Exception
68 {
69 getService().initialise();
70 getService().start();
71 ImmutableEndpoint endpoint = getTestInboundEndpoint("jcaInFlowEndpoint");
72 MuleEvent event = getTestEvent("Message");
73
74 try
75 {
76 service.sendEvent(event);
77 fail("Exception expected, JcaService does not support sendEvent()");
78 }
79 catch (Exception e)
80 {
81
82 }
83 }
84
85 @Test
86 public void testDispatchEvent() throws Exception
87 {
88 getService().initialise();
89 getService().start();
90 ImmutableEndpoint endpoint = getTestInboundEndpoint("jcaInFlowEndpoint");
91 MuleEvent event = getTestEvent("Message");
92
93 getService().dispatchEvent(event);
94 assertEquals(1, workManager.getScheduledWorkList().size());
95 assertEquals(0, workManager.getStartWorkList().size());
96 assertEquals(0, workManager.getDoWorkList().size());
97 }
98
99 @Test
100 public void testPause() throws MuleException
101 {
102 try
103 {
104 getService().pause();
105 fail("Exception expected, JcaService does not support pause()");
106 }
107 catch (IllegalStateException e)
108 {
109
110 }
111 }
112
113 @Test
114 public void testResume() throws MuleException
115 {
116 try
117 {
118 service.resume();
119 fail("Exception expected, JcaService does not support resume()");
120 }
121 catch (IllegalStateException e)
122 {
123
124 }
125 }
126
127 class TestMessageEndpointFactory implements MessageEndpointFactory
128 {
129
130 public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException
131 {
132 return null;
133 }
134
135 public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
136 {
137 return false;
138 }
139 }
140 }