User: dsundstrom Date: 01/12/10 18:17:58 Added: src/main/org/jboss/test/cmp2/relationship/oneToManyUnidirectional 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/oneToManyUnidirectional/A.java Index: A.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; import java.util.Collection; import javax.ejb.EJBLocalObject; public interface A extends EJBLocalObject { public Collection getB(); public void setB(Collection b); } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToManyUnidirectional/ABTest.java Index: ABTest.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; 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/oneToMany/unidirectional/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/oneToMany/unidirectional/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/oneToMany/unidirectional/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/oneToMany/unidirectional/fk/B"); } catch(Exception e) { e.printStackTrace(); fail("Exception in getFKBHome: " + e.getMessage()); } return null; } // a1.setB(a2.getB()); public void test_a1SetB_a2GetB_Table() { AHome aHome = getTableAHome(); BHome bHome = getTableBHome(); a1SetB_a2GetB(aHome, bHome); } // a1.setB(a2.getB()); public void test_a1SetB_a2GetB_FK() { AHome aHome = getFKAHome(); BHome bHome = getFKBHome(); a1SetB_a2GetB(aHome, bHome); } // a1.setB(a2.getB()); protected void a1SetB_a2GetB(AHome aHome, BHome bHome) { try { // Before change: A a1 = aHome.create(new Integer(1)); A a2 = aHome.create(new Integer(2)); Collection b1 = a1.getB(); Collection b2 = a2.getB(); B[] b1x = new B[20]; B[] b2x = new B[30]; for(int i=0; i<b1x.length; i++) { b1x[i] = bHome.create(new Integer(10000 + i)); b1.add(b1x[i]); } for(int i=0; i<b2x.length; i++) { b2x[i] = bHome.create(new Integer(20000 + i)); b2.add(b2x[i]); } // B b11, b12, ... , b1n; members of b1 for(int i=0; i<b1x.length; i++) { assertTrue(b1.contains(b1x[i])); } // B b21, b22, ... , b2m; members of b2 for(int i=0; i<b2x.length; i++) { assertTrue(b2.contains(b2x[i])); } // Change: a1.setB(a2.getB()); // Expected result: // a2.getB().isEmpty() assertTrue(a2.getB().isEmpty()); // b2.isEmpty() assertTrue(b2.isEmpty()); // b1 == a1.getB() assertTrue(b1 == a1.getB()); // b2 == a2.getB() assertTrue(b2 == a2.getB()); // a1.getB().contains(b21) // a1.getB().contains(b22) // a1.getB().contains(...) // a1.getB().contains(b2m) for(int i=0; i<b2x.length; i++) { assertTrue(a1.getB().contains(b2x[i])); } } catch(Exception e) { e.printStackTrace(); fail("Error in big old method: "); } } // a1.getB().add(b2m); public void test_a1GetB_addB2m_Table() { AHome aHome = getTableAHome(); BHome bHome = getTableBHome(); a1GetB_addB2m(aHome, bHome); } // a1.getB().add(b2m); public void test_a1GetB_addB2m_FK() { AHome aHome = getFKAHome(); BHome bHome = getFKBHome(); a1GetB_addB2m(aHome, bHome); } // a1.getB().add(b2m); protected void a1GetB_addB2m(AHome aHome, BHome bHome) { try { // Before change: A a1 = aHome.create(new Integer(1)); A a2 = aHome.create(new Integer(2)); Collection b1 = a1.getB(); Collection b2 = a2.getB(); B[] b1x = new B[20]; B[] b2x = new B[30]; for(int i=0; i<b1x.length; i++) { b1x[i] = bHome.create(new Integer(10000 + i)); b1.add(b1x[i]); } for(int i=0; i<b2x.length; i++) { b2x[i] = bHome.create(new Integer(20000 + i)); b2.add(b2x[i]); } // B b11, b12, ... , b1n; members of b1 for(int i=0; i<b1x.length; i++) { assertTrue(b1.contains(b1x[i])); } // B b21, b22, ... , b2m; members of b2 for(int i=0; i<b2x.length; i++) { assertTrue(b2.contains(b2x[i])); } // Change: // a1.getB().add(b2m); a1.getB().add(b2x[b2x.length-1]); // Expected result: // b1.contains(b11) // b1.contains(b12) // b1.contains(...) // b1.contains(b1n) for(int i=0; i<b1x.length; i++) { assertTrue(b1.contains(b1x[i])); } // b1.contains(b2m) assertTrue(b1.contains(b2x[b2x.length-1])); // b2.contains(b21) // b2.contains(b22) // b2.contains(...) // b2.contains(b2m_1) for(int i=0; i<b2x.length-1; i++) { assertTrue(b2.contains(b2x[i])); } } catch(Exception e) { e.printStackTrace(); fail("Error in test_b2mSetA_b1nGetA: "); } } // a1.getB().remove(b1n); public void test_a1GetB_removeB1n_Table() { AHome aHome = getTableAHome(); BHome bHome = getTableBHome(); a1GetB_removeB1n(aHome, bHome); } // a1.getB().remove(b1n); public void test_a1GetB_removeB1n_FK() { AHome aHome = getFKAHome(); BHome bHome = getFKBHome(); a1GetB_removeB1n(aHome, bHome); } // a1.getB().remove(b1n); protected void a1GetB_removeB1n(AHome aHome, BHome bHome) { try { // Before change: A a1 = aHome.create(new Integer(1)); A a2 = aHome.create(new Integer(2)); Collection b1 = a1.getB(); Collection b2 = a2.getB(); B[] b1x = new B[20]; B[] b2x = new B[30]; for(int i=0; i<b1x.length; i++) { b1x[i] = bHome.create(new Integer(10000 + i)); b1.add(b1x[i]); } for(int i=0; i<b2x.length; i++) { b2x[i] = bHome.create(new Integer(20000 + i)); b2.add(b2x[i]); } // B b11, b12, ... , b1n; members of b1 for(int i=0; i<b1x.length; i++) { assertTrue(b1.contains(b1x[i])); } // B b21, b22, ... , b2m; members of b2 for(int i=0; i<b2x.length; i++) { assertTrue(b2.contains(b2x[i])); } // Change: // a1.getB().remove(b1n); a1.getB().remove(b1x[b1x.length-1]); // Expected result: // b1 == a1.getB() assertTrue(b1 == a1.getB()); // b1.contains(b11) // b1.contains(b12) // b1.contains(...) // b1.contains(b1n_1) for(int i=0; i<b1x.length-1; i++) { assertTrue(b1.contains(b1x[i])); } // !(b1.contains(b1n)) assertTrue(!(b1.contains(b1x[b1x.length-1]))); } catch(Exception e) { e.printStackTrace(); fail("Error in test_b2mSetA_b1nGetA: "); } } 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/oneToManyUnidirectional/ABean.java Index: ABean.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; import java.util.Collection; 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 Collection getB(); public abstract void setB(Collection 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/oneToManyUnidirectional/AHome.java Index: AHome.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; 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/oneToManyUnidirectional/B.java Index: B.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; import javax.ejb.EJBLocalObject; public interface B extends EJBLocalObject { } 1.1 jbosstest/src/main/org/jboss/test/cmp2/relationship/oneToManyUnidirectional/BBean.java Index: BBean.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; 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 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/oneToManyUnidirectional/BHome.java Index: BHome.java =================================================================== package org.jboss.test.cmp2.relationship.oneToManyUnidirectional; 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