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