jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r390807 - /jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
Date Sun, 02 Apr 2006 10:40:59 GMT
Author: jukka
Date: Sun Apr  2 03:40:57 2006
New Revision: 390807

URL: http://svn.apache.org/viewcvs?rev=390807&view=rev
Log:
JCR-325: Added a simple test case for multi-value handling in document view import.

Modified:
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java?rev=390807&r1=390806&r2=390807&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
Sun Apr  2 03:40:57 2006
@@ -16,12 +16,18 @@
 package org.apache.jackrabbit.core.xml;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
 import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
 import javax.jcr.Session;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
 import org.apache.jackrabbit.core.TestRepository;
 
 import junit.framework.TestCase;
@@ -34,6 +40,39 @@
  */
 public class DocumentViewTest extends TestCase {
 
+    /** Test session. */
+    private Session session;
+
+    /**
+     * Sets up the test fixture.
+     *
+     * @throws Exception if an unexpected error occurs
+     */
+    protected void setUp() throws Exception {
+        session = TestRepository.getInstance().login();
+        JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
+            session.getWorkspace().getNodeTypeManager();
+        try {
+            manager.getNodeType("DocViewMultiValueTest");
+        } catch (NoSuchNodeTypeException e) {
+            String cnd = "[DocViewMultiValueTest] - test (boolean) multiple";
+            manager.registerNodeTypes(
+                    new ByteArrayInputStream(cnd.getBytes("UTF-8")),
+                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+        }
+    }
+
+    /**
+     * Tears down the test fixture.
+     *
+     * @throws Exception if an unexpected error occurs
+     */
+    protected void tearDown() throws Exception {
+        // TODO: Unregister the MultiValueTestType node type once Jackrabbit
+        // supports node type removal.
+        session.logout();
+    }
+
     /**
      * Test case for
      * <a href="http://issues.apache.org/jira/browse/JCR-369">JCR-369</a>:
@@ -42,7 +81,6 @@
      * @throws Exception if an unexpected error occurs
      */
     public void testTwoMixins() throws Exception {
-        Session session = TestRepository.getInstance().login();
         try {
             String xml = "<two-mixins-test"
                 + " jcr:mixinTypes=\"mix:referenceable mix:lockable\""
@@ -54,8 +92,39 @@
         } catch (ValueFormatException e) {
             fail("JCR-369: IllegalNameException when importing document view"
                     + " with two mixins");
-        } finally {
-            session.logout();
+        }
+    }
+
+    /**
+     * Test case for
+     * <a href="http://issues.apache.org/jira/browse/JCR-325">JCR-325</a>:
+     * docview roundtripping does not work with multivalue non-string properties
+     *
+     * @throws Exception if an unexpected error occurs
+     */
+    public void testMultiValue() throws Exception {
+        String message = "JCR-325: docview roundtripping does not work with"
+            + " multivalue non-string properties";
+
+        Node root = session.getRootNode();
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+        Node node = root.addNode("multi-value-test", "DocViewMultiValueTest");
+        node.setProperty("test", new String[] {"true", "false"});
+        session.exportDocumentView("/multi-value-test", buffer, true, true);
+        session.refresh(false); // Discard the transient multi-value-test node
+
+        session.importXML(
+                "/", new ByteArrayInputStream(buffer.toByteArray()),
+                ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
+        try {
+            Property property = root.getProperty("multi-value-test/test");
+            assertTrue(message, property.getDefinition().isMultiple());
+            assertEquals(message, property.getValues().length, 2);
+            assertTrue(message, property.getValues()[0].getBoolean());
+            assertFalse(message, property.getValues()[1].getBoolean());
+        } catch (PathNotFoundException e) {
+            fail(message);
         }
     }
 



Mime
View raw message