incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r408741 - /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/
Date Mon, 22 May 2006 20:10:13 GMT
Author: clombart
Date: Mon May 22 13:10:12 2006
New Revision: 408741

URL: http://svn.apache.org/viewvc?rev=408741&view=rev
Log: (empty)

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/AllTests.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/DefaultCollectionConverterImplTest.java
  (with props)
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/HashMapTest.java
  (with props)
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/MultiValueCollectionConverterImplTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/NTCollectionConverterImplTest.java
  (with props)

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

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/DefaultCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/DefaultCollectionConverterImplTest.java?rev=408741&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/DefaultCollectionConverterImplTest.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/DefaultCollectionConverterImplTest.java
Mon May 22 13:10:12 2006
@@ -0,0 +1,232 @@
+/* ========================================================================
+ * 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.collectionconverter;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.A;
+import org.apache.portals.graffito.jcr.testmodel.C;
+
+/**
+ * Test DefaultCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class DefaultCollectionConverterImplTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(DefaultCollectionConverterImplTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public DefaultCollectionConverterImplTest(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(DefaultCollectionConverterImplTest.class));
+    }
+
+    
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+            getPersistenceManager().save();
+        }        
+    	
+        super.tearDown();
+    }
+    
+    public void testDropElement()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setPath("/test");
+            C c1 = new C();
+            c1.setId("first");
+            c1.setName("First Element");
+            C c2 = new C();
+            c2.setId("second");
+            c2.setName("Second Element");
+            
+            C c3 = new C();
+            c3.setId("third");
+            c3.setName("Third Element");
+            
+            
+            Collection collection = new ArrayList();
+            collection.add(c1);
+            collection.add(c2);
+            collection.add(c3);
+            
+            a.setCollection(collection);
+            
+            persistenceManager.insert(a);
+            persistenceManager.save();
+            
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            a = (A) persistenceManager.getObject( "/test");
+            assertNotNull("a.collection is null", a.getCollection());
+            assertEquals("Incorrect a.collection size", 3, a.getCollection().size());
+            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("first"));
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            c1 = new C();
+            c1.setId("new first");
+            c1.setName("First Element");
+            
+            c2 = new C();
+            c2.setId("new second");
+            c2.setName("Second Element");
+            
+            collection = new ArrayList();
+            collection.add(c1);
+            collection.add(c2);
+            a.setCollection(collection);
+            
+            persistenceManager.update(a);
+            persistenceManager.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            a = (A) persistenceManager.getObject( "/test");
+            assertNotNull("a is null", a);
+            assertNotNull("a.collection is null", a.getCollection());
+            assertTrue("Incorrect collection size", a.getCollection().size() == 2);
+            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("new
first"));
+            
+            // --------------------------------------------------------------------------------
+            // Export to check the content
+            // --------------------------------------------------------------------------------
          
+            this.exportDocument("target/DefaultCollectionConverterExport.xml", "/test", true,
false);         
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+    public void testAddElement()
+    {
+        try
+        {
+
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setPath("/test");
+            C c1 = new C();
+            c1.setId("first");
+            c1.setName("First Element");
+            C c2 = new C();
+            c2.setId("second");
+            c2.setName("Second Element");
+            
+            C c3 = new C();
+            c3.setId("third");
+            c3.setName("Third Element");
+            
+            
+            Collection collection = new ArrayList();
+            collection.add(c1);
+            collection.add(c2);
+            collection.add(c3);
+            
+            a.setCollection(collection);
+            
+            persistenceManager.insert(a);
+            persistenceManager.save();
+            
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            a = (A) persistenceManager.getObject( "/test");
+            assertNotNull("a.collection is null", a.getCollection());
+            assertEquals("Incorrect a.collection size", 3, a.getCollection().size());
+            assertEquals("Incorrect a.collection", "first", ((C) a.getCollection().iterator().next()).getId());
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            C c4 = new C();
+            c4.setId("Fourth");
+            c4.setName("Fourth Element");
+                
+            collection = new ArrayList();
+            collection.add(c1);
+            collection.add(c2);
+            collection.add(c3);
+            collection.add(c4);
+            a.setCollection(collection);
+            
+            persistenceManager.update(a);
+            persistenceManager.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            a = (A) persistenceManager.getObject( "/test");
+            assertNotNull("a is null", a);
+            assertNotNull("a.collection is null", a.getCollection());
+            assertEquals("Incorrect collection size", 4, a.getCollection().size());
+            assertEquals("Incorrect a.collection", "first", ((C) a.getCollection().iterator().next()).getId());
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }    
+   
+}
\ No newline at end of file

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/DefaultCollectionConverterImplTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/HashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/HashMapTest.java?rev=408741&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/HashMapTest.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/HashMapTest.java
Mon May 22 13:10:12 2006
@@ -0,0 +1,150 @@
+/* ========================================================================
+ * 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.collectionconverter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.hashmap.Element;
+import org.apache.portals.graffito.jcr.testmodel.hashmap.HashMapElement;
+import org.apache.portals.graffito.jcr.testmodel.hashmap.Main;
+
+/**
+ * Test NTCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class HashMapTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(HashMapTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public HashMapTest(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(HashMapTest.class));
+    }
+
+    
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+            getPersistenceManager().save();
+        }        
+    	
+        super.tearDown();
+    }    
+    
+    public void testHashMap()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+        	
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+
+            Main main = new Main();
+            main.setPath("/test");
+            main.setText("Main text");
+            
+            HashMapElement hashMapElement = new HashMapElement();
+            Element e1 = new Element();
+            e1.setId("e1");
+            e1.setText("Element 1");
+            hashMapElement.addObject(e1);
+            
+            Element e2 = new Element();
+            e2.setId("e2");
+            e2.setText("Element 2");
+            hashMapElement.addObject(e2);
+            
+            main.setElements(hashMapElement);
+            
+            persistenceManager.insert(main);
+            persistenceManager.save();
+            
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            main = (Main) persistenceManager.getObject( "/test");
+            assertNotNull("main.getElements() is null", main.getElements());
+            assertTrue("Incorrect text", main.getText().equals("Main text"));           
+            assertTrue("Incorrect para element", ((Element) main.getElements().get("e1")).getText().equals("Element
1"));
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            hashMapElement = new HashMapElement();
+            e1 = new Element();
+            e1.setId("e1");
+            e1.setText("Element 1");
+            hashMapElement.addObject(e1);
+            
+            e2 = new Element();
+            e2.setId("e3");
+            e2.setText("Element 3");
+            hashMapElement.addObject(e2);
+
+            Element e3 = new Element();
+            e3.setId("e4");
+            e3.setText("Element 4");
+            hashMapElement.addObject(e3);
+            main.setElements(hashMapElement);
+            
+            persistenceManager.update(main);
+            persistenceManager.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            assertNotNull("main.getElements() is null", main.getElements());
+            assertTrue("Incorrect text", main.getText().equals("Main text"));           
+            assertTrue("Incorrect para element", ((Element) main.getElements().get("e4")).getText().equals("Element
4"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+
+   
+}
\ No newline at end of file

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/HashMapTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/MultiValueCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/MultiValueCollectionConverterImplTest.java?rev=408741&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/MultiValueCollectionConverterImplTest.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/MultiValueCollectionConverterImplTest.java
Mon May 22 13:10:12 2006
@@ -0,0 +1,142 @@
+/* ========================================================================
+ * 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.collectionconverter;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.A;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.MultiValue;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+/**
+ * Test NTCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class MultiValueCollectionConverterImplTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(MultiValueCollectionConverterImplTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public MultiValueCollectionConverterImplTest(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(MultiValueCollectionConverterImplTest.class));
+    }
+
+    
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+            getPersistenceManager().save();
+        }        
+    	
+        super.tearDown();
+    }    
+
+    public void testMultiValue()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+
+            MultiValue multiValue = new MultiValue();
+            multiValue.setPath("/test");
+            
+            ArrayList values = new ArrayList();
+            values.add("Value1");
+            values.add("Value2");
+            values.add("Value3");
+            values.add("Value4");
+            multiValue.setMultiValues(values);
+            
+            persistenceManager.insert(multiValue);
+            persistenceManager.save();
+            
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            multiValue = (MultiValue) persistenceManager.getObject( "/test");
+            assertNotNull("Object is null", multiValue);
+            assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues());
+            assertTrue("Incorrect number of values", multiValue.getMultiValues().size() ==
4);            
+            assertTrue("Incorrect collection element", ((String) multiValue.getMultiValues().iterator().next()).equals("Value1"));
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            values = new ArrayList();
+            values.add("Value1");
+            values.add("Value2");
+            values.add("Value3");
+            values.add("Value4");
+            values.add("Value5");
+            multiValue.setMultiValues(values);
+            
+            persistenceManager.update(multiValue);
+            persistenceManager.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+
+            multiValue = (MultiValue) persistenceManager.getObject( "/test");
+            assertNotNull("Object is null", multiValue);
+            assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues());
+            assertTrue("Incorrect number of values", multiValue.getMultiValues().size() ==
5);            
+            assertTrue("Incorrect collection element", ((String) multiValue.getMultiValues().iterator().next()).equals("Value1"));
+            
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+   
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/NTCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/NTCollectionConverterImplTest.java?rev=408741&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/NTCollectionConverterImplTest.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/NTCollectionConverterImplTest.java
Mon May 22 13:10:12 2006
@@ -0,0 +1,147 @@
+/* ========================================================================
+ * 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.collectionconverter;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.testmodel.A;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+/**
+ * Test NTCollectionConverterImpl
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class NTCollectionConverterImplTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(NTCollectionConverterImplTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public NTCollectionConverterImplTest(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(NTCollectionConverterImplTest.class));
+    }
+    
+    
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        if (getPersistenceManager().objectExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+            getPersistenceManager().save();
+        }        
+    	
+        super.tearDown();
+    }       
+
+    public void testCollection()
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+
+            Page page = new Page();
+            page.setPath("/test");
+            page.setTitle("Page Title");
+            
+            ArrayList paragraphs = new ArrayList();
+            
+            paragraphs.add(new Paragraph("Para 1"));
+            paragraphs.add(new Paragraph("Para 2"));
+            paragraphs.add(new Paragraph("Para 3"));
+            page.setParagraphs(paragraphs);
+            
+            persistenceManager.insert(page);
+            persistenceManager.save();
+            
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            page = (Page) persistenceManager.getObject( "/test");
+            assertNotNull("page.getParagraphs is null", page.getParagraphs());
+            assertTrue("Incorrect page title", page.getTitle().equals("Page Title"));
+            assertTrue("Incorrect page.getParagraphs size", page.getParagraphs().size() ==
3);
+            assertTrue("Incorrect para element", ((Paragraph) page.getParagraphs().iterator().next()).getText().equals("Para
1"));
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            paragraphs = new ArrayList();
+            
+            paragraphs.add(new Paragraph("Para 1"));
+            paragraphs.add(new Paragraph("Para 2"));
+            paragraphs.add(new Paragraph("Para 4"));
+            paragraphs.add(new Paragraph("Para 5"));
+            page.setParagraphs(paragraphs);
+            
+            persistenceManager.update(page);
+            persistenceManager.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+
+            page = (Page) persistenceManager.getObject( "/test");
+            assertNotNull("page.getParagraphs is null", page.getParagraphs());
+            assertTrue("Incorrect page title", page.getTitle().equals("Page Title"));
+            assertTrue("Incorrect page.getParagraphs size", page.getParagraphs().size() ==
4);
+            assertTrue("Incorrect para element", ((Paragraph) page.getParagraphs().iterator().next()).getText().equals("Para
1"));
+            
+            // --------------------------------------------------------------------------------
+            // Export to check the content
+            // --------------------------------------------------------------------------------
          
+            this.exportDocument("target/NTCollectionExport.xml", "/test", true, false);
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+
+   
+}
\ No newline at end of file

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/collectionconverter/NTCollectionConverterImplTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message