From graffito-commits-return-701-apmail-incubator-graffito-commits-archive=www.apache.org@incubator.apache.org Mon May 22 22:44:43 2006 Return-Path: Delivered-To: apmail-incubator-graffito-commits-archive@www.apache.org Received: (qmail 98557 invoked from network); 22 May 2006 22:44:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 May 2006 22:44:43 -0000 Received: (qmail 89705 invoked by uid 500); 22 May 2006 22:44:41 -0000 Mailing-List: contact graffito-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: graffito-dev@incubator.apache.org Delivered-To: mailing list graffito-commits@incubator.apache.org Received: (qmail 89139 invoked by uid 99); 22 May 2006 22:44:39 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 May 2006 15:44:39 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 May 2006 15:44:37 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 3D1401A987E; Mon, 22 May 2006 13:34:15 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r408759 - in /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/auto: ./ AllTests.java PersistenceManagerAutoTest.java Date: Mon, 22 May 2006 20:34:14 -0000 To: graffito-commits@incubator.apache.org From: clombart@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060522203415.3D1401A987E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 Alexandru Popescu + */ +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 Christophe Lombart + */ +public class PersistenceManagerAutoTest extends TestBase { + private final static Log log = LogFactory.getLog(PersistenceManagerAutoTest.class); + + /** + *

Defines the test case name for junit.

+ * @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