1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.jms.vendors;
12
13 import org.mule.tck.junit4.FunctionalTestCase;
14 import org.mule.transport.jms.JmsConnector;
15 import org.mule.transport.jms.xa.ConnectionFactoryWrapper;
16 import org.mule.transport.jms.xa.TargetInvocationHandler;
17
18 import java.lang.reflect.Method;
19 import java.lang.reflect.Proxy;
20
21 import javax.jms.Connection;
22 import javax.jms.ConnectionFactory;
23
24 import org.apache.activemq.ActiveMQXAConnectionFactory;
25 import org.junit.Test;
26
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 public class ActiveMQXaJmsConnectorTestCase extends FunctionalTestCase
31 {
32
33 @Override
34 protected String getConfigResources()
35 {
36 return "activemq-xa.xml";
37 }
38
39 @Test
40 public void testReflectiveXaCleanup() throws Exception
41 {
42 JmsConnector c = (JmsConnector)muleContext.getRegistry().lookupConnector("jmsConnector");
43 assertNotNull(c);
44
45 ConnectionFactory cf = c.getConnectionFactory();
46 assertTrue(cf instanceof ActiveMQXAConnectionFactory);
47
48 ConnectionFactoryWrapper wrapper = new ConnectionFactoryWrapper(cf);
49
50 Connection connection = wrapper.createConnection();
51 assertNotNull(connection);
52 assertTrue(Proxy.isProxyClass(connection.getClass()));
53
54 try
55 {
56 final Class clazz = connection.getClass();
57 Method cleanupMethod;
58 if (Proxy.isProxyClass(clazz))
59 {
60 TargetInvocationHandler handler =
61 (TargetInvocationHandler) Proxy.getInvocationHandler(connection);
62
63 connection = (Connection) handler.getTargetObject();
64 Class realConnectionClass = connection.getClass();
65 cleanupMethod = realConnectionClass.getMethod("cleanup", (Class[])null);
66 }
67 else
68 {
69 cleanupMethod = clazz.getMethod("cleanup", (Class[])null);
70 }
71
72
73 if (cleanupMethod != null)
74 {
75 cleanupMethod.invoke(connection, (Object[])null);
76 }
77 }
78 finally
79 {
80 connection.close();
81 }
82
83
84 }
85 }