1 22 package org.jboss.test.entityexc.test; 23 24 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 28 import javax.ejb.Handle ; 29 import javax.ejb.HomeHandle ; 30 import javax.ejb.CreateException ; 31 import javax.ejb.FinderException ; 32 import javax.ejb.EJBException ; 33 34 import javax.naming.InitialContext ; 35 36 import javax.transaction.TransactionRolledbackException ; 37 38 import javax.rmi.PortableRemoteObject ; 39 40 import org.jboss.test.entityexc.interfaces.EntityExcHome; 41 import org.jboss.test.entityexc.interfaces.EntityExc; 42 import org.jboss.test.entityexc.interfaces.MyAppException; 43 44 import junit.framework.Test; 45 import junit.framework.AssertionFailedError; 46 47 import org.jboss.test.JBossTestCase; 48 49 50 57 public class EntityExcUnitTestCase 58 extends JBossTestCase 59 { 60 63 public EntityExcUnitTestCase(String name) 64 { 65 super(name); 66 } 67 68 71 private void reset() 72 throws Exception 73 { 74 getLog().debug(" Resetting..."); 75 undeploy("entityexc.jar"); 76 deploy("entityexc.jar"); 77 getHome().resetDatabase(); 78 getLog().debug(" ...reset done OK"); 79 } 80 81 84 private EntityExcHome getHome() 85 throws Exception 86 { 87 return (EntityExcHome)getInitialContext().lookup(EntityExcHome.JNDI_NAME); 88 } 89 90 91 94 public void testBug463548() 95 throws Exception 96 { 97 getLog().debug( 98 "**************************************************************"); 99 getLog().debug(" testBug463548()"); 100 101 reset(); 102 103 boolean gotException = false; 104 105 try { 106 EntityExc bean = getHome().create(new Integer (1), EntityExc.EXC_CREATEEXCEPTION|EntityExc.F_FAIL_POSTCREATE|EntityExc.F_SETROLLBACKONLY); 107 108 } catch (TransactionRolledbackException ex) { 111 gotException = true; 112 getLog().error("Got unexpected TransactionRolledbackException", ex); 113 getLog().error("Container started the transaction, so we should get the CreateException"); 114 fail("EJB2.0 section 17.6.2.8 violation."); 115 } catch (CreateException ex) { 116 gotException = true; 117 getLog().debug("Got expected CreateException", ex); 118 } catch (Exception ex) { 119 gotException = true; 120 getLog().error("Unexpected exception", ex); 121 try { 124 EntityExc bean = getHome().findByPrimaryKey(new Integer (1), 0); 125 fail("Rolled back bean creation, but still in cache."); 126 } catch (AssertionFailedError ex2) { 127 throw ex2; 129 } catch (FinderException ex2) { 130 getLog().error("Got expected FinderException", ex2); 132 } catch (Throwable ex2) { 133 getLog().error("Got unexpected exception", ex2); 135 } 136 fail("Unexpected exception: " + ex); 137 } 138 139 if (!gotException) 140 fail("Did not get expected CreateException."); 141 142 try { 145 EntityExc bean = getHome().findByPrimaryKey(new Integer (1), 0); 146 fail("Rolled back bean creation, but still in cache 2."); 147 } catch (AssertionFailedError ex2) { 148 throw ex2; 150 } catch (FinderException ex2) { 151 getLog().error("Got expected FinderException", ex2); 153 } catch (Throwable ex2) { 154 getLog().error("Got unexpected exception", ex2); 156 } 157 getLog().debug( 158 "**************************************************************"); 159 } 160 161 public static Test suite() throws Exception 162 { 163 return getDeploySetup(EntityExcUnitTestCase.class, "entityexc.jar"); 164 } 165 } 166 | Popular Tags |