jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r165130 - in /incubator/jackrabbit/trunk: applications/test/ src/test/org/apache/jackrabbit/test/api/
Date Thu, 28 Apr 2005 11:40:03 GMT
Author: dpfister
Date: Thu Apr 28 04:40:01 2005
New Revision: 165130

URL: http://svn.apache.org/viewcvs?rev=165130&view=rev
Log:
Improved test cases

Modified:
    incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/DocumentViewImportTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationContext.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TreeComparator.java

Modified: incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties?rev=165130&r1=165129&r2=165130&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties (original)
+++ incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties Thu Apr 28
04:40:01 2005
@@ -250,6 +250,9 @@
 # a tree at a different location.
 javax.jcr.tck.SerializationTest.propertyValueMayChange= jcr:created jcr:uuid jcr:versionHistory
jcr:baseVersion jcr:predecessors P_Reference
 
+# List all properties which are skipped during xml import according specification chapter
7.3.3
+javax.jcr.tck.SerializationTest.propertySkipped=
+
 # The name of the test node types. For easier diagnostics, the node types have names
 # that tell you the kind of information they store
 javax.jcr.tck.SerializationTest.nodeTypesTestNode=NodeTypes
@@ -272,6 +275,9 @@
 javax.jcr.tck.SerializationTest.pathTestProperty=P_Path
 javax.jcr.tck.SerializationTest.referenceTestProperty=P_Reference
 javax.jcr.tck.SerializationTest.multiValueTestProperty=P_MultiValue
+
+# node type not allowing same name sibs
+javax.jcr.tck.SerializationTest.sameNameSibsFalseChildNodeDefinition=test:sameNameSibsFalseChildNodeDefinition
 
 # Test method: testVersioningExceptionSessionFileChild
 # specified nodetype must be versionable and allow child nodes of the same type.

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java?rev=165130&r1=165129&r2=165130&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
Thu Apr 28 04:40:01 2005
@@ -59,6 +59,8 @@
 
     protected final boolean WORKSPACE = true;
     protected final boolean SESSION = false;
+    protected boolean CONTENTHANDLER = true;
+    protected boolean STREAM = false;
 
     // the absolute path to the target nodes for the imports
     protected String target;
@@ -321,7 +323,8 @@
     /**
      * Creates a document with a element rootElem containing a jcr:uuid
      * attribute with the given uuid as value. This document is imported below
-     * the refTargetNode. If there is yet a node rootElem then this node is
+     * the node with path absPath. If nod node at absPth it is created.
+     * If there is yet a node rootElem below the then this node is
      * romoved in advance.
      *
      * @param uuid
@@ -331,7 +334,7 @@
      * @throws RepositoryException
      * @throws IOException
      */
-    public void importRefNodeDocument(String uuid, int uuidBehaviour,
+    public void importRefNodeDocument(String absPath, String uuid, int uuidBehaviour,
                                       boolean withWorkspace, boolean withHandler)
             throws RepositoryException, IOException, SAXException {
 
@@ -343,19 +346,26 @@
         root.setAttribute(propertyName1, "some text");
         document.appendChild(root);
 
-        // remove a yet existing node at the target
+        Node targetNode = null;
         try {
-            Node node = refTargetNode.getNode(rootElem);
-            node.remove();
-            session.save();
+            targetNode = (Node) session.getItem(absPath);
+            // remove a yet existing node at the target
+            try {
+                Node node = targetNode.getNode(rootElem);
+                node.remove();
+                session.save();
+            } catch (PathNotFoundException pnfe) {
+                // ok
+            }
         } catch (PathNotFoundException pnfe) {
-            // ok
+            // create the node
+            targetNode = createAncestors(absPath);
         }
 
         if (withHandler) {
-            importWithHandler(refTargetNode.getPath(), document, uuidBehaviour, withWorkspace);
+            importWithHandler(targetNode.getPath(), document, uuidBehaviour, withWorkspace);
         } else {
-            importXML(refTargetNode.getPath(), document, uuidBehaviour, withWorkspace);
+            importXML(targetNode.getPath(), document, uuidBehaviour, withWorkspace);
         }
         session.save();
     }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/DocumentViewImportTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/DocumentViewImportTest.java?rev=165130&r1=165129&r2=165130&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/DocumentViewImportTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/DocumentViewImportTest.java
Thu Apr 28 04:40:01 2005
@@ -28,7 +28,14 @@
 import javax.jcr.NamespaceException;
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.ItemExistsException;
+import javax.jcr.nodetype.ConstraintViolationException;
 import java.io.IOException;
+import java.io.FileInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * <code>DocumentViewImportTest</code> Tests importXML and
@@ -275,7 +282,7 @@
 
         String uuid = createReferenceableNode(referenced);
         // import a document with a element having the same uuid as the node referenced
-        importRefNodeDocument(uuid, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, withWorkspace,
withHandler);
+        importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
withWorkspace, withHandler);
 
         // different uuid?
         Node node = refTargetNode.getNode(rootElem);
@@ -293,7 +300,7 @@
 
         String uuid = createReferenceableNode(referenced);
         // import a document with a element having the same uuid as the node referenced
-        importRefNodeDocument(uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING,
+        importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING,
                 withWorkspace, withHandler);
 
         try {
@@ -323,7 +330,7 @@
 
         String uuid = createReferenceableNode(referenced);
         // import a document with a element having the same uuid as the node referenced
-        importRefNodeDocument(uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING,
+        importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING,
                 withWorkspace, withHandler);
 
         // should be replaced i.e should be modified, in case Workspace method is used
@@ -348,7 +355,7 @@
 
         String uuid = createReferenceableNode(referenced);
         try {
-            importRefNodeDocument(uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
+            importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
                     withWorkspace, withHandler);
             fail("UUID behavior IMPORT_UUID_COLLISION_THROW test is failed: " +
                     "should throw an Exception.");
@@ -365,5 +372,60 @@
                 throw e;
             }
         }
+    }
+  //-------------------------------< exception tests >--------------------------------------
+    /**
+     * Tests correct failure of importing a element wit the same UUID as the target node
or
+     * an ancestor of it in case of uuidBehavior IMPORT_UUID_COLLISION_REMOVE_EXISTING.
+     *
+     * The imported document contains a element with jcr:uuid attribute the same as the
+     * parent of the import target.
+     */
+    public void doTestSameUUIDAtAncestor(boolean withWorkspace, boolean withHandler)
+            throws RepositoryException, IOException, SAXException {
+
+        String uuid = createReferenceableNode(referenced);
+        Node node = testRootNode.getNode(referenced);
+        Node node2 = node.addNode("newParent");
+        session.save();
+        // import a document with a element having the same uuid as the node referenced
+        try {
+            importRefNodeDocument(node2.getPath(), uuid,
+                ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING,
+                    withWorkspace, withHandler);
+            fail("UUID collision with an ancestor of the target node hould throw a " +
+                    "SAXException or a ConstraintViolationException in case of " +
+                    "uuidBehavior IMPORT_UUID_COLLISION_REMOVE_EXISTING.");
+        } catch(SAXException se) {
+            if (!withHandler) {
+                throw se;
+            }
+            // ok
+        } catch (ConstraintViolationException cve) {
+            if (withHandler) {
+                throw cve;
+            }
+            // ok
+        }
+    }
+
+    public void testSameUUIDAtAncestorWorkspaceHandler()
+            throws RepositoryException, IOException, SAXException {
+        doTestSameUUIDAtAncestor(WORKSPACE, CONTENTHANDLER);
+    }
+
+    public void testSameUUIDAtAncestorWorkspace()
+            throws RepositoryException, IOException, SAXException {
+        doTestSameUUIDAtAncestor(WORKSPACE, STREAM);
+    }
+
+    public void testSameUUIDAtAncestorSessionHandler()
+            throws RepositoryException, IOException, SAXException  {
+        doTestSameUUIDAtAncestor(SESSION, CONTENTHANDLER);
+    }
+
+    public void testSameUUIDAtAncestorSession()
+            throws RepositoryException, IOException, SAXException{
+        doTestSameUUIDAtAncestor(SESSION, STREAM);
     }
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationContext.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationContext.java?rev=165130&r1=165129&r2=165130&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationContext.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationContext.java
Thu Apr 28 04:40:01 2005
@@ -34,6 +34,7 @@
     public String rootNodeName;
 
     public String propertyValueMayChange;
+    public String propertySkipped;
 
     public String nodeTypesTestNode;
     public String mixinTypeTestNode;
@@ -43,6 +44,8 @@
     public String referenceableNodeTestNode;
     public String orderChildrenTestNode;
     public String namespaceTestNode;
+    public String sameNameSibsFalseChildNodeDefinition;
+
 
     public String stringTestProperty;
     public String binaryTestProperty;
@@ -66,6 +69,7 @@
         rootNodeName = get("rootNodeName");
 
         propertyValueMayChange = " " + get("propertyValueMayChange") + " ";
+        propertySkipped = " " + get("propertySkipped") + " ";
 
         nodeTypesTestNode = get("nodeTypesTestNode");
         mixinTypeTestNode = get("mixinTypeTestNode");
@@ -75,6 +79,7 @@
         referenceableNodeTestNode = get("referenceableNodeTestNode");
         orderChildrenTestNode = get("orderChildrenTestNode");
         namespaceTestNode = get("namespaceTestNode");
+        sameNameSibsFalseChildNodeDefinition = get("sameNameSibsFalseChildNodeDefinition");
 
         stringTestProperty = get("stringTestProperty");
         binaryTestProperty = get("binaryTestProperty");

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationTest.java?rev=165130&r1=165129&r2=165130&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SerializationTest.java
Thu Apr 28 04:40:01 2005
@@ -25,24 +25,13 @@
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
-import javax.jcr.ImportUUIDBehavior;
-import javax.jcr.ItemExistsException;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Workspace;
+import javax.jcr.*;
 import javax.jcr.version.VersionException;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
+import javax.jcr.nodetype.*;
+import java.io.*;
+import java.util.ArrayList;
 
 /**
  * <code>SerializationTest</code> contains the test cases for the method
@@ -57,18 +46,18 @@
  * @keywords level2
  */
 public class SerializationTest extends AbstractJCRTest {
-    private Workspace workspace;
-    private File file;
-    private TreeComparator treeComparator;
-
-    private final boolean CONTENTHANDLER = true, STREAM = false;
-    private final boolean WORKSPACE = true, SESSION = false;
-    private final boolean SKIPBINARY = true, SAVEBINARY = false;
-    private final boolean NORECURSE = true, RECURSE = false;
+    protected Workspace workspace;
+    protected File file;
+    protected TreeComparator treeComparator;
+
+    protected final boolean CONTENTHANDLER = true, STREAM = false;
+    protected final boolean WORKSPACE = true, SESSION = false;
+    protected final boolean SKIPBINARY = true, SAVEBINARY = false;
+    protected final boolean NORECURSE = true, RECURSE = false;
 
-    private Session session;
+    protected Session session;
 
-    protected void setUp() throws RepositoryException, Exception {
+    public void setUp() throws RepositoryException, Exception {
         super.setUp();
 
         session = superuser;
@@ -81,46 +70,12 @@
         treeComparator.createComplexTree(treeComparator.WORKSPACE);
     }
 
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
         file.delete();
         super.tearDown();
     }
 
-    /**
-     * Imports a tree directly below a node that is checked in. This should
-     * fail, because you need to check out the node before you can make any
-     * changes to it or its children.
-     */
-    public void testVersioningExceptionSessionFileParent()
-            throws RepositoryException, NotExecutableException, IOException {
-        Node n = initVersioningException(true);
-
-        FileInputStream in = new FileInputStream(file);
-        try {
-            session.importXML(n.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
-            fail("Importing to a checked-in node must throw a VersionException.");
-        } catch (VersionException e) {
-            // success
-        }
-    }
-
-    /**
-     * Imports a tree below a child node of a checked-in node. This should fail,
-     * because you need to check out the node before you can make any changes to
-     * it or its children.
-     */
-    public void testVersioningExceptionSessionFileChild()
-            throws RepositoryException, NotExecutableException, IOException {
-        Node n = initVersioningException(false);
-        FileInputStream in = new FileInputStream(file);
-        try {
-            session.importXML(n.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
-            fail("Importing to a child of a checked-in node must throw a VersionException.");
-        } catch (VersionException e) {
-            // success
-        }
-    }
-
+// ---------------< versioning exception tests >-----------------------------------------
     /**
      * Creates a simple target tree consisting of a checked-in node and an
      * ordinary child node below. Throws a {@link NotExecutableException} if
@@ -131,13 +86,12 @@
      * @return The requested node (a node that is checked in or that has a
      *         parent that is checked in).
      */
-    private Node initVersioningException(boolean returnParent) throws RepositoryException,
NotExecutableException, IOException {
+    protected Node initVersioningException(boolean returnParent) throws RepositoryException,
NotExecutableException, IOException {
         Node vNode = testRootNode.addNode(nodeName1, testNodeType);
         if (!vNode.isNodeType(mixVersionable)) {
             throw new NotExecutableException("NodeType: " + testNodeType + " is not versionable");
         }
-        // add non-versionable child
-        Node vChild = vNode.addNode(nodeName2, ntBase);
+        Node vChild = vNode.addNode(nodeName2, testNodeType);
         session.save();
         vNode.checkin();
 
@@ -150,10 +104,78 @@
         }
     }
 
+    public void doTestVersioningExceptionFileParent(boolean useWorkspace, boolean useHandler)
+        throws RepositoryException, NotExecutableException, IOException, SAXException {
+        Node n = initVersioningException(true);
+
+        FileInputStream in = new FileInputStream(file);
+        try {
+            doImport(n.getPath(), in, useWorkspace, useHandler);
+            fail("Importing to a checked-in node must throw a ConstraintViolationException.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
+
+    public void doTestVersioningExceptionFileChild(boolean useWorkspace, boolean useHandler)
+        throws RepositoryException, NotExecutableException, IOException, SAXException {
+        Node n = initVersioningException(false);
+
+        FileInputStream in = new FileInputStream(file);
+        try {
+            doImport(n.getPath(), in, useWorkspace, useHandler);
+            fail("Importing to a child of a checked-in node must throw a ConstraintViolationException.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
+
+    public void testVersioningExceptionFileParentWorkspaceContentHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileParent(WORKSPACE, CONTENTHANDLER);
+    }
+
+    public void testVersioningExceptionFileParentSessionContentHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileParent(SESSION, CONTENTHANDLER);
+    }
+
+    public void testVersioningExceptionFileParentWorkspace()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileParent(WORKSPACE, STREAM);
+    }
+
+    public void testVersioningExceptionFileParentSession()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileParent(SESSION, STREAM);
+    }
+
+    public void testVersioningExceptionFileChildWorkspaceContentHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(WORKSPACE, CONTENTHANDLER);
+    }
+
+    public void testVersioningExceptionFileChildSessionContentHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(SESSION, CONTENTHANDLER);
+    }
+
+    public void testVersioningExceptionFileChildWorkspace()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(WORKSPACE, STREAM);
+    }
+
+    public void testVersioningExceptionFileChildSession()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(SESSION, STREAM);
+    }
+
+// ----------------< locking exceptions tests >----------------------------
     /**
      * Tests whether importing a tree respects locking.
      */
-    public void testLockException() throws RepositoryException, IOException {
+    public void doTestLockException(boolean useWorkspace, boolean useHandler)
+            throws RepositoryException, IOException, SAXException {
         Repository repository = session.getRepository();
         exportRepository(SKIPBINARY, RECURSE);
         if (repository.getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) != null) {
@@ -165,8 +187,7 @@
             session.removeLockToken(lock.getLockToken());   //remove the token, so the lock
is for me, too
             FileInputStream in = new FileInputStream(file);
             try {
-                session.importXML(lNode.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
-                fail("De-serializing to a locked node must throw a lock exception.");
+                doImport(lNode.getPath(), in, useWorkspace, useHandler);
             } catch (LockException e) {
                 // success
             }
@@ -175,6 +196,27 @@
         }
     }
 
+    public void testLockExceptionWorkspaceWithHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(WORKSPACE, CONTENTHANDLER);
+    }
+
+    public void testLockExceptionSessionWithHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(SESSION, CONTENTHANDLER);
+    }
+
+    public void testLockExceptionWorkspace()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(WORKSPACE, STREAM);
+    }
+
+    public void testLockExceptionSession()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestVersioningExceptionFileChild(SESSION, STREAM);
+    }
+
+//--------------< Import of invalid xml file tests >-------------------------------------------
     /**
      * Tests whether importing an invalid XML file throws a SAX exception. The
      * file used here is more or less garbage.
@@ -199,14 +241,14 @@
         helpTestSaxException(ih, in, "workspace");
     }
 
-    /**
+  /**
      * Helper method for testSaxException.
      *
      * @param ih
      * @param in
      */
     private void helpTestSaxException(ContentHandler ih, Reader in, String mode) {
-        XMLReader parser;
+        XMLReader parser = null;
         try {
             parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
             parser.setContentHandler(ih);
@@ -223,10 +265,53 @@
     }
 
     /**
+     *
+     * Tests whether importing an invalid XML file throws a InvalidSerializedDataException.
+     * The file used here is more or less garbage.
+     */
+    public void testInvalidXmlThrowsInvalidSerializedDataException()
+            throws RepositoryException, IOException{
+
+        String data = "<this is not a <valid> <xml> file/>";
+        ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
+
+        try {
+            session.importXML(treeComparator.targetFolder, in,
+                    ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+            fail("Importing a invalid XML file should throw a InvalidSerializedDataException.");
+        } catch (InvalidSerializedDataException e) {
+            // ok
+        }
+        in = new ByteArrayInputStream(data.getBytes());
+        try {
+            workspace.importXML(treeComparator.targetFolder, in, 0);
+            fail("Importing a invalid XML file should throw a InvalidSerializedDataException.");
+        } catch (InvalidSerializedDataException e) {
+            // ok
+        }
+    }
+
+// -------------------< PathNotFoundException tests >------------------------------------
+    /**
      * Supplying an invalid repository path for import must throw a
      * PathNotFoundException
      */
-    public void testGetImportContentHandlerExceptions() throws RepositoryException {
+    public void testWorkspaceGetImportContentHandlerExceptions() throws RepositoryException
{
+        //Specifying a path that does not exist throws a PathNotFound exception
+        try {
+            workspace.getImportContentHandler(treeComparator.targetFolder + "/thisIsNotAnExistingNode",
+                    ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+            fail("Specifying a non-existing path must throw a PathNotFoudException.");
+        } catch (PathNotFoundException e) {
+            // success
+        }
+    }
+
+    /**
+     * Supplying an invalid repository path for import must throw a
+     * PathNotFoundException
+     */
+    public void testSessionGetImportContentHandlerExceptions() throws RepositoryException
{
         //Specifying a path that does not exist throws a PathNotFound exception
         try {
             session.getImportContentHandler(treeComparator.targetFolder + "/thisIsNotAnExistingNode",
@@ -271,43 +356,130 @@
         }
     }
 
+// ---------------< Overwrite existing target node tests     >------------------------------
+// ---------------< in case same name siblings not supported >------------------------------
     /**
-     * Tries to overwrite an existing node.
-     * @tck.config nodetype name of a node type, that does not allow same name
-     *  siblings. The node type must allow child nodes of its own type.
-     * @tck.config nodename1 name for a node of type <code>nodetype</code>.
-     * @tck.config nodename2 name for a node of type <code>nodetype</code>.
-     */
-    public void testSessionImportXmlOverwriteException() throws RepositoryException, IOException
{
-        // If deserialization would overwrite an existing item, an ItemExistsException is
thrown.
-
-        // create a folder node and a child node
-        Node folder;
-        Node subfolder;
-        FileOutputStream out;
-        FileInputStream in;
-        folder = testRootNode.addNode(nodeName1, testNodeType);
-        subfolder = folder.addNode(nodeName1, testNodeType);
+     * Tries to overwrite an existing node. This only works for nodes that do
+     * not allow same-name siblings.
+     */
+    public void doTestOverwriteException(boolean useWorkspace, boolean useHandler)
+            throws RepositoryException, IOException, SAXException, NotExecutableException
{
+        //If deserialization would overwrite an existing item,
+        // an ItemExistsException respective a SAXException is thrown.
+
+        Node folder = testRootNode.addNode("myFolder", treeComparator.sc.sameNameSibsFalseChildNodeDefinition);
+        Node subfolder = folder.addNode("subfolder");
+
         session.save();
-        out = new FileOutputStream(file);
+        FileOutputStream out = new FileOutputStream(file);
         session.exportSystemView(subfolder.getPath(), out, true, true);
-        out.close();
-        in = new FileInputStream(file);
-        try {
-            session.importXML(folder.getPath(), in,
-                    ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
-            session.save();
-            fail("Overwriting an existing node during import must throw an ItemExistsException");
-        } catch (ItemExistsException e) {
+
+        FileInputStream in = new FileInputStream(file);
+        if (useHandler) {
+            try {
+            doImport(folder.getPath(), in, useWorkspace, useHandler);
+            fail("Overwriting an existing node during import must throw a SAXException");
+            } catch (SAXException e) {
             // success
+            }
+        }
+        else {
+            try {
+                doImport(folder.getPath(), in, useWorkspace, useHandler);
+                fail("Overwriting an existing node during import must throw an ItemExistsException");
+            } catch (ItemExistsException e) {
+                     // success
+            }
         }
     }
 
+   public void testOverwriteExceptionWorkspaceWithHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestOverwriteException(WORKSPACE, CONTENTHANDLER);
+    }
+
+    public void testOverwriteExceptionSessionWithHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestOverwriteException(SESSION, CONTENTHANDLER);
+    }
+
+    public void testOverwriteExceptionWorkspace()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestOverwriteException(WORKSPACE, STREAM);
+    }
+
+    public void testOverwriteExceptionSession()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestOverwriteException(SESSION, STREAM);
+    }
+
+  // ------------------< Node type constraint violation tests >--------------------------------
+    /**
+     * Create a node named ntBase with node type nt:base
+     * and creates a tree in the repository which will be exported
+     * and reimported below the node ntBase.
+     * @param useWorkspace
+     * @param useHandler
+     * @throws RepositoryException
+     * @throws FileNotFoundException
+     * @throws IOException
+     */
+    public void doTestNodeTypeConstraintViolation(boolean useWorkspace, boolean useHandler)
+          throws RepositoryException, FileNotFoundException, IOException, SAXException {
+
+        treeComparator.createExampleTree();
+        Node node = testRootNode.addNode("ntBase", ntBase);
+        session.save();
+
+        FileInputStream in = new FileInputStream(file);
+        if (useHandler) {
+            try {
+                doImport(node.getPath(), in, useWorkspace, useHandler);
+                fail("Node type constraint violation should throw a SAXException " +
+                        "during xml import using a Contenthandler.");
+            }  catch (SAXException se) {
+                // ok
+            }
+        }
+        else {
+            try {
+                doImport(node.getPath(), in, useWorkspace, useHandler);
+                 fail("Node type constraint violation should throw a  " +
+                        " InvalidSerializedDataException during xml import " +
+                         "using a Contenthandler.");
+            } catch (InvalidSerializedDataException isde) {
+            // ok
+            }
+        }
+    }
+
+
+  public void testNodeTypeConstraintViolationWorkspaceWithHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestNodeTypeConstraintViolation(WORKSPACE, CONTENTHANDLER);
+    }
+
+    public void testNodeTypeConstraintViolationSessionWithHandler()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestNodeTypeConstraintViolation(SESSION, CONTENTHANDLER);
+    }
+
+    public void testNodeTypeConstraintViolationWorkspace()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestNodeTypeConstraintViolation(WORKSPACE, STREAM);
+    }
+
+    public void testNodeTypeConstraintViolationSession()
+            throws RepositoryException, NotExecutableException, IOException, SAXException
{
+        doTestNodeTypeConstraintViolation(SESSION, STREAM);
+    }
+
+// ------------< tests that nothing is imported if session is closed before saving the
import >-----------------
     /**
      * Makes sure that importing into the session does not save anything if the
      * session is closed.
      */
-    public void testSessionImportXml() throws Exception {
+    public void testSessionImportXml() throws RepositoryException, IOException {
         FileInputStream in = new FileInputStream(file);
         exportRepository(SAVEBINARY, RECURSE);
         session.importXML(treeComparator.targetFolder, in,
@@ -315,12 +487,88 @@
 
         // after logout/login, no nodes are in the session
         session.logout();
-        superuser = null; // so tearDown won't fail
+        superuser = null; //so tearDown won't fail
+
+        session = helper.getReadWriteSession();
+        treeComparator.setSession(session);
+        treeComparator.compare(treeComparator.CHECK_EMPTY);
+    }
+
+
+    /**
+     * Makes sure that importing into the session does not save anything if the
+     * session is closed.
+     */
+    public void testSessionGetContentHandler() throws RepositoryException, IOException, SAXException
{
+        FileInputStream in = new FileInputStream(file);
+        exportRepository(SAVEBINARY, RECURSE);
+        doImportNoSave(treeComparator.targetFolder, in, CONTENTHANDLER);
+
+        // after logout/login, no nodes are in the session
+        session.logout();
+        superuser = null; //so tearDown won't fail
 
         session = helper.getReadWriteSession();
-        Node targetFolder = (Node) session.getItem(treeComparator.targetFolder);
-        assertFalse("Session.importXML() must not save imported nodes.", targetFolder.hasNodes());
+        treeComparator.setSession(session);
+        treeComparator.compare(treeComparator.CHECK_EMPTY);
+    }
+
+//----------------< import test helper >--------------------------------------------------------
+    /**
+     * Helper method which imports the given FileInputStream using Workspace or Session
+     * and via the methods importXML respective getImportContentHandler. Teh target node
of the
+     * import is specified with its absolut path.
+     *
+     * @param absPath
+     * @param in
+     * @param useWorkspace
+     * @param useHandler
+     * @throws RepositoryException
+     * @throws IOException
+     */
+    public void doImport(String absPath, FileInputStream in, boolean useWorkspace, boolean
useHandler)
+            throws RepositoryException, IOException, SAXException {
+        if (useHandler) {
+            if (useWorkspace) {
+                ContentHandler ih = workspace.getImportContentHandler(absPath, 0);
+                XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+                parser.setContentHandler(ih);
+                parser.setErrorHandler((ErrorHandler) ih);
+                parser.parse(new InputSource(in));
+            } else {
+                ContentHandler ih = session.getImportContentHandler(absPath, 0);
+
+                XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+                parser.setContentHandler(ih);
+                parser.setErrorHandler((ErrorHandler) ih);
+                parser.parse(new InputSource(in));
+                session.save();
+            }
+        } else {
+            if (useWorkspace) {
+                workspace.importXML(absPath, in, 0);
+            } else {
+                session.importXML(absPath, in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+                session.save();
+            }
+        }
+    }
+
+   public void doImportNoSave(String absPath, FileInputStream in, boolean useHandler)
+            throws RepositoryException, IOException, SAXException {
+        if (useHandler) {
+            ContentHandler ih = session.getImportContentHandler(absPath, 0);
+
+            XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+            parser.setContentHandler(ih);
+            parser.setErrorHandler((ErrorHandler) ih);
+            parser.parse(new InputSource(in));
+        }
+        else {
+            session.importXML(absPath, in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+        }
     }
+//------------< System view export import tests >-----------------------------------
 
     public void testExportSysView_stream_workspace_skipBinary_noRecurse() throws IOException,
RepositoryException {
         doTest(STREAM, WORKSPACE, SKIPBINARY, NORECURSE);
@@ -419,6 +667,7 @@
     private void exportRepository(boolean skipBinary, boolean noRecurse) throws IOException
{
         FileOutputStream out;
         try {
+            //File file = new File("C:\\exportTestOutput");
             out = new FileOutputStream(file);
             session.refresh(false); //move the workspace into the session, then save it.
The workspace is always valid, the session not necessarily.
             session.exportSystemView(treeComparator.getSourceRootPath(), out, skipBinary,
noRecurse);
@@ -462,6 +711,7 @@
                     parser.setContentHandler(ih);
                     parser.setErrorHandler((ErrorHandler) ih);
                     parser.parse(new InputSource(in));
+                    session.save();
                 } catch (SAXException e) {
                     fail("Error while parsing the imported repository: " + e);
                 }
@@ -472,6 +722,7 @@
             } else {
                 session.importXML(treeComparator.targetFolder, in,
                         ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+                session.save();
             }
         }
     }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TreeComparator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TreeComparator.java?rev=165130&r1=165129&r2=165130&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TreeComparator.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TreeComparator.java
Thu Apr 28 04:40:01 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.log4j.Level;
 
 import javax.jcr.Session;
 import javax.jcr.Workspace;
@@ -72,6 +73,10 @@
         init();
     }
 
+    public void setSession(Session session) {
+        this.session = session;
+    }
+    
     /**
      * Makes sure that the source and target folder exist, and are empty
      */
@@ -395,6 +400,14 @@
         while (ai.hasNext()) {
             Property pa = (Property) ai.next();
             String pName = null;
+            // todo
+            String pPath = null;
+            try {
+                pPath = pa.getPath();
+            } catch (RepositoryException e) {
+
+            }
+
             int pType = 0;
 
             try {
@@ -413,27 +426,31 @@
             }
 
             Property pb = null;
-            try {
-                pb = b.getProperty(pName);
-                //fail if the property is there but should not be
-                if (skipBinary && pType == PropertyType.BINARY) {
-                    fail("Property '" + pName + "' must not be available if skipBinary=true.");
+            // avoid skipped properties
+            if (!propertySkipped(pName)) {
+                try {
+                    pb = b.getProperty(pName);
+                    //fail if the property is there but should not be
+                    if (skipBinary && pType == PropertyType.BINARY) {
+                        // todo
+                        fail("Property '" + pPath + "' must not be available if skipBinary=true.");
+                    }
+
+                } catch (RepositoryException e) {
+                    //fail if the property is not there but should
+                    if (!(skipBinary && pType == PropertyType.BINARY)) {
+                        // todo
+                        fail("Property '" + pPath + "' not available: " + e);
+                        fail("Property '" + pPath + "' not available: " + e);
+                    }
                 }
 
-            } catch (RepositoryException e) {
-                //fail if the property is not there but should
+                //if the property should be available and is available, then compare source
and target value
                 if (!(skipBinary && pType == PropertyType.BINARY)) {
-                    fail("Property '" + pName + "' not available: " + e);
+                    compareProperties(pa, pb);
                 }
             }
-
-            //if the property should be available and is available, then compare source and
target value
-            if (!(skipBinary && pType == PropertyType.BINARY)) {
-                compareProperties(pa, pb);
-            }
-
         }
-
     }
 
     /**
@@ -572,6 +589,20 @@
         NodeIterator ni = n.getNodes();
         while (ni.hasNext()) {
             showTree((Node) ni.next(), level + 1);
+        }
+    }
+
+    /**
+     * Checks if a given property should be skipped during xml import.
+     *  
+     * @param propertyName
+     * @return
+     */
+   public boolean propertySkipped(String propertyName) {
+        if (sc.propertySkipped.indexOf(" " + propertyName + " ") < 0) {
+            return false;
+        } else {
+            return true;
         }
     }
 }



Mime
View raw message