1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import javax.resource.ResourceException ; 21 import javax.transaction.xa.XAException ; 22 import javax.transaction.xa.XAResource ; 23 import javax.transaction.xa.Xid ; 24 25 31 public class XAResourceInsertionInterceptorTest extends ConnectionInterceptorTestUtils { 32 33 private XAResourceInsertionInterceptor xaResourceInsertionInterceptor; 34 private XAResource xaResource; 35 private String name = "XAResource"; 36 37 protected void setUp() throws Exception { 38 super.setUp(); 39 xaResourceInsertionInterceptor = new XAResourceInsertionInterceptor(this, name); 40 } 41 42 protected void tearDown() throws Exception { 43 super.tearDown(); 44 xaResourceInsertionInterceptor = null; 45 } 46 47 public void testInsertXAResource() throws Exception { 48 ConnectionInfo connectionInfo = makeConnectionInfo(); 49 xaResource = new TestXAResource(); 50 managedConnection = new TestManagedConnection(xaResource); 51 xaResourceInsertionInterceptor.getConnection(connectionInfo); 52 xaResource.setTransactionTimeout(200); 53 assertEquals("Expected the same XAResource", 200, connectionInfo.getManagedConnectionInfo().getXAResource().getTransactionTimeout()); 55 } 56 57 58 private static class TestXAResource implements XAResource { 59 private int txTimeout; 60 61 public void commit(Xid xid, boolean onePhase) throws XAException { 62 } 63 64 public void end(Xid xid, int flags) throws XAException { 65 } 66 67 public void forget(Xid xid) throws XAException { 68 } 69 70 public int getTransactionTimeout() throws XAException { 71 return txTimeout; 72 } 73 74 public boolean isSameRM(XAResource xaResource) throws XAException { 75 return false; 76 } 77 78 public int prepare(Xid xid) throws XAException { 79 return 0; 80 } 81 82 public Xid [] recover(int flag) throws XAException { 83 return new Xid [0]; 84 } 85 86 public void rollback(Xid xid) throws XAException { 87 } 88 89 public boolean setTransactionTimeout(int seconds) throws XAException { 90 this.txTimeout = seconds; 91 return false; 92 } 93 94 public void start(Xid xid, int flags) throws XAException { 95 } 96 97 } 98 99 private static class TestManagedConnection extends TestPlainManagedConnection { 100 101 private final XAResource xaResource; 102 103 public TestManagedConnection(XAResource xaResource) { 104 this.xaResource = xaResource; 105 } 106 107 public XAResource getXAResource() throws ResourceException { 108 return xaResource; 109 } 110 111 112 } 113 } 114 | Popular Tags |