jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r584180 [1/2] - in /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm: ./ manager/query/ manager/uuid/ manager/version/ mapper/ querymanager/ testmodel/uuid/
Date Fri, 12 Oct 2007 15:09:20 GMT
Author: clombart
Date: Fri Oct 12 08:08:13 2007
New Revision: 584180

URL: http://svn.apache.org/viewvc?rev=584180&view=rev
Log:
Last step for the OCM unit tests. From now, we have the same setting for both mapper (xml file & annotations)

Added:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationMultiValueQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationScopeQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationSimpleQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerAtomicQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterIteratorQueryTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerIteratorQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterMultiValueQueryTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerMultiValueQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterScopeQueryTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerScopeQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerSimpleQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AnnotationUuidTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/DigesterUuidTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/ObjectContentManagerUuidTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/version/AnnotationBasicVersionningTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/version/DigesterBasicVersionningTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/version/ObjectContentManagerBasicVersionningTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/mapper/AnnotationMapperImplTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/querymanager/AnnotationQueryManagerTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/querymanager/DigesterQueryManagerTest.java
      - copied, changed from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/querymanager/QueryManagerTest.java
Removed:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerAtomicQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerIteratorQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerMultiValueQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerScopeQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerSimpleQueryTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/ObjectContentManagerUuidTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/version/ObjectContentManagerBasicVersionningTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/querymanager/QueryManagerTest.java
Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AllTests.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AllTests.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/version/AllTests.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/mapper/AllTests.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/mapper/DigesterMapperImplTest.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/querymanager/AllTests.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/testmodel/uuid/A.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/testmodel/uuid/Ancestor.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/testmodel/uuid/B.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/testmodel/uuid/B2.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/testmodel/uuid/Descendant.java

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java?rev=584180&r1=584179&r2=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java Fri Oct 12 08:08:13 2007
@@ -148,7 +148,11 @@
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.NTMain.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.NTDetail.class);
 		
-		
+		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.A.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.B.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.B2.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.Ancestor.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.Descendant.class);
 		Mapper mapper = new AnnotationMapperImpl(classes);
 		ocm = new ObjectContentManagerImpl(session, mapper);
 		

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AllTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AllTests.java?rev=584180&r1=584179&r2=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AllTests.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AllTests.java Fri Oct 12 08:08:13 2007
@@ -36,11 +36,16 @@
     public static Test buildSuite() {
         TestSuite suite= new TestSuite("Test for org.apache.jackrabbit.ocm.manager.query");
         //$JUnit-BEGIN$
-        suite.addTestSuite(ObjectContentManagerAtomicQueryTest.class);
-        suite.addTestSuite(ObjectContentManagerIteratorQueryTest.class);
-        suite.addTestSuite(ObjectContentManagerMultiValueQueryTest.class);
-        suite.addTestSuite(ObjectContentManagerScopeQueryTest.class);
-        suite.addTestSuite(ObjectContentManagerSimpleQueryTest.class);
+        suite.addTestSuite(AnnotationAtomicQueryTest.class);
+        suite.addTestSuite(AnnotationIteratorQueryTest.class);
+        suite.addTestSuite(AnnotationMultiValueQueryTest.class);
+        suite.addTestSuite(AnnotationScopeQueryTest.class);
+        suite.addTestSuite(AnnotationSimpleQueryTest.class);
+        suite.addTestSuite(DigesterAtomicQueryTest.class);
+        suite.addTestSuite(DigesterIteratorQueryTest.class);
+        suite.addTestSuite(DigesterMultiValueQueryTest.class);
+        suite.addTestSuite(DigesterScopeQueryTest.class);
+        suite.addTestSuite(DigesterSimpleQueryTest.class);
         
         //$JUnit-END$
 

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java?rev=584180&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java Fri Oct 12 08:08:13 2007
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.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.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.testmodel.Atomic;
+
+/**
+ * Test Query on atomic fields
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class AnnotationAtomicQueryTest extends AnnotationTestBase
+{
+	private final static Log log = LogFactory.getLog(AnnotationAtomicQueryTest.class);
+	private Date date = new Date();
+	
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public AnnotationAtomicQueryTest(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(AnnotationAtomicQueryTest.class));
+	}
+	
+    
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}	
+	
+
+	public void testQueryAtomicFields()
+	{
+
+		try
+		{
+			
+			this.importData(date);
+			ObjectContentManager ocm = this.getObjectContentManager();
+			
+			// 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 = ocm.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 = ocm.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 = ocm.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 = ocm.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 = ocm.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 = ocm.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 = ocm.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 = ocm.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addGreaterThan("date", date);
+			query = queryManager.createQuery(filter);
+			
+			result = ocm.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
+
+			// Test contains method
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains(".", "JCR");
+			query = queryManager.createQuery(filter);
+			
+			result = ocm.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains("string", "JCR");
+			query = queryManager.createQuery(filter);
+			
+			result = ocm.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains("string", "ocm");
+			query = queryManager.createQuery(filter);
+			
+			result = ocm.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
+		{
+
+			ObjectContentManager ocm = getObjectContentManager();
+			
+			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.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.setString("Test String JCR " + i);
+				     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 the ocm repository".getBytes());
+					 a.setInputStream(new ByteArrayInputStream("Another Stream".getBytes()));
+					 a.setString("Test String " + i);
+				}
+				ocm.insert(a);
+				
+				
+			}
+			ocm.save();
+
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+			fail("Exception occurs during the unit test : " + e);
+		}
+
+	}
+	
+}
\ No newline at end of file

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java?rev=584180&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java Fri Oct 12 08:08:13 2007
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.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.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.testmodel.Page;
+import org.apache.jackrabbit.ocm.testmodel.Paragraph;
+
+
+/**
+ * Test Object Iterator
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class AnnotationIteratorQueryTest extends AnnotationTestBase
+{
+    private final static Log log = LogFactory.getLog(AnnotationIteratorQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public AnnotationIteratorQueryTest(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(AnnotationIteratorQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+		this.importData();
+        
+    }
+    
+    public void tearDown() throws Exception
+    {
+    	cleanUpRepisotory();
+        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);    	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      
+    	      long  start = System.currentTimeMillis();
+    	      Iterator iterator = ocm.getObjectIterator(query);
+    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
+    	          	      
+    	      start = System.currentTimeMillis();
+    	      Collection result = ocm.getObjects(query);
+    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));   
+    	      
+    	      start = System.currentTimeMillis();
+    	      iterator = ocm.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
+		{
+    		ObjectContentManager ocm = getObjectContentManager();
+    		
+        	if (ocm.objectExists("/test"))
+            {
+                ocm.remove("/test");
+            }
+        	
+			ObjectContentManagerImpl ocmImpl = (ObjectContentManagerImpl) ocm;
+			
+			Session session = ocmImpl.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);
+			
+			ocm.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);
+			
+			ocm.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);
+			
+			ocm.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);
+			
+			ocm.insert(page);
+			
+			ocm.save();
+			
+
+			
+		}
+		catch (RepositoryException e)
+		{
+			
+			e.printStackTrace();
+		}            
+                
+
+    }
+}
\ No newline at end of file

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationMultiValueQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationMultiValueQueryTest.java?rev=584180&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationMultiValueQueryTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationMultiValueQueryTest.java Fri Oct 12 08:08:13 2007
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.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.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.testmodel.MultiValue;
+
+/**
+ * Test NTCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class AnnotationMultiValueQueryTest extends AnnotationTestBase
+{
+    private final static Log log = LogFactory.getLog(AnnotationMultiValueQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public AnnotationMultiValueQueryTest(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(AnnotationMultiValueQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+		this.importData();
+        
+    }
+    
+    public void tearDown() throws Exception
+    {
+    	cleanUpRepisotory();
+        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);    	      
+	      ObjectContentManager ocm = this.getObjectContentManager();
+	      Collection result = ocm.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);    	      
+	      ocm = this.getObjectContentManager();
+	      result = ocm.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
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+			ObjectContentManagerImpl ocmImpl = (ObjectContentManagerImpl) ocm;
+			
+			Session session = ocmImpl.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);
+            ocm.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);
+            ocm.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);
+            ocm.insert(multiValue);
+                                   
+            ocm.save();
+            
+        }
+        catch(Exception e)
+        {
+        	e.printStackTrace();
+        	fail("Impossible to insert objects");
+        }
+    	
+    }
+}
\ No newline at end of file

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationScopeQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationScopeQueryTest.java?rev=584180&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationScopeQueryTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationScopeQueryTest.java Fri Oct 12 08:08:13 2007
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.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.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.DigesterTestBase;
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.testmodel.Page;
+import org.apache.jackrabbit.ocm.testmodel.Paragraph;
+
+
+/**
+ * Test QueryManagerImpl Query methods
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class AnnotationScopeQueryTest extends AnnotationTestBase
+{
+    private final static Log log = LogFactory.getLog(AnnotationScopeQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public AnnotationScopeQueryTest(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(AnnotationScopeQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+		this.importData();
+		//this.importDocument("data.xml", "/");
+        
+		
+    }
+    
+    public void tearDown() throws Exception
+    {
+    	cleanUpRepisotory();
+        super.tearDown();
+    }	
+    
+    /**
+     * Test equalTo
+     *
+     */
+    public void testsetScope()
+    {
+
+    	try
+    	{
+    		
+              	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      // Search on subtree (test/node1)
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);    
+    	      filter.setScope("/test/node1//");
+    	      Query query = queryManager.createQuery(filter);    	      
+    	      ocm = this.getObjectContentManager();
+    	      Collection result = ocm.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);    	      
+    	      ocm = this.getObjectContentManager();
+    	      result = ocm.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);    	      
+    	      ocm = this.getObjectContentManager();
+    	      result = ocm.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);    	      
+    	      ocm = this.getObjectContentManager();
+    	      result = ocm.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);    	      
+    	      ocm = this.getObjectContentManager();
+    	      result = ocm.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 4", result.size() == 4);
+    	      
+    	      queryManager = this.getQueryManager();
+    	      filter = queryManager.createFilter(Page.class);    
+    	      filter.setScope("/test/node1/");    	      
+    	      query = queryManager.createQuery(filter);    	      
+    	      ocm = this.getObjectContentManager();
+    	      result = ocm.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 2", result.size() == 2);
+    	      assertTrue ("Invalid object in the collection" , this.contains(result, "/test/node1/page1", Page.class));
+    	      assertTrue ("Invalid object in the collection" , this.contains(result, "/test/node1/page2", Page.class));
+    	      
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    
+    private void importData() throws JcrMappingException 
+    {
+        
+    	try
+		{
+    		ObjectContentManager ocm = getObjectContentManager();
+        	
+			ObjectContentManagerImpl ocmImpl = (ObjectContentManagerImpl) ocm;
+			
+			Session session = ocmImpl.getSession();
+			Node root = session.getRootNode();
+			root.addNode("test");
+			root.addNode("test/node1");
+			root.addNode("test/node2");
+			
+			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);
+			
+			ocm.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);
+			
+			ocm.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);
+			
+			ocm.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);
+			
+			ocm.insert(page);
+			ocm.save();
+			
+			
+		}
+		catch (RepositoryException e)
+		{
+			
+			e.printStackTrace();
+		}            
+                
+
+    }
+}
\ No newline at end of file

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationSimpleQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationSimpleQueryTest.java?rev=584180&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationSimpleQueryTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationSimpleQueryTest.java Fri Oct 12 08:08:13 2007
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.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.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.DigesterTestBase;
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.testmodel.Page;
+import org.apache.jackrabbit.ocm.testmodel.Paragraph;
+
+
+/**
+ * Test QueryManagerImpl Query methods
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class AnnotationSimpleQueryTest extends AnnotationTestBase
+{
+    private final static Log log = LogFactory.getLog(AnnotationSimpleQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public AnnotationSimpleQueryTest(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(AnnotationSimpleQueryTest.class));
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        importData();
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+    	cleanUpRepisotory();
+        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);
+    	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      Paragraph paragraph = (Paragraph) ocm.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);
+    	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      Collection result = ocm.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);
+    	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      Collection result = ocm.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);
+    	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      Collection result = ocm.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");
+    	      
+    	      ObjectContentManager ocm = this.getObjectContentManager();
+    	      Collection result = ocm.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 
+    {
+    	ObjectContentManager ocm = getObjectContentManager();
+
+        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);
+        
+        ocm.insert(page);  
+        ocm.save();
+                
+
+    }
+}
\ No newline at end of file

Copied: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java (from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerAtomicQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java?p2=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java&p1=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerAtomicQueryTest.java&r1=580157&r2=584180&rev=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerAtomicQueryTest.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java Fri Oct 12 08:08:13 2007
@@ -40,16 +40,16 @@
  *
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
  */
-public class ObjectContentManagerAtomicQueryTest extends DigesterTestBase
+public class DigesterAtomicQueryTest extends DigesterTestBase
 {
-	private final static Log log = LogFactory.getLog(ObjectContentManagerAtomicQueryTest.class);
+	private final static Log log = LogFactory.getLog(DigesterAtomicQueryTest.class);
 	private Date date = new Date();
 	
 	/**
 	 * <p>Defines the test case name for junit.</p>
 	 * @param testName The test case name.
 	 */
-	public ObjectContentManagerAtomicQueryTest(String testName) throws Exception
+	public DigesterAtomicQueryTest(String testName) throws Exception
 	{
 		super(testName);
 		
@@ -58,7 +58,7 @@
 	public static Test suite()
 	{
 		// All methods starting with "test" will be executed in the test suite.
-		return new RepositoryLifecycleTestSetup(new TestSuite(ObjectContentManagerAtomicQueryTest.class));
+		return new RepositoryLifecycleTestSetup(new TestSuite(DigesterAtomicQueryTest.class));
 	}
 	
     

Copied: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterIteratorQueryTest.java (from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerIteratorQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterIteratorQueryTest.java?p2=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterIteratorQueryTest.java&p1=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerIteratorQueryTest.java&r1=580157&r2=584180&rev=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerIteratorQueryTest.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterIteratorQueryTest.java Fri Oct 12 08:08:13 2007
@@ -46,15 +46,15 @@
  *
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
  */
-public class ObjectContentManagerIteratorQueryTest extends DigesterTestBase
+public class DigesterIteratorQueryTest extends DigesterTestBase
 {
-    private final static Log log = LogFactory.getLog(ObjectContentManagerIteratorQueryTest.class);
+    private final static Log log = LogFactory.getLog(DigesterIteratorQueryTest.class);
 
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public ObjectContentManagerIteratorQueryTest(String testName)  throws Exception
+    public DigesterIteratorQueryTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -63,7 +63,7 @@
     {
         // All methods starting with "test" will be executed in the test suite.
         return new RepositoryLifecycleTestSetup(
-                new TestSuite(ObjectContentManagerIteratorQueryTest.class));
+                new TestSuite(DigesterIteratorQueryTest.class));
     }
 
     /**
@@ -78,12 +78,7 @@
     
     public void tearDown() throws Exception
     {
-        if (getObjectContentManager().objectExists("/test"))
-        {
-            getObjectContentManager().remove("/test");
-            
-        }    
-        getObjectContentManager().save();
+    	cleanUpRepisotory();
         super.tearDown();
     }	
     

Copied: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterMultiValueQueryTest.java (from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerMultiValueQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterMultiValueQueryTest.java?p2=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterMultiValueQueryTest.java&p1=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerMultiValueQueryTest.java&r1=580157&r2=584180&rev=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerMultiValueQueryTest.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterMultiValueQueryTest.java Fri Oct 12 08:08:13 2007
@@ -41,15 +41,15 @@
  *
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
  */
-public class ObjectContentManagerMultiValueQueryTest extends DigesterTestBase
+public class DigesterMultiValueQueryTest extends DigesterTestBase
 {
-    private final static Log log = LogFactory.getLog(ObjectContentManagerMultiValueQueryTest.class);
+    private final static Log log = LogFactory.getLog(DigesterMultiValueQueryTest.class);
 
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public ObjectContentManagerMultiValueQueryTest(String testName)  throws Exception
+    public DigesterMultiValueQueryTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -58,7 +58,7 @@
     {
         // All methods starting with "test" will be executed in the test suite.
         return new RepositoryLifecycleTestSetup(
-                new TestSuite(ObjectContentManagerMultiValueQueryTest.class));
+                new TestSuite(DigesterMultiValueQueryTest.class));
     }
 
     /**
@@ -73,12 +73,7 @@
     
     public void tearDown() throws Exception
     {
-        if (getObjectContentManager().objectExists("/test"))
-        {
-            getObjectContentManager().remove("/test");
-            
-        }    
-        getObjectContentManager().save();
+    	cleanUpRepisotory();
         super.tearDown();
     }	
     

Copied: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterScopeQueryTest.java (from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerScopeQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterScopeQueryTest.java?p2=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterScopeQueryTest.java&p1=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerScopeQueryTest.java&r1=580157&r2=584180&rev=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerScopeQueryTest.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterScopeQueryTest.java Fri Oct 12 08:08:13 2007
@@ -45,15 +45,15 @@
  *
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
  */
-public class ObjectContentManagerScopeQueryTest extends DigesterTestBase
+public class DigesterScopeQueryTest extends DigesterTestBase
 {
-    private final static Log log = LogFactory.getLog(ObjectContentManagerScopeQueryTest.class);
+    private final static Log log = LogFactory.getLog(DigesterScopeQueryTest.class);
 
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public ObjectContentManagerScopeQueryTest(String testName)  throws Exception
+    public DigesterScopeQueryTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -62,7 +62,7 @@
     {
         // All methods starting with "test" will be executed in the test suite.
         return new RepositoryLifecycleTestSetup(
-                new TestSuite(ObjectContentManagerScopeQueryTest.class));
+                new TestSuite(DigesterScopeQueryTest.class));
     }
 
     /**
@@ -79,11 +79,7 @@
     
     public void tearDown() throws Exception
     {
-        if (getObjectContentManager().objectExists("/test"))
-        {
-            getObjectContentManager().remove("/test");            
-        }    
-        getObjectContentManager().save();
+    	cleanUpRepisotory();
         super.tearDown();
     }	
     

Copied: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java (from r580157, jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerSimpleQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java?p2=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java&p1=jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerSimpleQueryTest.java&r1=580157&r2=584180&rev=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/ObjectContentManagerSimpleQueryTest.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterSimpleQueryTest.java Fri Oct 12 08:08:13 2007
@@ -40,15 +40,15 @@
  *
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
  */
-public class ObjectContentManagerSimpleQueryTest extends DigesterTestBase
+public class DigesterSimpleQueryTest extends DigesterTestBase
 {
-    private final static Log log = LogFactory.getLog(ObjectContentManagerSimpleQueryTest.class);
+    private final static Log log = LogFactory.getLog(DigesterSimpleQueryTest.class);
 
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public ObjectContentManagerSimpleQueryTest(String testName)  throws Exception
+    public DigesterSimpleQueryTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -57,7 +57,7 @@
     {
         // All methods starting with "test" will be executed in the test suite.
         return new RepositoryLifecycleTestSetup(
-                new TestSuite(ObjectContentManagerSimpleQueryTest.class));
+                new TestSuite(DigesterSimpleQueryTest.class));
     }
 
     /**
@@ -74,8 +74,7 @@
      */
     public void tearDown() throws Exception
     {
-    	getObjectContentManager().remove("/test");
-    	getObjectContentManager().save();
+    	cleanUpRepisotory();
     	
         super.tearDown();
     }

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AllTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AllTests.java?rev=584180&r1=584179&r2=584180&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AllTests.java (original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AllTests.java Fri Oct 12 08:08:13 2007
@@ -36,7 +36,8 @@
     public static Test buildSuite() {
         TestSuite suite= new TestSuite("Test for org.apache.jackrabbit.ocm.jcr.manager.uuid");
         //$JUnit-BEGIN$
-        suite.addTestSuite(ObjectContentManagerUuidTest.class);
+        suite.addTestSuite(AnnotationUuidTest.class);
+        suite.addTestSuite(DigesterUuidTest.class);
         
         //$JUnit-END$
 

Added: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AnnotationUuidTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AnnotationUuidTest.java?rev=584180&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AnnotationUuidTest.java (added)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/test/java/org/apache/jackrabbit/ocm/manager/uuid/AnnotationUuidTest.java Fri Oct 12 08:08:13 2007
@@ -0,0 +1,523 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.uuid;
+
+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.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.testmodel.uuid.A;
+import org.apache.jackrabbit.ocm.testmodel.uuid.B;
+import org.apache.jackrabbit.ocm.testmodel.uuid.B2;
+import org.apache.jackrabbit.ocm.testmodel.uuid.Descendant;
+
+
+/**
+ * Test on UUID & references
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class AnnotationUuidTest extends AnnotationTestBase
+{
+    private final static Log log = LogFactory.getLog(AnnotationUuidTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public AnnotationUuidTest(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(AnnotationUuidTest.class));
+    }
+
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+    	cleanUpRepisotory();    	
+        super.tearDown();
+    }
+    
+    /**
+     * 
+     *  Map the jcr uuid into a String attribute
+     *  
+     */
+    public void testUuid()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object A in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setPath("/test");
+            a.setStringData("testdata");
+            ocm.insert(a);
+            ocm.save();           
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (A) ocm.getObject( "/test");
+            assertNotNull("a is null", a);
+            String uuidA = a.getUuid();
+            assertNotNull("uuid is null", uuidA);
+            System.out.println("UUID : " + uuidA);
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            a.setStringData("testdata2");
+            ocm.update(a);
+            ocm.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (A) ocm.getObject("/test");
+            assertNotNull("a is null", a);
+            assertTrue("The uuid has been modified", uuidA.equals(a.getUuid()));
+            
+            // --------------------------------------------------------------------------------
+            // Get the object with the uuid
+            // --------------------------------------------------------------------------------           
+            a = (A) ocm.getObjectByUuid(uuidA);
+            assertNotNull("a is null", a);
+            assertTrue("Invalid object found with the uuid ", "testdata2".equals(a.getStringData()));
+            
+            // --------------------------------------------------------------------------------
+            // Get the object with an invalid uuid
+            // --------------------------------------------------------------------------------           
+            try 
+            {
+                a = (A) ocm.getObjectByUuid("1234");
+                fail("Exception not throw");
+            }
+            catch(Exception e)
+            {
+            	//Throws an exception due to an invalid uuid
+            	System.out.println(e);
+
+            }
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    /**
+     * 
+     * Map a Reference into a String attribute. 
+     * Object B has an attribute containing the object A uuid. 
+     *
+     */
+    public void testFieldReference()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object A in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setPath("/test");
+            a.setStringData("testdata");
+            ocm.insert(a);
+            ocm.save();           
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (A) ocm.getObject( "/test");
+            assertNotNull("a is null", a);
+            String uuidA = a.getUuid();
+            assertNotNull("uuid is null", uuidA);
+            System.out.println("UUID : " + uuidA);
+                        
+            // --------------------------------------------------------------------------------
+            // Create and store an object B in the repository which has a reference to A
+            // --------------------------------------------------------------------------------
+            B b = new B();
+            b.setReference2A(uuidA);
+            b.setPath("/testB");
+            ocm.insert(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve the object B with an invalid reference 
+            // --------------------------------------------------------------------------------            
+            b = (B) ocm.getObject("/testB");
+            assertNotNull("b is null", b);
+            assertTrue("Invalid uuid property", b.getReference2A().equals(uuidA));
+            
+            // --------------------------------------------------------------------------------
+            // Update the object B with an invalid reference 
+            // --------------------------------------------------------------------------------
+            b.setReference2A("1245");
+            try
+            {
+            	ocm.update(b);            	
+            	fail("Exception not throw");
+            }
+            catch(Exception e)
+            {
+            	//Throws an exception due to an invalid uuid
+            	System.out.println("Invalid uuid : " + e);
+            	
+            }
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    /**
+     * 
+     * Map a Reference into a bean attribute. 
+     * Object B has an attribute containing the object A. 
+     * The jcr node matching to the object B contains a reference (the jcr node matching to the object B).   
+     *
+     */
+    public void testBeanReference()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object A in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setPath("/test");
+            a.setStringData("testdata");
+            ocm.insert(a);
+            ocm.save();           
+
+            // --------------------------------------------------------------------------------
+            // Get the object a
+            // --------------------------------------------------------------------------------           
+            a = (A) ocm.getObject( "/test");
+            assertNotNull("a is null", a);
+            String uuidA = a.getUuid();
+            assertNotNull("uuid is null", uuidA);
+            System.out.println("UUID : " + uuidA);
+            
+            // --------------------------------------------------------------------------------
+            // Create and store an object B in the repository which has a reference to A
+            // --------------------------------------------------------------------------------
+            B2 b = new B2();
+            b.setA(a);
+            b.setPath("/testB2");
+            ocm.insert(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve object B
+            // --------------------------------------------------------------------------------
+            b = (B2) ocm.getObject("/testB2");
+            a = b.getA();
+            assertNotNull("a is null", a);
+            assertTrue("Invalid object a", a.getStringData().equals("testdata"));
+            assertTrue("Invalid uuid property", a.getUuid().equals(uuidA));
+
+            // --------------------------------------------------------------------------------
+            // Update object B with an null value
+            // --------------------------------------------------------------------------------
+            b.setA(null);
+            ocm.update(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve object B
+            // --------------------------------------------------------------------------------
+            b = (B2) ocm.getObject("/testB2");
+            a = b.getA();
+            assertNull("a is not null", a);
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    /**
+     * Map a list of uuid  into a collection of String 
+     * The list is defined in a jcr property (Referece type / multi values) 
+     *
+     */
+    public void testCollectionOfUuid()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object A in the repository
+            // --------------------------------------------------------------------------------
+            A a1 = new A();
+            a1.setPath("/a1");
+            a1.setStringData("testdata1");
+            ocm.insert(a1);
+            
+            A a2 = new A();
+            a2.setPath("/a2");
+            a2.setStringData("testdata2");
+            ocm.insert(a2);            
+            ocm.save();           
+
+            // --------------------------------------------------------------------------------
+            // Get the objects
+            // --------------------------------------------------------------------------------           
+            a1 = (A) ocm.getObject( "/a1");
+            assertNotNull("a1 is null", a1);
+            a2 = (A) ocm.getObject( "/a2");
+            assertNotNull("a2 is null", a2);
+            ArrayList references = new ArrayList();
+            references.add(a1.getUuid());
+            references.add(a2.getUuid());
+            
+            // --------------------------------------------------------------------------------
+            // Create and store an object B in the repository which has a collection of A
+            // --------------------------------------------------------------------------------
+            B b = new B();
+            b.setPath("/testB");
+            b.setMultiReferences(references);
+            ocm.insert(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve object B
+            // --------------------------------------------------------------------------------
+            b = (B) ocm.getObject("/testB");
+            Collection allref = b.getMultiReferences();
+            assertNotNull("collection is null", allref);
+            assertTrue("Invalid number of items in the collection", allref.size() == 2);
+
+            // --------------------------------------------------------------------------------
+            // Update object B with invalid uuid
+            // --------------------------------------------------------------------------------
+            allref.add("12345");
+            b.setMultiReferences(allref);
+            try
+            {
+            	ocm.update(b);            	
+            	fail("Exception not throw");
+            }
+            catch(Exception e)
+            {
+            	//Throws an exception due to an invalid uuid
+            	System.out.println("Invalid uuid value in the collection : " + e);
+            	
+            }
+            
+            // --------------------------------------------------------------------------------
+            // Update object B with an null value
+            // --------------------------------------------------------------------------------
+            b.setMultiReferences(null);
+            ocm.update(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve object B
+            // --------------------------------------------------------------------------------
+            b = (B) ocm.getObject("/testB");            
+            assertNull("a is not null", b.getMultiReferences());
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    /**
+     * Map a list of uuid  into a collection
+     * The list is defined in a jcr property (multi values) 
+     *
+     */
+    public void testCollectionOfBeanWithUuid()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object A in the repository
+            // --------------------------------------------------------------------------------
+            A a1 = new A();
+            a1.setPath("/a1");
+            a1.setStringData("testdata1");
+            ocm.insert(a1);
+            
+            A a2 = new A();
+            a2.setPath("/a2");
+            a2.setStringData("testdata2");
+            ocm.insert(a2);            
+            ocm.save();           
+
+            // --------------------------------------------------------------------------------
+            // Get the objects
+            // --------------------------------------------------------------------------------           
+            a1 = (A) ocm.getObject( "/a1");
+            assertNotNull("a1 is null", a1);
+            a2 = (A) ocm.getObject( "/a2");
+            assertNotNull("a2 is null", a2);
+            ArrayList references = new ArrayList();
+            references.add(a1);
+            references.add(a2);
+            
+            // --------------------------------------------------------------------------------
+            // Create and store an object B in the repository which has a collection of A
+            // --------------------------------------------------------------------------------
+            B2 b = new B2();
+            b.setPath("/testB2");
+            b.setMultiReferences(references);
+            ocm.insert(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve object B
+            // --------------------------------------------------------------------------------
+            b = (B2) ocm.getObject("/testB2");
+            Collection allref = b.getMultiReferences();
+            assertNotNull("collection is null", allref);
+            assertTrue("Invalid number of items in the collection", allref.size() == 2);
+            this.contains(allref, "/a1" , A.class);
+            this.contains(allref, "/a2" , A.class);
+
+            // --------------------------------------------------------------------------------
+            // Update object B with an null value
+            // --------------------------------------------------------------------------------
+            b.setMultiReferences(null);
+            ocm.update(b);
+            ocm.save();
+            
+            // --------------------------------------------------------------------------------
+            // Retrieve object B
+            // --------------------------------------------------------------------------------
+            b = (B2) ocm.getObject("/testB2");            
+            assertNull("a is not null", b.getMultiReferences());
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    
+    
+    /**
+     * Test on uuid field defined in an ancestor class
+     *
+     */
+    public void testDescendantAncestor()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object A in the repository
+            // --------------------------------------------------------------------------------
+            Descendant a = new Descendant();
+            a.setPath("/descendant");
+            a.setStringData("testdata");
+            ocm.insert(a);
+            ocm.save();           
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (Descendant) ocm.getObject( "/descendant");
+            assertNotNull("a is null", a);
+            String uuidA = a.getUuid();
+            assertNotNull("uuid is null", uuidA);
+            System.out.println("UUID : " + uuidA);
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            a.setStringData("testdata2");
+            ocm.update(a);
+            ocm.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (Descendant) ocm.getObject("/descendant");
+            assertNotNull("a is null", a);
+            assertTrue("The uuid has been modified", uuidA.equals(a.getUuid()));
+            
+            // --------------------------------------------------------------------------------
+            // Get the object with the uuid
+            // --------------------------------------------------------------------------------           
+            a = (Descendant) ocm.getObjectByUuid(uuidA);
+            assertNotNull("a is null", a);
+            assertTrue("Invalid object found with the uuid ", "testdata2".equals(a.getStringData()));
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+}
\ No newline at end of file



Mime
View raw message