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/metadata RepositoryElementsTest.java
Date Tue, 29 Apr 2003 15:43:27 GMT
arminw      2003/04/29 08:43:27

  Modified:    src/test/org/apache/ojb/broker Content.java
                        BrokerExamples.java AbstractArticle.java
                        ProductGroupProxy.java PolymorphicExtents.java
                        PBListenerTest.java Qualifier.java
                        FieldConversionTest_3.java QueryTest.java
                        AllTests.java
               src/test/org/apache/ojb/odmg Master.java Site.java
                        RITest.java PersonImpl.java MultiDBUsageTest.java
                        CollectionsTest.java
               src/test/org/apache/ojb/broker/sequence
                        SMDatabaseSequence.java SMInterface.java
                        SequenceManagerTest.java
               src/test/org/apache/ojb/performance PerfArticle.java
  Added:       src/test/org/apache/ojb/broker/metadata
                        RepositoryElementsTest.java
  Log:
  - make persistent objects serializable
  - update test cases
  - add repository elements test written by Virender Dogra
  
  Revision  Changes    Path
  1.2       +5 -3      db-ojb/src/test/org/apache/ojb/broker/Content.java
  
  Index: Content.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/Content.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Content.java	9 Apr 2003 13:33:31 -0000	1.1
  +++ Content.java	29 Apr 2003 15:43:26 -0000	1.2
  @@ -1,12 +1,14 @@
   package org.apache.ojb.broker;
   
  +import java.io.Serializable;
  +
   /**
  - * This interface is used to test extent aware path expressions 
  + * This interface is used to test extent aware path expressions
    * @author <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
    */
  -public interface Content
  +public interface Content extends Serializable
   {
       int getId();
  -    
  +
       void setId(int id);
   }
  
  
  
  1.15      +16 -28    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- BrokerExamples.java	26 Apr 2003 23:18:23 -0000	1.14
  +++ BrokerExamples.java	29 Apr 2003 15:43:26 -0000	1.15
  @@ -7,6 +7,7 @@
   import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
  +import org.apache.commons.lang.SerializationUtils;
   
   /** Demo Application that shows basic concepts for Applications using the PersistenceBroker
    * as a mediator for persistence
  @@ -15,7 +16,7 @@
   {
       public static void main(String[] args)
       {
  -        String[] arr = {BrokerExamples.class.getClass().getName()};
  +        String[] arr = {BrokerExamples.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  @@ -138,33 +139,20 @@
        */
       public void testObjectCache() throws Exception
       {
  -        // this test only makes sense in singlevm mode !
  -        PersistenceBrokerConfiguration config = null;
  -        try
  -        {
  -            config =
  -                    (PersistenceBrokerConfiguration) PersistenceBrokerFactory
  -                    .getConfigurator()
  -                    .getConfigurationFor(
  -                            null);
  -        }
  -        catch (ConfigurationException e)
  -        {
  -            fail(e.getMessage());
  -        }
  -
  -            Article tmpArticle = createArticle(testId);
  -            Identity tmpOID = new Identity(tmpArticle, broker);
  -            broker.store(tmpArticle);
  -            broker.clearCache();
  -            Article cached =
  -                    (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) broker.serviceObjectCache().lookup(tmpOID);
  -            assertNotNull("now object should be found in cache", cached);
  -            assertEquals("should be same reference", cached, article);
  -
  +        Article tmpArticle = createArticle(testId);
  +        Identity tmpOID = new Identity(tmpArticle, broker);
  +        broker.beginTransaction();
  +        broker.store(tmpArticle);
  +        broker.commitTransaction();
  +        broker.clearCache();
  +        Article cached =
  +                (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) broker.serviceObjectCache().lookup(tmpOID);
  +        assertNotNull("now object should be found in cache", cached);
  +        assertEquals("should be the same Identity", new Identity(cached, broker), new Identity(article,broker));
  +        assertEquals("objects should have identical values", cached.toString(), article.toString());
       }
   
       /**
  
  
  
  1.3       +4 -3      db-ojb/src/test/org/apache/ojb/broker/AbstractArticle.java
  
  Index: AbstractArticle.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AbstractArticle.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractArticle.java	24 Dec 2002 14:06:45 -0000	1.2
  +++ AbstractArticle.java	29 Apr 2003 15:43:26 -0000	1.3
  @@ -6,13 +6,14 @@
       /** return a string representaion of an article*/
       public String toString()
       {
  -        String group = "" + productGroupId;
  -        if (productGroup != null) group = productGroup.getName();
  +        String groupId = "" + productGroupId;
  +        String groupName = productGroup != null ? productGroup.getName() : null;
   
           return "----\n" +
                   "Article No:   " + articleId + "\n" +
                   "Description:  " + articleName + "\n" +
  -                "ProductGroup: " + group + "\n" +
  +                "ProductGroupId: " + groupId + "\n" +
  +                "ProductGroupName: " + groupName + "\n" +
                   "stock:        " + stock + "\n" +
                   "price:        " + price + "\n" +
                   "stock-value   " + getStockValue() + "\n";
  
  
  
  1.4       +7 -4      db-ojb/src/test/org/apache/ojb/broker/ProductGroupProxy.java
  
  Index: ProductGroupProxy.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ProductGroupProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProductGroupProxy.java	5 Oct 2002 15:20:42 -0000	1.3
  +++ ProductGroupProxy.java	29 Apr 2003 15:43:26 -0000	1.4
  @@ -1,5 +1,8 @@
   package org.apache.ojb.broker;
   
  +import java.util.List;
  +import java.io.Serializable;
  +
   //#ifdef JDK13
   import java.lang.reflect.InvocationHandler;
   //#else
  @@ -11,7 +14,7 @@
   /**
    * Proxy class for ProductGroup.
    */
  -public class ProductGroupProxy extends VirtualProxy implements InterfaceProductGroup, java.io.Serializable
  +public class ProductGroupProxy extends VirtualProxy implements InterfaceProductGroup, Serializable
   {
       public ProductGroupProxy()
       {
  @@ -33,7 +36,7 @@
   
   
       /** return List of all Articles in productgroup*/
  -    public java.util.List getAllArticles()
  +    public List getAllArticles()
       {
           return realSubject().getAllArticles();
       }
  @@ -45,7 +48,7 @@
       }
   
       /** return groupname*/
  -    public java.lang.String getName()
  +    public String getName()
       {
           return realSubject().getName();
       }
  @@ -60,7 +63,7 @@
           try
           {
               ProductGroup result = (ProductGroup) getRealSubject();
  -            if (result == null) throw new NullPointerException();
  +            if (result == null) throw new NullPointerException("Real subject was null");
               return result;
           }
           catch (Throwable t)
  
  
  
  1.13      +14 -22    db-ojb/src/test/org/apache/ojb/broker/PolymorphicExtents.java
  
  Index: PolymorphicExtents.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PolymorphicExtents.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PolymorphicExtents.java	8 Mar 2003 19:22:56 -0000	1.12
  +++ PolymorphicExtents.java	29 Apr 2003 15:43:26 -0000	1.13
  @@ -159,33 +159,25 @@
   	/** TestThreadsNLocks to lookup items from extent classes*/
   	public void testRetrieveObjectByIdentity()
   	{
  -		try
  -		{
  -			Article example = new Article();
  -			example.setArticleId(200);
  -			// id not present in table ARTICLES but int table CDS
  -			Identity oid = new Identity(example, broker);
  +        Article example = new Article();
  +        example.setArticleId(200);
  +        // id not present in table ARTICLES but int table CDS
  +        Identity oid = new Identity(example, broker);
   
  -			InterfaceArticle result = (InterfaceArticle) broker.getObjectByIdentity(oid);
  +        InterfaceArticle result = (InterfaceArticle) broker.getObjectByIdentity(oid);
   
  -			assertNotNull("should find a CD-article", result);
  -			assertTrue("should be of type CdArticle", (result instanceof CdArticle));
  +        assertNotNull("should find a CD-article", result);
  +        assertTrue("should be of type CdArticle", (result instanceof CdArticle));
   
  -			example = new Article();
  -			example.setArticleId(100);
  -			// id not present in table ARTICLES but int table CDS
  -			oid = new Identity(example, broker);
  +        example = new Article();
  +        example.setArticleId(100);
  +        // id not present in table ARTICLES but int table CDS
  +        oid = new Identity(example, broker);
   
  -			result = (InterfaceArticle) broker.getObjectByIdentity(oid);
  +        result = (InterfaceArticle) broker.getObjectByIdentity(oid);
   
  -			assertNotNull("should find a Book-article", result);
  -			assertTrue("should be of type BookArticle", (result instanceof BookArticle));
  -
  -		}
  -		catch (Throwable t)
  -		{
  -			fail(t.getMessage());
  -		}
  +        assertNotNull("should find a Book-article", result);
  +        assertTrue("should be of type BookArticle", (result instanceof BookArticle));
   	}
   
   	/** try to load polymorphic references
  
  
  
  1.2       +9 -2      db-ojb/src/test/org/apache/ojb/broker/PBListenerTest.java
  
  Index: PBListenerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PBListenerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PBListenerTest.java	12 Apr 2003 23:24:40 -0000	1.1
  +++ PBListenerTest.java	29 Apr 2003 15:43:26 -0000	1.2
  @@ -4,6 +4,8 @@
   
   import java.io.Serializable;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +
   /**
    * This TestClass tests OJB facilities to work with persistence
    * aware instances.
  @@ -84,8 +86,8 @@
           broker.beginTransaction();
           broker.store(lookedUp);
           broker.commitTransaction();
  -        assertEquals(true, obj.getCalledBeforeUpdate());
  -        assertEquals(true, obj.getCalledAfterUpdate());
  +        assertEquals(true, lookedUp.getCalledBeforeUpdate());
  +        assertEquals(true, lookedUp.getCalledAfterUpdate());
       }
   
       /**
  @@ -450,6 +452,11 @@
           public void setId(int id)
           {
               this.id = id;
  +        }
  +
  +        public String toString()
  +        {
  +            return ToStringBuilder.reflectionToString(this);
           }
       }
   
  
  
  
  1.2       +7 -5      db-ojb/src/test/org/apache/ojb/broker/Qualifier.java
  
  Index: Qualifier.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/Qualifier.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Qualifier.java	9 Apr 2003 13:33:31 -0000	1.1
  +++ Qualifier.java	29 Apr 2003 15:43:26 -0000	1.2
  @@ -1,16 +1,18 @@
   package org.apache.ojb.broker;
   
  +import java.io.Serializable;
  +
   /**
  - * This interface is used to test extent aware path expressions 
  + * This interface is used to test extent aware path expressions
    * @author <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
    */
  -public interface Qualifier
  +public interface Qualifier extends Serializable
   {
       int getId();
  -    
  +
       void setId(int id);
  -    
  +
       String getName();
  -    
  +
       void setName(String name);
   }
  
  
  
  1.3       +2 -2      db-ojb/src/test/org/apache/ojb/broker/FieldConversionTest_3.java
  
  Index: FieldConversionTest_3.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/FieldConversionTest_3.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FieldConversionTest_3.java	5 Mar 2003 14:38:17 -0000	1.2
  +++ FieldConversionTest_3.java	29 Apr 2003 15:43:26 -0000	1.3
  @@ -142,7 +142,7 @@
       //****************************************************************************
       // inner class
       //****************************************************************************
  -    public class Node implements Serializable
  +    public static class Node implements Serializable
       {
           private long uid;  // primary key
           private long refId;
  
  
  
  1.28      +8 -5      db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- QueryTest.java	8 Apr 2003 16:21:34 -0000	1.27
  +++ QueryTest.java	29 Apr 2003 15:43:26 -0000	1.28
  @@ -270,8 +270,8 @@
       public void testPathExpressionsMtoN2()
       {
           Criteria crit = new Criteria();
  -        crit.addEqualTo("projects.roles.roleName", "developer"); 
  -        crit.addLike("projects.persons.lastname", "%b%"); 
  +        crit.addEqualTo("projects.roles.roleName", "developer");
  +        crit.addLike("projects.persons.lastname", "%b%");
           Query q = QueryFactory.newQuery(Person.class, crit);
   
           Collection results = broker.getCollectionByQuery(q);
  @@ -372,7 +372,9 @@
   		// this test can only succeed in singlevm mode:
   		if (!BrokerHelper.isRunningInServerMode())
   		{
  -			assertTrue("ProductGroups should be the same", cdPg.getRealSubject() == pg.getRealSubject());
  +			assertNotNull(pg);
  +			assertNotNull(cdPg);
  +            assertEquals("ProductGroups should be identical", pg.getRealSubject().toString(),cdPg.getRealSubject().toString());
   		}
   
   	}
  @@ -464,6 +466,7 @@
   		assertNotNull(results);
   		assertTrue(results.size() > 0);
   		InterfaceProductGroup pg = (InterfaceProductGroup) results.toArray()[0];
  +        assertNotNull(pg.getAllArticles());
   		int articleSize = pg.getAllArticles().size();
   		String articleString = pg.getAllArticles().toString();
   
  @@ -712,7 +715,7 @@
   			list.add(iter.next());
   		}
   
  -		// 3 Books , 1 Dairy Product 
  +		// 3 Books , 1 Dairy Product
   		assertEquals("check size", list.size(), 4);
   	}
   
  @@ -781,7 +784,7 @@
               list.add(iter.next());
           }
   
  -        // ProductGroups 5 
  +        // ProductGroups 5
           assertEquals("check size", list.size(), 1);
       }
   
  
  
  
  1.25      +2 -0      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AllTests.java	12 Apr 2003 23:24:40 -0000	1.24
  +++ AllTests.java	29 Apr 2003 15:43:26 -0000	1.25
  @@ -5,6 +5,7 @@
   import org.apache.ojb.broker.metadata.CustomAttributesTest;
   import org.apache.ojb.broker.metadata.MetadataTest;
   import org.apache.ojb.broker.metadata.RepositoryPersistorTest;
  +import org.apache.ojb.broker.metadata.RepositoryElementsTest;
   import org.apache.ojb.broker.sequence.SequenceManagerTest;
   
   /**
  @@ -72,6 +73,7 @@
           suite.addTest(new TestSuite(ObjectCacheTest.class));
           suite.addTest(new TestSuite(ReferenceTest.class));
           suite.addTest(new TestSuite(ExtentAwarePathExpressionsTest.class));
  +        suite.addTest(new TestSuite(RepositoryElementsTest.class));
           return suite;
       }
   
  
  
  
  1.4       +8 -8      db-ojb/src/test/org/apache/ojb/odmg/Master.java
  
  Index: Master.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/Master.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Master.java	8 Apr 2003 20:19:29 -0000	1.3
  +++ Master.java	29 Apr 2003 15:43:26 -0000	1.4
  @@ -13,19 +13,19 @@
       public String masterText;
       public Vector collDetailFKinPK = new Vector();
       public Vector collDetailFKnoPK = new Vector();
  -    
  +
       public Master(Integer id, String text)
       {
           masterId = id;
           masterText = text;
       }
  -    
  +
       public Master()
       {
           super();
       }
  -    
  -    
  +
  +
       public String toString()
       {
           StringBuffer strBuf = new StringBuffer("Master: masterId = " + masterId);
  @@ -34,9 +34,9 @@
           {
               java.util.Iterator it = collDetailFKinPK.iterator();
               while (it.hasNext())
  -                strBuf.append(it.next().toString() + " ");    
  +                strBuf.append(it.next().toString() + " ");
           }
  -        strBuf.append("] collDetailFKnoPK [");        
  +        strBuf.append("] collDetailFKnoPK [");
           if (collDetailFKnoPK != null)
           {
               java.util.Iterator it = collDetailFKnoPK.iterator();
  @@ -50,7 +50,7 @@
        * Gets the collDetailFKinPK.
        * @return Returns a java.util.Vector
        */
  -    public java.util.Vector getCollDetailFKinPK()
  +    public Vector getCollDetailFKinPK()
       {
           return collDetailFKinPK;
       }
  @@ -68,7 +68,7 @@
        * Gets the collDetailFKnoPK.
        * @return Returns a java.util.Vector
        */
  -    public java.util.Vector getCollDetailFKnoPK()
  +    public Vector getCollDetailFKnoPK()
       {
           return collDetailFKnoPK;
       }
  
  
  
  1.2       +4 -2      db-ojb/src/test/org/apache/ojb/odmg/Site.java
  
  Index: Site.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/Site.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Site.java	2 Oct 2002 23:55:15 -0000	1.1
  +++ Site.java	29 Apr 2003 15:43:26 -0000	1.2
  @@ -1,11 +1,13 @@
   package org.apache.ojb.odmg;
   
  +import java.io.Serializable;
  +
   /**
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class Site
  +public class Site implements Serializable
   {
       private Integer id;
       private String name;
  
  
  
  1.11      +123 -86   db-ojb/src/test/org/apache/ojb/odmg/RITest.java
  
  Index: RITest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/RITest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RITest.java	6 Feb 2003 21:30:03 -0000	1.10
  +++ RITest.java	29 Apr 2003 15:43:26 -0000	1.11
  @@ -3,7 +3,6 @@
   import junit.framework.TestCase;
   import org.apache.ojb.broker.Contract;
   import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.TestHelper;
   import org.odmg.DList;
   import org.odmg.Database;
  @@ -11,6 +10,10 @@
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.Vector;
  +
   /** Demo Application that shows basic concepts for Applications using the OJB ODMG
    * implementation as an transactional object server.
    */
  @@ -53,8 +56,9 @@
        * Test referential integrity with the ODMG-Layer, the foreign key
        * is not a part of the primary key of the detail.
        */
  -    public void testFKnoPK() throws Exception
  +    public void testStoreFKnoPK() throws Exception
       {
  +        long timestamp = System.currentTimeMillis();
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           try
  @@ -62,34 +66,25 @@
               db.open(databaseName, Database.OPEN_READ_WRITE);
               Transaction tx = odmg.newTransaction();
               tx.begin();
  +            Master master_1 = populatedMasterFKnoPK(tx, 5, timestamp);
  +            Master master_2 = populatedMasterFKnoPK(tx, 5, timestamp);
   
  -            Master aMaster1 = new Master();
  -            aMaster1.masterText = "Master 1";
  -            aMaster1.collDetailFKnoPK = new java.util.Vector();
  -            new Identity(aMaster1,((HasBroker)tx).getBroker());
  -            for (int i = 0; i < 100; i++)
  -            {
  -                DetailFKnoPK aDetail = new DetailFKnoPK();
  -                aDetail.detailText = "Artikel " + i + " in Produktgruppe 1";
  -                aDetail.master = aMaster1;
  -                aMaster1.collDetailFKnoPK.add(aDetail);
  -            }
  +            db.makePersistent(master_1);
  +            db.makePersistent(master_2);
  +            tx.commit();
   
  -            Master aMaster2 = new Master();
  -            aMaster2.masterText = "Master 2";
  -            aMaster2.collDetailFKnoPK = new java.util.Vector();
  -            new Identity(aMaster2,((HasBroker)tx).getBroker());
  -            for (int i = 0; i < 5; i++)
  -            {
  -                DetailFKnoPK aDetail = new DetailFKnoPK();
  -                aDetail.detailText = "Artikel " + i + " in Produktgruppe 1";
  -                aDetail.master = aMaster2;
  -                aMaster2.collDetailFKnoPK.add(aDetail);
  -            }
  +            // Check stored objects
  +            OQLQuery query = odmg.newOQLQuery();
  +            query.create("select masters from " + Master.class.getName() + " where masterText
like $1");
  +            query.bind("%" + timestamp);
  +            DList allMasters = (DList) query.execute();
  +            assertEquals("We should found master objects", 2, allMasters.size());
  +            Master lookup_1 = (Master) allMasters.get(0);
   
  -            db.makePersistent(aMaster1);
  -            db.makePersistent(aMaster2);
  -            tx.commit();
  +            Collection col_in = lookup_1.getCollDetailFKinPK();
  +            Collection col_no = lookup_1.getCollDetailFKnoPK();
  +            assertEquals("Should found none " + DetailFKinPK.class.getName() + " objects",
0, col_in.size());
  +            assertEquals("Should found " + DetailFKnoPK.class.getName() + " objects", 5,
col_no.size());
           }
           finally
           {
  @@ -101,8 +96,9 @@
        * Test referential integrity with the ODMG-Layer, the foreign key
        * is part of the primary key of the detail table in this case
        */
  -    public void testFKinPK() throws Exception
  +    public void testStoreFKinPK() throws Exception
       {
  +        final long timestamp = System.currentTimeMillis();
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           try
  @@ -111,36 +107,24 @@
               Transaction tx = odmg.newTransaction();
               tx.begin();
   
  -            Master aMaster1 = new Master();
  -            aMaster1.masterText = "Master 1";
  -            aMaster1.collDetailFKinPK = new java.util.Vector();
  -            new Identity(aMaster1, ((HasBroker)tx).getBroker());
  -            for (int i = 0; i < 5; i++)
  -            {
  -                DetailFKinPK aDetail = new DetailFKinPK();
  -                aDetail.detailText = "Artikel " + i + " in Produktgruppe 1";
  -                aDetail.masterId = aMaster1.masterId;
  -                aDetail.master = aMaster1;
  -                aMaster1.collDetailFKinPK.add(aDetail);
  -            }
  -            Master aMaster2 = new Master();
  -            aMaster2.masterText = "Master 2";
  -            aMaster2.collDetailFKinPK = new java.util.Vector();
  -            new Identity(aMaster2,((HasBroker)tx).getBroker());
  -            for (int i = 0; i < 5; i++)
  -            {
  -                DetailFKinPK aDetail = new DetailFKinPK();
  -                aDetail.detailText = "Artikel " + i + " in Produktgruppe 1";
  -                aDetail.master = aMaster2;
  -                aDetail.masterId = aMaster2.masterId;
  -                aMaster2.collDetailFKinPK.add(aDetail);
  -            }
  -
  +            Master master_1 = populatedMasterFKinPK(tx, 5, timestamp);
  +            Master master_2 = populatedMasterFKinPK(tx, 5, timestamp);
   
  -            db.makePersistent(aMaster1);
  -            db.makePersistent(aMaster2);
  +            db.makePersistent(master_1);
  +            db.makePersistent(master_2);
               tx.commit();
   
  +            // Check stored objects
  +            OQLQuery query = odmg.newOQLQuery();
  +            query.create("select masters from " + Master.class.getName() + " where masterText
like $1");
  +            query.bind("%" + timestamp);
  +            DList allMasters = (DList) query.execute();
  +            assertEquals("We should found master objects", 2, allMasters.size());
  +            Master lookup_1 = (Master) allMasters.get(0);
  +            Collection col_in = lookup_1.getCollDetailFKinPK();
  +            Collection col_no = lookup_1.getCollDetailFKnoPK();
  +            assertEquals("Should found none " + DetailFKnoPK.class.getName() + " objects",
0, col_no.size());
  +            assertEquals("Should found " + DetailFKinPK.class.getName() + " objects", 5,
col_in.size());
           }
           finally
           {
  @@ -148,35 +132,78 @@
           }
       }
   
  -    public void testDelete() throws Exception
  +    private Master populatedMasterFKnoPK(Transaction tx, int countDetailObjects, long timestamp)
  +            throws Exception
  +    {
  +        Master master = new Master();
  +        master.masterText = "Master_timestamp_" + timestamp;
  +        master.collDetailFKnoPK = new Vector();
  +        new Identity(master, ((HasBroker) tx).getBroker());
  +        for (int i = 0; i < countDetailObjects; i++)
  +        {
  +            DetailFKnoPK aDetail = new DetailFKnoPK();
  +            aDetail.detailText = "DetailFK*no*PK count " + i + ", associate master " +
master.masterId + " timestamp_" + timestamp;
  +            aDetail.master = master;
  +            master.collDetailFKnoPK.add(aDetail);
  +        }
  +        return master;
  +    }
  +
  +    private Master populatedMasterFKinPK(Transaction tx, int countDetailObjects, long timestamp)
  +            throws Exception
       {
  -        // 1. Insert some objects into the database, some of them with
  -        // details in DetailFKinPK, some of them in DetailFKnoPK
  -        testFKinPK();
  -        testFKnoPK();
  +        Master master = new Master();
  +        master.masterText = "Master_timestamp_" + timestamp;
  +        master.collDetailFKinPK = new Vector();
  +        new Identity(master, ((HasBroker) tx).getBroker());
  +        for (int i = 0; i < countDetailObjects; i++)
  +        {
  +            DetailFKinPK aDetail = new DetailFKinPK();
  +            aDetail.detailText = "DetailFKinPK count " + i + ", associate master " + master.masterId
+ " timestamp_" + timestamp;
  +            aDetail.master = master;
  +            master.collDetailFKinPK.add(aDetail);
  +        }
  +        return master;
  +    }
   
  +    public void testDelete() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           db.open(databaseName, Database.OPEN_READ_WRITE);
           try
           {
  -
  -
               // 2. Get a list of all Masters
               Transaction tx = odmg.newTransaction();
               tx.begin();
  +            // 1. Insert some objects into the database, some of them with
  +            // details in DetailFKinPK, some of them in DetailFKnoPK
  +            Master master_1 = populatedMasterFKinPK(tx, 7, timestamp);
  +            Master master_2 = populatedMasterFKinPK(tx, 6, timestamp);
  +            Master master_3 = populatedMasterFKnoPK(tx, 7, timestamp);
  +            Master master_4 = populatedMasterFKnoPK(tx, 6, timestamp);
  +
  +            tx.lock(master_1, Transaction.WRITE);
  +            tx.lock(master_2, Transaction.WRITE);
  +            tx.lock(master_3, Transaction.WRITE);
  +            tx.lock(master_4, Transaction.WRITE);
  +            tx.commit();
   
  +            tx.begin();
               OQLQuery query = odmg.newOQLQuery();
  -
  -            query.create("select allmasters from " + Master.class.getName());
  +            query.create("select masters from " + Master.class.getName() + " where masterText
like $1");
  +            query.bind("%" + timestamp);
               DList allMasters = (DList) query.execute();
   
               // Iterator over all Master objects
  -            java.util.Iterator it = allMasters.iterator();
  +            Iterator it = allMasters.iterator();
  +            int counter = 0;
               while (it.hasNext())
               {
  +                ++counter;
                   Master aMaster = (Master) it.next();
  -                java.util.Iterator it2 = aMaster.collDetailFKinPK.iterator();
  +                Iterator it2 = aMaster.collDetailFKinPK.iterator();
                   while (it2.hasNext())
                       db.deletePersistent(it2.next());
                   it2 = aMaster.collDetailFKnoPK.iterator();
  @@ -184,13 +211,20 @@
                       db.deletePersistent(it2.next());
                   db.deletePersistent(aMaster);
               }
  -
               tx.commit();
  +            assertEquals("Wrong count of Master objects found", 4, counter);
  +
  +            query = odmg.newOQLQuery();
  +            query.create("select masters from " + Master.class.getName() + " where masterText
like $1");
  +            query.bind("%" + timestamp);
  +            allMasters = (DList) query.execute();
  +            assertEquals("Delete of Master objects failed", 0, allMasters.size());
  +
               db.close();
           }
           finally
           {
  -            
  +
           }
       }
   
  @@ -198,12 +232,13 @@
       {
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
  -        final String contractPk = "The Contract";
  +        final String contractPk = "The Contract_" + System.currentTimeMillis();
           Contract obj1 = new Contract();
           Contract obj2 = new Contract();
   
           obj1.setPk(contractPk);
           obj1.setContractValue2(1);
  +
           obj2.setPk(contractPk);
           obj2.setContractValue2(2);
   
  @@ -213,11 +248,20 @@
               // 1. Insert object
               Transaction tx = odmg.newTransaction();
               tx.begin();
  +            /*
  +            arminw:
  +            seems to have problems when within a tx a object
  +            was stored/deleted.
  +            Without obj1 test pass
  +            TODO: fix this
  +            */
               db.makePersistent(obj1);
  -            db.deletePersistent(obj1);
               db.makePersistent(obj2);
  +            db.deletePersistent(obj1);
               tx.commit();
  -            obj2 = getContract(contractPk, odmg);
  +            Collection result = getContract(contractPk, odmg);
  +            assertEquals("We should found exact one contract", 1, result.size());
  +            obj2 = (Contract) result.iterator().next();
               if (obj2 == null)
               {
                   fail("Contract not found");
  @@ -232,7 +276,9 @@
               db.deletePersistent(obj2);
               db.makePersistent(obj1);
               tx.commit();
  -            obj1 = getContract(contractPk, odmg);
  +            result = getContract(contractPk, odmg);
  +            assertEquals("We should found exact one contract", 1, result.size());
  +            obj1 = (Contract) result.iterator().next();
               if (obj1 == null)
               {
                   fail("Contract not found");
  @@ -247,7 +293,8 @@
               db.deletePersistent(obj1);
               tx.commit();
   
  -            if (getContract(contractPk, odmg) != null)
  +            result = getContract(contractPk, odmg);
  +            if (result.size() > 0)
               {
                   fail("Contract was not deleted");
               }
  @@ -258,22 +305,12 @@
           }
       }
   
  -    private Contract getContract(String pk, Implementation odmg)
  +    private Collection getContract(String pk, Implementation odmg)
               throws Exception
       {
           OQLQuery query = odmg.newOQLQuery();
  -        query.create("select c from " + Contract.class.getName() + " where pk=$1");
  +        query.create("select c from " + Contract.class.getName() + " where pk like $1");
           query.bind(pk);
  -
  -        ManageableCollection all = (ManageableCollection) query.execute();
  -        java.util.Iterator it = all.ojbIterator();
  -        if (it.hasNext())
  -        {
  -            return (Contract) it.next();
  -        }
  -        else
  -        {
  -            return null;
  -        }
  +        return (Collection) query.execute();
       }
   }
  
  
  
  1.3       +2 -1      db-ojb/src/test/org/apache/ojb/odmg/PersonImpl.java
  
  Index: PersonImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/PersonImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PersonImpl.java	15 Feb 2003 16:05:26 -0000	1.2
  +++ PersonImpl.java	29 Apr 2003 15:43:26 -0000	1.3
  @@ -10,8 +10,9 @@
   
   import java.util.ArrayList;
   import java.util.Arrays;
  +import java.io.Serializable;
   
  -public class PersonImpl implements Person
  +public class PersonImpl implements Person, Serializable
   {
       // technical attributes only needed for O/R mapping
       private int id;
  
  
  
  1.7       +13 -5     db-ojb/src/test/org/apache/ojb/odmg/MultiDBUsageTest.java
  
  Index: MultiDBUsageTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/MultiDBUsageTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MultiDBUsageTest.java	5 Feb 2003 20:04:40 -0000	1.6
  +++ MultiDBUsageTest.java	29 Apr 2003 15:43:26 -0000	1.7
  @@ -1,10 +1,5 @@
   package org.apache.ojb.odmg;
   
  -import java.util.ArrayList;
  -import java.util.Collection;
  -import java.util.Iterator;
  -import java.util.List;
  -
   import junit.framework.TestCase;
   import org.apache.ojb.broker.FarAwayClass;
   import org.apache.ojb.broker.PBKey;
  @@ -20,6 +15,11 @@
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
  +
   /**
    * Do some rollback tests and check behavior within transactions.
    * CAUTION: This tests works only against the default repository.
  @@ -56,6 +56,14 @@
           {
               db_1.close();
               odmg_1 = null;
  +        }
  +        catch (Exception e)
  +        {
  +            // ignore
  +        }
  +
  +        try
  +        {
               db_2.close();
               odmg_2 = null;
           }
  
  
  
  1.3       +5 -4      db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java
  
  Index: CollectionsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionsTest.java	12 Mar 2003 12:42:18 -0000	1.2
  +++ CollectionsTest.java	29 Apr 2003 15:43:26 -0000	1.3
  @@ -12,6 +12,7 @@
   import java.util.Arrays;
   import java.util.Vector;
   import java.util.List;
  +import java.io.Serializable;
   
   /**
    * Test case handles with collections.
  @@ -160,7 +161,7 @@
       //****************************************************************************
       // inner classes
       //****************************************************************************
  -    public static class Gatherer
  +    public static class Gatherer implements Serializable
       {
           private Integer gatId;
           private String name;
  @@ -235,7 +236,7 @@
           }
       }
   
  -    public static interface CollectibleBIF
  +    public static interface CollectibleBIF extends Serializable
       {
           Integer getColId();
   
  @@ -324,7 +325,7 @@
           }
       }
   
  -    public static interface CollectibleAIF
  +    public static interface CollectibleAIF extends Serializable
       {
           Integer getColId();
   
  
  
  
  1.2       +4 -2      db-ojb/src/test/org/apache/ojb/broker/sequence/SMDatabaseSequence.java
  
  Index: SMDatabaseSequence.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SMDatabaseSequence.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SMDatabaseSequence.java	22 Dec 2002 17:12:22 -0000	1.1
  +++ SMDatabaseSequence.java	29 Apr 2003 15:43:27 -0000	1.2
  @@ -1,11 +1,13 @@
   package org.apache.ojb.broker.sequence;
   
  +import java.io.Serializable;
  +
   /**
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class SMDatabaseSequence
  +public class SMDatabaseSequence implements Serializable
   {
       private Integer seqId;
       private String name;
  
  
  
  1.2       +4 -2      db-ojb/src/test/org/apache/ojb/broker/sequence/SMInterface.java
  
  Index: SMInterface.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SMInterface.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SMInterface.java	28 Oct 2002 15:48:35 -0000	1.1
  +++ SMInterface.java	29 Apr 2003 15:43:27 -0000	1.2
  @@ -1,11 +1,13 @@
   package org.apache.ojb.broker.sequence;
   
  +import java.io.Serializable;
  +
   /**
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public interface SMInterface
  +public interface SMInterface extends Serializable
   {
       public Integer getId();
       public void setId(Integer id);
  
  
  
  1.20      +3 -2      db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java
  
  Index: SequenceManagerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SequenceManagerTest.java	11 Apr 2003 21:59:49 -0000	1.19
  +++ SequenceManagerTest.java	29 Apr 2003 15:43:27 -0000	1.20
  @@ -5,6 +5,7 @@
   import java.util.List;
   import java.util.TreeSet;
   import java.util.Collection;
  +import java.io.Serializable;
   
   import junit.framework.TestCase;
   import org.apache.ojb.broker.*;
  @@ -715,7 +716,7 @@
       // ******************************************************************************
       // inner class
       // ******************************************************************************
  -    public static class AbstractSMObject
  +    public static class AbstractSMObject implements Serializable
       {
           private Integer objectId;
   
  
  
  
  1.2       +3 -2      db-ojb/src/test/org/apache/ojb/performance/PerfArticle.java
  
  Index: PerfArticle.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfArticle.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PerfArticle.java	6 Feb 2003 01:20:54 -0000	1.1
  +++ PerfArticle.java	29 Apr 2003 15:43:27 -0000	1.2
  @@ -1,6 +1,7 @@
   package org.apache.ojb.performance;
   
   import java.math.BigDecimal;
  +import java.io.Serializable;
   
   /**
    * Persistent object interface.
  @@ -8,7 +9,7 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public interface PerfArticle
  +public interface PerfArticle extends Serializable
   {
       public Long getArticleId();
   
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/metadata/RepositoryElementsTest.java
  
  Index: RepositoryElementsTest.java
  ===================================================================
  package org.apache.ojb.broker.metadata;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.lang.reflect.Field;
  import java.util.Arrays;
  
  /**
   * @author Virender Dogra
   * @version Apr 16, 2003 6:14:56 PM
   *
   */
  public class RepositoryElementsTest extends TestCase
  {
  
      /**
       * Constructor for RespositoryElementsTest.
       * @param name
       */
      public RepositoryElementsTest(String name)
      {
          super(name);
      }
  
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run(RepositoryElementsTest.suite());
      }
  
      public static Test suite()
      {
          // Reflection is used here to add all
          // the testXXX() methods to the suite.
          TestSuite suite = new TestSuite(RepositoryElementsTest.class);
          return suite;
  
      }
  
      /*
       * @see TestCase#setUp()
       */
      protected void setUp() throws Exception
      {
          super.setUp();
      }
  
      /*
       * @see TestCase#tearDown()
       */
      protected void tearDown() throws Exception
      {
          super.tearDown();
      }
  
      /**
       * Method testForDuplicateElements.
       *
       * This test is to check that there are no constants with the same values. This
       * method collates the required data and then calls another resuable method to do the
       * final checking
       */
  
      public void testForDuplicateElements() throws Exception
      {
  
          Class c = RepositoryElements.class;
          Field[] fields = c.getDeclaredFields();
  
          //  make a string array of all the field values
          String[] fieldvalues = new String[fields.length];
  
          for (int i = 0; i < fields.length; i++)
          {
              try
              {
                  fieldvalues[i] = c.getDeclaredField(fields[i].getName()).get(fields[i]).toString();
              }
              catch (IllegalAccessException e)
              {
                  System.out.println(e);
                  throw e;
              }
              catch (NoSuchFieldException e)
              {
                  System.out.println("No such field " + fields[i] + " " + e);
                  throw e;
              }
          }
  
          Arrays.sort(fieldvalues);
  
          try
          {
              checkForDuplicateConstant(fieldvalues);
              assertTrue(true);
          }
          catch (DuplicateRepositoryElementsFound e)
          {
              // Constants with similar values found
              fail(
                      e.getMessage()
                      + "\n All the constants values in string sort order that i read are
-> \n"
                      + fieldValuesToString(fieldvalues));
  
          }
  
      }
  
      private String fieldValuesToString(String[] fieldvalues)
      {
          StringBuffer result = new StringBuffer(100);
  
          for (int i = 0; i < fieldvalues.length; i++)
          {
              result.append(fieldvalues[i].toString()).append(',');
          }
  
          return result.substring(0, ((result.length()) - 1));
      }
  
      /**
       * Method checkForDuplicateConstant.: This method checks for duplicate constant
       * values
       * @param fieldvalues
       * @throws DuplicateRepositoryElementsFound
       */
      private void checkForDuplicateConstant(String[] fieldvalues)
              throws DuplicateRepositoryElementsFound
      {
          for (int i = 1; i < fieldvalues.length; i++)
          {
              if (fieldvalues[i - 1].equals(fieldvalues[i]))
              {
                  throw new DuplicateRepositoryElementsFound(fieldvalues[i]);
              }
          }
      }
  
  }
  
  
  /**
   * This exception is for the case when constants with
   * similar values are found in the RepositoryElements class
   */
  
  class DuplicateRepositoryElementsFound extends Exception
  {
  
  
      /* (non-Javadoc)
       * @see java.lang.Throwable#Throwable(java.lang.String)
       */
      public DuplicateRepositoryElementsFound(String errorMsg)
      {
          super("Duplicate value of " + errorMsg + " found");
      }
  }
  
  
  

Mime
View raw message