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 [1/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
Author: clombart
Date: Mon May 22 13:47:35 2006
New Revision: 408762

URL: http://svn.apache.org/viewvc?rev=408762&view=rev
Log:
Reorganise the unit tests

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceConcreteClassTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceConcreteClassTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceHierarchyTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/ProxyTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerAtomicQueryTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerIteratorQueryTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerMultiValueQueryTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerScopeQueryTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/query/PersistenceManagerSimpleQueryTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/version/AllTests.java
    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/beanconverter/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/AllTests.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/AllTests.java Mon May 22 13:47:35 2006
@@ -0,0 +1,44 @@
+/* ========================================================================
+ * 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.beanconverter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+
+
+/**
+ * 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.beanconverter");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(BeanDescriptorTest.class);
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2000-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.beanconverter;
+
+
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
+import org.apache.portals.graffito.jcr.testmodel.B;
+import org.apache.portals.graffito.jcr.testmodel.D;
+import org.apache.portals.graffito.jcr.testmodel.DFull;
+import org.apache.portals.graffito.jcr.testmodel.E;
+
+/**
+ * ObjectConverter test for bean-descriptor with inner bean inlined and inner bean with
+ * custom converter.
+ * 
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class BeanDescriptorTest extends TestBase {
+    private ObjectConverter objectConverter;
+    
+    public BeanDescriptorTest(String testname) {
+        super(testname);
+    }
+
+    public static Test suite() {
+
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(new TestSuite(BeanDescriptorTest.class));
+    }
+    
+    
+    /**
+     * @see org.apache.portals.graffito.jcr.TestBase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.objectConverter = new ObjectConverterImpl(this.mapper, this.converterProvider);
+
+        clean();
+    }
+
+    
+    /**
+     * @see org.apache.portals.graffito.jcr.TestBase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        clean();
+        super.tearDown();
+    }
+
+    private void clean() throws Exception {
+        if(getSession().itemExists("/someD")) {
+            getSession().getItem("/someD").remove();
+            getSession().save();
+        }
+    }
+    
+    public void testInlined() throws Exception {
+        System.out.println("inlined");
+        
+        B expB = new B();
+        expB.setB1("b1value");
+        expB.setB2("b2value");
+        D expD = new D();
+        expD.setPath("/someD");
+        expD.setD1("d1value");
+        expD.setB1(expB);
+        
+       persistenceManager.insert( expD);
+       persistenceManager.save();
+        
+        D actD = (D) persistenceManager.getObject( "/someD");
+        
+        assertEquals(expD.getD1(), actD.getD1());
+        assertEquals(expB.getB1(), actD.getB1().getB1());
+        assertEquals(expB.getB2(), actD.getB1().getB2());
+        
+        DFull actDFull = (DFull) persistenceManager.getObject( DFull.class,  "/someD");
+        
+        assertEquals(expD.getD1(), actDFull.getD1());
+        assertEquals(expB.getB1(), actDFull.getB1());
+        assertEquals(expB.getB2(), actDFull.getB2());
+        
+        expB.setB1("updatedvalue1");
+        
+        persistenceManager.update( expD);
+        getSession().save();
+        
+        actD = (D) persistenceManager.getObject( "/someD");
+        
+        assertEquals(expD.getD1(), actD.getD1());
+        assertEquals(expB.getB1(), actD.getB1().getB1());
+        assertEquals(expB.getB2(), actD.getB1().getB2());
+        
+        actDFull = (DFull) persistenceManager.getObject( DFull.class,  "/someD");
+        
+        assertEquals(expD.getD1(), actDFull.getD1());
+        assertEquals(expB.getB1(), actDFull.getB1());
+        assertEquals(expB.getB2(), actDFull.getB2());
+        
+            
+        expD.setB1(null);
+        persistenceManager.update( expD);
+        getSession().save();
+        
+        actD = (D) persistenceManager.getObject(  "/someD");
+        
+        assertEquals(expD.getD1(), actD.getD1());
+        assertNull("b1 was not  removed", actD.getB1());
+        
+        actDFull = (DFull) persistenceManager.getObject( DFull.class,  "/someD");
+        
+        assertEquals(expD.getD1(), actDFull.getD1());
+        assertNull("b1 was not  removed", actDFull.getB1());
+        assertNull("b2 wan not remove", actDFull.getB2());
+
+    }
+    
+    
+    public void testBeanDescriptorConverter() throws Exception 
+    {
+        
+        B expB = new B();
+        expB.setB1("b1value");
+        expB.setB2("b2value");
+        E expE = new E();
+        expE.setPath("/someD");
+        expE.setD1("d1value");
+        expE.setB1(expB);
+        
+        
+        persistenceManager.insert( expE);
+        persistenceManager.save();
+       
+        E actE = (E) persistenceManager.getObject( "/someD");
+       
+        assertEquals(expE.getD1(), actE.getD1());
+        
+        expE.setD1("updatedvalueD1");
+        expB.setB1("updatedvalue1");
+        
+        persistenceManager.update( expE);
+        persistenceManager.save();
+               
+        actE = (E) persistenceManager.getObject(  "/someD");
+        
+        assertEquals(expE.getD1(), actE.getD1());
+                        
+        expE.setB1(null);
+        persistenceManager.update( expE);
+        persistenceManager.save();
+        
+        actE = (E) persistenceManager.getObject(  "/someD");
+        
+        assertEquals(expE.getD1(), actE.getD1());        
+        
+   
+        List messages = FakeBeanConverter.getLog();
+        assertEquals(6, messages.size());
+        assertEquals("insert at path /someD", messages.get(0));
+        assertEquals("get from path /someD", messages.get(1));
+        assertEquals("update at path /someD", messages.get(2));
+        assertEquals("get from path /someD", messages.get(3));
+        assertEquals("remove from path /someD", messages.get(4));
+        assertEquals("get from path /someD", messages.get(5));
+
+    }
+    
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java Mon May 22 13:47:35 2006
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2000-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.beanconverter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.AbstractBeanConverterImpl;
+import org.apache.portals.graffito.jcr.testmodel.B;
+
+public class FakeBeanConverter extends AbstractBeanConverterImpl {
+
+    private static  List log = new ArrayList();
+    
+    public FakeBeanConverter(ObjectConverter objectConverter) {
+		super(objectConverter);
+		 
+		 
+	}
+
+	public static List getLog() {
+        return log;
+    }
+        
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#insert(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Object)
+     */
+    public void insert(Session session, Node parentNode, BeanDescriptor descriptor, Object object) throws PersistenceException {
+        try {
+            log.add("insert at path " + parentNode.getPath());
+            
+        }
+        catch(RepositoryException re) {
+            throw new PersistenceException(re);
+        }
+    } 
+
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#update(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Object)
+     */
+    public void update(Session session, Node parentNode, BeanDescriptor descriptor, Object object) throws PersistenceException {
+        try {
+            log.add("update at path " + parentNode.getPath());
+        }
+        catch(RepositoryException re) {
+            throw new PersistenceException(re);
+        }
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#getObject(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Class)
+     */
+    public Object getObject(Session session, Node parentNode, BeanDescriptor descriptor, Class beanClass) throws PersistenceException {
+        try {
+            log.add("get from path " + parentNode.getPath());
+        }
+        catch(RepositoryException re) {
+            throw new PersistenceException(re);
+        }
+        // The B object is not important for the unit test. 
+        // The unit test checks only the log generated by this converter
+        return new B(); 
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#remove(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String)
+     */
+    public void remove(Session session, Node parentNode, BeanDescriptor descriptor) throws PersistenceException {
+        try {
+            log.add("remove from path " + parentNode.getPath());
+        }
+        catch(RepositoryException re) {
+            throw new PersistenceException(re);
+        }
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/AllTests.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/AllTests.java Mon May 22 13:47:35 2006
@@ -0,0 +1,45 @@
+/* ========================================================================
+ * 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.inheritance;
+
+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.inheritance");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(PersistenceManagerInheritanceConcreteClassTest.class);
+        suite.addTestSuite(PersistenceManagerInheritanceHierarchyTest.class);        
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceConcreteClassTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceConcreteClassTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceConcreteClassTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceConcreteClassTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,342 @@
+/* ========================================================================
+ * 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.inheritance;
+
+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.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.ContentImpl;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentImpl;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentStream;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.FolderImpl;
+
+/**
+ * Test inheritance with node type per concrete class (without  discreminator field)
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerInheritanceConcreteClassTest extends TestBase {
+	private final static Log log = LogFactory.getLog(PersistenceManagerInheritanceConcreteClassTest.class);
+
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerInheritanceConcreteClassTest(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(
+				PersistenceManagerInheritanceConcreteClassTest.class));
+	}
+
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}
+
+
+	public void testRetrieveSingleton() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Insert a  Document 
+			//---------------------------------------------------------------------------------------------------------			
+            DocumentImpl document = new DocumentImpl();
+            document.setPath("/document1");
+            document.setName("document name");
+            document.setContentType("plain/text"); 
+            DocumentStream documentStream = new DocumentStream();
+            documentStream.setEncoding("utf-8");
+            documentStream.setContent("Test Content".getBytes());
+            document.setDocumentStream(documentStream);
+            
+            persistenceManager.insert(document);
+			persistenceManager.save();
+			
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve a document object
+			//---------------------------------------------------------------------------------------------------------						
+
+			document = (DocumentImpl) persistenceManager.getObject( "/document1");
+			assertEquals("Document path is invalid", document.getPath(), "/document1");
+			assertEquals("Content type  is invalid", document.getContentType(), "plain/text");
+			assertNotNull("document stream is null", document.getDocumentStream());
+			assertTrue("Invalid document stream ", document.getDocumentStream().getEncoding().equals("utf-8"));
+			
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Update  a descendant object
+			//---------------------------------------------------------------------------------------------------------						
+			document.setName("anotherName");
+			persistenceManager.update(document);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the updated descendant object
+			//---------------------------------------------------------------------------------------------------------						
+			document = (DocumentImpl) persistenceManager.getObject( "/document1");
+			assertEquals("document name is incorrect", document.getName(), "anotherName");
+			assertEquals("Document path is invalid", document.getPath(), "/document1");
+			assertEquals("Content type  is invalid", document.getContentType(), "plain/text");
+			assertNotNull("document stream is null", document.getDocumentStream());
+			assertTrue("Invalid document stream", document.getDocumentStream().getEncoding().equals("utf-8"));
+
+			CmsObjectImpl cmsObject = (CmsObjectImpl) persistenceManager.getObject( "/document1");
+			assertEquals("cmsObject name is incorrect", cmsObject.getName(), "anotherName");
+			assertEquals("cmsObject path is invalid", cmsObject.getPath(), "/document1");
+           			
+	
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+	}
+
+	
+	public void testRetrieveCollection() {
+		PersistenceManager persistenceManager = this.getPersistenceManager();
+
+		//---------------------------------------------------------------------------------------------------------
+		// Insert cmsobjects
+		//---------------------------------------------------------------------------------------------------------			
+        DocumentImpl document = new DocumentImpl();
+        document.setPath("/document1");
+        document.setName("document name 1");
+        document.setContentType("plain/text"); 
+        DocumentStream documentStream = new DocumentStream();
+        documentStream.setEncoding("utf-8");
+        documentStream.setContent("Test Content".getBytes());
+        document.setDocumentStream(documentStream);        
+        persistenceManager.insert(document);
+        
+        document = new DocumentImpl();
+        document.setPath("/document2");        
+        document.setName("document name 2");
+        document.setContentType("plain/text"); 
+        documentStream = new DocumentStream();
+        documentStream.setEncoding("utf-8");
+        documentStream.setContent("Test Content".getBytes());
+        document.setDocumentStream(documentStream);       
+        persistenceManager.insert(document);
+
+        document = new DocumentImpl();
+        document.setPath("/document3");        
+        document.setName("document 3");
+        document.setContentType("plain/text"); 
+        documentStream = new DocumentStream();
+        documentStream.setEncoding("utf-8");
+        documentStream.setContent("Test Content 3".getBytes());
+        document.setDocumentStream(documentStream);       
+        persistenceManager.insert(document);
+        
+        FolderImpl folder = new FolderImpl();
+        folder.setPath("/folder1");
+        folder.setName("folder1");
+        persistenceManager.insert(folder);
+ 
+
+        document = new DocumentImpl();        
+        document.setName("document4");
+        document.setContentType("plain/text"); 
+        documentStream = new DocumentStream();
+        documentStream.setEncoding("utf-8");
+        documentStream.setContent("Test Content 4".getBytes());
+        document.setDocumentStream(documentStream);       
+
+        FolderImpl subFolder = new FolderImpl();
+        subFolder.setName("subfolder");
+        
+        folder = new FolderImpl();
+        folder.setPath("/folder2");
+        folder.setName("folder2");        
+        folder.addChild(document);
+        folder.addChild(subFolder);
+        persistenceManager.insert(folder);               		
+        
+        
+		Atomic a = new Atomic();
+		a.setPath("/atomic");
+		a.setBooleanPrimitive(true);
+		persistenceManager.insert(a);
+
+		persistenceManager.save();
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Folders found on the root level
+		//---------------------------------------------------------------------------------------------------------			
+		QueryManager queryManager = persistenceManager.getQueryManager();
+		Filter filter = queryManager.createFilter(FolderImpl.class);
+		Query query = queryManager.createQuery(filter);
+		filter.setScope("/");
+		Collection result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of folders found", result.size(), 2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2", FolderImpl.class));		
+		
+	
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Documents 
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(DocumentImpl.class);
+		
+		filter.addLike("name", "document name%");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of documents  found", result.size(),2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
+
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve folder2 
+		//---------------------------------------------------------------------------------------------------------	
+		FolderImpl folder2 = (FolderImpl) persistenceManager.getObject( "/folder2");
+		assertNotNull("folder 2 is null", folder2);
+		assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,2);
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));
+		
+		
+		CmsObjectImpl cmsObject = (CmsObjectImpl) persistenceManager.getObject( "/folder2");
+		assertNotNull("folder 2 is null", cmsObject);
+		assertTrue("Invalid instance for folder 2",  cmsObject instanceof FolderImpl);
+		assertEquals("Invalid number of documents  found in folder2 children",  folder2.getChildren().size(),2);
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Contents (ancestor of Documents) 
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(ContentImpl.class);
+		filter.addLike("name", "document name%");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of documents  found", result.size(),2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
+		
+				
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve all cmsobjects found on the root level
+		//---------------------------------------------------------------------------------------------------------					
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(CmsObjectImpl.class);
+		filter.setScope("/");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),5);
+		assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));	
+		assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class));		
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));	
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class));
+
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve all cmsobjects found anywhere
+		//---------------------------------------------------------------------------------------------------------					
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(CmsObjectImpl.class);		
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),7);
+		assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));	
+		assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2/document4", DocumentImpl.class));		
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));	
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2/subfolder",FolderImpl.class));
+		
+	}
+	  
+	public void testBeanCollection() {
+		PersistenceManager persistenceManager = this.getPersistenceManager();
+
+		//---------------------------------------------------------------------------------------------------------
+		// Insert cmsobjects
+		//---------------------------------------------------------------------------------------------------------
+		 FolderImpl folder = new FolderImpl();		
+	     folder.setPath("/mainfolder");
+	     folder.setName("Main folder");        
+	    
+	     for (int i=1; i<=100;i++)
+	     {
+	         DocumentImpl document = new DocumentImpl();	        
+	         document.setName("document" + i);
+	         document.setContentType("plain/text"); 
+	         DocumentStream documentStream = new DocumentStream();
+	         documentStream.setEncoding("utf-8");
+	         documentStream.setContent("Test Content".getBytes());
+	         document.setDocumentStream(documentStream);
+	         folder.addChild(document);
+	         
+	         FolderImpl subFolder = new FolderImpl();
+	         subFolder.setName("folder" + i);
+	         subFolder.addChild(document);
+	         folder.addChild(subFolder);
+	         	    	 
+	     }
+	     log.debug("Save the folder and its 200 children");   
+	     persistenceManager.insert(folder);
+	     persistenceManager.save();
+	     log.debug("End - Save the folder and its 200 children");
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Folder
+		//---------------------------------------------------------------------------------------------------------			
+		folder  = (FolderImpl) persistenceManager.getObject("/mainfolder");
+		assertNotNull("Folder is null",folder);		
+		Collection children = folder.getChildren();
+		assertEquals("Invalid number of children", children.size(), 200);
+	     for (int i=1; i<=100;i++)
+	     {
+		     assertTrue("Invalid item in the collection : " +"/mainfolder/document" + i , this.contains(children, "/mainfolder/document" + i,DocumentImpl.class));
+		    assertTrue("Invalid item in the collection : " + "/mainfolder/folder" + i, this.contains(children, "/mainfolder/folder" + i, FolderImpl.class));
+	     }
+		
+	
+	}	
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/inheritance/PersistenceManagerInheritanceHierarchyTest.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.inheritance;
+
+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.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant;
+
+/**
+ * Test inheritance with node type per hierarchy stategy (with discreminator field)
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerInheritanceHierarchyTest extends TestBase {
+	private final static Log log = LogFactory.getLog(PersistenceManagerInheritanceHierarchyTest.class);
+
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerInheritanceHierarchyTest(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(
+				PersistenceManagerInheritanceHierarchyTest.class));
+	}
+
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}
+
+
+	public void testRetrieveSingleton() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Insert a descendant object
+			//---------------------------------------------------------------------------------------------------------			
+			Descendant descendant = new Descendant();
+			descendant.setDescendantField("descendantValue");
+			descendant.setAncestorField("ancestorValue");
+			descendant.setPath("/test");
+			persistenceManager.insert(descendant);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve a descendant object
+			//---------------------------------------------------------------------------------------------------------						
+			descendant = null;
+			descendant = (Descendant) persistenceManager.getObject(	 "/test");
+			assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
+			assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "ancestorValue");
+			assertEquals("Descendant descendantField is invalid", descendant	.getDescendantField(), "descendantValue");
+
+			//---------------------------------------------------------------------------------------------------------
+			// Update  a descendant object
+			//---------------------------------------------------------------------------------------------------------						
+			descendant.setAncestorField("anotherAncestorValue");
+			persistenceManager.update(descendant);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the updated descendant object
+			//---------------------------------------------------------------------------------------------------------						
+			descendant = null;
+			descendant = (Descendant) persistenceManager.getObject(	 "/test");
+			assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
+			assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "anotherAncestorValue");
+			assertEquals("Descendant descendantField is invalid", descendant	.getDescendantField(), "descendantValue");
+
+			Ancestor ancestor = (Ancestor) persistenceManager.getObject("/test");
+			assertTrue("Invalid object instance", ancestor instanceof Descendant );
+			assertEquals("Ancestor  path is invalid", ancestor.getPath(), "/test");
+			assertEquals("Ancestor ancestorField is invalid", ancestor.getAncestorField(), "anotherAncestorValue");
+			
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+	}
+
+	
+	public void testRetrieveCollection() {
+		PersistenceManager persistenceManager = this.getPersistenceManager();
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Insert  descendant objects
+		//---------------------------------------------------------------------------------------------------------			
+		Descendant descendant = new Descendant();
+		descendant.setDescendantField("descendantValue");
+		descendant.setAncestorField("ancestorValue");
+		descendant.setPath("/descendant1");
+		persistenceManager.insert(descendant);
+
+		descendant = new Descendant();
+		descendant.setDescendantField("descendantValue2");
+		descendant.setAncestorField("ancestorValue2");
+		descendant.setPath("/descendant2");
+		persistenceManager.insert(descendant);
+
+		SubDescendant subDescendant = new SubDescendant();
+		subDescendant.setDescendantField("descendantValue2");
+		subDescendant.setAncestorField("ancestorValue2");
+		subDescendant.setPath("/subdescendant");
+		subDescendant.setSubDescendantField("subdescendantvalue");
+		persistenceManager.insert(subDescendant);		
+
+		 subDescendant = new SubDescendant();
+		subDescendant.setDescendantField("descendantValue3");
+		subDescendant.setAncestorField("ancestorValue2");
+		subDescendant.setPath("/subdescendant2");
+		subDescendant.setSubDescendantField("subdescendantvalue1");
+		persistenceManager.insert(subDescendant);		
+		
+		
+		AnotherDescendant anotherDescendant = new AnotherDescendant();
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
+		anotherDescendant.setAncestorField("ancestorValue3");
+		anotherDescendant.setPath("/anotherdescendant1");
+		persistenceManager.insert(anotherDescendant);
+
+		anotherDescendant = new AnotherDescendant();
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
+		anotherDescendant.setAncestorField("ancestorValue4");
+		anotherDescendant.setPath("/anotherdescendant2");
+		persistenceManager.insert(anotherDescendant);
+
+		anotherDescendant = new AnotherDescendant();
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue2");
+		anotherDescendant.setAncestorField("ancestorValue5");
+		anotherDescendant.setPath("/anotherdescendant3");
+		persistenceManager.insert(anotherDescendant);
+
+		
+		Atomic a = new Atomic();
+		a.setPath("/atomic");
+		a.setBooleanPrimitive(true);
+		persistenceManager.insert(a);
+
+		persistenceManager.save();
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Descendant class
+		//---------------------------------------------------------------------------------------------------------			
+		QueryManager queryManager = persistenceManager.getQueryManager();
+		Filter filter = queryManager.createFilter(Descendant.class);
+		Query query = queryManager.createQuery(filter);
+
+		Collection result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of Descendant found", result.size(), 4);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
+		
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve AnotherDescendant class
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(AnotherDescendant.class);
+		filter.addEqualTo("anotherDescendantField", "anotherDescendantValue");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of AnotherDescendant found", result.size(),2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1", AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2", AnotherDescendant.class));
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve some descendants & subdescendants
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(Descendant.class);		
+		filter.addEqualTo("descendantField","descendantValue2");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),2);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve all class
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(Ancestor.class);		
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),7);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1", AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2", AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant3", AnotherDescendant.class));		
+
+ 
+	}
+	    
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/AllTests.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/AllTests.java Mon May 22 13:47:35 2006
@@ -0,0 +1,45 @@
+/* ========================================================================
+ * 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.interfaces;
+
+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.interfaces");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(PersistenceManagerInterfaceConcreteClassTest.class);
+        suite.addTestSuite(PersistenceManagerInterfaceHierarchyTest.class);        
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceConcreteClassTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceConcreteClassTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceConcreteClassTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceConcreteClassTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,355 @@
+/* ========================================================================
+ * 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.interfaces;
+
+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.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentImpl;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentStream;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.FolderImpl;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.Content;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.Document;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.Folder;
+
+/**
+ * Test interface (with discreminator field)
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerInterfaceConcreteClassTest extends TestBase {
+	private final static Log log = LogFactory.getLog(PersistenceManagerInterfaceConcreteClassTest.class);
+
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerInterfaceConcreteClassTest(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(
+				PersistenceManagerInterfaceConcreteClassTest.class));
+	}
+
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}
+
+
+	public void testRetrieveSingleton() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Insert 
+			//---------------------------------------------------------------------------------------------------------			
+            DocumentImpl documentImpl = new DocumentImpl();
+            documentImpl.setPath("/document1");
+            documentImpl.setName("document name");
+            documentImpl.setContentType("plain/text"); 
+            DocumentStream documentStream = new DocumentStream();
+            documentStream.setEncoding("utf-8");
+            documentStream.setContent("Test Content".getBytes());
+            documentImpl.setDocumentStream(documentStream);
+            Document document = documentImpl;
+            
+            persistenceManager.insert(document);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve 
+			//---------------------------------------------------------------------------------------------------------						
+			document = (Document) persistenceManager.getObject( "/document1");
+			assertTrue("Invalid implementation for Document", document instanceof DocumentImpl);
+			assertEquals("Document path is invalid", document.getPath(), "/document1");
+			assertEquals("Content type  is invalid", document.getContentType(), "plain/text");
+			assertNotNull("document stream is null", document.getDocumentStream());
+			assertTrue("Invalid document stream ", document.getDocumentStream().getEncoding().equals("utf-8"));
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Update  a document
+			//---------------------------------------------------------------------------------------------------------						
+			document.setName("anotherName");
+			persistenceManager.update(document);
+			persistenceManager.save();
+			
+             //	---------------------------------------------------------------------------------------------------------
+			// Retrieve the updated descendant object
+			//---------------------------------------------------------------------------------------------------------						
+			document = (Document) persistenceManager.getObject( "/document1");
+			assertTrue("Invalid implementation for Document", document instanceof DocumentImpl);
+			assertEquals("document name is incorrect", document.getName(), "anotherName");
+			assertEquals("Document path is invalid", document.getPath(), "/document1");
+			assertEquals("Content type  is invalid", document.getContentType(), "plain/text");
+			assertNotNull("document stream is null", document.getDocumentStream());
+			assertTrue("Invalid document stream", document.getDocumentStream().getEncoding().equals("utf-8"));
+
+			CmsObject cmsObject = (CmsObject) persistenceManager.getObject( "/document1");
+			assertEquals("cmsObject name is incorrect", cmsObject.getName(), "anotherName");
+			assertEquals("cmsObject path is invalid", cmsObject.getPath(), "/document1");			
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+	}
+	
+	
+	public void testRetrieveCollection() {
+	PersistenceManager persistenceManager = this.getPersistenceManager();
+
+	//---------------------------------------------------------------------------------------------------------
+	// Insert cmsobjects
+	//---------------------------------------------------------------------------------------------------------			
+    DocumentImpl document = new DocumentImpl();
+    document.setPath("/document1");
+    document.setName("document name 1");
+    document.setContentType("plain/text"); 
+    DocumentStream documentStream = new DocumentStream();
+    documentStream.setEncoding("utf-8");
+    documentStream.setContent("Test Content".getBytes());
+    document.setDocumentStream(documentStream);        
+    persistenceManager.insert(document);
+    
+    document = new DocumentImpl();
+    document.setPath("/document2");        
+    document.setName("document name 2");
+    document.setContentType("plain/text"); 
+    documentStream = new DocumentStream();
+    documentStream.setEncoding("utf-8");
+    documentStream.setContent("Test Content".getBytes());
+    document.setDocumentStream(documentStream);       
+    persistenceManager.insert(document);
+
+    document = new DocumentImpl();
+    document.setPath("/document3");        
+    document.setName("document 3");
+    document.setContentType("plain/text"); 
+    documentStream = new DocumentStream();
+    documentStream.setEncoding("utf-8");
+    documentStream.setContent("Test Content 3".getBytes());
+    document.setDocumentStream(documentStream);       
+    persistenceManager.insert(document);
+    
+    FolderImpl folder = new FolderImpl();
+    folder.setPath("/folder1");
+    folder.setName("folder1");
+    persistenceManager.insert(folder);
+
+
+    document = new DocumentImpl();        
+    document.setName("document4");
+    document.setContentType("plain/text"); 
+    documentStream = new DocumentStream();
+    documentStream.setEncoding("utf-8");
+    documentStream.setContent("Test Content 4".getBytes());
+    document.setDocumentStream(documentStream);       
+
+    FolderImpl subFolder = new FolderImpl();
+    subFolder.setName("subfolder");
+    
+    folder = new FolderImpl();
+    folder.setPath("/folder2");
+    folder.setName("folder2");        
+    folder.addChild(document);
+    folder.addChild(subFolder);
+    persistenceManager.insert(folder);               		
+
+    
+	Atomic a = new Atomic();
+	a.setPath("/atomic");
+	a.setBooleanPrimitive(true);
+	persistenceManager.insert(a);
+
+	persistenceManager.save();
+
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve Folders found on the root level
+	//---------------------------------------------------------------------------------------------------------			
+	QueryManager queryManager = persistenceManager.getQueryManager();
+	Filter filter = queryManager.createFilter(Folder.class);
+	Query query = queryManager.createQuery(filter);
+	filter.setScope("/");
+	Collection result = persistenceManager.getObjects(query);
+	assertEquals("Invalid number of folders found", result.size(), 2);
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder2", FolderImpl.class));		
+	
+
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve Documents 
+	//---------------------------------------------------------------------------------------------------------			
+	queryManager = persistenceManager.getQueryManager();
+	filter = queryManager.createFilter(Document.class);
+	
+	filter.addLike("name", "document name%");
+	query = queryManager.createQuery(filter);
+
+	result = persistenceManager.getObjects(query);
+	assertEquals("Invalid number of documents  found", result.size(),2);
+	assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
+
+	
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve folder2 
+	//---------------------------------------------------------------------------------------------------------	
+	Folder folder2 = (Folder) persistenceManager.getObject( "/folder2");
+	assertNotNull("folder 2 is null", folder2);
+	assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,2);
+	assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));
+	
+	
+	CmsObject cmsObject = (CmsObject) persistenceManager.getObject( "/folder2");
+	assertNotNull("folder 2 is null", cmsObject);
+	assertTrue("Invalid instance for folder 2",  cmsObject instanceof FolderImpl);
+	assertEquals("Invalid number of documents  found in folder2 children",  folder2.getChildren().size(),2);
+	assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));
+	
+	Folder childFolder = (Folder) persistenceManager.getObject( "/folder2/subfolder");
+	Folder parenFolder  = childFolder.getParentFolder();
+	assertNotNull("parent folder  is null", parenFolder);
+	assertTrue("Invalid instance for parent folder",  parenFolder instanceof FolderImpl);
+	assertEquals("Invalid number of documents  found in folder2 children",  parenFolder.getChildren().size(),2);
+	assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/document4", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/subfolder", FolderImpl.class));
+	
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve Contents (ancestor of Documents) 
+	//---------------------------------------------------------------------------------------------------------			
+	queryManager = persistenceManager.getQueryManager();
+	filter = queryManager.createFilter(Content.class);
+	filter.addLike("name", "document name%");
+	query = queryManager.createQuery(filter);
+
+	result = persistenceManager.getObjects(query);
+	assertEquals("Invalid number of documents  found", result.size(),2);
+	assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
+	
+			
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve all cmsobjects found on the root level
+	//---------------------------------------------------------------------------------------------------------					
+	queryManager = persistenceManager.getQueryManager();
+	filter = queryManager.createFilter(CmsObject.class);
+	filter.setScope("/");
+	query = queryManager.createQuery(filter);
+
+	result = persistenceManager.getObjects(query);
+	assertEquals("Invalid ancestor object found", result.size(),5);
+	assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));	
+	assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class));		
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));	
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class));
+
+	
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve all cmsobjects found anywhere
+	//---------------------------------------------------------------------------------------------------------					
+	queryManager = persistenceManager.getQueryManager();
+	filter = queryManager.createFilter(CmsObject.class);		
+	query = queryManager.createQuery(filter);
+
+	result = persistenceManager.getObjects(query);
+	assertEquals("Invalid ancestor object found", result.size(),7);
+	assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));	
+	assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder2/document4", DocumentImpl.class));		
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));	
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class));
+	assertTrue("Invalid item in the collection", this.contains(result, "/folder2/subfolder",FolderImpl.class));
+	
+}
+ 
+
+public void testBeanCollection() {
+	PersistenceManager persistenceManager = this.getPersistenceManager();
+
+	//---------------------------------------------------------------------------------------------------------
+	// Insert cmsobjects
+	//---------------------------------------------------------------------------------------------------------
+	 Folder folder = new FolderImpl();		
+     folder.setPath("/mainfolder");
+     folder.setName("Main folder");        
+    
+     for (int i=1; i<=100;i++)
+     {
+         Document document = new DocumentImpl();	        
+         document.setName("document" + i);
+         document.setContentType("plain/text"); 
+         DocumentStream documentStream = new DocumentStream();
+         documentStream.setEncoding("utf-8");
+         documentStream.setContent("Test Content".getBytes());
+         document.setDocumentStream(documentStream);
+         folder.addChild(document);
+         
+         Folder subFolder = new FolderImpl();
+         subFolder.setName("folder" + i);
+         subFolder.addChild(document);
+         folder.addChild(subFolder);
+         	    	 
+     }
+     log.debug("Save the folder and its 200 children");   
+     persistenceManager.insert(folder);
+     persistenceManager.save();
+     log.debug("End - Save the folder and its 200 children");
+
+	//---------------------------------------------------------------------------------------------------------	
+	// Retrieve Folder
+	//---------------------------------------------------------------------------------------------------------			
+	folder  = (Folder) persistenceManager.getObject("/mainfolder");
+	assertNotNull("Folder is null",folder);		
+	Collection children = folder.getChildren();
+	assertEquals("Invalid number of children", children.size(), 200);
+     for (int i=1; i<=100;i++)
+     {
+    	   
+        assertTrue("Invalid item in the collection : " +"/mainfolder/document" + i , this.contains(children, "/mainfolder/document" + i,DocumentImpl.class));
+	    assertTrue("Invalid item in the collection : " + "/mainfolder/folder" + i, this.contains(children, "/mainfolder/folder" + i, FolderImpl.class));
+     }
+}
+
+
+	
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceHierarchyTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceHierarchyTest.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceHierarchyTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/interfaces/PersistenceManagerInterfaceHierarchyTest.java Mon May 22 13:47:35 2006
@@ -0,0 +1,195 @@
+/* ========================================================================
+ * 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.interfaces;
+
+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.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.AnotherInterface;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.Interface;
+
+/**
+ * Test interface (with discreminator field)
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerInterfaceHierarchyTest extends TestBase {
+	private final static Log log = LogFactory.getLog(PersistenceManagerInterfaceHierarchyTest.class);
+
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerInterfaceHierarchyTest(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(
+				PersistenceManagerInterfaceHierarchyTest.class));
+	}
+
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}
+
+
+	public void testRetrieveSingleton() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Insert 
+			//---------------------------------------------------------------------------------------------------------			
+			AnotherDescendant  anotherDescendant = new AnotherDescendant();
+			anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
+			anotherDescendant.setAncestorField("ancestorValue");
+			anotherDescendant.setPath("/test");
+			persistenceManager.insert(anotherDescendant);
+
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve 
+			//---------------------------------------------------------------------------------------------------------						
+			Interface result =  (Interface) persistenceManager.getObject("/test");
+			assertNotNull("Object is null", result);
+			anotherDescendant = (AnotherDescendant) result; 
+			
+			assertEquals("Descendant path is invalid", anotherDescendant.getPath(), "/test");
+			assertEquals("Descendant ancestorField is invalid", anotherDescendant.getAncestorField(), "ancestorValue");
+			assertEquals("Descendant descendantField is invalid", anotherDescendant	.getAnotherDescendantField(), "anotherDescendantValue");
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+	}
+	
+	
+	public void testRetrieveCollection() {
+		
+		PersistenceManager persistenceManager = this.getPersistenceManager();
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Insert  descendant objects
+		//---------------------------------------------------------------------------------------------------------			
+		Descendant descendant = new Descendant();
+		descendant.setDescendantField("descendantValue");
+		descendant.setAncestorField("ancestorValue");
+		descendant.setPath("/descendant1");
+		persistenceManager.insert(descendant);
+
+		descendant = new Descendant();
+		descendant.setDescendantField("descendantValue2");
+		descendant.setAncestorField("ancestorValue2");
+		descendant.setPath("/descendant2");
+		persistenceManager.insert(descendant);
+
+		SubDescendant subDescendant = new SubDescendant();
+		subDescendant.setDescendantField("descendantValue2");
+		subDescendant.setAncestorField("ancestorValue2");
+		subDescendant.setPath("/subdescendant");
+		subDescendant.setSubDescendantField("subdescendantvalue");
+		persistenceManager.insert(subDescendant);		
+
+		 subDescendant = new SubDescendant();
+		subDescendant.setDescendantField("descendantValue3");
+		subDescendant.setAncestorField("ancestorValue2");
+		subDescendant.setPath("/subdescendant2");
+		subDescendant.setSubDescendantField("subdescendantvalue1");
+		persistenceManager.insert(subDescendant);		
+		
+		
+		AnotherDescendant anotherDescendant = new AnotherDescendant();
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
+		anotherDescendant.setAncestorField("ancestorValue3");
+		anotherDescendant.setPath("/anotherdescendant1");
+		persistenceManager.insert(anotherDescendant);
+
+		anotherDescendant = new AnotherDescendant();
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
+		anotherDescendant.setAncestorField("ancestorValue4");
+		anotherDescendant.setPath("/anotherdescendant2");
+		persistenceManager.insert(anotherDescendant);
+
+		anotherDescendant = new AnotherDescendant();
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue2");
+		anotherDescendant.setAncestorField("ancestorValue5");
+		anotherDescendant.setPath("/anotherdescendant3");
+		persistenceManager.insert(anotherDescendant);
+
+		
+		Atomic a = new Atomic();
+		a.setPath("/atomic");
+		a.setBooleanPrimitive(true);
+		persistenceManager.insert(a);
+
+		persistenceManager.save();
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Descendant class (implements  Interface.class)
+		//---------------------------------------------------------------------------------------------------------			
+		QueryManager queryManager = persistenceManager.getQueryManager();
+		Filter filter = queryManager.createFilter(Interface.class);
+		Query query = queryManager.createQuery(filter);
+
+		Collection result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of  interface  found", result.size(),3);
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1", AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2", AnotherDescendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant3", AnotherDescendant.class));
+		
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Descendant class and its children (implements  AnotherInterface.class)
+		//---------------------------------------------------------------------------------------------------------			
+	    queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(AnotherInterface.class);
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of  interface  found", result.size(),4);
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant",SubDescendant.class));		
+		assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2",SubDescendant.class));
+
+	}
+	
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/AllTests.java?rev=408762&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/proxy/AllTests.java Mon May 22 13:47:35 2006
@@ -0,0 +1,45 @@
+/* ========================================================================
+ * 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 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.proxy");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(ProxyTest.class);
+        
+        //$JUnit-END$
+
+        return suite;
+    }
+}



Mime
View raw message