db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/test/org/apache/ojb/odmg UserTestCases.java
Date Tue, 24 Dec 2002 14:10:46 GMT
arminw      2002/12/24 06:10:46

  Modified:    src/test/org/apache/ojb/odmg UserTestCases.java
  Log:
  update test case
  
  Revision  Changes    Path
  1.4       +54 -21    jakarta-ojb/src/test/org/apache/ojb/odmg/UserTestCases.java
  
  Index: UserTestCases.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/odmg/UserTestCases.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UserTestCases.java	8 Nov 2002 14:01:27 -0000	1.3
  +++ UserTestCases.java	24 Dec 2002 14:10:46 -0000	1.4
  @@ -2,12 +2,17 @@
   
   import junit.framework.TestCase;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.singlevm.PersistenceBrokerConfiguration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
   import org.odmg.Database;
   import org.odmg.Implementation;
  +import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  +import java.util.List;
  +
  +
   /**
    * Collection of test cases sent by OJB users
    *
  @@ -28,12 +33,12 @@
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
   
  -        db.open("repository.xml", Database.OPEN_READ_WRITE);
  +        db.open(TestHelper.DEF_JCD_ALIAS, Database.OPEN_READ_WRITE);
           //System.out.println("TEST: Database open");
   
           // insert an object with UNIQUE field NAME="A site"
           //System.out.println("TEST: Insert first object");
  -        newSite(odmg,"A site", 2, 1);
  +        newSite(odmg, "A site", 2, 1);
   
           // insert another object with UNIQUE field NAME="A site"
           // This should not create a new object (UNIQUE fields conflict) but
  @@ -41,7 +46,7 @@
           //System.out.println("TEST: Insert second object, should fail");
           try
           {
  -            newSite(odmg,"A site", 3, 2);
  +            newSite(odmg, "A site", 3, 2);
               assertTrue("We should get a SqlException 'Violation of unique index'", false);
           }
           catch (Exception e)
  @@ -55,13 +60,13 @@
           //System.out.println("TEST: Insert third object");
           try
           {
  -            newSite(odmg,"Another site", 1, 2);
  +            newSite(odmg, "Another site", 1, 2);
               assertTrue(true);
           }
           catch (Exception e)
           {
               e.printStackTrace();
  -            assertTrue("This exception should not happend: "+e.getMessage(), false);
  +            assertTrue("This exception should not happend: " + e.getMessage(), false);
               throw e;
           }
   
  @@ -69,7 +74,7 @@
           //System.out.println("TEST: Database closed");
       }
   
  -    private void newSite(Implementation odmg,String name, int year, int semester) throws
Exception
  +    private void newSite(Implementation odmg, String name, int year, int semester) throws
Exception
       {
           Transaction tx = null;
           tx = odmg.newTransaction();
  @@ -85,6 +90,47 @@
           tx.commit();
       }
   
  +    public void testSimpleQueryDelete() throws Exception
  +    {
  +        Implementation odmg = OJB.getInstance();
  +        Database db = odmg.newDatabase();
  +        String name = "testSimpleQueryDelete - " + System.currentTimeMillis();
  +
  +        db.open(databaseName, Database.OPEN_READ_WRITE);
  +        Site site = new Site();
  +        site.setName(name);
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +        tx.lock(site, Transaction.WRITE);
  +        tx.commit();
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select sites from " + Site.class.getName() + " where name=$1");
  +        query.bind(name);
  +        tx.begin();
  +        List result = (List) query.execute();
  +        if (result.size() == 0)
  +        {
  +            fail("Stored object not found");
  +        }
  +        tx.commit();
  +
  +        tx.begin();
  +        db.deletePersistent(site);
  +        tx.commit();
  +
  +        query = odmg.newOQLQuery();
  +        query.create("select sites from " + Site.class.getName() + " where name=$1");
  +        query.bind(name);
  +        tx.begin();
  +        List result2 = (List) query.execute();
  +        if (result2.size() > 0)
  +        {
  +            fail("We should not found deleted objects");
  +        }
  +        tx.commit();
  +    }
  +
   
       public static void main(String[] args)
       {
  @@ -108,20 +154,7 @@
   
       public void setUp()
       {
  -        try
  -        {
  -            databaseName =
  -                    ((PersistenceBrokerConfiguration) PersistenceBrokerFactory
  -                    .getConfigurator()
  -                    .getConfigurationFor(null))
  -                    .getRepositoryFilename();
  -        }
  -        catch (ConfigurationException e)
  -        {
  -            System.err.println("Error while lookup database name, set default db name");
  -            e.printStackTrace();
  -            databaseName = "repository.xml";
  -        }
  +        databaseName = TestHelper.DEF_JCD_ALIAS;
       }
   
       protected void tearDown() throws Exception
  
  
  

Mime
View raw message