incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r388280 - in /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr: ./ persistence/impl/ testmodel/ testmodel/inheritance/
Date Thu, 23 Mar 2006 21:46:09 GMT
Author: clombart
Date: Thu Mar 23 13:46:08 2006
New Revision: 388280

URL: http://svn.apache.org/viewcvs?rev=388280&view=rev
Log:
* Finalise the unit test for the first inheritance mapping strategy (node type per hierarchy)
* Now starting the implementation of the second one (node type per concrete class). 

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Content.java
      - copied, changed from r383676, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Content.java
Removed:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Content.java
Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/CmsObject.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Document.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=388280&r1=388279&r2=388280&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
Thu Mar 23 13:46:08 2006
@@ -24,9 +24,11 @@
 import java.io.InputStream;
 import java.sql.Timestamp;
 import java.util.Calendar;
+import java.util.Collection;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import javax.jcr.ImportUUIDBehavior;
@@ -69,7 +71,9 @@
 import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
 import org.apache.portals.graffito.jcr.query.QueryManager;
 import org.apache.portals.graffito.jcr.query.impl.QueryManagerImpl;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
 import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor;
 import org.xml.sax.ContentHandler;
 
 /**
@@ -257,7 +261,30 @@
 		return this.queryManager;
 	}
 	
-	public void cleanUpRepisotory() {
+    protected boolean contains(Collection result, String path, Class objectClass)
+    {
+            Iterator iterator = result.iterator();
+            while (iterator.hasNext())
+            {
+                Object  object = (Ancestor) iterator.next();
+                if (ReflectionUtils.getNestedProperty(object, "path").equals(path))
+                {
+                    if (object.getClass() == objectClass)
+                    {
+                       return true;	
+                    }
+                    else
+                    {
+                    	   return false;
+                    }
+ 
+                }
+            }
+            return false;
+    }
+
+	
+	protected  void cleanUpRepisotory() {
 		try 
 		{
 				Session session = this.getSession();		

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java?rev=388280&r1=388279&r2=388280&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java
Thu Mar 23 13:46:08 2006
@@ -44,7 +44,9 @@
         suite.addTestSuite(PersistenceManagerSameNameSiblingTest.class);
         suite.addTestSuite(PersistenceManagerScopeQueryTest.class);
         suite.addTestSuite(PersistenceManagerSimpleQueryTest.class);
+        suite.addTestSuite(PersistenceManagerSimpleInheritanceTest.class);
         suite.addTestSuite(PersistenceManagerTest.class);
+        
         //$JUnit-END$
 
         return suite;

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java?rev=388280&r1=388279&r2=388280&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java
Thu Mar 23 13:46:08 2006
@@ -18,10 +18,6 @@
 
 import java.util.Collection;
 
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Session;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -37,6 +33,7 @@
 import org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant;
 
 /**
  * Test inheritance with node type per hierarchy stategy (with discreminator field)
@@ -117,13 +114,6 @@
 			assertEquals("Ancestor ancestorField is invalid", ancestor.getAncestorField(), "anotherAncestorValue");
 			
 			
-			//---------------------------------------------------------------------------------------------------------
-			// Remove Descendant
-			//---------------------------------------------------------------------------------------------------------
					
-//			persistenceManager.remove("/test");
-//			persistenceManager.save();
-			
-			
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail();
@@ -150,6 +140,21 @@
 		descendant.setPath("/descendant2");
 		persistenceManager.insert(descendant);
 
+		SubDescendant subDescendant = new SubDescendant();
+		subDescendant.setDescendantField("descendantValue2");
+		subDescendant.setAncestorField("ancestorValue2");
+		subDescendant.setPath("/subdescendant");
+		subDescendant.setSubDescendantField("subdescendantvalue");
+		persistenceManager.insert(subDescendant);		
+
+		 subDescendant = new SubDescendant();
+		subDescendant.setDescendantField("descendantValue3");
+		subDescendant.setAncestorField("ancestorValue2");
+		subDescendant.setPath("/subdescendant2");
+		subDescendant.setSubDescendantField("subdescendantvalue1");
+		persistenceManager.insert(subDescendant);		
+		
+		
 		AnotherDescendant anotherDescendant = new AnotherDescendant();
 		anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
 		anotherDescendant.setAncestorField("ancestorValue3");
@@ -168,6 +173,7 @@
 		anotherDescendant.setPath("/anotherdescendant3");
 		persistenceManager.insert(anotherDescendant);
 
+		
 		Atomic a = new Atomic();
 		a.setPath("/atomic");
 		a.setBooleanPrimitive(true);
@@ -183,7 +189,12 @@
 		Query query = queryManager.createQuery(filter);
 
 		Collection result = persistenceManager.getObjects(query);
-		assertEquals("Invalid number of Descendant found", result.size(), 2);
+		assertEquals("Invalid number of Descendant found", result.size(), 4);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
+		
 
 		//---------------------------------------------------------------------------------------------------------

 		// Retrieve AnotherDescendant class
@@ -195,26 +206,40 @@
 
 		result = persistenceManager.getObjects(query);
 		assertEquals("Invalid number of AnotherDescendant found", result.size(),2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1",
AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2",
AnotherDescendant.class));
+
+		//---------------------------------------------------------------------------------------------------------

+		// Retrieve some descendants & subdescendants
+		//---------------------------------------------------------------------------------------------------------
		
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(Descendant.class);		
+		filter.addEqualTo("descendantField","descendantValue2");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
 		
 		//---------------------------------------------------------------------------------------------------------

-		// Retrieve AnotherDescendant class
+		// Retrieve all class
 		//---------------------------------------------------------------------------------------------------------
		
 		queryManager = persistenceManager.getQueryManager();
 		filter = queryManager.createFilter(Ancestor.class);		
 		query = queryManager.createQuery(filter);
 
 		result = persistenceManager.getObjects(query);
-		assertEquals("Invalid ancestor object found", result.size(),5);
-		
-		
-//		persistenceManager.remove("/descendant1");
-//		persistenceManager.remove("/descendant2");
-//		persistenceManager.remove("/anotherdescendant1");
-//		persistenceManager.remove("/anotherdescendant2");
-//		persistenceManager.remove("/anotherdescendant3");
-//		persistenceManager.remove("/atomic");
-//		persistenceManager.save();
-	}
-	
+		assertEquals("Invalid ancestor object found", result.size(),7);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1",
AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2",
AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant3",
AnotherDescendant.class));		
 
+ 
+	}
+	    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/CmsObject.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/CmsObject.java?rev=388280&r1=388279&r2=388280&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/CmsObject.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/CmsObject.java
Thu Mar 23 13:46:08 2006
@@ -15,181 +15,33 @@
  */
 package org.apache.portals.graffito.jcr.testmodel.inheritance;
 
-import java.util.Date;
 
 
 /**
  * CmsObject test
  * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
  * 
  * 
  */
 public class CmsObject
 {
-    public static final long serialVersionUID = 1;
-    
-    protected Long objectId;
-        
-    protected Long parentId;  //parent folder id
-    protected Folder parentFolder;
     
+    protected String path;        
     protected String name;
     
-    protected String description;
-    protected String title;
-    protected Date creationDate;
-    protected Date lastModified;
-    
-    /** 
-     * Special attribute telling OJB the object's concrete type.
-     *  
-     */    
-    protected String ojbConcreteClass; 
-       
-    /**
-     * Constructor
-     */
-    public CmsObject()
-    {
-        ojbConcreteClass = this.getClass().getName();       
-    }
-    
-    
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getPath() {
+		return path;
+	}
+	public void setPath(String path) {
+		this.path = path;
+	}
+        
         
-    /**
-     * @return Returns the parentFolder.
-     */
-    public Folder getParentFolder()
-    {
-        return parentFolder;
-    }
-
-    /**
-     * @param parentFolder The parentFolder to set.
-     */
-    public void setParentFolder(Folder parentFolder)
-    {
-        this.parentFolder = parentFolder;
-    }
-
-    /**
-     * @param parentId The parentId to set.
-     */
-    public void setParentId(Long parentId)
-    {
-        this.parentId = parentId;
-    }
-
-    /**
-     * @return Returns the parentId.
-     */
-    public Long getParentId()
-    {
-        return parentId;
-    }
-       
-    
-    /**
-     * @return Returns the objectId.
-     */
-    public Long getObjectId()
-    {
-        return objectId;
-    }
-
-    /**
-     * @param objectId The objectId to set.
-     */
-    public void setObjectId(Long objectId)
-    {
-        this.objectId = objectId;
-    }
-    
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#getName()
-     */
-    public String getName()
-    {
-        return this.name;
-    }
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#setName(java.lang.String)
-     */
-    public void setName(String name)
-    {
-        this.name = name;
-    }
-
-    
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#getCreationDate()
-     */
-    public Date getCreationDate()
-    {
-        return this.creationDate;
-    }
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#setCreationDate(java.util.Date)
-     */
-    public void setCreationDate(Date creationDate)
-    {
-        this.creationDate = creationDate;
-    }
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#getLastModified()
-     */
-    public Date getLastModified()
-    {
-        return this.lastModified;
-    }
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#setLastModified(java.util.Date)
-     */
-    public void setLastModified(Date lastModified)
-    {
-        this.lastModified = lastModified;
-    }
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#getDescription()
-     */
-    public String getDescription()
-    {
-        return this.description;
-    }
-
-    /* 
-     * @see org.apache.portals.graffito.model.CmsObject#setDescription(java.lang.String)
-     */
-    public void setDescription(String v)
-    {
-        this.description = v;
-    }
-
-    /** 
-     * @see org.apache.portals.graffito.model.CmsObject#getTitle()
-     */
-    public String getTitle()
-    {
-        return this.title;
-    }
-
-    /** 
-     * @see org.apache.portals.graffito.model.CmsObject#setTitle(java.lang.String)
-     */    
-    public void setTitle(String title)
-    {
-        this.title = title;
-    }
-    
-    
- 
-    
-    
 }

Copied: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Content.java
(from r383676, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Content.java)
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Content.java?p2=incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Content.java&p1=incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Content.java&r1=383676&r2=388280&rev=388280&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Content.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Content.java
Thu Mar 23 13:46:08 2006
@@ -13,13 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.graffito.jcr.testmodel;
+package org.apache.portals.graffito.jcr.testmodel.inheritance;
 
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-
-import java.io.UnsupportedEncodingException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Document.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Document.java?rev=388280&r1=388279&r2=388280&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Document.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Document.java
Thu Mar 23 13:46:08 2006
@@ -16,11 +16,8 @@
 package org.apache.portals.graffito.jcr.testmodel.inheritance;
 
 
-import java.util.*;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.jcr.testmodel.Content;
 
 /**
  * CMS VersionnedDocument implementation.



Mime
View raw message