incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r326977 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/persistence/impl/ test-config/ test/org/apache/portals/graffito/jcr/ test/org/apache/portals/graffito/jcr/persistence/atomicconverter/ test/org/apa...
Date Thu, 20 Oct 2005 19:05:16 GMT
Author: clombart
Date: Thu Oct 20 12:04:56 2005
New Revision: 326977

URL: http://svn.apache.org/viewcvs?rev=326977&view=rev
Log:
* Better support for JCR same name sibling
* Review unit test

Added:
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSameNameSiblingTest.java
Removed:
    incubator/graffito/trunk/jcr-mapping/src/test-config/repository-old.xml
Modified:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
    incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImplTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/HashMapTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImplTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerIteratorQueryTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerMultiValueQueryTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerRemoveTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Page.java

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
Thu Oct 20 12:04:56 2005
@@ -29,7 +29,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
@@ -40,7 +39,7 @@
 
 /** 
  * 
- * Default implementation for {@link org.apache.jackrabbit.core.state.PersistenceManager}
+ * Default implementation for {@link org.apache.portals.graffito.jcr.persistence.PersistenceManager}
  * 
  * @author Sandro Boehme
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe</a>
@@ -112,7 +111,6 @@
 	}
 
 	/**
-	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.String,
java.lang.Object)
 	 */
 	public void insert(String path, Object object) 
@@ -121,7 +119,19 @@
 		{
 			if (session.itemExists(path))
 			{
-				throw new PersistenceException("Path already exists : " + path);
+				Item item = session.getItem(path);
+			    if (item.isNode())
+			    {			    	
+			    	if ( ! ((Node)item).getDefinition().allowsSameNameSiblings())
+			    	{
+			    		throw new PersistenceException("Path already exists and it is not supporting the
same name sibling : " + path);
+			    	}
+			    }
+			    else
+			    {			    
+			    	throw new PersistenceException("Path already exists and it is a property : " + path);
+			    }
+				
 			}
 		}
 		catch (RepositoryException e)
@@ -134,7 +144,6 @@
 	}
 
 	/**
-	 * 
 	 * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#update(java.lang.String,
java.lang.Object)
 	 */
 	public void update(String path, Object object) 
@@ -183,25 +192,36 @@
 		try
 		{
 
-			String jcrExpression = this.queryManager.buildJCRExpression(query);						
+			String jcrExpression = this.queryManager.buildJCRExpression(query);
+			log.debug("Remove Objects with expression : " + jcrExpression);
+						
 			javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(jcrExpression,
javax.jcr.query.Query.XPATH);
 			QueryResult queryResult = jcrQuery.execute();
 			NodeIterator nodeIterator = queryResult.getNodes();
-
-			
+            ArrayList nodes = new ArrayList();
+            
 			while (nodeIterator.hasNext())
 			{
 				Node node = nodeIterator.nextNode();
 				log.debug("Remove node : " + node.getPath());
-				node.remove();
+				// it is not possible to remove nodes from an NodeIterator
+				// So, we add the node found in a collection to remove them after
+				nodes.add(node);
 			}
-
+			
+			// Remove all collection nodes
+            for(int i = 0; i < nodes.size(); i++)
+            {
+                Node node = (Node) nodes.get(i);
+                node.remove();
+            }
 			
 		}
 		catch (RepositoryException e)
 		{
-			throw new PersistenceException("Impossible to delte the object collection", e);
+			throw new PersistenceException("Impossible to get the object collection", e);
 		}
+		
 		
 	}
 

Modified: incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml Thu Oct 20 12:04:56
2005
@@ -66,7 +66,7 @@
 	</class-descriptor>
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph">
-		<field-descriptor fieldName="text" jcrName="graffito:text" />
+		<field-descriptor fieldName="text" jcrName="graffito:text"/>
 	</class-descriptor>
 
 
@@ -80,7 +80,7 @@
 	</class-descriptor>
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Element"
jcrNodeType="graffito:element">
-		<field-descriptor fieldName="id" jcrName="graffito:id" />
+		<field-descriptor fieldName="id" jcrName="graffito:id"  />
 		<field-descriptor fieldName="text" jcrName="graffito:text" />
 	</class-descriptor>
 </graffito-jcr>

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
Thu Oct 20 12:04:56 2005
@@ -30,9 +30,11 @@
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Repository;
 import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
 import junit.framework.TestCase;
 
+import org.apache.portals.graffito.jcr.exception.RepositoryException;
 import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.BinaryTypeConverterImpl;
@@ -51,81 +53,62 @@
 import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
 import org.xml.sax.ContentHandler;
 
-/** 
+/**
  * Base class for testcases. Provides priviledged access to the jcr test
  * repository.
- *
+ * 
  * @author <a href="mailto:okiessler@apache.org">Oliver Kiessler</a>
  * @version $Id: Exp $
  */
 public abstract class TestBase extends TestCase
 {
-	/** 
-	 * Jcr session to work with.
-	 */
+
 	protected Session session;
 
 	private PersistenceManager persistenceManager;
 
 	private QueryManager queryManager;
 
+	DigesterMapperImpl mapper;
+
 	private static boolean isInit = false;
 
 	/**
-	 * <p>Defines the test case name for junit.</p>
-	 * @param testName The test case name.
+	 * <p>
+	 * Defines the test case name for junit.
+	 * </p>
+	 * 
+	 * @param testName
+	 *            The test case name.
 	 */
-	public TestBase(String testName) throws Exception
+	public TestBase(String testName)
 	{
 		super(testName);
-		if (!isInit)
-		{
-			RepositoryUtil.registerRepository("repositoryTest", "./src/test-config/repository.xml",
"./target/repository");
-			isInit = true;
-		}
-	}
 
-	/** Setting up the testcase.
-	 * @see junit.framework.TestCase#setUp()
-	 */
-	protected void setUp() throws Exception
-	{
 		try
 		{
-			super.setUp();
-			String[] files = { "./src/test-config/jcrmapping.xml", "./src/test-config/jcrmapping-atomic.xml"
};
-			DigesterMapperImpl mapper = new DigesterMapperImpl(files);
-			Repository repository = RepositoryUtil.getRepository("repositoryTest");
-
-			session = RepositoryUtil.login(repository, "superuser", "superuser");
-
-			// TODO : After Spring integration, move the following code into the assembly script
-
-			HashMap atomicTypeConverters = new HashMap();
-			atomicTypeConverters.put(String.class, new StringTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(InputStream.class, new BinaryTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(long.class, new LongTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Long.class, new LongTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(int.class, new IntTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Integer.class, new IntTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(double.class, new DoubleTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Double.class, new DoubleTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Calendar.class, new CalendarTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(GregorianCalendar.class, new CalendarTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Date.class, new UtilDateTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(byte[].class, new ByteArrayTypeConverterImpl(session.getValueFactory()));
-			atomicTypeConverters.put(Timestamp.class, new TimestampTypeConverterImpl(session.getValueFactory()));
-			queryManager = new QueryManagerImpl(mapper, atomicTypeConverters);
-			persistenceManager = new PersistenceManagerImpl(mapper, atomicTypeConverters, queryManager,
session);
+			if (!isInit)
+			{
+				RepositoryUtil.registerRepository("repositoryTest", "./src/test-config/repository.xml",
"./target/repository");
+				isInit = true;
+			}
+
 		}
 		catch (Exception e)
 		{
 			e.printStackTrace();
-			fail();
+			fail("Impossible to init the repository");
 		}
+	}
 
+	/**
+	 * Setting up the testcase.
+	 * 
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	protected void setUp() throws Exception
+	{
+		super.setUp();
 	}
 
 	/**
@@ -133,21 +116,64 @@
 	 */
 	public void tearDown() throws Exception
 	{
-		getPersistenceManager().logout();
 		super.tearDown();
 	}
 
-	
-	/** Getter for property persistenceManager.
+	/**
+	 * Getter for property persistenceManager.
+	 * 
 	 * @return jcrSession
 	 */
 	public PersistenceManager getPersistenceManager()
 	{
-		return persistenceManager;
+		try
+		{
+			if (persistenceManager == null)
+			{
+				initPersistenceManager();
+			}
+			return persistenceManager;
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	protected void initPersistenceManager() throws UnsupportedRepositoryOperationException,
javax.jcr.RepositoryException
+	{
+		Repository repository = RepositoryUtil.getRepository("repositoryTest");
+		String[] files = { "./src/test-config/jcrmapping.xml", "./src/test-config/jcrmapping-atomic.xml"
};
+		session = RepositoryUtil.login(repository, "superuser", "superuser");		
+		HashMap atomicTypeConverters = new HashMap();
+		atomicTypeConverters.put(String.class, new StringTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(InputStream.class, new BinaryTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(long.class, new LongTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Long.class, new LongTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(int.class, new IntTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Integer.class, new IntTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(double.class, new DoubleTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Double.class, new DoubleTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Boolean.class, new BooleanTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Calendar.class, new CalendarTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(GregorianCalendar.class, new CalendarTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Date.class, new UtilDateTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(byte[].class, new ByteArrayTypeConverterImpl(session.getValueFactory()));
+		atomicTypeConverters.put(Timestamp.class, new TimestampTypeConverterImpl(session.getValueFactory()));
+		
+		mapper = new DigesterMapperImpl(files);						
+		queryManager = new QueryManagerImpl(mapper, atomicTypeConverters);
+		persistenceManager = new PersistenceManagerImpl(mapper, atomicTypeConverters, queryManager,
session);
+		
 	}
 
-	/** Setter for property jcrSession.
-	 * @param persistenceManager The persistence manager 
+	/**
+	 * Setter for property jcrSession.
+	 * 
+	 * @param persistenceManager
+	 *            The persistence manager
 	 */
 	public void setPersistenceManager(PersistenceManager persistenceManager)
 	{

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
Thu Oct 20 12:04:56 2005
@@ -54,13 +54,6 @@
         return new TestSuite(AtomicTest.class);
     }
 
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
 
     /**
      * @see junit.framework.TestCase#tearDown()
@@ -81,7 +74,7 @@
         try
         {
         	PersistenceManager persistenceManager = getPersistenceManager();
-
+        	
             // --------------------------------------------------------------------------------
             // Create and store an object graph in the repository
             // --------------------------------------------------------------------------------

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
Thu Oct 20 12:04:56 2005
@@ -17,15 +17,9 @@
 package org.apache.portals.graffito.jcr.persistence.atomicconverter;
 
 import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Collection;
 import java.util.Date;
 
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.Session;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -33,11 +27,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.portals.graffito.jcr.TestBase;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
-import org.apache.portals.graffito.jcr.testmodel.A;
 import org.apache.portals.graffito.jcr.testmodel.Atomic;
-import org.apache.portals.graffito.jcr.testmodel.B;
-import org.apache.portals.graffito.jcr.testmodel.C;
-import org.apache.portals.graffito.jcr.testmodel.Folder;
 
 /**
  * Test Atomic perisstence fields
@@ -52,7 +42,7 @@
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public NullAtomicTest(String testName)  throws Exception
+    public NullAtomicTest(String testName)
     {
         super(testName);
     }
@@ -63,13 +53,6 @@
         return new TestSuite(NullAtomicTest.class);
     }
     
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
 
     /**
      * @see junit.framework.TestCase#tearDown()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImplTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImplTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImplTest.java
Thu Oct 20 12:04:56 2005
@@ -53,14 +53,6 @@
         return new TestSuite(DefaultCollectionConverterImplTest.class);
     }
 
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
-
     
     /**
      * @see junit.framework.TestCase#tearDown()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/HashMapTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/HashMapTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/HashMapTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/HashMapTest.java
Thu Oct 20 12:04:56 2005
@@ -55,14 +55,6 @@
         return new TestSuite(HashMapTest.class);
     }
 
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
-
     
     /**
      * @see junit.framework.TestCase#tearDown()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImplTest.java
Thu Oct 20 12:04:56 2005
@@ -56,14 +56,6 @@
         return new TestSuite(MultiValueCollectionConverterImplTest.class);
     }
 
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
-
     
     /**
      * @see junit.framework.TestCase#tearDown()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImplTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImplTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImplTest.java
Thu Oct 20 12:04:56 2005
@@ -55,14 +55,6 @@
         return new TestSuite(NTCollectionConverterImplTest.class);
     }
     
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
-
     
     /**
      * @see junit.framework.TestCase#tearDown()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
Thu Oct 20 12:04:56 2005
@@ -60,15 +60,6 @@
 		return new TestSuite(PersistenceManagerAtomicQueryTest.class);
 	}
 	
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-		this.importData(date);
-        
-    }
     
     public void tearDown() throws Exception
     {
@@ -81,7 +72,7 @@
 			}
 
 		}
-    
+        getPersistenceManager().save();
         super.tearDown();
     }	
 	
@@ -92,6 +83,7 @@
 		try
 		{
 			
+			this.importData(date);
 			PersistenceManager persistenceManager = this.getPersistenceManager();
 			
 			// Test Boolean value 
@@ -204,13 +196,6 @@
 		{
 
 			PersistenceManager persistenceManager = getPersistenceManager();
-			
-			if (persistenceManager.objectExists("/test"))
-			{
-				persistenceManager.remove("/test");
-			}
-
-			
 			
 			for (int i = 1; i <= 100; i++)
 			{

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerIteratorQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerIteratorQueryTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerIteratorQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerIteratorQueryTest.java
Thu Oct 20 12:04:56 2005
@@ -78,9 +78,9 @@
         if (getPersistenceManager().objectExists("/test"))
         {
             getPersistenceManager().remove("/test");
-            getPersistenceManager().save();
+            
         }    
-        
+        getPersistenceManager().save();
         super.tearDown();
     }	
     

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerMultiValueQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerMultiValueQueryTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerMultiValueQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerMultiValueQueryTest.java
Thu Oct 20 12:04:56 2005
@@ -73,9 +73,9 @@
         if (getPersistenceManager().objectExists("/test"))
         {
             getPersistenceManager().remove("/test");
-            getPersistenceManager().save();
+            
         }    
-        
+        getPersistenceManager().save();
         super.tearDown();
     }	
     

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerRemoveTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerRemoveTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerRemoveTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerRemoveTest.java
Thu Oct 20 12:04:56 2005
@@ -81,6 +81,7 @@
 			}
 
 		}
+		getPersistenceManager().save();
 
 		super.tearDown();
 	}
@@ -102,6 +103,7 @@
 			filter.addEqualTo("booleanObject" , new Boolean(false));
 			Query query = queryManager.createQuery(filter);
 			persistenceManager.remove(query);
+			persistenceManager.save();
 
 			filter = queryManager.createFilter(Atomic.class);
 			filter.setScope("//");

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSameNameSiblingTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSameNameSiblingTest.java?rev=326977&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSameNameSiblingTest.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSameNameSiblingTest.java
Thu Oct 20 12:04:56 2005
@@ -0,0 +1,203 @@
+/* ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================================
+ */
+package org.apache.portals.graffito.jcr.persistence.impl;
+
+import java.io.ByteArrayInputStream;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+import org.apache.portals.graffito.jcr.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+/**
+ * Test Query on atomic fields
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerSameNameSiblingTest extends TestBase
+{
+	private final static Log log = LogFactory.getLog(PersistenceManagerSameNameSiblingTest.class);
+	private Date date = new Date();
+	
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerSameNameSiblingTest(String testName) throws Exception
+	{
+		super(testName);
+		
+	}
+
+	public static Test suite()
+	{
+		// All methods starting with "test" will be executed in the test suite.
+		return new TestSuite(PersistenceManagerSameNameSiblingTest.class);
+	}
+
+
+	public void testSameNameSiblings()
+	{
+
+		try
+		{
+			this.importData(date);
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+				
+			// Query all objects 
+			QueryManager queryManager = this.getQueryManager();
+			Filter filter = queryManager.createFilter(Atomic.class);	
+			filter.setScope("/");
+			Query query = queryManager.createQuery(filter);
+			Collection result = persistenceManager.getObjects(query);
+            assertTrue("Incorrect number of objects found", result.size() == 10);
+                         
+            // Get objects
+            Atomic atomic = (Atomic) persistenceManager.getObject(Atomic.class, "/test[2]");
+            assertNotNull("Object /test[2] not found", atomic);
+            
+            atomic = (Atomic) persistenceManager.getObject(Atomic.class, "/test[10]");
+            assertNotNull("Object /test[2] not found", atomic);            
+            
+            // Update the object 
+            atomic.setString("Modified Test String 10");
+            persistenceManager.update("/test[10]", atomic);
+            persistenceManager.save();
+
+            // Query on the attribute "string"
+            queryManager = this.getQueryManager();
+			filter = queryManager.createFilter(Atomic.class);	
+			filter.addLike("string", "Modified%");			
+			query = queryManager.createQuery(filter);
+			result = persistenceManager.getObjects(query);
+			assertTrue("Incorrect number of objects found", result.size() == 1);
+            
+			atomic = (Atomic) persistenceManager.getObject(query);
+			assertNotNull("Object not found", atomic);
+			assertTrue("Incorrect Object", atomic.getString().equals("Modified Test String 10"));
  
+			
+            // Delete all objects
+            queryManager = this.getQueryManager();
+			filter = queryManager.createFilter(Atomic.class);	
+			filter.setScope("/");
+			query = queryManager.createQuery(filter) ;           
+            persistenceManager.remove(query);
+            persistenceManager.save();
+
+			result = persistenceManager.getObjects(query);
+            assertTrue("Incorrect number of objects found", result.size() == 0);
+            
+            
+		}
+		catch (Exception e)
+		{
+			 e.printStackTrace();
+             fail();
+		}
+
+	}
+
+	public void testUnsupportedSameNameSiblings()
+	{
+		     PersistenceManager persistenceManager = getPersistenceManager();
+             try
+             {
+            	 
+            	 Page page = new Page();
+            	 page.setTitle("Page Title");            	 
+            	 persistenceManager.insert("/page", page);
+            	 persistenceManager.save();
+            	 
+            	 Paragraph p1 = new Paragraph("para1");
+            	 persistenceManager.insert("/page/paragraph", p1);
+            	 Paragraph p2 = new Paragraph("para1");
+            	 persistenceManager.insert("/page/paragraph", p2);
+                 fail();            	 
+            	 
+             }
+             catch(Exception e)
+             {
+    		            	 persistenceManager.remove("/page");
+            	 persistenceManager.save();
+             }
+	}
+	
+	
+	private void importData(Date date)
+	{
+		try
+		{
+
+			PersistenceManager persistenceManager = getPersistenceManager();
+			
+			
+			for (int i = 1; i <= 10; i++)
+			{
+				Atomic a = new Atomic();
+				a.setBooleanObject(new Boolean(i%2==0));
+				a.setBooleanPrimitive(true);
+				a.setIntegerObject(new Integer(100 * i));
+				a.setIntPrimitive(200 + i);
+				a.setString("Test String " + i);
+				a.setDate(date);
+				Calendar calendar = Calendar.getInstance();
+				calendar.set(1976, 4, 20, 15, 40);
+				a.setCalendar(calendar);
+				a.setDoubleObject(new Double(2.12 + i));
+				a.setDoublePrimitive(1.23 + i);
+				long now = System.currentTimeMillis();
+				a.setTimestamp(new Timestamp(now));
+				if ((i % 2) == 0)
+				{
+				     a.setByteArray("This is small object stored in a JCR repository".getBytes());
+				     a.setInputStream(new ByteArrayInputStream("Test inputstream".getBytes()));
+				}
+				else
+				{
+					 a.setByteArray("This is small object stored in a Graffito repository".getBytes());
+					 a.setInputStream(new ByteArrayInputStream("Another Stream".getBytes()));
+				}
+				persistenceManager.insert("/test", a);
+				
+				
+			}
+			persistenceManager.save();
+
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+			fail("Exception occurs during the unit test : " + e);
+		}
+
+	}
+	
+}
\ No newline at end of file

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerScopeQueryTest.java
Thu Oct 20 12:04:56 2005
@@ -76,10 +76,9 @@
     {
         if (getPersistenceManager().objectExists("/test"))
         {
-            getPersistenceManager().remove("/test");
-            getPersistenceManager().save();
+            getPersistenceManager().remove("/test");            
         }    
-        
+        getPersistenceManager().save();
         super.tearDown();
     }	
     

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
Thu Oct 20 12:04:56 2005
@@ -73,6 +73,8 @@
     public void tearDown() throws Exception
     {
     	getPersistenceManager().remove("/test");
+    	getPersistenceManager().save();
+    	
         super.tearDown();
     }
     

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
Thu Oct 20 12:04:56 2005
@@ -60,13 +60,6 @@
         return new TestSuite(PersistenceManagerTest.class);
     }
 
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-    }
 
     /**
      * @see junit.framework.TestCase#tearDown()
@@ -74,6 +67,7 @@
     public void tearDown() throws Exception
     {
     	getPersistenceManager().remove("/test");
+    	getPersistenceManager().save();
         super.tearDown();
     }
     

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/query/impl/QueryManagerTest.java
Thu Oct 20 12:04:56 2005
@@ -16,21 +16,16 @@
  */
 package org.apache.portals.graffito.jcr.query.impl;
 
-import java.util.ArrayList;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.portals.graffito.jcr.TestBase;
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
 import org.apache.portals.graffito.jcr.query.Filter;
 import org.apache.portals.graffito.jcr.query.Query;
 import org.apache.portals.graffito.jcr.query.QueryManager;
 import org.apache.portals.graffito.jcr.testmodel.C;
-import org.apache.portals.graffito.jcr.testmodel.Page;
-import org.apache.portals.graffito.jcr.testmodel.Paragraph;
 
 
 /**
@@ -49,6 +44,7 @@
     public QueryManagerTest(String testName)  throws Exception
     {
         super(testName);
+        initPersistenceManager();
     }
 
     public static Test suite()

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Page.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Page.java?rev=326977&r1=326976&r2=326977&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Page.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Page.java
Thu Oct 20 12:04:56 2005
@@ -16,6 +16,7 @@
 
 package org.apache.portals.graffito.jcr.testmodel;
 
+import java.util.ArrayList;
 import java.util.Collection;
 
 /** 
@@ -56,6 +57,17 @@
     {
         this.title = title;
     }
+    
+    public void addParagraph(Paragraph paragraph)
+    {
+    	if (paragraphs == null)
+    	{
+    		paragraphs = new ArrayList();
+    	}
+    	
+    	paragraphs.add(paragraph);
+    }
+    
     
     
 }



Mime
View raw message