jtolentino    2005/09/22 04:48:42

  Added:       
m2/unit-tests/openejb-builder/src/test/java/org/openejb/deployment/entity/cmp/cmr/manytomany
                        ManyToManyCompoundPKTest.java ManyToManyTest.java
  Log:

  Forgot that cvs does not automatically recurse addition of new directories. 
Committing repository and unit-tests directories. unit-tests: Modified unit 
tests with hard-coded references to directories based on base dir. repository: 
Artifacts that are generated by building Geronimo or exists in Maven 1 remote 
repo but not in Maven 2.
  
  Revision  Changes    Path
  1.1                  
openejb/m2/unit-tests/openejb-builder/src/test/java/org/openejb/deployment/entity/cmp/cmr/manytomany/ManyToManyCompoundPKTest.java
  
  Index: ManyToManyCompoundPKTest.java
  ===================================================================
  /* ====================================================================

   * Redistribution and use of this software and associated documentation

   * ("Software"), with or without modification, are permitted provided

   * that the following conditions are met:

   *

   * 1. Redistributions of source code must retain copyright

   *    statements and notices.  Redistributions must also contain a

   *    copy of this document.

   *

   * 2. Redistributions in binary form must reproduce this list of

   *    conditions and the following disclaimer in the documentation

   *    and/or other materials provided with the distribution.

   *

   * 3. The name "OpenEJB" must not be used to endorse or promote

   *    products derived from this Software without prior written

   *    permission of The OpenEJB Group.  For written permission,

   *    please contact [EMAIL PROTECTED]

   *

   * 4. Products derived from this Software may not be called "OpenEJB"

   *    nor may "OpenEJB" appear in their names without prior written

   *    permission of The OpenEJB Group. OpenEJB is a registered

   *    trademark of The OpenEJB Group.

   *

   * 5. Due credit should be given to the OpenEJB Project

   *    (http://openejb.org/).

   *

   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS

   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT

   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL

   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,

   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,

   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)

   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED

   * OF THE POSSIBILITY OF SUCH DAMAGE.

   *

   * ====================================================================

   *

   * This software consists of voluntary contributions made by many

   * individuals on behalf of the OpenEJB Project.  For more information

   * please see <http://openejb.org/>.

   *

   * ====================================================================

   */

  package org.openejb.deployment.entity.cmp.cmr.manytomany;

  

  import java.sql.Connection;

  import java.sql.ResultSet;

  import java.sql.SQLException;

  import java.sql.Statement;

  import java.util.HashSet;

  import java.util.Iterator;

  import java.util.Set;

  

  import org.apache.geronimo.transaction.context.TransactionContext;

  import org.openejb.deployment.entity.cmp.cmr.AbstractCMRTest;

  import org.openejb.deployment.entity.cmp.cmr.CompoundPK;

  

  /**

   *

   * @version $Revision: 1.1 $ $Date: 2005/09/22 08:48:42 $

   */

  public class ManyToManyCompoundPKTest extends AbstractCMRTest {

      private ALocalHome ahome;

      private ALocal a;

      private BLocalHome bhome;

      private BLocal b;

  

      public void testAGetBExistingAB() throws Exception {

          TransactionContext ctx = newTransactionContext();

          a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), "value1"));

          Set bSet = a.getB();

          assertEquals(2, bSet.size());

          for (Iterator iter = bSet.iterator(); iter.hasNext();) {

              b = (BLocal) iter.next();

              if ( b.getField1().equals(new Integer(11)) ) {

                  assertEquals("value11", b.getField2());

              } else if ( b.getField1().equals(new Integer(22)) ) {

                  assertEquals("value22", b.getField2());

              } else {

                  fail();

              }

          }

          ctx.commit();

      }

      

      public void testBGetAExistingAB() throws Exception {

          TransactionContext ctx = newTransactionContext();

          BLocal b = bhome.findByPrimaryKey(new Integer(22));

          Set aSet = b.getA();

          assertEquals(3, aSet.size());

          for (Iterator iter = aSet.iterator(); iter.hasNext();) {

              a = (ALocal) iter.next();

              if ( a.getField1().equals(new Integer(1)) ) {

                  assertEquals("value1", a.getField2());

              } else if ( a.getField1().equals(new Integer(2)) ) {

                  assertEquals("value2", a.getField2());

              } else if ( a.getField1().equals(new Integer(3)) ) {

                  assertEquals("value3", a.getField2());

              } else {

                  fail();

              }

          }

          ctx.commit();

      }

      

      private void assertStateDropExisting() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM MTM");

          assertTrue(rs.next());

          assertEquals(0, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

  

      public void testASetBDropExisting() throws Exception {

          TransactionContext ctx = newTransactionContext();

          ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), 
"value1"));

          a.setB(new HashSet());

          a = ahome.findByPrimaryKey(new CompoundPK(new Integer(2), "value2"));

          a.setB(new HashSet());

          a = ahome.findByPrimaryKey(new CompoundPK(new Integer(3), "value3"));

          a.setB(new HashSet());

          ctx.commit();

  

          assertStateDropExisting();

      }

  

      public void testBSetADropExisting() throws Exception {

          TransactionContext ctx = newTransactionContext();

          BLocal b = bhome.findByPrimaryKey(new Integer(11));

          b.setA(new HashSet());

          b = bhome.findByPrimaryKey(new Integer(22));

          b.setA(new HashSet());

          ctx.commit();

  

          assertStateDropExisting();

      }

  

      private TransactionContext prepareNewAB() throws Exception {

          CompoundPK pkA = new CompoundPK(new Integer(4), "value4");

          

          TransactionContext ctx = newTransactionContext();

          a = ahome.create(pkA);

          b = bhome.create(new Integer(33));

          b.setField2("value33");

          return ctx;

      }

  

      private void assertStateNewAB() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 
4 AND fka2 = 'value4' AND fkb1 = 33");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

  

          rs = s.executeQuery("SELECT COUNT(*) FROM A WHERE a1 = 4 AND a2 = 
'value4'");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

  

          rs = s.executeQuery("SELECT b2 FROM B WHERE b1 = 33");

          assertTrue(rs.next());

          assertEquals("value33", rs.getString(1));

          rs.close();

          s.close();

          c.close();

      }

      

      public void testASetBNewAB() throws Exception {

          TransactionContext ctx = prepareNewAB();

          Set bSet = a.getB();

          bSet.add(b);

          ctx.commit();

          

          assertStateNewAB();

      }

  

      public void testBSetANewAB() throws Exception {

          TransactionContext ctx = prepareNewAB();

          Set aSet = b.getA();

          aSet.add(a);

          ctx.commit();

          

          assertStateNewAB();

      }

  

      private TransactionContext prepareExistingBNewA() throws Exception {

          CompoundPK pkA = new CompoundPK(new Integer(4), "value4");

          

          TransactionContext ctx = newTransactionContext();

          a = ahome.create(pkA);

          b = bhome.findByPrimaryKey(new Integer(11));

          return ctx;

      }

  

      private void assertStateExistingBNewA() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM A WHERE a1 = 4 
AND a2 = 'value4'");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

  

          rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 4 AND fka2 
= 'value4' AND fkb1 = 11");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

      

      public void testASetBExistingBNewA() throws Exception {

          TransactionContext ctx = prepareExistingBNewA();

          Set bSet = a.getB();

          bSet.add(b);

          ctx.commit();

          

          assertStateExistingBNewA();

      }

  

      public void testBSetAExistingBNewA() throws Exception {

          TransactionContext ctx = prepareExistingBNewA();

          Set aSet = b.getA();

          aSet.add(a);

          ctx.commit();

          

          assertStateExistingBNewA();

      }

  

      private TransactionContext prepareExistingANewB() throws Exception {

          CompoundPK pkA = new CompoundPK(new Integer(1), "value1");

          

          TransactionContext ctx = newTransactionContext();

          a = ahome.findByPrimaryKey(pkA);

          b = bhome.create(new Integer(33));

          b.setField2("value33");

          return ctx;

      }

      

      private void assertStateExistingANewB() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT b2 FROM B WHERE b1 = 33");

          assertTrue(rs.next());

          assertEquals("value33", rs.getString(1));

          rs.close();

          

          rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 1 AND fka2 
= 'value1' AND fkb1 = 33");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

      

      public void testASetBExistingANewB() throws Exception {

          TransactionContext ctx = prepareExistingANewB();

          Set bSet = a.getB();

          bSet.add(b);

          ctx.commit();

          

          assertStateExistingANewB();

      }

  

      public void testBSetAExistingANewB() throws Exception {

          TransactionContext ctx = prepareExistingANewB();

          Set aSet = b.getA();

          aSet.add(a);

          ctx.commit();

          

          assertStateExistingANewB();

      }

  

      public void testRemoveRelationships() throws Exception {

          TransactionContext ctx = newTransactionContext();

          ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), 
"value1"));

          a.remove();

          ctx.commit();

  

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 
1 AND fka2 = 'value1'");

          assertTrue(rs.next());

          assertEquals(0, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

      

      protected void setUp() throws Exception {

          super.setUp();

          

          ahome = (ALocalHome) super.ahome;

          bhome = (BLocalHome) super.bhome;

      }

      

      protected void buildDBSchema(Connection c) throws Exception {

          Statement s = c.createStatement();

          try {

              s.execute("DROP TABLE A");

          } catch (SQLException e) {

              // ignore

          }

          try {

              s.execute("DROP TABLE B");

          } catch (SQLException e) {

              // ignore

          }

          try {

              s.execute("DROP TABLE MTM");

          } catch (SQLException e) {

              // ignore

          }

          

          s.execute("CREATE TABLE A(A1 INTEGER, A2 VARCHAR(50))");

          s.execute("CREATE TABLE B(B1 INTEGER, B2 VARCHAR(50))");

          s.execute("CREATE TABLE MTM(FKA1 INTEGER, FKA2 VARCHAR(50), FKB1 
INTEGER)");

          

          s.execute("INSERT INTO A(A1, A2) VALUES(1, 'value1')");

          s.execute("INSERT INTO A(A1, A2) VALUES(2, 'value2')");

          s.execute("INSERT INTO A(A1, A2) VALUES(3, 'value3')");

          s.execute("INSERT INTO B(B1, B2) VALUES(11, 'value11')");

          s.execute("INSERT INTO B(B1, B2) VALUES(22, 'value22')");

          s.execute("INSERT INTO MTM(FKA1, FKA2, FKB1) VALUES(1, 'value1', 
11)");

          s.execute("INSERT INTO MTM(FKA1, FKA2, FKB1) VALUES(1, 'value1', 
22)");

          s.execute("INSERT INTO MTM(FKA1, FKA2, FKB1) VALUES(2, 'value2', 
22)");

          s.execute("INSERT INTO MTM(FKA1, FKA2, FKB1) VALUES(3, 'value3', 
22)");        

          s.close();

          c.close();

      }

  

      protected String getEjbJarDD() {

          return "src/test/test-cmp/manytomany/compoundpk/ejb-jar.xml";

      }

  

      protected String getOpenEjbJarDD() {

          return "src/test/test-cmp/manytomany/compoundpk/openejb-jar.xml";

      }

  

      protected EJBClass getA() {

          return new EJBClass(ABean.class, ALocalHome.class, ALocal.class);

      }

  

      protected EJBClass getB() {

          return new EJBClass(BBean.class, BLocalHome.class, BLocal.class);

      }

      

  }

  
  
  
  1.1                  
openejb/m2/unit-tests/openejb-builder/src/test/java/org/openejb/deployment/entity/cmp/cmr/manytomany/ManyToManyTest.java
  
  Index: ManyToManyTest.java
  ===================================================================
  /* ====================================================================

   * Redistribution and use of this software and associated documentation

   * ("Software"), with or without modification, are permitted provided

   * that the following conditions are met:

   *

   * 1. Redistributions of source code must retain copyright

   *    statements and notices.  Redistributions must also contain a

   *    copy of this document.

   *

   * 2. Redistributions in binary form must reproduce this list of

   *    conditions and the following disclaimer in the documentation

   *    and/or other materials provided with the distribution.

   *

   * 3. The name "OpenEJB" must not be used to endorse or promote

   *    products derived from this Software without prior written

   *    permission of The OpenEJB Group.  For written permission,

   *    please contact [EMAIL PROTECTED]

   *

   * 4. Products derived from this Software may not be called "OpenEJB"

   *    nor may "OpenEJB" appear in their names without prior written

   *    permission of The OpenEJB Group. OpenEJB is a registered

   *    trademark of The OpenEJB Group.

   *

   * 5. Due credit should be given to the OpenEJB Project

   *    (http://openejb.org/).

   *

   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS

   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT

   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL

   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,

   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,

   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)

   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED

   * OF THE POSSIBILITY OF SUCH DAMAGE.

   *

   * ====================================================================

   *

   * This software consists of voluntary contributions made by many

   * individuals on behalf of the OpenEJB Project.  For more information

   * please see <http://openejb.org/>.

   *

   * ====================================================================

   */

  package org.openejb.deployment.entity.cmp.cmr.manytomany;

  

  import java.sql.Connection;

  import java.sql.ResultSet;

  import java.sql.SQLException;

  import java.sql.Statement;

  import java.util.HashSet;

  import java.util.Iterator;

  import java.util.Set;

  

  import org.apache.geronimo.transaction.context.TransactionContext;

  import org.openejb.deployment.entity.cmp.cmr.AbstractCMRTest;

  

  /**

   *

   * @version $Revision: 1.1 $ $Date: 2005/09/22 08:48:42 $

   */

  public class ManyToManyTest extends AbstractCMRTest {

      private ALocalHome ahome;

      private ALocal a;

      private BLocalHome bhome;

      private BLocal b;

  

      public void testAGetBExistingAB() throws Exception {

          TransactionContext ctx = newTransactionContext();

          a = ahome.findByPrimaryKey(new Integer(1));

          Set bSet = a.getB();

          assertEquals(2, bSet.size());

          for (Iterator iter = bSet.iterator(); iter.hasNext();) {

              b = (BLocal) iter.next();

              if ( b.getField1().equals(new Integer(11)) ) {

                  assertEquals("value11", b.getField2());

              } else if ( b.getField1().equals(new Integer(22)) ) {

                  assertEquals("value22", b.getField2());

              } else {

                  fail();

              }

          }

          ctx.commit();

      }

      

      public void testBGetAExistingAB() throws Exception {

          TransactionContext ctx = newTransactionContext();

          BLocal b = bhome.findByPrimaryKey(new Integer(22));

          Set aSet = b.getA();

          assertEquals(3, aSet.size());

          for (Iterator iter = aSet.iterator(); iter.hasNext();) {

              a = (ALocal) iter.next();

              if ( a.getField1().equals(new Integer(1)) ) {

                  assertEquals("value1", a.getField2());

              } else if ( a.getField1().equals(new Integer(2)) ) {

                  assertEquals("value2", a.getField2());

              } else if ( a.getField1().equals(new Integer(3)) ) {

                  assertEquals("value3", a.getField2());

              } else {

                  fail();

              }

          }

          ctx.commit();

      }

  

      private void assertStateDropExisting() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM MTM");

          assertTrue(rs.next());

          assertEquals(0, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

  

      public void testASetBDropExisting() throws Exception {

          TransactionContext ctx = newTransactionContext();

          ALocal a = ahome.findByPrimaryKey(new Integer(1));

          a.setB(new HashSet());

          a = ahome.findByPrimaryKey(new Integer(2));

          a.setB(new HashSet());

          a = ahome.findByPrimaryKey(new Integer(3));

          a.setB(new HashSet());

          ctx.commit();

  

          assertStateDropExisting();

      }

  

      public void testBSetADropExisting() throws Exception {

          TransactionContext ctx = newTransactionContext();

          BLocal b = bhome.findByPrimaryKey(new Integer(11));

          b.setA(new HashSet());

          b = bhome.findByPrimaryKey(new Integer(22));

          b.setA(new HashSet());

          ctx.commit();

  

          assertStateDropExisting();

      }

  

      private TransactionContext prepareNewAB() throws Exception {

          TransactionContext ctx = newTransactionContext();

          a = ahome.create(new Integer(4));

          a.setField2("value4");

          b = bhome.create(new Integer(33));

          b.setField2("value33");

          return ctx;

      }

  

      private void assertStateNewAB() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 
4 AND fkb1 = 33");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

  

          rs = s.executeQuery("SELECT a2 FROM A WHERE a1 = 4");

          assertTrue(rs.next());

          assertEquals("value4", rs.getString(1));

  

          rs = s.executeQuery("SELECT b2 FROM B WHERE b1 = 33");

          assertTrue(rs.next());

          assertEquals("value33", rs.getString(1));

          rs.close();

          s.close();

          c.close();

      }

      

      public void testASetBNewAB() throws Exception {

          TransactionContext ctx = prepareNewAB();

          Set bSet = a.getB();

          bSet.add(b);

          ctx.commit();

          

          assertStateNewAB();

      }

  

      public void testBSetANewAB() throws Exception {

          TransactionContext ctx = prepareNewAB();

          Set aSet = b.getA();

          aSet.add(a);

          ctx.commit();

          

          assertStateNewAB();

      }

  

      private TransactionContext prepareExistingBNewA() throws Exception {

          TransactionContext ctx = newTransactionContext();

          a = ahome.create(new Integer(4));

          a.setField2("value4");

          b = bhome.findByPrimaryKey(new Integer(11));

          return ctx;

      }

  

      private void assertStateExistingBNewA() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT a2 FROM A WHERE a1 = 4");

          assertTrue(rs.next());

          assertEquals("value4", rs.getString(1));

          rs.close();

  

          rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 4 AND fkb1 
= 11");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

      

      public void testASetBExistingBNewA() throws Exception {

          TransactionContext ctx = prepareExistingBNewA();

          Set bSet = a.getB();

          bSet.add(b);

          ctx.commit();

          

          assertStateExistingBNewA();

      }

  

      public void testBSetAExistingBNewA() throws Exception {

          TransactionContext ctx = prepareExistingBNewA();

          Set aSet = b.getA();

          aSet.add(a);

          ctx.commit();

          

          assertStateExistingBNewA();

      }

  

      private TransactionContext prepareExistingANewB() throws Exception {

          TransactionContext ctx = newTransactionContext();

          a = ahome.findByPrimaryKey(new Integer(1));

          b = bhome.create(new Integer(33));

          b.setField2("value33");

          return ctx;

      }

      

      private void assertStateExistingANewB() throws Exception {

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT b2 FROM B WHERE b1 = 33");

          assertTrue(rs.next());

          assertEquals("value33", rs.getString(1));

          rs.close();

          

          rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 1 AND fkb1 
= 33");

          assertTrue(rs.next());

          assertEquals(1, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

      

      public void testASetBExistingANewB() throws Exception {

          TransactionContext ctx = prepareExistingANewB();

          Set bSet = a.getB();

          bSet.add(b);

          ctx.commit();

          

          assertStateExistingANewB();

      }

  

      public void testBSetAExistingANewB() throws Exception {

          TransactionContext ctx = prepareExistingANewB();

          Set aSet = b.getA();

          aSet.add(a);

          ctx.commit();

          

          assertStateExistingANewB();

      }

  

      public void testRemoveRelationships() throws Exception {

          TransactionContext ctx = newTransactionContext();

          ALocal a = ahome.findByPrimaryKey(new Integer(1));

          a.remove();

          ctx.commit();

  

          Connection c = ds.getConnection();

          Statement s = c.createStatement();

          ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM MTM WHERE fka1 = 
1");

          assertTrue(rs.next());

          assertEquals(0, rs.getInt(1));

          rs.close();

          s.close();

          c.close();

      }

  

      protected void setUp() throws Exception {

          super.setUp();

          

          ahome = (ALocalHome) super.ahome;

          bhome = (BLocalHome) super.bhome;

      }

      

      protected void buildDBSchema(Connection c) throws Exception {

          Statement s = c.createStatement();

          try {

              s.execute("DROP TABLE A");

          } catch (SQLException e) {

              // ignore

          }

          try {

              s.execute("DROP TABLE B");

          } catch (SQLException e) {

              // ignore

          }

          try {

              s.execute("DROP TABLE MTM");

          } catch (SQLException e) {

              // ignore

          }

          

          s.execute("CREATE TABLE A(A1 INTEGER, A2 VARCHAR(50))");

          s.execute("CREATE TABLE B(B1 INTEGER, B2 VARCHAR(50), FKA1 INTEGER)");

          s.execute("CREATE TABLE MTM(FKA1 INTEGER, FKB1 INTEGER)");

          

          s.execute("INSERT INTO A(A1, A2) VALUES(1, 'value1')");

          s.execute("INSERT INTO A(A1, A2) VALUES(2, 'value2')");

          s.execute("INSERT INTO A(A1, A2) VALUES(3, 'value3')");

          s.execute("INSERT INTO B(B1, B2) VALUES(11, 'value11')");

          s.execute("INSERT INTO B(B1, B2) VALUES(22, 'value22')");

          s.execute("INSERT INTO MTM(FKA1, FKB1) VALUES(1, 11)");

          s.execute("INSERT INTO MTM(FKA1, FKB1) VALUES(1, 22)");

          s.execute("INSERT INTO MTM(FKA1, FKB1) VALUES(2, 22)");

          s.execute("INSERT INTO MTM(FKA1, FKB1) VALUES(3, 22)");        

          s.close();

          c.close();

      }

  

      protected String getEjbJarDD() {

          return "src/test/test-cmp/manytomany/simplepk/ejb-jar.xml";

      }

  

      protected String getOpenEjbJarDD() {

          return "src/test/test-cmp/manytomany/simplepk/openejb-jar.xml";

      }

  

      protected EJBClass getA() {

          return new EJBClass(ABean.class, ALocalHome.class, ALocal.class);

      }

  

      protected EJBClass getB() {

          return new EJBClass(BBean.class, BLocalHome.class, BLocal.class);

      }

      

  }

  
  
  

Reply via email to