You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2006/07/25 11:06:14 UTC

svn commit: r425338 - in /jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api: ExportSysViewTest.java SysViewContentHandler.java

Author: mreutegg
Date: Tue Jul 25 02:06:13 2006
New Revision: 425338

URL: http://svn.apache.org/viewvc?rev=425338&view=rev
Log:
JCR-489: TCK: Incorrect check of namespace mappings in System View XML export

Modified:
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SysViewContentHandler.java

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java?rev=425338&r1=425337&r2=425338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java (original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java Tue Jul 25 02:06:13 2006
@@ -23,7 +23,6 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.helpers.XMLReaderFactory;
 
-import javax.jcr.Workspace;
 import javax.jcr.Session;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -46,27 +45,22 @@
  */
 public class ExportSysViewTest extends AbstractJCRTest {
 
-    private Workspace workspace;
     private File file;
 
-    private final boolean WORKSPACE = true, SESSION = false;
     private final boolean SKIPBINARY = true, SAVEBINARY = false;
     private final boolean NORECURSE = true, RECURSE = false;
 
     private Session session;
     private String testPath;
-    private Node testNode;
 
 
     protected void setUp() throws Exception {
         isReadOnly = true;
         session = helper.getReadOnlySession();
-        workspace = session.getWorkspace();
         file = File.createTempFile("SysViewExportTest", ".xml");
 
         super.setUp();
         this.testPath = testRoot;
-        this.testNode = (Node) session.getItem(testPath);
     }
 
     protected void tearDown() throws Exception {
@@ -77,90 +71,44 @@
         super.tearDown();
     }
 
-    /*
-    // tests with content handler
-    public void testExportSysView_handler_workspace_skipBinary_noRecurse()
-            throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(WORKSPACE, SKIPBINARY, NORECURSE);
-    }
-
-    public void testExportSysView_handler_workspace_skipBinary_recurse()
-            throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(WORKSPACE, SKIPBINARY, RECURSE);
-    }
-
-    public void testExportSysView_handler_workspace_saveBinary_noRecurse()
-            throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(WORKSPACE, SAVEBINARY, NORECURSE);
-    }
-
-    public void testExportSysView_handler_workspace_saveBinary_recurse()
-            throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(WORKSPACE, SAVEBINARY, RECURSE);
-    }
-  */
-
     public void testExportSysView_handler_session_skipBinary_noRecurse()
             throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(SESSION, SKIPBINARY, NORECURSE);
+        doTestWithHandler(SKIPBINARY, NORECURSE);
     }
 
     public void testExportSysView_handler_session_skipBinary_recurse()
             throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(SESSION, SKIPBINARY, RECURSE);
+        doTestWithHandler(SKIPBINARY, RECURSE);
     }
 
     public void testExportSysView_handler_session_saveBinary_noRecurse()
             throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(SESSION, SAVEBINARY, NORECURSE);
+        doTestWithHandler(SAVEBINARY, NORECURSE);
     }
 
     public void testExportSysView_handler_session_saveBinary_recurse()
             throws IOException, RepositoryException, SAXException, IOException {
-        doTestWithHandler(SESSION, SAVEBINARY, RECURSE);
+        doTestWithHandler(SAVEBINARY, RECURSE);
     }
 
-    /*
-       // tests with output stream
-       public void testExportSysView_stream_workspace_skipBinary_noRecurse()
-               throws IOException, RepositoryException, SAXException {
-           doTestWithStream(WORKSPACE, SKIPBINARY, NORECURSE);
-       }
-
-       public void testExportSysView_stream_workspace_skipBinary_recurse()
-               throws IOException, RepositoryException, SAXException {
-           doTestWithStream(WORKSPACE, SKIPBINARY, RECURSE);
-       }
-
-       public void testExportSysView_stream_workspace_saveBinary_noRecurse()
-               throws IOException, RepositoryException, SAXException {
-           doTestWithStream(WORKSPACE, SAVEBINARY, NORECURSE);
-       }
-
-       public void testExportSysView_stream_workspace_saveBinary_recurse()
-               throws IOException, RepositoryException, SAXException {
-           doTestWithStream(WORKSPACE, SAVEBINARY, RECURSE);
-       }
-      */
-
     public void testExportSysView_stream_session_skipBinary_recurse()
             throws IOException, RepositoryException, SAXException {
-        doTestWithStream(SESSION, SKIPBINARY, RECURSE);
+        doTestWithStream(SKIPBINARY, RECURSE);
     }
 
     public void testExportSysView_stream_session_skipBinary_noRecurse()
             throws IOException, RepositoryException, SAXException {
-        doTestWithStream(SESSION, SKIPBINARY, NORECURSE);
+        doTestWithStream(SKIPBINARY, NORECURSE);
     }
 
     public void testExportSysView_stream_session_saveBinary_noRecurse()
             throws IOException, RepositoryException, SAXException {
-        doTestWithStream(SESSION, SAVEBINARY, NORECURSE);
+        doTestWithStream(SAVEBINARY, NORECURSE);
     }
 
     public void testExportSysView_stream_session_saveBinary_recurse()
             throws IOException, RepositoryException, SAXException {
-        doTestWithStream(SESSION, SAVEBINARY, RECURSE);
+        doTestWithStream(SAVEBINARY, RECURSE);
     }
 
     /**
@@ -168,22 +116,11 @@
      * @throws SAXException
      * @throws IOException
      */
-    public void doTestWithHandler(boolean workspace, boolean skipBinary, boolean noRecurse)
+    public void doTestWithHandler(boolean skipBinary, boolean noRecurse)
             throws RepositoryException, SAXException, IOException {
 
-        ContentHandler contentHandler;
-        try {
-
-            contentHandler = new SysViewContentHandler(testPath, session, skipBinary, noRecurse);
-
-            if (workspace) {
-                //workspace.exportSysView(testPath, contentHandler, skipBinary, noRecurse);
-            } else {
-                session.exportSystemView(testPath, contentHandler, skipBinary, noRecurse);
-            }
-        } catch (RepositoryException re) {
-            fail("Could not initialize the contenthandler due to: " + re.toString());
-        }
+        ContentHandler contentHandler = new SysViewContentHandler(testPath, session, skipBinary, noRecurse);
+        session.exportSystemView(testPath, contentHandler, skipBinary, noRecurse);
     }
 
     /**
@@ -191,19 +128,14 @@
      * @throws SAXException
      * @throws IOException
      */
-    public void doTestWithStream(boolean workSpace,
-                                 boolean skipBinary, boolean noRecurse)
+    public void doTestWithStream(boolean skipBinary, boolean noRecurse)
             throws RepositoryException, SAXException, IOException {
 
         BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
 
-        Session thisSession = session;
-        if (workSpace) {
-            thisSession = workspace.getSession();
-        }
         try {
-            thisSession.exportSystemView(testPath, os, false, false);
-            SysViewParser parser = new SysViewParser(testPath, thisSession, SAVEBINARY, RECURSE);
+            session.exportSystemView(testPath, os, false, false);
+            SysViewParser parser = new SysViewParser(testPath, session, SAVEBINARY, RECURSE);
             parser.parse(file);
         } catch (RepositoryException re) {
             fail("Could not initialize the contenthandler due to: " + re.toString());
@@ -231,7 +163,7 @@
                 throws SAXException, RepositoryException {
             this.nodePath = nodePath;
             this.handler = new SysViewContentHandler(nodePath, session, skipBinary, noRecurse);
-            parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+            parser = XMLReaderFactory.createXMLReader();
             parser.setContentHandler(this.handler);
         }
 

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SysViewContentHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SysViewContentHandler.java?rev=425338&r1=425337&r2=425338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SysViewContentHandler.java (original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SysViewContentHandler.java Tue Jul 25 02:06:13 2006
@@ -29,7 +29,6 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.NodeIterator;
 import javax.jcr.PropertyType;
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyIterator;
 import javax.jcr.Property;
 import javax.jcr.Value;
@@ -42,6 +41,8 @@
 import java.util.Stack;
 import java.util.Hashtable;
 import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
 
 import junit.framework.Assert;
 
@@ -335,26 +336,30 @@
     }
 
     public void endDocument() throws SAXException {
-        // check the prefixes exported
+        // check exported namespaces
         try {
-            NamespaceRegistry nsr = session.getWorkspace().getNamespaceRegistry();
-            String[] registeredPrefixes = nsr.getPrefixes();
-            // check against the found prefixes
-/*
-            // invalid test: only the referenced namespaces need to be declared;
-            // apart from that, the 'xml' namespace, although registered,
-            // is never declared in the system view xml as this would be illegal
-            checkCondition("Size of included prefixes is not the size of " +
-                    "registered prefixes", registeredPrefixes.length == prefixes.size()) ;
-*/
-            for (int i=0; i<registeredPrefixes.length;i++) {
-                String prefix = registeredPrefixes[1];
-                String uri = nsr.getURI(prefix);
-                checkCondition("Registered prefix "+prefix + " not included",
-                    prefixes.containsKey(prefix) && prefixes.get(prefix).equals(uri) );
+            Map sessionNamespaces = new HashMap();
+            String[] sessionPrefixes = session.getNamespacePrefixes();
+            for (int i = 0; i < sessionPrefixes.length; i++) {
+                sessionNamespaces.put(sessionPrefixes[i], session.getNamespaceURI(sessionPrefixes[i]));
+            }
+
+            // check prefixes against namespace mapping in session
+            for (Iterator it = prefixes.keySet().iterator(); it.hasNext(); ) {
+                String prefix = (String) it.next();
+                if ("xml".equals(prefix)) {
+                    Assert.fail("Prefix mapping for 'xml' must not be exported.");
+                }
+
+                String uri = (String) prefixes.get(prefix);
+                checkCondition("Exported uri " + uri + " is not a registered namespace.",
+                        sessionNamespaces.containsValue(uri));
+                checkCondition("Exported prefix " + prefix + " does not match " +
+                        "current namespacce mapping in Session",
+                        sessionNamespaces.containsKey(prefix));
             }
         } catch (RepositoryException re) {
-            //
+            throw new SAXException(re);
         }
     }