You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2006/05/22 20:34:14 UTC

svn commit: r408759 - in /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto: ./ AllTests.java PersistenceManagerAutoTest.java

Author: clombart
Date: Mon May 22 13:34:14 2006
New Revision: 408759

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

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/PersistenceManagerAutoTest.java

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/AllTests.java?rev=408759&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/AllTests.java Mon May 22 13:34:14 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.auto;
+
+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.auto");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(PersistenceManagerAutoTest.class);
+
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/PersistenceManagerAutoTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/PersistenceManagerAutoTest.java?rev=408759&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/PersistenceManagerAutoTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto/PersistenceManagerAutoTest.java Mon May 22 13:34:14 2006
@@ -0,0 +1,171 @@
+/* ========================================================================
+ * 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.auto;
+
+import java.util.Map;
+
+import javax.jcr.Repository;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+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.mapper.impl.DigesterMapperImpl;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.DefaultAtomicTypeConverterProvider;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
+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.query.impl.QueryManagerImpl;
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+import org.apache.portals.graffito.jcr.testmodel.Atomic;
+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.Document;
+import org.apache.portals.graffito.jcr.testmodel.interfaces.Folder;
+
+/**
+ * Test autoupdate setting
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerAutoTest extends TestBase {
+	private final static Log log = LogFactory.getLog(PersistenceManagerAutoTest.class);
+
+	/**
+	 * <p>Defines the test case name for junit.</p>
+	 * @param testName The test case name.
+	 */
+	public PersistenceManagerAutoTest(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(
+				PersistenceManagerAutoTest.class));
+	}
+
+	public void tearDown() throws Exception {
+
+		cleanUpRepisotory();
+		super.tearDown();
+		
+	}
+
+	
+	public void testAuto() {
+		
+		PersistenceManager persistenceManager = this.getPersistenceManager();
+
+		//---------------------------------------------------------------------------------------------------------
+		// Insert cmsobjects
+		//---------------------------------------------------------------------------------------------------------
+	    Folder  folder = new FolderImpl();
+	    folder.setPath("/folder2");
+	    folder.setName("folder2");        
+		
+	    Document document = new DocumentImpl();
+	    document.setPath("/folder2/document4");
+	    document.setName("document4");
+	    document.setContentType("plain/text"); 
+	    DocumentStream documentStream = new DocumentStream();
+	    documentStream.setEncoding("utf-8");
+	    documentStream.setContent("Test Content 4".getBytes());
+	    document.setDocumentStream(documentStream);       
+
+	    Folder subFolder = new FolderImpl();
+	    subFolder.setName("subfolder");
+	    subFolder.setPath("/folder2/subfolder");
+	    	    	    
+	    folder.addChild(document);
+	    folder.addChild(subFolder);
+	    persistenceManager.insert(folder);               		
+		persistenceManager.save();
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// 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() ,0); // autoInsert = false
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Insert nested objects
+		//---------------------------------------------------------------------------------------------------------
+		persistenceManager.insert(subFolder);
+		persistenceManager.insert(document);
+		persistenceManager.save();
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve folder2 
+		//---------------------------------------------------------------------------------------------------------	
+		 folder2 = (Folder) persistenceManager.getObject( "/folder2");
+		assertNotNull("folder 2 is null", folder2);
+		assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,0); // autoInsert = false
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve children attribute 
+		//---------------------------------------------------------------------------------------------------------			
+		persistenceManager.retrieveMappedAttribute(folder2, "children");
+		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));		
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Update 
+		//---------------------------------------------------------------------------------------------------------	
+		folder2.setChildren(null);
+		persistenceManager.update(folder2); // autoupdate = true for the children attribute. So no update on the children collection
+		persistenceManager.save();
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve children attribute 
+		//---------------------------------------------------------------------------------------------------------			
+		persistenceManager.retrieveMappedAttribute(folder2, "children");
+		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));		
+		
+		
+	}
+	
+	protected void initPersistenceManager() throws UnsupportedRepositoryOperationException, javax.jcr.RepositoryException
+	{
+		Repository repository = RepositoryUtil.getRepository("repositoryTest");
+		String[] files = { "./src/test-config/jcrmapping-auto.xml"};
+		session = RepositoryUtil.login(repository, "superuser", "superuser");
+
+		
+		mapper = new DigesterMapperImpl(files).buildMapper();
+        converterProvider = new DefaultAtomicTypeConverterProvider();
+        Map atomicTypeConverters = converterProvider.getAtomicTypeConverters();
+		queryManager = new QueryManagerImpl(mapper, atomicTypeConverters);
+        ObjectConverter objectConverter = new ObjectConverterImpl(mapper, converterProvider);
+		persistenceManager = new PersistenceManagerImpl(mapper, objectConverter, queryManager, session);
+		
+	}	
+	
+}
\ No newline at end of file