db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r528056 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb: broker/ odmg/
Date Thu, 12 Apr 2007 17:29:52 GMT
Author: arminw
Date: Thu Apr 12 10:29:50 2007
New Revision: 528056

URL: http://svn.apache.org/viewvc?view=rev&rev=528056
Log:
update tests, modify test classes

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AbstractProductGroup.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Gourmet.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNMapping.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Person.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PolymorphicExtents.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Project.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/ProxyExamples.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/M2NTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AbstractProductGroup.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AbstractProductGroup.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AbstractProductGroup.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AbstractProductGroup.java
Thu Apr 12 10:29:50 2007
@@ -15,8 +15,11 @@
         {
             allArticlesInGroup = new Vector();
         }
-        article.setProductGroup(this);
-        allArticlesInGroup.add(article);
+        if(!allArticlesInGroup.contains(article))
+        {
+            allArticlesInGroup.add(article);
+            article.setProductGroup(this);
+        }
     }
 
     /** return group id*/

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Gourmet.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Gourmet.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Gourmet.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Gourmet.java Thu Apr 12
10:29:50 2007
@@ -4,6 +4,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
+import java.util.ArrayList;
 
 /**
  * class used in testing polymorphic m:n collections
@@ -14,39 +15,44 @@
 {
     int gourmetId;
     String name;
-    List favoriteFood = new Vector();
-	/**
-	 * Constructor for Gourmet.
-	 */
-	public Gourmet()
-	{
-		super();
-	}
+    List favoriteFood;
     
+    /**
+     * Constructor for Gourmet.
+     */
+    public Gourmet()
+    {
+        super();
+    }
+
     public Gourmet(String name)
     {
         this.name = name;
     }
-    
+
     public List getFavoriteFood()
     {
         return favoriteFood;
     }
-    
+
     public void addFavoriteFood(InterfaceFood food)
     {
-        favoriteFood.add(food);
+        if(favoriteFood == null) favoriteFood = new ArrayList();
+        if(!favoriteFood.contains(food))
+        {
+            favoriteFood.add(food);
+        }
+    }
+
+    /**
+     * Returns the gourmetId.
+     * @return int
+     */
+    public int getGourmetId()
+    {
+        return gourmetId;
     }
 
-	/**
-	 * Returns the gourmetId.
-	 * @return int
-	 */
-	public int getGourmetId()
-	{
-		return gourmetId;
-	}
-    
     public String toString()
     {
      StringBuffer text = new StringBuffer("Gourmet: id = " + gourmetId + "\n");
@@ -58,7 +64,7 @@
         text.append(it.next().toString());
         text.append("\n-------\n");
      }
-     return text.toString();   
+     return text.toString();
     }
 
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNMapping.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNMapping.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNMapping.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/MtoNMapping.java Thu Apr
12 10:29:50 2007
@@ -329,20 +329,17 @@
     public void testInsertAndDelete() throws Exception
     {
         int projectsCount = 2;
-        String name = "testInsertAndDelete_" + System.currentTimeMillis();
+        String name = ojbTestMethodIdentifier();
         Person pers = new Person();
         pers.setFirstname(name);
 
-        List projects = new ArrayList();
         for(int i = 0;i<projectsCount;i++)
         {
             Project p = new Project();
             p.setTitle(name);
-            projects.add(p);
+            p.addPersons(pers);
         }
 
-        pers.setProjects(projects);
-
         broker.beginTransaction();
         broker.store(pers);
         broker.commitTransaction();
@@ -351,23 +348,21 @@
         broker.clearCache();
 
         pers = (Person) broker.getObjectByIdentity(oid);
-        projects = new ArrayList(pers.getProjects());
+        List projects = new ArrayList(pers.getProjects());
         assertEquals(projectsCount, projects.size());
         // remove one project
-        projects.remove(0);
+        pers.removeProjects((Project) projects.get(0), false);
 
         // add two new projects
         Project newProj = new Project();
         newProj.setTitle(name);
         newProj.setDescription("New test Project for Person_" + pers.getId());
-        projects.add(newProj);
+        pers.addProjects(newProj);
 
         newProj = new Project();
         newProj.setTitle(name);
         newProj.setDescription("New test Project for Person_" + pers.getId());
-        projects.add(newProj);
-
-        pers.setProjects(projects);
+        pers.addProjects(newProj);
 
         broker.beginTransaction();
         broker.store(pers);

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Person.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Person.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Person.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Person.java Thu Apr 12
10:29:50 2007
@@ -26,6 +26,7 @@
 package org.apache.ojb.broker;
 
 import java.util.Collection;
+import java.util.ArrayList;
 import java.io.Serializable;
 
 public class Person implements Serializable
@@ -96,6 +97,27 @@
     public void setProjects(Collection projects)
     {
         this.projects = projects;
+    }
+
+    public void addProjects(Project project)
+    {
+        if(projects == null) projects = new ArrayList();
+        if(! projects.contains(project))
+        {
+            projects.add(project);
+            project.addPersons(this);
+        }
+    }
+
+    public void removeProjects(Project project, boolean sync)
+    {
+        if(projects != null)
+        {
+            if(projects.remove(project) && sync)
+            {
+                project.removePersons(this, false);
+            }
+        }
     }
 
     public String toString()

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PolymorphicExtents.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PolymorphicExtents.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PolymorphicExtents.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/PolymorphicExtents.java
Thu Apr 12 10:29:50 2007
@@ -23,26 +23,6 @@
 		super(name);
 	}
 
-	protected Article createArticle(String name)
-	{
-		Article a = new Article();
-		a.setArticleName(name);
-		a.setIsSelloutArticle(true);
-		a.setMinimumStock(100);
-		a.setOrderedUnits(17);
-		a.setPrice(0.45);
-		a.setProductGroupId(new Integer(1));
-		a.setStock(234);
-		a.setSupplierId(4);
-		a.setUnit("bottle");
-		ProductGroup tmpPG = new ProductGroup();
-		tmpPG.setId(new Integer(1));
-		Identity pgID = new Identity(tmpPG, broker);
-		ProductGroupProxy pgProxy = new ProductGroupProxy(broker.getPBKey(),pgID);
-		a.setProductGroup(pgProxy);
-		return a;
-	}
-
 	/** TestThreadsNLocks query support for polymorphic extents*/
 	public void testCollectionByQuery()
 	{
@@ -66,11 +46,8 @@
 	 */
 	public void testCollectionRetrieval() throws Exception
 	{
-		ProductGroup example = new ProductGroup();
-        example.setId(new Integer(5));
-
-        ProductGroup group =
-            (ProductGroup) broker.getObjectByQuery(QueryFactory.newQuery(example));
+        Identity oid = broker.serviceIdentity().buildIdentity(ProductGroup.class, new Integer(5));
+        ProductGroup group = (ProductGroup) broker.getObjectByIdentity(oid);
 
         // 7 Articles, 2 Books, 3 Cds
         assertEquals("check size",group.getAllArticles().size(),12);

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Project.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Project.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Project.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/Project.java Thu Apr 12
10:29:50 2007
@@ -26,6 +26,7 @@
 package org.apache.ojb.broker;
 
 import java.util.Collection;
+import java.util.ArrayList;
 import java.io.Serializable;
 
 public class Project implements Serializable
@@ -96,6 +97,27 @@
     public void setPersons(Collection persons)
     {
         this.persons = persons;
+    }
+
+    public void addPersons(Person person)
+    {
+        if(persons == null) persons = new ArrayList();
+        if(! persons.contains(person))
+        {
+            persons.add(person);
+            person.addProjects(this);
+        }
+    }
+
+    public void removePersons(Person person, boolean sync)
+    {
+        if(persons != null)
+        {
+            if(persons.remove(person) && sync)
+            {
+                person.removeProjects(this, false);
+            }
+        }
     }
 
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/ProxyExamples.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/ProxyExamples.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/ProxyExamples.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/ProxyExamples.java Thu
Apr 12 10:29:50 2007
@@ -43,7 +43,7 @@
      */
     public void testProgrammedProxies() throws Exception
     {
-        String name = "testDynamicProxies_" + System.currentTimeMillis();
+        String name = ojbTestMethodIdentifier();
         Vector myArticles = new Vector();
 // In the following code we will generate 10 Proxy-objects.
         ProductGroup pg = new ProductGroup();
@@ -89,9 +89,7 @@
 // in the following code we will touch fields of the ProductGroup references.
 // Now proxies in the AllArticlesInGroup collection need to be materialized
 //System.out.println("now playing with product group no. 2");
-        Object[] pkvals = new Object[1];
-        pkvals[0] = new Integer(2);
-        Identity id = new Identity(ProductGroup.class, ProductGroup.class, pkvals);
+        Identity id = broker.serviceIdentity().buildIdentity(ProductGroup.class, new Integer(2));
         InterfaceProductGroup group2 = null;
         try
         {

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java Thu Apr
12 10:29:50 2007
@@ -1455,14 +1455,6 @@
         query.setPathClass("allArticlesInGroup", CdArticle.class);
         pg = (ProductGroupProxy) broker.getObjectByQuery(query);
 
-        // this test can only succeed in singlevm mode:
-//        if (!BrokerHelper.isRunningInServerMode())
-//        {
-//            assertNotNull(pg);
-//            assertNotNull(cdPg);
-//            assertEquals("ProductGroups should be identical", pg.getRealSubject().toString(),
cdPg.getRealSubject().toString());
-//        }
-
         assertNotNull(pg);
         assertNotNull(cdPg);
         assertEquals("ProductGroups should be identical", pg.getRealSubject().toString(),
cdPg.getRealSubject().toString());

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
Thu Apr 12 10:29:50 2007
@@ -28,7 +28,6 @@
  * 1:1 relation from Executive to Manager
  * 1:n relation from Manager to Executive
  *
- * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  * @version $Id$
  */
 public class InheritanceMultipleTableTest extends ODMGTestCase
@@ -1032,7 +1031,11 @@
             {
                 carrels = new ArrayList();
             }
-            carrels.add(address);
+            if(!carrels.contains(address))
+            {
+                carrels.add(address);
+                address.addEmployee(this);
+            }
         }
 
         public List getCarrels()
@@ -1148,7 +1151,11 @@
             {
                 employees = new ArrayList();
             }
-            employees.add(emp);
+            if(!employees.contains(emp))
+            {
+                employees.add(emp);
+                emp.addCarrel(this);
+            }
         }
 
         public List getEmployees()

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/M2NTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/M2NTest.java?view=diff&rev=528056&r1=528055&r2=528056
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/M2NTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/M2NTest.java Thu Apr 12 10:29:50
2007
@@ -28,7 +28,6 @@
  * <p/>
  * TODO: we need more tests doing delete/update operations on M:N relations
  *
- * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  * @version $Id$
  */
 public class M2NTest extends ODMGTestCase
@@ -965,6 +964,24 @@
             this.movies = movies;
         }
 
+        public void addMovie(Movie movie)
+        {
+            if(movies == null)
+            {
+                movies = new MovieManageableCollectionImpl();
+            }
+            if(!movies.contains(movie))
+            {
+                movies.add(movie);
+                /*
+                 can't use this, because we use two different actor lists in class
+                 movie (actors + actors2). This dosen't make sense, but we use this for
+                 a specific test case
+                */
+                //movie.addActors(this);
+            }
+        }
+
         public Integer getId()
         {
             return id;
@@ -1055,8 +1072,17 @@
             {
                 actors = new ArrayList();
             }
-            if(!actors.contains(actor)) actors.add(actor);
-            else throw new OJBRuntimeException("Can't add same object twice");
+            if(!actors.contains(actor))
+            {
+                actors.add(actor);
+                /*
+                 can't use this, because we use two different actor lists in class
+                 movie (actors + actors2). This dosen't make sense, but we use this for
+                 a specific test case
+                */
+                //actor.addMovie(this);
+            }
+            //else throw new OJBRuntimeException("Can't add same object twice");
         }
 
         public void addActors2(Actor actor)
@@ -1065,8 +1091,17 @@
             {
                 actors2 = new ArrayList();
             }
-            if(!actors2.contains(actor)) actors2.add(actor);
-            else throw new OJBRuntimeException("Can't add same object twice");
+            if(!actors2.contains(actor))
+            {
+                actors2.add(actor);
+                /*
+                 can't use this, because we use two different actor lists in class
+                 movie (actors + actors2). This dosen't make sense, but we use this for
+                 a specific test case
+                */
+                //actor.addMovie(this);
+            }
+            //else throw new OJBRuntimeException("Can't add same object twice");
         }
 
         public Collection getActors()
@@ -1342,7 +1377,7 @@
             {
                 counties = new LinkedList();
             }
-            counties.add(county);
+            if(!counties.contains(county)) counties.add(county);
         }
 
         public void removeCounty(County county)



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


Mime
View raw message