db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker BrokerExamples.java
Date Wed, 19 Feb 2003 22:13:27 GMT
arminw      2003/02/19 14:13:27

  Modified:    src/test/org/apache/ojb/broker BrokerExamples.java
  Log:
  update test case
  
  Revision  Changes    Path
  1.12      +68 -102   db-ojb/src/test/org/apache/ojb/broker/BrokerExamples.java
  
  Index: BrokerExamples.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/BrokerExamples.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BrokerExamples.java	5 Feb 2003 20:03:42 -0000	1.11
  +++ BrokerExamples.java	19 Feb 2003 22:13:27 -0000	1.12
  @@ -1,7 +1,6 @@
   package org.apache.ojb.broker;
   
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.cache.ObjectCacheFactory;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.query.QueryByIdentity;
  @@ -16,12 +15,11 @@
   {
       public static void main(String[] args)
       {
  -        String[] arr = { CLASS.getName()};
  +        String[] arr = {BrokerExamples.class.getClass().getName()};
           junit.textui.TestRunner.main(arr);
       }
   
       PersistenceBroker broker;
  -    private static Class CLASS = BrokerExamples.class;
       private int testId = 88881;
   
       /**
  @@ -106,7 +104,7 @@
               example.setId(i);
   
               ProductGroup group =
  -                (ProductGroup) broker.getObjectByQuery(QueryFactory.newQuery(example));
  +                    (ProductGroup) broker.getObjectByQuery(QueryFactory.newQuery(example));
               assertEquals("should be equal", i, group.getId());
           }
       }
  @@ -115,7 +113,7 @@
        * Insert the method's description here.
        * Creation date: (23.12.2000 20:05:49)
        */
  -    public void testModifications()
  +    public void testModifications() throws Exception
       {
           //create a new Article and play with it
           Article article = new Article();
  @@ -124,22 +122,13 @@
           article.setArticleId(testId);
           article.setProductGroupId(1);
   
  -        try
  +        for (int i = 1; i < 50; i++)
           {
  -            for (int i = 1; i < 50; i++)
  -            {
  -                article.addToStock(10);
  -                broker.store(article);
  -                broker.delete(article);
  -                broker.store(article);
  -
  -            }
  +            article.addToStock(10);
  +            broker.store(article);
  +            broker.delete(article);
  +            broker.store(article);
           }
  -        catch (Throwable t)
  -        {
  -            fail(t.getMessage());
  -        }
  -
       }
   
       /**
  @@ -147,17 +136,17 @@
        * if the Cache has not been flushed by the GC, All previously loaded Objects are still
hot.
        * I.e. they are reloaded from the Cache and not materialized from the RDBMS
        */
  -    public void testObjectCache()
  +    public void testObjectCache() throws Exception
       {
           // this test only makes sense in singlevm mode !
           PersistenceBrokerConfiguration config = null;
           try
           {
               config =
  -                (PersistenceBrokerConfiguration) PersistenceBrokerFactory
  +                    (PersistenceBrokerConfiguration) PersistenceBrokerFactory
                       .getConfigurator()
                       .getConfigurationFor(
  -                    null);
  +                            null);
           }
           catch (ConfigurationException e)
           {
  @@ -170,10 +159,10 @@
               broker.store(tmpArticle);
               broker.clearCache();
               Article cached =
  -                (Article) ObjectCacheFactory.getInstance().getObjectCache().lookup(tmpOID);
  +                    (Article) broker.serviceObjectCache().lookup(tmpOID);
               assertNull("After flushing Object should be not in cache", cached);
               Article article = (Article) broker.getObjectByQuery(new QueryByIdentity(tmpOID));
  -            cached = (Article) ObjectCacheFactory.getInstance().getObjectCache().lookup(tmpOID);
  +            cached = (Article) broker.serviceObjectCache().lookup(tmpOID);
               assertNotNull("now object should be found in cache", cached);
               assertEquals("should be same reference", cached, article);
           }
  @@ -212,10 +201,10 @@
           try
           {
               config =
  -                (PersistenceBrokerConfiguration) PersistenceBrokerFactory
  +                    (PersistenceBrokerConfiguration) PersistenceBrokerFactory
                       .getConfigurator()
                       .getConfigurationFor(
  -                    null);
  +                            null);
           }
           catch (ConfigurationException e)
           {
  @@ -234,7 +223,7 @@
                   // switch to shallow retrieval
                   ClassDescriptor cld = broker.getClassDescriptor(Article.class);
                   ObjectReferenceDescriptor ord =
  -                    (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptors().get(0);
  +                        (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptors().get(0);
                   ord.setCascadeRetrieve(false);
                   // should work without setting cld
                   // broker.setClassDescriptor(cld);
  @@ -263,17 +252,17 @@
       /**
        * tests the PB.retrieveReference() feature
        */
  -    public void testRetrieveReference()
  +    public void testRetrieveReference() throws Exception
       {
           // this test only makes sense in singlevm mode !
           PersistenceBrokerConfiguration config = null;
           try
           {
               config =
  -                (PersistenceBrokerConfiguration) PersistenceBrokerFactory
  +                    (PersistenceBrokerConfiguration) PersistenceBrokerFactory
                       .getConfigurator()
                       .getConfigurationFor(
  -                    null);
  +                            null);
           }
           catch (ConfigurationException e)
           {
  @@ -281,43 +270,32 @@
           }
           if (!config.isRunningInServerMode())
           {
  -            try
  -            {
  -                // ensure there is an item to find
  -                Article tmpArticle = createArticle(testId);
  -                Identity tmpOID = new Identity(tmpArticle, broker);
  -                broker.store(tmpArticle);
  -                broker.clearCache();
  +            // ensure there is an item to find
  +            Article tmpArticle = createArticle(testId);
  +            Identity tmpOID = new Identity(tmpArticle, broker);
  +            broker.store(tmpArticle);
  +            broker.clearCache();
   
  -                // switch to shallow retrieval
  -                ClassDescriptor cld = broker.getClassDescriptor(Article.class);
  -                // article only has one ord
  -                ObjectReferenceDescriptor ord =
  +            // switch to shallow retrieval
  +            ClassDescriptor cld = broker.getClassDescriptor(Article.class);
  +            // article only has one ord
  +            ObjectReferenceDescriptor ord =
                       (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptors().get(0);
  -                ord.setCascadeRetrieve(false);
  -                // should work without setting cld
  -                // broker.setClassDescriptor(cld);
  -
  -                Article article = (Article) broker.getObjectByIdentity(tmpOID);
  -                assertNull("now reference should be null", article.getProductGroup());
  -
  -                // now force loading:
  -                broker.retrieveReference(article, "productGroup");
  -                assertNotNull("now reference should NOT be null", article.getProductGroup());
  -
  -                // repair cld
  -                ord.setCascadeRetrieve(true);
  -                // should work without setting cld
  -                // broker.setClassDescriptor(cld);
  -
  -
  -            }
  -            catch (Throwable t)
  -            {
  -                System.out.println(t.getMessage());
  -                t.printStackTrace();
  -                fail(t.getMessage());
  -            }
  +            ord.setCascadeRetrieve(false);
  +            // should work without setting cld
  +            // broker.setClassDescriptor(cld);
  +
  +            Article article = (Article) broker.getObjectByIdentity(tmpOID);
  +            assertNull("now reference should be null", article.getProductGroup());
  +
  +            // now force loading:
  +            broker.retrieveReference(article, "productGroup");
  +            assertNotNull("now reference should NOT be null", article.getProductGroup());
  +
  +            // repair cld
  +            ord.setCascadeRetrieve(true);
  +            // should work without setting cld
  +            // broker.setClassDescriptor(cld);
           }
       }
   
  @@ -331,10 +309,10 @@
           try
           {
               config =
  -                (PersistenceBrokerConfiguration) PersistenceBrokerFactory
  +                    (PersistenceBrokerConfiguration) PersistenceBrokerFactory
                       .getConfigurator()
                       .getConfigurationFor(
  -                    null);
  +                            null);
           }
           catch (ConfigurationException e)
           {
  @@ -342,43 +320,31 @@
           }
           if (!config.isRunningInServerMode())
           {
  -            try
  -            {
  -                // ensure there is an item to find
  -                Article tmpArticle = createArticle(testId);
  -                Identity tmpOID = new Identity(tmpArticle, broker);
  -                broker.store(tmpArticle);
  -                broker.clearCache();
  +            // ensure there is an item to find
  +            Article tmpArticle = createArticle(testId);
  +            Identity tmpOID = new Identity(tmpArticle, broker);
  +            broker.store(tmpArticle);
  +            broker.clearCache();
   
  -                // switch to shallow retrieval
  -                ClassDescriptor cld = broker.getClassDescriptor(Article.class);
  -                ObjectReferenceDescriptor ord =
  +            // switch to shallow retrieval
  +            ClassDescriptor cld = broker.getClassDescriptor(Article.class);
  +            ObjectReferenceDescriptor ord =
                       (ObjectReferenceDescriptor) cld.getObjectReferenceDescriptors().get(0);
  -                ord.setCascadeRetrieve(false);
  -                // should work without setting cld
  -                // broker.setClassDescriptor(cld);
  -
  -                Article article = (Article) broker.getObjectByIdentity(tmpOID);
  -                assertNull("now reference should be null", article.getProductGroup());
  -
  -                // now force loading:
  -                broker.retrieveAllReferences(article);
  -                assertNotNull("now reference should NOT be null", article.getProductGroup());
  -
  -                // clean up cld
  -                ord.setCascadeRetrieve(true);
  -                // should work without setting cld
  -                // broker.setClassDescriptor(cld);
  -
  -
  -            }
  -            catch (Throwable t)
  -            {
  -                System.out.println(t.getMessage());
  -                t.printStackTrace();
  -                fail(t.getMessage());
  -            }
  +            ord.setCascadeRetrieve(false);
  +            // should work without setting cld
  +            // broker.setClassDescriptor(cld);
  +
  +            Article article = (Article) broker.getObjectByIdentity(tmpOID);
  +            assertNull("now reference should be null", article.getProductGroup());
  +
  +            // now force loading:
  +            broker.retrieveAllReferences(article);
  +            assertNotNull("now reference should NOT be null", article.getProductGroup());
  +
  +            // clean up cld
  +            ord.setCascadeRetrieve(true);
  +            // should work without setting cld
  +            // broker.setClassDescriptor(cld);
           }
       }
  -
   }
  
  
  

Mime
View raw message