You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2005/03/16 02:11:59 UTC

cvs commit: db-ojb/src/test/org/apache/ojb/odmg NamedRootsTest.java

arminw      2005/03/15 17:11:59

  Modified:    src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        NamedRootsTest.java
  Log:
  fix test case
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.1   +59 -152   db-ojb/src/test/org/apache/ojb/odmg/NamedRootsTest.java
  
  Index: NamedRootsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/NamedRootsTest.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- NamedRootsTest.java	22 Jun 2004 18:16:22 -0000	1.1
  +++ NamedRootsTest.java	16 Mar 2005 01:11:58 -0000	1.1.2.1
  @@ -1,14 +1,10 @@
   package org.apache.ojb.odmg;
   
   
  -import junit.framework.TestCase;
  -import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.junit.ODMGTestCase;
   import org.apache.ojb.odmg.shared.Article;
  +import org.apache.ojb.odmg.shared.ProductGroup;
   import org.odmg.DList;
  -import org.odmg.Database;
  -import org.odmg.Implementation;
  -import org.odmg.ODMGException;
   import org.odmg.ObjectNameNotFoundException;
   import org.odmg.ObjectNameNotUniqueException;
   import org.odmg.Transaction;
  @@ -19,102 +15,55 @@
    *
    * @version $Id$
    */
  -public class NamedRootsTest extends TestCase
  +public class NamedRootsTest extends ODMGTestCase
   {
  +    private ProductGroup testProductGroup;
  +
       public static void main(String[] args)
       {
  -        String[] arr = {CLASS.getName()};
  +        String[] arr = {NamedRootsTest.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  -    private static Class CLASS = NamedRootsTest.class;
  -    private String databaseName;
  -
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (24.12.2000 00:33:40)
  -     */
       public NamedRootsTest(String name)
       {
           super(name);
       }
   
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:59:14)
  -     */
  -    private void clearNRM()
  -    {
  -        try
  -        {
  -            /*
  -            org.apache.ojb.broker.metadata.ClassDescriptor cld = ojb.broker.metadata.DescriptorRepository.getInstance().getDescriptorFor(NamedRootsEntry.class);
  -
  -            java.sql.Statement stmt = org.apache.ojb.broker.accesslayer.StatementManager.getGenericStatement(cld);
  -            String nrmTable = cld.getTableName();
  -            String scheme = cld.getScheme();
  -            if (scheme != null)
  -            {	nrmTable = scheme + "." + nrmTable;
  -            }
  -
  -            stmt.executeUpdate("DELETE FROM " + nrmTable);
  -             */
  -        }
  -        catch (Throwable t)
  -        {
  -        }
  -    }
  -
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:58:53)
  -     */
  -    public void setUp()
  +    protected void setUp() throws Exception
       {
  -        databaseName = TestHelper.DEF_DATABASE_NAME;
  -    }
  -
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:59:14)
  -     */
  -    public void tearDown()
  -    {
  -        databaseName = null;
  -        clearNRM();
  +        super.setUp();
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +        testProductGroup = new ProductGroup();
  +        testProductGroup.setGroupName("NamedRootsTest_" + System.currentTimeMillis());
  +        database.makePersistent(testProductGroup);
  +        tx.commit();
       }
   
  -    private static int count = 0;
       private Article createArticle()
       {
           Article example = new Article();
  -        example.setArticleId(++count);
  -        example.setArticleName("named roots article No. "+(count));
  -        example.setProductGroupId(1);
  -
  +        example.setArticleName(testProductGroup.getName());
  +        example.setProductGroupId(testProductGroup.getId());
           return example;
       }
   
       public void testBind() throws Exception
       {
  -        String bindingName = "binding_for_testBind";
  -
  -        // get facade instance
  -        Implementation odmg = OJB.getInstance();
  -        Database db = odmg.newDatabase();
  -        //open database
  -        db.open(databaseName, Database.OPEN_READ_WRITE);
  -        // clean up roots map
  -        clearNRM();
  -
  +        String bindingName = "testBind_" + System.currentTimeMillis();
  +        TransactionImpl tx = (TransactionImpl) odmg.newTransaction();
  +        //bind object to name
  +        tx.begin();
           Article example = createArticle();
  +        database.makePersistent(example);
  +        tx.commit();
   
  -        Transaction tx = odmg.newTransaction();
           tx.begin();
           try
           {
  -            db.bind(example, bindingName);
  -            Article value = (Article) db.lookup(bindingName);
  +            database.bind(example, bindingName);
  +            Article value = (Article) database.lookup(bindingName);
               assertTrue("Could not lookup object for binding name: "+bindingName, value != null);
               tx.commit();
           }
  @@ -132,7 +81,7 @@
           try
           {
               tx.begin();
  -            db.bind(example, bindingName);
  +            database.bind(example, bindingName);
               tx.commit();
               fail("We expected a ObjectNameNotUniqueException, but was not thrown");
           }
  @@ -146,49 +95,42 @@
           try
           {
               tx.begin();
  -            db.unbind(bindingName);
  +            database.unbind(bindingName);
               tx.commit();
           }
           catch (ObjectNameNotFoundException ex)
           {
               fail("Can't unbind " + bindingName + ": "+ex.getMessage());
           }
  -
  -        db.close();
       }
   
       public void testDoubleBindInOneTx() throws Exception
       {
  -        String bindingName = "binding_for_testDoubleBindInOneTx";
  +        String bindingName = "testDoubleBindInOneTx_" + System.currentTimeMillis();
   
           DList foundList = null;
  -        // get facade instance
  -        Implementation odmg = OJB.getInstance();
  -        Database db = odmg.newDatabase();
  -        //open database
  -        db.open(databaseName, Database.OPEN_READ_WRITE);
           Transaction tx = odmg.newTransaction();
           tx.begin();
  -        db.bind(odmg.newDList(), bindingName);
  +        database.bind(odmg.newDList(), bindingName);
   
  -        foundList = (DList)db.lookup(bindingName);
  +        foundList = (DList)database.lookup(bindingName);
           assertTrue("Could not found bound DList", foundList != null);
           foundList = null;
   
  -        db.unbind(bindingName);
  +        database.unbind(bindingName);
           try
           {
  -            foundList = (DList) db.lookup(bindingName);
  +            foundList = (DList) database.lookup(bindingName);
               fail("Found unbound DList");
           }
           catch (ObjectNameNotFoundException ex)
           {
           }
   
  -        db.bind(odmg.newDList(), bindingName);
  +        database.bind(odmg.newDList(), bindingName);
           try
           {
  -            foundList = (DList) db.lookup(bindingName);
  +            foundList = (DList) database.lookup(bindingName);
           }
           catch (ObjectNameNotFoundException ex)
           {
  @@ -201,38 +143,33 @@
           tx.begin();
           try
           {
  -            DList newList = (DList)db.lookup(bindingName);
  -            db.unbind(bindingName);
  +            DList newList = (DList) database.lookup(bindingName);
  +            assertNotNull(newList);
  +            database.unbind(bindingName);
           }
           catch (ObjectNameNotFoundException ex)
           {
               fail("Could not found bound DList in new tx");
           }
           tx.commit();
  -
  -        db.close();
       }
   
   
       public void testLookup() throws Exception
       {
  -        String bindingName = "binding_for_testLookup";
  -        // get facade instance
  -        Implementation odmg = OJB.getInstance();
  -        Database db = odmg.newDatabase();
  -        db.open(databaseName, Database.OPEN_READ_WRITE);
  -
  +        String bindingName = "testLookup_" + System.currentTimeMillis();
           // clear named roots.
  -        clearNRM();
  -        Transaction tx = odmg.newTransaction();
  +        TransactionImpl tx = (TransactionImpl) odmg.newTransaction();
           //bind object to name
           tx.begin();
           Article example = createArticle();
  -        Identity oid = new Identity(example, ((HasBroker)tx).getBroker());
  +        database.makePersistent(example);
  +        tx.commit();
   
  +        tx.begin();
           try 
           {
  -            db.bind(example, bindingName);
  +            database.bind(example, bindingName);
               tx.commit();
           }
           catch (ObjectNameNotUniqueException ex)
  @@ -243,13 +180,12 @@
   
           // TestThreadsNLocks look up
           Article lookedUp1 = null;
  -        tx = odmg.newTransaction();
  +        tx = (TransactionImpl) odmg.newTransaction();
           tx.begin();
  -
           try
           {
               // lookup by name binding
  -            lookedUp1 = (Article) db.lookup(bindingName);
  +            lookedUp1 = (Article) database.lookup(bindingName);
           }
           catch (ObjectNameNotFoundException ex)
           {
  @@ -264,46 +200,31 @@
           try
           {
               tx.begin();
  -            db.unbind(bindingName);
  +            database.unbind(bindingName);
               tx.commit();
           }
           catch (ObjectNameNotFoundException ex)
           {
               fail("Can't unbind " + bindingName + ": "+ex.getMessage());
           }
  -
  -        db.close();
       }
   
       public void testUnBind() throws Exception
       {
  -        String name = "binding_for_testUnBind";
  -        // get facade instance
  -        Implementation odmg = OJB.getInstance();
  -        Database db = odmg.newDatabase();
  -
  -        //open database
  -        try
  -        {
  -            db.open(databaseName, Database.OPEN_READ_WRITE);
  -        }
  -        catch (ODMGException ex)
  -        {
  -            fail("ODMGException: " + ex.getMessage());
  -        }
  -
  -        // clear named roots.
  -        clearNRM();
  +        String name = "testUnBind_" + System.currentTimeMillis();
   
           Transaction tx = odmg.newTransaction();
  -        // 1. perform binding
  +        //bind object to name
           tx.begin();
  -
           Article example = createArticle();
  +        database.makePersistent(example);
  +        tx.commit();
   
  +        // 1. perform binding
  +        tx.begin();
           try
           {
  -            db.bind(example, name);
  +            database.bind(example, name);
               tx.commit();
           }
           catch (ObjectNameNotUniqueException ex)
  @@ -317,7 +238,7 @@
           tx.begin();
           try
           {
  -            db.unbind(name);
  +            database.unbind(name);
               tx.commit();
           }
           catch (ObjectNameNotFoundException ex)
  @@ -331,29 +252,15 @@
           tx.begin();
           try
           {
  -            Article value = (Article) db.lookup(name);
  +            Article value = (Article) database.lookup(name);
  +            assertNotNull("Should not find unbind name '" + name+"'", value);
  +            fail("name " + name + " should not be known after unbind");
           }
           catch (ObjectNameNotFoundException ex)
           {
  -            // OK !
  -            tx.commit();
  -            // close database
  -            try
  -            {
  -                db.close();
  -            }
  -            catch (ODMGException e)
  -            {
  -                fail("ODMGException: " + e.getMessage());
  -            }
  -
  -            return;
  +            // OK, expected
  +            assertTrue(true);
           }
  -
  -        // NOT OK!
           tx.abort();
  -        db.close();
  -        fail("name " + name + " should not be known after unbind");
  -
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org