incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r408762 [2/2] - in /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence: beanconverter/ inheritance/ interfaces/ proxy/ query/ version/
Date Mon, 22 May 2006 20:47:36 GMT
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/ProxyTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/ProxyTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/ProxyTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/ProxyTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,199 @@
+/* ========================================================================
+ * 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.proxy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.proxy.Detail;
+import org.apache.portals.graffito.jcr.testmodel.proxy.Main;
+
+/**
+ * Test inheritance with node type per concrete class (without  discreminator field)
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class ProxyTest extends TestBase {
+	private final static Log log = LogFactory.getLog(ProxyTest.class);
+
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public ProxyTest(String testName) throws Exception {
+		super(testName);
+
+	}
+
+	public static Test suite() {
+		// All methods starting with "test" will be executed in the test suite.
+		return new RepositoryLifecycleTestSetup(new TestSuite(
+				ProxyTest.class));
+	}
+
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}
+
+	public void testBeanProxy() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			Detail detail = new Detail();
+			detail.setField("FieldValue");			
+			
+			Detail proxyDetail = new Detail();
+			proxyDetail.setField("ProxyFieldValue");
+			
+			Main main = new Main();
+			main.setPath("/test");
+			main.setDetail(detail);
+			main.setProxyDetail(proxyDetail);
+							
+            persistenceManager.insert(main);
+			persistenceManager.save();
+			
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the main object
+			//---------------------------------------------------------------------------------------------------------						
+			main = (Main) persistenceManager.getObject( "/test");
+			assertNotNull("detail is null", main.getDetail());
+			assertTrue("Invalid detail bean", main.getDetail().getField().equals("FieldValue"));
+
+			assertNotNull("proxydetail is null", main.getProxyDetail());
+			Object proxyObject = main.getProxyDetail();
+			assertTrue("Invalid class specify for the proxy bean", proxyObject  instanceof Detail);
+			assertTrue("Invalid proxy detail bean",proxyDetail .getField().equals("ProxyFieldValue"));
+			
+			Detail nullDetail = main.getNullDetail();
+			assertNull("nulldetail is not  null",nullDetail );
+
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Update  
+			//---------------------------------------------------------------------------------------------------------						
+			 detail = new Detail();
+			detail.setField("AnotherFieldValue");			
+			
+			proxyDetail = new Detail();
+			proxyDetail.setField("AnotherProxyFieldValue");
+			
+			main.setDetail(detail);
+			main.setProxyDetail(proxyDetail);
+			
+			persistenceManager.update(main);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the main object
+			//---------------------------------------------------------------------------------------------------------						
+
+			main = (Main) persistenceManager.getObject( "/test");
+			assertNotNull("detail is null", main.getDetail());
+			assertTrue("Invalid detail bean", main.getDetail().getField().equals("AnotherFieldValue"));
+
+			assertNotNull("proxydetail is null", main.getProxyDetail());
+			proxyObject = main.getProxyDetail();
+			assertTrue("Invalid class specify for the proxy bean", proxyObject  instanceof Detail);
+			assertTrue("Invalid proxy detail bean",proxyDetail .getField().equals("AnotherProxyFieldValue"));
+						
+			assertNull("nulldetail is not  null",main.getNullDetail());
+				
+	
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+		
+	}
+	
+	public void testCollectionProxy() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			ArrayList  details= new ArrayList();
+			for(int i=1; i<=100;i++)
+			{
+				Detail detail = new Detail();
+				detail.setField("field" + i);				
+				details.add(detail);
+			}
+			
+			Main main = new Main();
+			main.setProxyCollection(details);
+			main.setPath("/test");							
+            persistenceManager.insert(main);
+			persistenceManager.save();
+			
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the main object
+			//---------------------------------------------------------------------------------------------------------						
+			main = (Main) persistenceManager.getObject( "/test");
+			assertNotNull("main is null", main);
+
+            Collection result = main.getProxyCollection();
+            assertEquals("Invalide size", result.size(), 100);
+            assertNull("nullcollectionproxy  is not null", main.getNullProxyCollection());
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Update  
+			//---------------------------------------------------------------------------------------------------------
+            
+            Detail detail = new Detail();
+			detail.setField("newFieldValue");			
+			result.add(detail);
+			main.setProxyCollection(result);
+			persistenceManager.update(main);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the main object
+			//---------------------------------------------------------------------------------------------------------						
+			main = (Main) persistenceManager.getObject("/test");
+			assertNotNull("main  is null", main);
+            assertEquals("Invalide size",main.getProxyCollection().size(), 101);
+            assertNull("nullcollectionproxy  is not null", main.getNullProxyCollection());
+            
+	
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+		
+	}
+
+
+
+	    
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/AllTests.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/AllTests.java Mon May 22 13:47:35 2006
@@ -0,0 +1,49 @@
+/* ========================================================================
+ * 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.query;
+
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Package level tests.
+ * 
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class AllTests {
+
+    public static Test suite() {
+        return new RepositoryLifecycleTestSetup(buildSuite());
+    }
+
+    public static Test buildSuite() {
+        TestSuite suite= new TestSuite("Test for org.apache.portals.graffito.jcr.persistence.query");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(PersistenceManagerAtomicQueryTest.class);
+        suite.addTestSuite(PersistenceManagerIteratorQueryTest.class);
+        suite.addTestSuite(PersistenceManagerMultiValueQueryTest.class);
+        suite.addTestSuite(PersistenceManagerScopeQueryTest.class);
+        suite.addTestSuite(PersistenceManagerSimpleQueryTest.class);
+        
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerAtomicQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerAtomicQueryTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerAtomicQueryTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerAtomicQueryTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,243 @@
+/* ========================================================================
+ * 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.query;
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+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;
+
+/**
+ * Test Query on atomic fields
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerAtomicQueryTest extends TestBase
+{
+	private final static Log log = LogFactory.getLog(PersistenceManagerAtomicQueryTest.class);
+	private Date date = new Date();
+	
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerAtomicQueryTest(String testName) throws Exception
+	{
+		super(testName);
+		
+	}
+
+	public static Test suite()
+	{
+		// All methods starting with "test" will be executed in the test suite.
+		return new RepositoryLifecycleTestSetup(new TestSuite(PersistenceManagerAtomicQueryTest.class));
+	}
+	
+    
+    public void tearDown() throws Exception
+    {
+
+		for (int i = 1; i <= 100; i++)
+		{
+			if (getPersistenceManager().objectExists("/test" + i))
+			{
+				getPersistenceManager().remove("/test" + i);
+			}
+
+		}
+        getPersistenceManager().save();
+        super.tearDown();
+    }	
+	
+
+	public void testQueryAtomicFields()
+	{
+
+		try
+		{
+			
+			this.importData(date);
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+			
+			// Test Boolean value 
+			QueryManager queryManager = this.getQueryManager();
+			Filter filter = queryManager.createFilter(Atomic.class);
+			filter.addEqualTo("booleanObject", new Boolean(true));
+			Query query = queryManager.createQuery(filter);
+			
+			long start = System.currentTimeMillis();
+			Collection result = persistenceManager.getObjects(query);
+			System.out.println("getObjects  : " + (System.currentTimeMillis() - start));
+			
+			assertTrue("Invalid number of objects - should be = 50", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);
+			filter.addEqualTo("booleanPrimitive", new Boolean(false));
+			query = queryManager.createQuery(filter);
+
+			start = System.currentTimeMillis();
+			result = persistenceManager.getObjects(query);
+			System.out.println("getObjects 2 : " + (System.currentTimeMillis() - start));
+			assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
+			
+			
+			// Test int value
+			filter = queryManager.createFilter(Atomic.class);
+			filter.addBetween("integerObject", new Integer(0), new Integer(500));
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 5", result.size() == 5);
+			
+			filter = queryManager.createFilter(Atomic.class);
+			filter.addLessOrEqualThan("intPrimitive", new Integer(236));
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 36", result.size() == 36);
+
+			
+			//Test Date & Calendar
+			filter = queryManager.createFilter(Atomic.class);
+			Calendar calendar = Calendar.getInstance();
+			calendar.set(2012, 12, 01);
+			filter.addLessThan("calendar", calendar);
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+
+			filter = queryManager.createFilter(Atomic.class);
+			calendar = Calendar.getInstance();
+			calendar.set(1975, 12, 01);
+			filter.addLessThan("calendar", calendar);
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addEqualTo("date", date);
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addBetween("date", date, new Date());
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+			
+			// Test contains method
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains(".", "JCR");
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains("byteArray", "Graffito");
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains("byteArray", "String");
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
+
+
+			
+		}
+		catch (Exception e)
+		{
+			 e.printStackTrace();
+             fail();
+		}
+
+	}
+
+	private void importData(Date date)
+	{
+		try
+		{
+
+			PersistenceManager persistenceManager = getPersistenceManager();
+			
+			for (int i = 1; i <= 100; i++)
+			{
+				Atomic a = new Atomic();
+				a.setPath("/test" + i);
+				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(a);
+				
+				
+			}
+			persistenceManager.save();
+
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+			fail("Exception occurs during the unit test : " + e);
+		}
+
+	}
+	
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerIteratorQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerIteratorQueryTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerIteratorQueryTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerIteratorQueryTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,221 @@
+/* ========================================================================
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
+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.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+
+/**
+ * Test Object Iterator
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerIteratorQueryTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerIteratorQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerIteratorQueryTest(String testName)  throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(
+                new TestSuite(PersistenceManagerIteratorQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+		this.importData();
+        
+    }
+    
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+            
+        }    
+        getPersistenceManager().save();
+        super.tearDown();
+    }	
+    
+    /**
+     * Test equalTo
+     *
+     */
+    public void testsetScope()
+    {
+
+    	try
+    	{
+    		
+    		  // No scope    		  
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Page.class);        	      
+    	      Query query = queryManager.createQuery(filter);    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      
+    	      long  start = System.currentTimeMillis();
+    	      Iterator iterator = persistenceManager.getObjectIterator(query);
+    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
+    	          	      
+    	      start = System.currentTimeMillis();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));   
+    	      
+    	      start = System.currentTimeMillis();
+    	      iterator = persistenceManager.getObjectIterator(query);
+    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));       	      
+
+    	      
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    
+    private void importData() throws JcrMappingException 
+    {
+        
+    	try
+		{
+    		PersistenceManager persistenceManager = getPersistenceManager();
+    		
+        	if (persistenceManager.objectExists("/test"))
+            {
+                persistenceManager.remove("/test");
+            }
+        	
+			PersistenceManagerImpl persistenceManagerImpl = (PersistenceManagerImpl) persistenceManager;
+			
+			Session session = persistenceManagerImpl.getSession();
+			Node root = session.getRootNode();
+			root.addNode("test");
+			root.addNode("test/node1");
+			root.addNode("test/node2");
+			
+			root.save();
+			
+			Page page = new Page();
+			page.setPath("/test/node1/page1");
+			page.setTitle("Page 1 Title");
+			
+			ArrayList paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 1"));
+			paragraphs.add(new Paragraph("Para 2"));
+			paragraphs.add(new Paragraph("Para 3"));
+			paragraphs.add(new Paragraph("Another Para "));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+						
+			
+			page = new Page();
+			page.setPath("/test/node1/page2");
+			page.setTitle("Page 2 Title");
+			
+			paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 1"));
+			paragraphs.add(new Paragraph("Para 2"));
+			paragraphs.add(new Paragraph("Para 5"));
+			paragraphs.add(new Paragraph("Another Para"));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+			
+			page = new Page();
+			page.setPath("/test/node2/page1");
+			page.setTitle("Page 3 Title");
+			
+			paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 1"));
+			paragraphs.add(new Paragraph("Para 4"));
+			paragraphs.add(new Paragraph("Para 5"));
+			paragraphs.add(new Paragraph("Another Para"));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+
+			page = new Page();
+			page.setPath("/test/node2/page2");
+			page.setTitle("Page 4 Title");
+			
+			paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 6"));
+			paragraphs.add(new Paragraph("Para 7"));
+			paragraphs.add(new Paragraph("Para 8"));
+			paragraphs.add(new Paragraph("Another Para"));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+			
+			persistenceManager.save();
+			
+
+			
+		}
+		catch (RepositoryException e)
+		{
+			
+			e.printStackTrace();
+		}            
+                
+
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerMultiValueQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerMultiValueQueryTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerMultiValueQueryTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerMultiValueQueryTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,174 @@
+/* ========================================================================
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
+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.MultiValue;
+
+/**
+ * Test NTCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerMultiValueQueryTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerMultiValueQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerMultiValueQueryTest(String testName)  throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(
+                new TestSuite(PersistenceManagerMultiValueQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+		this.importData();
+        
+    }
+    
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+            
+        }    
+        getPersistenceManager().save();
+        super.tearDown();
+    }	
+    
+    public void testMultiValueSearch()
+    {
+        try
+        {
+        	
+  	      QueryManager queryManager = this.getQueryManager();
+	      Filter filter = queryManager.createFilter(MultiValue.class);    
+	      filter.addEqualTo("multiValues", "Value1");
+	      Query query = queryManager.createQuery(filter);    	      
+	      PersistenceManager persistenceManager = this.getPersistenceManager();
+	      Collection result = persistenceManager.getObjects(query);
+	      assertTrue("Invalid number of objects - should be = 3", result.size() == 3);            
+          
+  	      queryManager = this.getQueryManager();
+	      filter = queryManager.createFilter(MultiValue.class);    
+	      filter.addEqualTo("multiValues", "Value9");
+	      query = queryManager.createQuery(filter);    	      
+	      persistenceManager = this.getPersistenceManager();
+	      result = persistenceManager.getObjects(query);
+	      assertTrue("Invalid number of objects - should be = 1", result.size() == 1);
+	      MultiValue multiValue = (MultiValue)result.iterator().next();
+	      assertTrue("Incorrect MultiValue found ", multiValue.getName().equals("m3"));
+	      
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+
+    public void importData()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+			PersistenceManagerImpl persistenceManagerImpl = (PersistenceManagerImpl) persistenceManager;
+			
+			Session session = persistenceManagerImpl.getSession();
+			Node root = session.getRootNode();
+			root.addNode("test");
+
+            MultiValue multiValue = new MultiValue();
+            multiValue.setPath("/test/m1");
+            multiValue.setName("m1");
+            ArrayList values = new ArrayList();
+            values.add("Value1");
+            values.add("Value2");
+            values.add("Value3");
+            values.add("Value4");
+            multiValue.setMultiValues(values);
+            persistenceManager.insert(multiValue);
+            
+            multiValue = new MultiValue();
+            multiValue.setPath("/test/m2");
+            multiValue.setName("m2");
+            values = new ArrayList();
+            values.add("Value1");
+            values.add("Value5");
+            values.add("Value6");
+            values.add("Value7");            
+            multiValue.setMultiValues(values);
+            persistenceManager.insert(multiValue);
+            
+            multiValue = new MultiValue();
+            multiValue.setPath("/test/m3");
+            multiValue.setName("m3");
+            values = new ArrayList();
+            values.add("Value1");
+            values.add("Value2");
+            values.add("Value8");
+            values.add("Value9");
+            
+            multiValue.setMultiValues(values);
+            persistenceManager.insert(multiValue);
+                                   
+            persistenceManager.save();
+            
+        }
+        catch(Exception e)
+        {
+        	e.printStackTrace();
+        	fail("Impossible to insert objects");
+        }
+    	
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerScopeQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerScopeQueryTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerScopeQueryTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerScopeQueryTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,242 @@
+/* ========================================================================
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
+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.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+
+/**
+ * Test QueryManagerImpl Query methods
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerScopeQueryTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerScopeQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerScopeQueryTest(String testName)  throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(
+                new TestSuite(PersistenceManagerScopeQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+		this.importData();
+        
+    }
+    
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");            
+        }    
+        getPersistenceManager().save();
+        super.tearDown();
+    }	
+    
+    /**
+     * Test equalTo
+     *
+     */
+    public void testsetScope()
+    {
+
+    	try
+    	{
+    		
+              	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      // Search on subtree (test/node1)
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);    
+    	      filter.setScope("/test/node1//");
+    	      Query query = queryManager.createQuery(filter);    	      
+    	      persistenceManager = this.getPersistenceManager();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 8", result.size() == 8);
+    	      
+    	      
+    	      queryManager = this.getQueryManager();
+    	      filter = queryManager.createFilter(Paragraph.class);    
+    	      filter.setScope("/test//");
+    	      query = queryManager.createQuery(filter);    	      
+    	      persistenceManager = this.getPersistenceManager();
+    	      result = persistenceManager.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 16", result.size() == 16);
+    	      
+    	      // Test on children 
+    	      queryManager = this.getQueryManager();
+    	      filter = queryManager.createFilter(Paragraph.class);    
+    	      filter.setScope("/test/");
+    	      query = queryManager.createQuery(filter);    	      
+    	      persistenceManager = this.getPersistenceManager();
+    	      result = persistenceManager.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
+    	      
+              // Search on scope and properties
+    	      queryManager = this.getQueryManager();
+    	      filter = queryManager.createFilter(Paragraph.class);    
+    	      filter.setScope("/test//");
+    	      filter.addEqualTo("text", "Para 1");
+    	      query = queryManager.createQuery(filter);    	      
+    	      persistenceManager = this.getPersistenceManager();
+    	      result = persistenceManager.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 3", result.size() == 3);
+
+    	      
+    	      queryManager = this.getQueryManager();
+    	      filter = queryManager.createFilter(Paragraph.class);    
+    	      filter.setScope("/test//");
+    	      filter.addContains("text", "another");
+    	      query = queryManager.createQuery(filter);    	      
+    	      persistenceManager = this.getPersistenceManager();
+    	      result = persistenceManager.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 4", result.size() == 4);
+    	      
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    
+    private void importData() throws JcrMappingException 
+    {
+        
+    	try
+		{
+    		PersistenceManager persistenceManager = getPersistenceManager();
+        	
+			PersistenceManagerImpl persistenceManagerImpl = (PersistenceManagerImpl) persistenceManager;
+			
+			Session session = persistenceManagerImpl.getSession();
+			Node root = session.getRootNode();
+			root.addNode("test");
+			root.addNode("test/node1");
+			root.addNode("test/node2");
+			
+			root.save();
+			
+			Page page = new Page();
+			page.setPath("/test/node1/page1");
+			page.setTitle("Page 1 Title");
+			
+			ArrayList paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 1"));
+			paragraphs.add(new Paragraph("Para 2"));
+			paragraphs.add(new Paragraph("Para 3"));
+			paragraphs.add(new Paragraph("Another Para "));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+						
+			
+			page = new Page();
+			page.setPath("/test/node1/page2");
+			page.setTitle("Page 2 Title");
+			
+			paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 1"));
+			paragraphs.add(new Paragraph("Para 2"));
+			paragraphs.add(new Paragraph("Para 5"));
+			paragraphs.add(new Paragraph("Another Para"));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+			
+			page = new Page();
+			page.setPath("/test/node2/page1");
+			page.setTitle("Page 3 Title");
+			
+			paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 1"));
+			paragraphs.add(new Paragraph("Para 4"));
+			paragraphs.add(new Paragraph("Para 5"));
+			paragraphs.add(new Paragraph("Another Para"));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert( page);
+
+			page = new Page();
+			page.setPath("/test/node2/page2");
+			page.setTitle("Page 4 Title");
+			
+			paragraphs = new ArrayList();
+			
+			paragraphs.add(new Paragraph("Para 6"));
+			paragraphs.add(new Paragraph("Para 7"));
+			paragraphs.add(new Paragraph("Para 8"));
+			paragraphs.add(new Paragraph("Another Para"));
+			page.setParagraphs(paragraphs);
+			
+			persistenceManager.insert(page);
+			persistenceManager.save();
+
+			
+		}
+		catch (RepositoryException e)
+		{
+			
+			e.printStackTrace();
+		}            
+                
+
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerSimpleQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerSimpleQueryTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerSimpleQueryTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerSimpleQueryTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,280 @@
+/* ========================================================================
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+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.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+
+/**
+ * Test QueryManagerImpl Query methods
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerSimpleQueryTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerSimpleQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerSimpleQueryTest(String testName)  throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(
+                new TestSuite(PersistenceManagerSimpleQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        importData();
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+    	getPersistenceManager().remove("/test");
+    	getPersistenceManager().save();
+    	
+        super.tearDown();
+    }
+    
+    /**
+     * Test equalTo
+     *
+     */
+    public void testGetObjectEqualsTo()
+    {
+
+    	try
+    	{
+    		    		      		 
+    		  // Build the Query Object
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);
+    	      filter.addEqualTo("text", "Para 1");    	          	     
+    	      
+    	      
+    	      Query query = queryManager.createQuery(filter);
+    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      Paragraph paragraph = (Paragraph) persistenceManager.getObject(query);
+    	      assertNotNull("Object is null", paragraph);    	      
+    	      assertTrue("Invalid paragraph found" , paragraph.getText().equals("Para 1"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }    
+    
+    /**
+     * Test equalTo
+     *
+     */
+    public void testGetObjectsEqualsTo()
+    {
+
+    	try
+    	{
+    		    		      		 
+    		  // Build the Query Object
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);
+    	      filter.addEqualTo("text", "Para 1");    	          	     
+    	      filter.setScope("/test/");
+    	      
+    	      Query query = queryManager.createQuery(filter);
+    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      assertEquals("Invalid number of objects - should be = 1", 1, result.size());
+    	      Paragraph paragraph = (Paragraph) result.iterator().next();
+    	      assertTrue("Invalid paragraph found" , paragraph.getText().equals("Para 1"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    /**
+     * Test the like "like" expression
+     */
+    public void testGetObjectsLike()
+    {
+
+    	try
+    	{
+    		
+    		  // Build the Query Object
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);
+    	      filter.addLike("text", "Para%");    	          	     
+    	      filter.setScope("/test/");
+    	      
+    	      Query query = queryManager.createQuery(filter);
+    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      assertEquals("Invalid number of objects - should be = 3", 3, result.size());
+
+    	      Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
+    	      assertTrue("Invalid paragraph found", paragraphs[0].getText().equals("Para 1"));
+    	      assertTrue("Invalid paragraph found", paragraphs[1].getText().equals("Para 2"));
+    	      assertTrue("Invalid paragraph found", paragraphs[2].getText().equals("Para 3"));
+    	      
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    
+    
+    /**
+     * Build an or expression between 2 filters
+     *
+     */
+    public void testGetObjectsOr()
+    {
+
+    	try
+    	{
+    		
+    		  // Build the Query Object
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter1 = queryManager.createFilter(Paragraph.class);
+    	      filter1.addEqualTo("text", "Para 1");    	     
+    	      filter1.setScope("/test/");
+
+    	      Filter filter2 = queryManager.createFilter(Paragraph.class);
+    	      filter2.addEqualTo("text", "Para 2");    	     
+    	      
+              filter1.addOrFilter(filter2);
+    	      
+    	      Query query = queryManager.createQuery(filter1);
+    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      assertEquals("Invalid number of objects - should be = 2", 2, result.size());
+    	      
+    	      Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
+    	      assertTrue("Invalid paragraph found", paragraphs[0].getText().equals("Para 1"));
+    	      assertTrue("Invalid paragraph found", paragraphs[1].getText().equals("Para 2"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    
+    public void testGetObjectOrderBy()
+    {
+
+    	try
+    	{
+    		
+    		  // Build the Query Object
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);
+    	      filter.addLike("text", "Para%");    	          	     
+    	      filter.setScope("/test/");
+    	      
+    	      Query query = queryManager.createQuery(filter);
+    	      query.addOrderByDescending("text");
+    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      assertEquals("Invalid number of objects - should be = 3", 3, result.size());
+
+    	      Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
+    	      assertTrue("Invalid paragraph found", paragraphs[0].getText().equals("Para 3"));
+    	      assertTrue("Invalid paragraph found", paragraphs[1].getText().equals("Para 2"));
+    	      assertTrue("Invalid paragraph found", paragraphs[2].getText().equals("Para 1"));
+    	      
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    
+    private void importData() throws JcrMappingException 
+    {
+    	PersistenceManager persistenceManager = getPersistenceManager();
+
+        Page page = new Page();
+        page.setPath("/test");
+        page.setTitle("Page Title");
+        
+        ArrayList paragraphs = new ArrayList();
+        
+        paragraphs.add(new Paragraph("Para 1"));
+        paragraphs.add(new Paragraph("Para 2"));
+        paragraphs.add(new Paragraph("Para 3"));
+        paragraphs.add(new Paragraph("Another Para "));
+        page.setParagraphs(paragraphs);
+        
+        persistenceManager.insert(page);  
+        persistenceManager.save();
+                
+
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/AllTests.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/AllTests.java Mon May 22 13:47:35 2006
@@ -0,0 +1,46 @@
+/* ========================================================================
+ * 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.version;
+
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Package level tests.
+ * 
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class AllTests {
+
+    public static Test suite() {
+        return new RepositoryLifecycleTestSetup(buildSuite());
+    }
+
+    public static Test buildSuite() {
+        TestSuite suite= new TestSuite("Test for org.apache.portals.graffito.jcr.persistence.version");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(PersistenceManagerBasicVersionningTest.class);
+       
+        
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/PersistenceManagerBasicVersionningTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/PersistenceManagerBasicVersionningTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/PersistenceManagerBasicVersionningTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/PersistenceManagerBasicVersionningTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,165 @@
+package org.apache.portals.graffito.jcr.persistence.version;
+
+
+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.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+import org.apache.portals.graffito.jcr.version.Version;
+import org.apache.portals.graffito.jcr.version.VersionIterator;
+
+/**
+ * Test Query on atomic fields
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerBasicVersionningTest extends TestBase
+{
+	private final static Log log = LogFactory.getLog(PersistenceManagerBasicVersionningTest.class);
+	private Date date = new Date();
+	
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerBasicVersionningTest(String testName) throws Exception
+	{
+		super(testName);
+		
+	}
+
+	public static Test suite()
+	{
+		// All methods starting with "test" will be executed in the test suite.
+		return new RepositoryLifecycleTestSetup(
+                new TestSuite(PersistenceManagerBasicVersionningTest.class));
+	}
+
+    public void tearDown() throws Exception
+    {
+    	PersistenceManager persistenceManager = getPersistenceManager();
+	    persistenceManager.remove("/page");
+    	persistenceManager.save();
+       
+        super.tearDown();
+    }	
+
+	public void testSimpleVersion()
+	{
+		     PersistenceManager persistenceManager = getPersistenceManager();
+             try
+             {
+            	 
+            	 Page page = new Page();
+            	 page.setPath("/page");
+            	 page.setTitle("Page Title");            	 
+            	 page.addParagraph(new Paragraph("para1"));
+            	 page.addParagraph(new Paragraph("para2"));
+            	 persistenceManager.insert(page);
+            	 persistenceManager.save();
+            	 
+                 
+            	 page.addParagraph(new Paragraph("para3"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update(page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page");
+            	 
+            	 page.addParagraph(new Paragraph("para4"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update(page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page");            	 
+
+            	 VersionIterator versionIterator = persistenceManager.getAllVersions("/page");
+            	 assertNotNull("VersionIterator is null", versionIterator);
+            	 assertTrue("Invalid number of versions found", versionIterator.getSize() == 3);
+            	 
+            	 while (versionIterator.hasNext())
+            	 {
+            		 Version version = (Version) versionIterator.next();
+            		 log.info("version found : " + version.getPath() + " - " +  version.getCreated().getTime());
+            		 
+            	 }
+            	 
+            	 Version baseVersion = persistenceManager.getBaseVersion("/page");
+            	 System.out.println("Base version : " + baseVersion.getName());
+
+            	 Version rootVersion = persistenceManager.getRootVersion("/page");
+            	 System.out.println("Root version : " + rootVersion.getName());
+            	 //this.exportDocument("/home/christophe/export.xml", "/jcr:system/jcr:versionStorage", true, false);
+            	             	
+             //Get the lasted version 
+            	 page = (Page) persistenceManager.getObject( "/page");
+            	 assertNotNull("Last version is nulll", page);
+            	 assertTrue("Invalid number of paragraph found in the last  version", page.getParagraphs().size() == 4);
+
+            	 
+            	 //Get the object matching to the first version 
+            Page  page1 = (Page) persistenceManager.getObject( "/page", "1.0");
+            	 assertNotNull("version 1.0 object is null", page1);
+            	 assertTrue("Invalid number of paragraph found in the root version", page1.getParagraphs().size() == 3);
+
+             }
+             catch(Exception e)
+             {
+            	 e.printStackTrace();
+            	 fail(e.getMessage());
+            	 
+             }
+	}
+
+	
+	public void testVersionLabels()
+	{
+		     PersistenceManager persistenceManager = getPersistenceManager();
+             try
+             {
+            	 
+            	 Page page = new Page();
+            	 page.setPath("/page");
+            	 page.setTitle("Page Title");            	 
+            	 page.addParagraph(new Paragraph("para1"));
+            	 page.addParagraph(new Paragraph("para2"));
+            	 persistenceManager.insert(page);
+            	 persistenceManager.save();
+            	 
+                 
+            	 page.addParagraph(new Paragraph("para3"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update(page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page", new String[] {"A", "B"});
+            	 
+            	 page.addParagraph(new Paragraph("para4"));
+            	 persistenceManager.checkout("/page");
+            	 persistenceManager.update(page);
+            	 persistenceManager.save();
+            	 persistenceManager.checkin("/page", new String[] {"C", "D"});         	 
+
+            	 String[] allLabels = persistenceManager.getAllVersionLabels("/page");
+            	 assertTrue("Incorrect number of labels", allLabels.length == 4);
+
+            	 String[] versionLabels = persistenceManager.getVersionLabels("/page", "1.1");
+            	 assertTrue("Incorrect number of labels", versionLabels.length == 2);
+            	 assertTrue("Incorrect label", versionLabels[0].equals("C") || versionLabels[0].equals("D"));
+            	 assertTrue("Incorrect label", versionLabels[1].equals("C") || versionLabels[0].equals("D"));
+            	
+
+             }
+             catch(Exception e)
+             {
+            	 e.printStackTrace();
+            	 fail(); 
+             }
+	}
+	
+}
\ No newline at end of file



Mime
View raw message