1 22 package org.jboss.test.cts.ejb; 23 24 import java.util.Properties ; 25 import javax.ejb.DuplicateKeyException ; 26 import javax.naming.InitialContext ; 27 28 import org.jboss.test.util.ejb.EJBTestCase; 29 import org.jboss.test.JBossTestCase; 30 import org.jboss.test.cts.interfaces.CtsCmpLocalHome; 31 import org.jboss.test.cts.interfaces.CtsCmpLocal; 32 import org.jboss.test.cts.keys.AccountPK; 33 import org.jboss.logging.Logger; 34 import junit.framework.Test; 35 36 41 public class LocalEjbTests extends EJBTestCase 42 { 43 Logger log = Logger.getLogger(LocalEjbTests.class); 44 45 public LocalEjbTests(String methodName) 46 { 47 super(methodName); 48 } 49 50 public static Test suite() throws Exception 51 { 52 return JBossTestCase.getDeploySetup(LocalEjbTests.class, "cts.jar"); 53 } 54 55 public void setUpEJB(java.util.Properties props) throws Exception 56 { 57 super.setUpEJB(props); 58 } 59 60 public void tearDownEJB(Properties props) throws Exception 61 { 62 super.tearDownEJB(props); 63 } 64 65 public void testEntityIdentity() throws Exception 66 { 67 InitialContext ctx = new InitialContext (); 68 CtsCmpLocalHome home = (CtsCmpLocalHome) ctx.lookup("ejbcts/LocalCMPBean"); 69 AccountPK key1 = new AccountPK("1"); 70 CtsCmpLocal bean1 = null; 71 try 72 { 73 bean1 = home.create(key1, "testEntityIdentity"); 74 } 75 catch(DuplicateKeyException e) 76 { 77 bean1 = home.findByPrimaryKey(key1); 78 } 79 AccountPK key2 = new AccountPK("2"); 80 CtsCmpLocal bean2 = null; 81 try 82 { 83 bean2 = home.create(key2, "testEntityIdentity"); 84 } 85 catch(DuplicateKeyException e) 86 { 87 bean2 = home.findByPrimaryKey(key2); 88 } 89 CtsCmpLocalHome home2 = (CtsCmpLocalHome) ctx.lookup("ejbcts/LocalCMPBean2"); 90 CtsCmpLocal bean12 = null; 91 try 92 { 93 bean12 = home2.create(key1, "testEntityIdentity"); 94 } 95 catch(DuplicateKeyException e) 96 { 97 bean12 = home2.findByPrimaryKey(key1); 98 } 99 100 boolean isIdentical = false; 101 isIdentical = bean1.isIdentical(bean1); 102 log.debug(bean1+" isIdentical to "+bean1+" = "+isIdentical); 103 assertTrue(bean1+" isIdentical to "+bean1, isIdentical == true); 104 isIdentical = bean2.isIdentical(bean1); 105 log.debug(bean2+" isIdentical to "+bean1+" = "+isIdentical); 106 assertTrue(bean2+" isIdentical to "+bean1, isIdentical == false); 107 isIdentical = bean1.isIdentical(bean12); 108 log.debug(bean1+" isIdentical to "+bean12+" = "+isIdentical); 109 assertTrue(bean1+" isIdentical to "+bean12, isIdentical == false); 110 } 111 } 112 | Popular Tags |