1 22 package org.jboss.test.jca.test; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import javax.transaction.TransactionRolledbackException ; 27 28 import junit.framework.Test; 29 30 import org.jboss.test.JBossTestCase; 31 import org.jboss.test.jca.interfaces.XAExceptionSession; 32 import org.jboss.test.jca.interfaces.XAExceptionSessionHome; 33 import org.jboss.test.jca.interfaces.XAExceptionTestSession; 34 import org.jboss.test.jca.interfaces.XAExceptionTestSessionHome; 35 36 43 public class XAExceptionUnitTestCase extends JBossTestCase 44 { 45 public XAExceptionUnitTestCase(String name) 46 { 47 super(name); 48 } 49 50 public static Test suite() throws Exception 51 { 52 Test t1 = getDeploySetup(XAExceptionUnitTestCase.class, "jcatest.jar"); 53 Test t2 = getDeploySetup(t1, "testadapter-ds.xml"); 54 return getDeploySetup(t2, "jbosstestadapter.rar"); 55 } 56 57 public void testXAExceptionToTransactionRolledbackException() throws Exception 58 { 59 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 60 XAExceptionSession x = xh.create(); 61 try 62 { 63 x.testXAExceptionToTransactionRolledbackException(); 64 } 65 catch (TransactionRolledbackException tre) 66 { 67 getLog().info("testXAExceptionToRollbackException passed"); 68 return; 69 } 70 fail("expected TransactionRolledbackException not thrown"); 71 } 72 73 public void testXAExceptionToTransactionRolledbackExceptionOnServer() throws Exception 74 { 75 XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome"); 76 XAExceptionTestSession xt = xth.create(); 77 xt.testXAExceptionToTransactionRolledbackException(); 78 } 79 80 public void testXAExceptionToTransactionRolledbackLocalExceptionOnServer() throws Exception 81 { 82 XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome"); 83 XAExceptionTestSession xt = xth.create(); 84 xt.testXAExceptionToTransactionRolledbackLocalException(); 85 } 86 87 public void testRMERRInOnePCToTransactionRolledbackException() throws Exception 88 { 89 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 90 XAExceptionSession x = xh.create(); 91 try 92 { 93 x.testRMERRInOnePCToTransactionRolledbackException(); 94 } 95 catch (TransactionRolledbackException tre) 96 { 97 getLog().info("testXAExceptionToRollbackException passed"); 98 return; 99 } 100 fail("expected TransactionRolledbackException not thrown"); 101 } 102 103 public void testRMERRInOnePCToTransactionRolledbackExceptionOnServer() throws Exception 104 { 105 XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome"); 106 XAExceptionTestSession xt = xth.create(); 107 xt.testRMERRInOnePCToTransactionRolledbackException(); 108 } 109 110 public void testXAExceptionToTransactionRolledbacLocalkExceptionOnServer() throws Exception 111 { 112 XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome"); 113 XAExceptionTestSession xt = xth.create(); 114 xt.testXAExceptionToTransactionRolledbacLocalkException(); 115 } 116 117 public void testSimulateConnectionError() throws Exception 118 { 119 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 120 XAExceptionSession x = xh.create(); 121 x.simulateConnectionError(); 122 } 123 124 public void testSimulateConnectionErrorWithTwoHandles() throws Exception 125 { 126 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 127 XAExceptionSession x = xh.create(); 128 x.simulateConnectionErrorWithTwoHandles(); 129 } 130 131 public void testGetConnectionResourceError() throws Exception 132 { 133 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 134 XAExceptionSession x = xh.create(); 135 try 136 { 137 x.simulateError("getConnectionResource", 10); 138 } 139 finally 140 { 141 flushConnections(); 142 } 143 } 144 145 public void testGetConnectionRuntimeError() throws Exception 146 { 147 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 148 XAExceptionSession x = xh.create(); 149 try 150 { 151 x.simulateError("getConnectionRuntime", 10); 152 } 153 finally 154 { 155 flushConnections(); 156 } 157 } 158 159 public void testCreateManagedConnectionResourceError() throws Exception 160 { 161 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 162 XAExceptionSession x = xh.create(); 163 try 164 { 165 x.simulateFactoryError("createManagedConnectionResource", 10); 166 } 167 finally 168 { 169 flushConnections(); 170 } 171 } 172 173 public void testCreateManagedConnectionRuntimeError() throws Exception 174 { 175 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 176 XAExceptionSession x = xh.create(); 177 try 178 { 179 x.simulateFactoryError("createManagedConnectionRuntime", 10); 180 } 181 finally 182 { 183 flushConnections(); 184 } 185 } 186 187 public void testMatchManagedConnectionResourceError() throws Exception 188 { 189 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 190 XAExceptionSession x = xh.create(); 191 try 192 { 193 x.simulateFactoryError("matchManagedConnectionResource", 10); 194 } 195 finally 196 { 197 flushConnections(); 198 } 199 } 200 201 public void testMatchManagedConnectionRuntimeError() throws Exception 202 { 203 XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome"); 204 XAExceptionSession x = xh.create(); 205 try 206 { 207 x.simulateFactoryError("matchManagedConnectionRuntime", 10); 208 } 209 finally 210 { 211 flushConnections(); 212 } 213 } 214 215 protected void flushConnections() 216 { 217 try 218 { 219 MBeanServerConnection server = getServer(); 220 server.invoke(new ObjectName ("jboss.jca:service=ManagedConnectionPool,name=JBossTestCF"), "flush", new Object [0], new String [0]); 221 } 222 catch (Exception e) 223 { 224 log.warn("Unable to flush connections", e); 225 } 226 } 227 } 228 | Popular Tags |