User: dsundstrom Date: 01/12/10 18:17:59 Added: src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional A.java ABTest.java ABean.java AHome.java B.java BBean.java BHome.java Log: Initial revision of the CMP 2.0 relation test. These test are based on the EJB 2.0 specification. Revision Changes Path 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/A.java Index: A.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import javax.ejb.EJBLocalObject; public interface A extends EJBLocalObject { public B getB(); public void setB(B b); } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/ABTest.java Index: ABTest.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import java.util.Collection; import java.util.Iterator; import javax.naming.InitialContext; import junit.framework.TestCase; import net.sourceforge.junitejb.EJBTestCase; public class ABTest extends EJBTestCase { public ABTest(String name) { super(name); } private AHome getTableAHome() { try { InitialContext jndiContext = new InitialContext(); return (AHome) jndiContext.lookup("relation/oneToOne/bidirectional/table/A"); } catch(Exception e) { e.printStackTrace(); fail("Exception in getTableAHome: " + e.getMessage()); } return null; } private BHome getTableBHome() { try { InitialContext jndiContext = new InitialContext(); return (BHome) jndiContext.lookup("relation/oneToOne/bidirectional/table/B"); } catch(Exception e) { e.printStackTrace(); fail("Exception in getTableBHome: " + e.getMessage()); } return null; } private AHome getFKAHome() { try { InitialContext jndiContext = new InitialContext(); return (AHome) jndiContext.lookup("relation/oneToOne/bidirectional/fk/A"); } catch(Exception e) { e.printStackTrace(); fail("Exception in getFKAHome: " + e.getMessage()); } return null; } private BHome getFKBHome() { try { InitialContext jndiContext = new InitialContext(); return (BHome) jndiContext.lookup("relation/oneToOne/bidirectional/fk/B"); } catch(Exception e) { e.printStackTrace(); fail("Exception in getFKBHome: " + e.getMessage()); } return null; } private A a1; private A a2; private B b1; private B b2; protected void beforeChange(AHome aHome, BHome bHome) throws Exception { a1 = aHome.create(new Integer(1)); a2 = aHome.create(new Integer(2)); b1 = bHome.create(new Integer(10)); b2 = bHome.create(new Integer(20)); a1.setB(b1); a2.setB(b2); assertTrue(b1.isIdentical(a1.getB())); assertTrue(b2.isIdentical(a2.getB())); } // a1.setB(a2.getB()); public void test_a1SetB_a2GetB_Table() throws Exception { AHome aHome = getTableAHome(); BHome bHome = getTableBHome(); beforeChange(aHome, bHome); a1SetB_a2GetB(aHome, bHome); } // a1.setB(a2.getB()); public void test_a1SetB_a2GetB_FK() throws Exception { AHome aHome = getFKAHome(); BHome bHome = getFKBHome(); beforeChange(aHome, bHome); a1SetB_a2GetB(aHome, bHome); } // a1.setB(a2.getB()); protected void a1SetB_a2GetB(AHome aHome, BHome bHome) throws Exception { // Change: a1.setB(a2.getB()); // Expected result: // b2.isIdentical(a1.getB()) assertTrue(b2.isIdentical(a1.getB())); // a2.getB() == null assertNull(a2.getB()); // b1.getA() == null assertNull(b1.getA()); // a1.isIdentical(b2.getA()) assertTrue(a1.isIdentical(b2.getA())); } public void setUpEJB() throws Exception { AHome aHome; BHome bHome; aHome = getTableAHome(); bHome = getTableBHome(); deleteAllAsAndBs(aHome, bHome); aHome = getFKAHome(); bHome = getFKBHome(); deleteAllAsAndBs(aHome, bHome); } public void tearDownEJB() throws Exception { } public void deleteAllAsAndBs(AHome aHome, BHome bHome) throws Exception { // delete all As Iterator currentAs = aHome.findAll().iterator(); while(currentAs.hasNext()) { A a = (A)currentAs.next(); a.remove(); } // delete all Bs Iterator currentBs = bHome.findAll().iterator(); while(currentBs.hasNext()) { B b = (B)currentBs.next(); b.remove(); } } } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/ABean.java Index: ABean.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import javax.ejb.EntityBean; import javax.ejb.EntityContext; public abstract class ABean implements EntityBean { transient private EntityContext ctx; public Integer ejbCreate(Integer id) { setId(id); return null; } public void ejbPostCreate(Integer id) { } public abstract Integer getId(); public abstract void setId(Integer id); public abstract B getB(); public abstract void setB(B b); public void setEntityContext(EntityContext ctx) { this.ctx = ctx; } public void unsetEntityContext() { this.ctx = null; } public void ejbActivate() { } public void ejbPassivate() { } public void ejbLoad() { } public void ejbStore() { } public void ejbRemove() { } } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/AHome.java Index: AHome.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import java.util.Collection; import javax.ejb.CreateException; import javax.ejb.EJBLocalHome; import javax.ejb.FinderException; public interface AHome extends EJBLocalHome { public A create(Integer id) throws CreateException; public A findByPrimaryKey(Integer id) throws FinderException; public Collection findAll() throws FinderException; } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/B.java Index: B.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import javax.ejb.EJBLocalObject; public interface B extends EJBLocalObject { public A getA(); public void setA(A a); } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/BBean.java Index: BBean.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import javax.ejb.EntityBean; import javax.ejb.EntityContext; public abstract class BBean implements EntityBean { transient private EntityContext ctx; public Integer ejbCreate(Integer id) { setId(id); return null; } public void ejbPostCreate(Integer id) { } public abstract Integer getId(); public abstract void setId(Integer id); public abstract A getA(); public abstract void setA(A a); public void setEntityContext(EntityContext ctx) { this.ctx = ctx; } public void unsetEntityContext() { this.ctx = null; } public void ejbActivate() { } public void ejbPassivate() { } public void ejbLoad() { } public void ejbStore() { } public void ejbRemove() { } } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToOneBidirectional/BHome.java Index: BHome.java =================================================================== package org.jboss.test.cmp2.relationship.oneToOneBidirectional; import java.util.Collection; import javax.ejb.CreateException; import javax.ejb.EJBLocalHome; import javax.ejb.FinderException; public interface BHome extends EJBLocalHome { public B create(Integer id) throws CreateException; public B findByPrimaryKey(Integer id) throws FinderException; public Collection findAll() throws FinderException; }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development