incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r290789 - in /incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr: ./ mapper/ persistence/atomicconverter/ persistence/impl/ repository/ testmodel/
Date Wed, 21 Sep 2005 18:51:38 GMT
Author: clombart
Date: Wed Sep 21 11:51:27 2005
New Revision: 290789

URL: http://svn.apache.org/viewcvs?rev=290789&view=rev
Log:
Review unit tests

Added:
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
      - copied, changed from r280409, incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
      - copied, changed from r280409, incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java
Removed:
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestAll.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java
Modified:
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=290789&r1=290788&r2=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
Wed Sep 21 11:51:27 2005
@@ -16,18 +16,24 @@
  */
 package org.apache.portals.graffito.jcr;
 
+import java.io.BufferedOutputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import junit.framework.TestCase;
 
 import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
-import org.apache.portals.graffito.jcr.persistence.CustomNodeTypeCreator;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
-import org.apache.portals.graffito.jcr.persistence.impl.CustomNodeTypeCreatorImpl;
 import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
 import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
-
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
 
 /** 
  * Base class for testcases. Provides priviledged access to the jcr test
@@ -38,33 +44,42 @@
  */
 public abstract class TestBase extends TestCase
 {
-    /** Jcr session to work with.
+    /** 
+     * Jcr session to work with.
      */
+	protected Session session; 
+	
+	
     private PersistenceManager persistenceManager;
 
+    private static boolean isInit = false;
+
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public TestBase(String testName)
+    public TestBase(String testName) throws Exception
     {
         super(testName);
-    }    
+        if ( ! isInit)
+        {
+            RepositoryUtil.registerRepository("repositoryTest", "./src/test-config/repository.xml",
"./target/repository");
+            isInit = true;
+        }
+    }
 
     /** Setting up the testcase.
      * @see junit.framework.TestCase#setUp()
      */
     protected void setUp() throws Exception
     {
-        DigesterMapperImpl mapper =  new DigesterMapperImpl("src/test-config/jcrmapping.xml");
-               
-        RepositoryUtil.registerRepository("repositoryTest", "src/test-config/repository.xml",
"target/repository");
+        super.setUp();
+        DigesterMapperImpl mapper = new DigesterMapperImpl("./src/test-config/jcrmapping.xml");
         Repository repository = RepositoryUtil.getRepository("repositoryTest");
-        // optaining a read/write session to the repository
-        Session session = RepositoryUtil.login(repository, "superuser", "superuser");
-        CustomNodeTypeCreator customNodeTypeCreator = new CustomNodeTypeCreatorImpl();
-        persistenceManager = new PersistenceManagerImpl(mapper, repository, session, customNodeTypeCreator);
-        persistenceManager.setupRepository();
+        
+        session = RepositoryUtil.login(repository, "superuser", "superuser");        
+        persistenceManager = new PersistenceManagerImpl(mapper, repository, session);
+        
         
     }
 
@@ -73,9 +88,9 @@
      */
     public void tearDown() throws Exception
     {
-        getPersistenceManager().getSession().save();
-        getPersistenceManager().getSession().logout();
-    }    
+        getPersistenceManager().logout();    
+        super.tearDown();
+    }
 
     /** Getter for property persistenceManager.
      * @return jcrSession
@@ -92,4 +107,18 @@
     {
         this.persistenceManager = persistenceManager;
     }
+    
+    public void exportDocument(String filePath, String nodePath, boolean skipBinary, boolean
noRecurse)
+    {
+        try {
+			BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(filePath));  
     
+			ContentHandler handler = new org.apache.xml.serialize.XMLSerializer(os, null).asContentHandler();
+			    session.exportDocumentView(nodePath, handler, skipBinary, noRecurse);
+		} catch (Exception e) 
+		{
+			System.out.println("Impossible to export the content from : " + nodePath);
+			e.printStackTrace();
+		}
+    }
+    
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java?rev=290789&r1=290788&r2=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
Wed Sep 21 11:51:27 2005
@@ -76,7 +76,7 @@
     {
         try
         {
-            DigesterMapperImpl mapper = new DigesterMapperImpl("./src/test/jcrmapping.xml");
+            DigesterMapperImpl mapper = new DigesterMapperImpl("./src/test-config/jcrmapping.xml");
             assertNotNull("Mapper is null", mapper);
             
             ClassDescriptor classDescriptor = mapper.getClassDescriptor(A.class);
@@ -98,6 +98,7 @@
         }
         catch (JcrMappingException e)
         {
+              e.printStackTrace();
               fail("Impossible to retrieve the converter " + e);
         }
     }

Copied: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
(from r280409, incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java)
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java?p2=incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java&p1=incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java&r1=280409&r2=290789&rev=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AtomicTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/AtomicTest.java
Wed Sep 21 11:51:27 2005
@@ -14,9 +14,10 @@
  * limitations under the License.
  * ========================================================================
  */
-package org.apache.portals.graffito.jcr.persistence.impl;
+package org.apache.portals.graffito.jcr.persistence.atomicconverter;
 
 import java.io.ByteArrayInputStream;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -51,7 +52,7 @@
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public AtomicTest(String testName)
+    public AtomicTest(String testName) throws Exception
     {
         super(testName);
     }
@@ -87,6 +88,8 @@
             a.setCalendar(Calendar.getInstance());
             a.setDoubleObject(new Double(2.12));
             a.setDoublePrimitive(1.23);
+            long now = System.currentTimeMillis();
+            a.setTimestamp(new Timestamp(now));
             
             ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes());
             a.setInputStream(byteArrayInputStream);
@@ -119,7 +122,8 @@
             assertTrue("Incorrect double primitive", a.getDoublePrimitive() == 1.23);
             
             assertNotNull("Incorrect input stream primitive", a.getInputStream());
-            
+            assertNotNull("Incorrect timestamp", a.getTimestamp());
+            assertTrue("Invalid timestamp value ", a.getTimestamp().getTime() == now);
             
         }
         catch (Exception e)

Copied: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
(from r280409, incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java)
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java?p2=incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java&p1=incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java&r1=280409&r2=290789&rev=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/NullAtomicTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomicconverter/NullAtomicTest.java
Wed Sep 21 11:51:27 2005
@@ -14,7 +14,7 @@
  * limitations under the License.
  * ========================================================================
  */
-package org.apache.portals.graffito.jcr.persistence.impl;
+package org.apache.portals.graffito.jcr.persistence.atomicconverter;
 
 import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
@@ -51,7 +51,7 @@
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public NullAtomicTest(String testName)
+    public NullAtomicTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -76,9 +76,8 @@
             // Create and store an object graph in the repository
             // --------------------------------------------------------------------------------
             Atomic a = new Atomic();
-            a.setBooleanPrimitive(true);
-            a.setIntegerObject(new Integer(100));
-            a.setIntPrimitive(200);
+            
+            a.setIntegerObject(new Integer(100));            
             a.setDate(new Date());
             byte[] content = "Test Byte".getBytes();
             a.setByteArray(content);
@@ -100,10 +99,10 @@
             assertNotNull("a is null", a);
             assertNull("Boolean object is not null", a.getBooleanObject());
             
-            assertTrue("Incorrect boolean primitive", a.isBooleanPrimitive());
+            assertFalse("Incorrect boolean primitive", a.isBooleanPrimitive());
             assertNotNull("Integer Object is null", a.getIntegerObject());
             assertTrue("Incorrect Integer object", a.getIntegerObject().intValue() == 100);
-            assertTrue("Incorrect int primitive", a.getIntPrimitive() == 200);
+            assertTrue("Incorrect int primitive", a.getIntPrimitive() == 0);
             assertNull("String object is not null", a.getString());            
             assertNotNull("Byte array object is null", a.getByteArray());
             assertTrue("Incorrect byte object", new String(a.getByteArray()).equals("Test
Byte"));

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java?rev=290789&r1=290788&r2=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
Wed Sep 21 11:51:27 2005
@@ -48,7 +48,7 @@
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public PersistenceManagerTest(String testName)
+    public PersistenceManagerTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -102,28 +102,6 @@
             getPersistenceManager().insert("/test", a);
 
             // --------------------------------------------------------------------------------
-            // Check the jcr node structure
-            // --------------------------------------------------------------------------------
-            Session session = getPersistenceManager().getSession();
-            Node node = (Node) session.getItem("/test");
-            assertNotNull("A is null", node);
-            
-            assertTrue("Incorrect Name for '/test'", node.getName().equals("test"));
-
-            Property a1 = node.getProperty("a1");
-            assertNotNull("a1  is null", a1);
-            assertTrue("Incorrect a1", a1.getString().equals("a1"));
-            
-            Node nodeB = node.getNode("b");
-            assertNotNull("b is null", nodeB);
-            assertTrue("Incorrect b", nodeB.getName().equals("b"));
-            
-            Node nodeCollection = node.getNode("collection");
-            assertNotNull("collection is null", nodeCollection);
-            assertTrue("Incorrect number of items in the collection", nodeCollection.getNodes().getSize()
== 3);
-            
-             
-            // --------------------------------------------------------------------------------
             // Get the object
             // --------------------------------------------------------------------------------
          
             a = (A) getPersistenceManager().getObject(A.class, "/test");
@@ -165,145 +143,5 @@
         
     }
     
-    /**
-     * 
-     * Test for Folder object 
-     *
-     */
-    public void testFolder()
-    {
-        try
-        {
-
-            if (getPersistenceManager().itemExists("/test"))
-            {
-                getPersistenceManager().remove("/test");
-            }
-
-            // --------------------------------------------------------------------------------
-            // Create and store a folder in the repository
-            // --------------------------------------------------------------------------------
-            Folder folder = new Folder();
-            folder.setCreationDate(new Date());
-            folder.setDescription("Folder description");
-            folder.setTitle("Folder Title");
-            folder.setLastModified(new Date());
-            
-            folder.setName("TestFolder");
-            folder.setTitle("Folder Title");
-
-            getPersistenceManager().insert("/test", folder);
-
-            // --------------------------------------------------------------------------------
-            // Check the jcr node structure
-            // --------------------------------------------------------------------------------
-            Session session = getPersistenceManager().getSession();
-            Node folderNode = (Node) session.getItem("/test");
-            assertNotNull("Folder node is null", folderNode);
-            
-            //TODO - custom node types not working yet!
-            //assertTrue("Incorrect primary type", folderNode.getPrimaryNodeType().getName().equals("graffito:folder"));
-            
-            assertTrue("Incorrect Name for '/test'", folderNode.getName().equals("test"));
-
-            Property description = folderNode.getProperty("description");
-            assertNotNull("Folder description  is null", description);
-            assertTrue("Incorrect description for '/test'", description.getString().equals("Folder
description"));
 
-            // --------------------------------------------------------------------------------
-            // Get the object
-            // --------------------------------------------------------------------------------
          
-            folder = (Folder) getPersistenceManager().getObject(Folder.class, "/test");
-            assertNotNull("Folder object is null", folder);
-            assertTrue("Incorrect description for folder object", folder.getDescription().equals("Folder
description"));
-
-            // --------------------------------------------------------------------------------
-            // Update the object
-            // --------------------------------------------------------------------------------
          
-//            folder.setDescription("new folder description");
-//            getPersistenceManager().update("/test", folder);
-//
-//            assertTrue("Incorrect description for folder object", ((Property) session.getItem("/test/graffito:description"))
-//                    .getString().equals("new folder description"));
-            
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-            fail("Exception occurs during the unit test : " + e);
-        }
-    }
-    
-    /**
-     * 
-     * Test for document object 
-     *
-     */
-//    public void testDocument()
-//    {
-//        try
-//        {
-//
-//            if (getPersistenceManager().itemExists("/testdoc"))
-//            {
-//                getPersistenceManager().remove("/testdoc");
-//            }
-//
-//            // --------------------------------------------------------------------------------
-//            // Create and store a document in the repository
-//            // --------------------------------------------------------------------------------
-//            Document document = new Document();
-//            document.setCreationDate(new Date());
-//            document.setDescription("Document description");
-//            document.setTitle("Document Title");
-//            document.setLastModified(new Date());           
-//            document.setName("testdoc");
-//            
-//            Content content = new Content();
-//            content.setContent("test".getBytes());
-//            document.setContentType("plain/text");
-//            content.setEncoding("utf-8");
-//            document.setContent(content);            
-//            
-//            getPersistenceManager().insert("/testdoc", document);
-//
-//            // --------------------------------------------------------------------------------
-//            // Check the jcr node structure
-//            // --------------------------------------------------------------------------------
-//            Session session = getPersistenceManager().getSession();
-//            Node documentNode = (Node) session.getItem("/testdoc");
-//            assertNotNull("Document node is null", documentNode);
-//            
-//            //TODO - custom node types not working yet!
-//            //assertTrue("Incorrect primary type", documentNode.getPrimaryNodeType().getName().equals("graffito:file"));
-//            
-//            assertTrue("Incorrect Name for '/testdoc'", documentNode.getName().equals("testdoc"));
-//
-//            Property description = documentNode.getProperty("graffito:description");
-//            assertNotNull("document description  is null", description);
-//            assertTrue("Incorrect description for '/testdoc'", description.getString().equals("Document
description"));
-//
-//            // --------------------------------------------------------------------------------
-//            // Get the object
-//            // --------------------------------------------------------------------------------
          
-//            document = (Document) getPersistenceManager().getObject(Document.class, "/testdoc");
-//            assertNotNull("Folder object is null", document);
-//            assertTrue("Incorrect description for folder object", document.getDescription().equals("Document
description"));
-//
-//            // --------------------------------------------------------------------------------
-//            // Update the object
-//            // --------------------------------------------------------------------------------
          
-//            document.setDescription("new document description");
-//            getPersistenceManager().update("/testdoc", document);
-//
-//            assertTrue("Incorrect description for document object", ((Property) session.getItem("/testdoc/graffito:description"))
-//                    .getString().equals("new document description"));
-//
-//        }
-//        catch (Exception e)
-//        {
-//            e.printStackTrace();
-//            fail("Exception occurs during the unit test : " + e);
-//        }
-//    }
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java?rev=290789&r1=290788&r2=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/repository/RepositoryUtilTest.java
Wed Sep 21 11:51:27 2005
@@ -35,7 +35,7 @@
 public class RepositoryUtilTest extends TestCase
 {
     private final static Log log = LogFactory.getLog(RepositoryUtilTest.class);
-
+    private static boolean isInit = false;
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
@@ -51,7 +51,11 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-        RepositoryUtil.registerRepository("repositoryTest", "src/conf/repository.xml", "target/repository");
+        if (! isInit)
+        {
+            RepositoryUtil.registerRepository("repositoryTest", "src/test-config/repository.xml",
"target/repository");
+            isInit = true;
+        }
     }
 
     /**

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java?rev=290789&r1=290788&r2=290789&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Atomic.java
Wed Sep 21 11:51:27 2005
@@ -16,6 +16,7 @@
 package org.apache.portals.graffito.jcr.testmodel;
 
 import java.io.InputStream;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -40,6 +41,7 @@
     private Double doubleObject;
     private double doublePrimitive;
     private InputStream inputStream;
+    private Timestamp timestamp;
     
     
     public Boolean getBooleanObject()
@@ -129,6 +131,14 @@
     public void setInputStream(InputStream inputStream)
     {
         this.inputStream = inputStream;
+    }
+    public Timestamp getTimestamp()
+    {
+        return timestamp;
+    }
+    public void setTimestamp(Timestamp timestamp)
+    {
+        this.timestamp = timestamp;
     }
     
     



Mime
View raw message