1 22 package org.jboss.ejb3.test.txexceptions.unit; 23 24 import javax.ejb.EJBException ; 25 import org.jboss.ejb3.test.txexceptions.AnnotatedAppException; 26 import org.jboss.ejb3.test.txexceptions.DeploymentDescriptorAppException; 27 import org.jboss.ejb3.test.txexceptions.AppException; 28 import org.jboss.ejb3.test.txexceptions.CheckedRollbackException; 29 import org.jboss.ejb3.test.txexceptions.DeploymentDescriptorCheckedRollbackException; 30 import org.jboss.ejb3.test.txexceptions.Dao; 31 import org.jboss.ejb3.test.txexceptions.NoRollbackRemoteException; 32 import org.jboss.ejb3.test.txexceptions.NoRollbackRuntimeException; 33 import org.jboss.ejb3.test.txexceptions.RollbackRemoteException; 34 import org.jboss.ejb3.test.txexceptions.RollbackRuntimeException; 35 import org.jboss.ejb3.test.txexceptions.SimpleEntity; 36 import org.jboss.test.JBossTestCase; 37 import junit.framework.Test; 38 39 43 public class TxExceptionsTestCase extends JBossTestCase 44 { 45 org.jboss.logging.Logger log = getLog(); 46 47 static boolean deployed = false; 48 static int test = 0; 49 50 public TxExceptionsTestCase(String name) 51 { 52 super(name); 53 } 54 55 public void testRequiresNewWithLookedUpEntityManager() throws Exception 56 { 57 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 58 dao.testRequiresNewWithLookedUpEntityManager(); 59 } 60 public void testAnnotatedAppException() throws Exception 61 { 62 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 63 64 boolean exceptionThrown = false; 65 try 66 { 67 dao.createThrowAnnotatedAppException(1); 68 } 69 catch (AnnotatedAppException e) 70 { 71 exceptionThrown = true; 72 } 73 assertTrue(exceptionThrown); 74 assertNotNull(dao.get(1)); 75 dao.remove(1); 76 } 77 78 public void testDeploymentDescriptorAppException() throws Exception 79 { 80 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 81 82 boolean exceptionThrown = false; 83 try 84 { 85 dao.createThrowDeploymentDescriptorAppException(1); 86 } 87 catch (DeploymentDescriptorAppException e) 88 { 89 exceptionThrown = true; 90 } 91 assertTrue(exceptionThrown); 92 assertNotNull(dao.get(1)); 93 dao.remove(1); 94 } 95 96 public void testAppException() throws Exception 97 { 98 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 99 100 boolean exceptionThrown = false; 101 try 102 { 103 dao.createThrowAppException(1); 104 } 105 catch (AppException e) 106 { 107 exceptionThrown = true; 108 } 109 assertTrue(exceptionThrown); 110 assertNotNull(dao.get(1)); 111 dao.remove(1); 112 } 113 114 public void testNoRollbackRemoteException() throws Exception 115 { 116 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 117 118 boolean exceptionThrown = false; 119 try 120 { 121 dao.createThrowNoRollbackRemoteException(1); 122 } 123 catch (NoRollbackRemoteException e) 124 { 125 exceptionThrown = true; 126 } 127 assertTrue(exceptionThrown); 128 assertNotNull(dao.get(1)); 129 dao.remove(1); 130 } 131 132 public void testNoRollbackRuntimexception() throws Exception 133 { 134 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 135 136 boolean exceptionThrown = false; 137 try 138 { 139 dao.createThrowNoRollbackRuntimeException(1); 140 } 141 catch (NoRollbackRuntimeException e) 142 { 143 exceptionThrown = true; 144 } 145 assertTrue(exceptionThrown); 146 assertNotNull(dao.get(1)); 147 dao.remove(1); 148 } 149 150 public void testDeploymentDescriptorCheckedRollbackException() throws Exception 151 { 152 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 153 154 try 155 { 156 dao.createThrowDeploymentDescriptorCheckedRollbackException(1); 157 fail(); 158 } 159 catch (DeploymentDescriptorCheckedRollbackException e) 160 { 161 } 162 163 SimpleEntity entity = dao.get(1); 164 165 if (entity != null) 166 dao.remove(1); 167 168 assertNull(entity); 169 } 170 171 public void testCheckedRollbackException() throws Exception 172 { 173 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 174 175 try 176 { 177 dao.createThrowCheckedRollbackException(1); 178 fail(); 179 } 180 catch (CheckedRollbackException e) 181 { 182 } 183 184 SimpleEntity entity = dao.get(1); 185 186 if (entity != null) 187 dao.remove(1); 188 189 assertNull(entity); 190 } 191 192 public void testRollbackRemoteException() throws Exception 193 { 194 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 195 196 try 197 { 198 dao.createThrowRollbackRemoteException(1); 199 fail(); 200 } 201 catch (RollbackRemoteException e) 202 { 203 } 204 205 SimpleEntity entity = dao.get(1); 206 207 if (entity != null) 208 dao.remove(1); 209 210 assertNull(entity); 211 } 212 213 public void testRollbackRuntimeException() throws Exception 214 { 215 Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote"); 216 217 try 218 { 219 dao.createThrowRollbackRuntimeException(1); 220 fail(); 221 } 222 catch (EJBException e) 223 { 224 assertTrue(e.getCausedByException() instanceof RollbackRuntimeException); 225 } 226 227 SimpleEntity entity = dao.get(1); 228 229 if (entity != null) 230 dao.remove(1); 231 232 assertNull(entity); 233 } 234 235 public static Test suite() throws Exception 236 { 237 return getDeploySetup(TxExceptionsTestCase.class, "txexceptions-test.jar"); 238 } 239 } | Popular Tags |