jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r167911 - in /incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api: NamespaceRemappingTest.java SessionTest.java ValueFactoryTest.java
Date Tue, 03 May 2005 14:22:59 GMT
Author: dpfister
Date: Tue May  3 07:22:59 2005
New Revision: 167911

URL: http://svn.apache.org/viewcvs?rev=167911&view=rev
Log:
Added and enhanced tests

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ValueFactoryTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java?rev=167911&r1=167910&r2=167911&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
Tue May  3 07:22:59 2005
@@ -174,6 +174,40 @@
     }
 
     /**
+     * Tests if {@link javax.jcr.Session#getNamespacePrefixes()} returns
+     * all prefixes currently set for this session, including all those
+     * registered in the NamespaceRegistry but not over-ridden by a
+     * Session.setNamespacePrefix, plus those currently set locally by
+     * Session.setNamespacePrefix.
+     */
+    public void testGetNamespacePrefixes() throws RepositoryException {
+        String testPrefix = getUnusedPrefix();
+
+        // remap the jcr uri
+        session.setNamespacePrefix(testPrefix, NS_JCR_URI);
+
+        String prefixes[] = session.getNamespacePrefixes();
+
+        assertEquals("Session.getNamespacePrefixes() must return all prefixes " +
+                "currently set for this session.",
+                nsr.getPrefixes().length,
+                session.getNamespacePrefixes().length);
+
+        // the prefix of the jcr uri as set in the namespace registry
+        String prefixNSR = nsr.getPrefix(NS_JCR_URI);
+
+        // test if the "NSR prefix" (and over-ridden by the session) is not
+        // returned by Session.getNamespacePrefixes()
+        for (int i = 0; i < prefixes.length; i++) {
+            if (prefixes[i].equals(prefixNSR)) {
+                fail("Session.getNamespacePrefixes() must not return the " +
+                     "prefixes over-ridden by Session.setNamespacePrefix");
+            }
+        }
+    }
+
+
+    /**
      * Returns a namespace prefix that is not in use.
      *
      * @return a namespace prefix that is not in use.
@@ -204,4 +238,4 @@
         }
         return uri + count;
     }
-}
\ No newline at end of file
+}

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java?rev=167911&r1=167910&r2=167911&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java Tue
May  3 07:22:59 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.RepositoryException;
@@ -26,6 +27,13 @@
 import javax.jcr.Session;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Value;
+import javax.jcr.Repository;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.lock.LockException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Hashtable;
 
 /**
  * <code>SessionTest</code> contains all test cases for the
@@ -224,6 +232,58 @@
         } catch (ConstraintViolationException e) {
             // ok try to save the source
         }
+    }
+
+    /**
+     * Calls <code>{@link javax.jcr.Session#move(String src, String dest)} where
+     * the parent node of src is locked.<br/> <br/> Should throw a <code>{@link
+     * javax.jcr.LockException} immediately or on save.
+     */
+    public void testMoveLockException()
+        throws NotExecutableException, RepositoryException {
+
+        Session session = superuser;
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // create a node that is lockable
+        Node lockableNode = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it lockable if it is not
+        if (!lockableNode.isNodeType(mixLockable)) {
+            if (lockableNode.canAddMixin(mixLockable)) {
+                lockableNode.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not lockable
and does not " +
+                        "allow to add mix:lockable");
+            }
+        }
+
+        // add a sub node (the one that is tried to move later on)
+        Node srcNode = lockableNode.addNode(nodeName1, testNodeType);
+
+        testRootNode.save();
+
+        // remove first slash of path to get rel path to root
+        String pathRelToRoot = lockableNode.getPath().substring(1);
+
+        // access node through another session to lock it
+        Session session2 = helper.getSuperuserSession();
+        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
+        node2.lock(true, true);
+
+        try {
+            String destPath = testRoot + "/" + nodeName2;
+            session.move(srcNode.getPath(), destPath);
+            testRootNode.save();
+            fail("A LockException is thrown either immediately or on save  if a lock prevents
the move.");
+        }
+        catch (LockException e){
+            // success
+        }
+
+        session2.logout();
     }
 
     /**

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ValueFactoryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ValueFactoryTest.java?rev=167911&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ValueFactoryTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ValueFactoryTest.java
Tue May  3 07:22:59 2005
@@ -0,0 +1,306 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.RepositoryException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import java.util.Calendar;
+import java.util.ArrayList;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+/**
+ * <code>ValueFactoryTest</code> tests the different ValueFactory.createValue
methods.
+ *
+ * @test
+ * @sources ValueFactoryTest.java
+ * @executeClass org.apache.jackrabbit.test.api.ValueFactoryTest
+ * @keywords level2
+ */
+public class ValueFactoryTest extends AbstractJCRTest {
+
+    private Session session;
+    private ValueFactory valueFactory;
+
+    private static final boolean booleanValue = false;
+    private Calendar dateValue = null;
+    private static final double doubleValue = 3.1414926;
+    private static final long  longValue = Long.MAX_VALUE;
+    private Node referenceNode = null;
+    private Node notReferenceableNode = null;
+    private static final String stringValue = "a string";
+    private static String nameValue = "aName";
+    private static String pathValue = "/a/Path[1]";
+    private byte[] binaryValue = null;
+
+    private  ArrayList values = new ArrayList();
+
+    private String dateValueFail = nameValue;
+    private static final String doubleValueFail = nameValue;
+    private static final String  longValueFail = nameValue;
+    private static String nameValueFail = ";pre fix::name;";
+    private static String pathValueFail =nameValueFail;
+
+    private static int[] types = {PropertyType.DATE, PropertyType.DOUBLE, PropertyType.LONG,
+                           PropertyType.NAME, PropertyType.PATH, PropertyType.REFERENCE,
+                           PropertyType.STRING, PropertyType.BINARY, PropertyType.BOOLEAN};
+
+
+    public void setUp() throws Exception {
+        super.setUp();
+        session = helper.getReadWriteSession();
+        try {
+            valueFactory = session.getValueFactory();
+        } catch (UnsupportedRepositoryOperationException e) {
+            String message = "ValueFactory Test not executable: " + e.getMessage();
+            throw new NotExecutableException(message);
+        }
+        //notReferenceableNode = getProperty(not_ReferenceableNode);
+        nameValue = testRootNode.getName();
+        pathValue = testRootNode.getPath();
+        dateValue = Calendar.getInstance();
+        binaryValue = createRandomString(10).getBytes();
+        referenceNode = createReferenceableNode(nodeName1);
+    }
+
+    /**
+     * Create a referenceable node under the testRootNode
+     * or null if it is not possible to create one.
+     * @param name
+     * @return
+     * @throws RepositoryException
+     */
+    public Node createReferenceableNode(String name) throws RepositoryException {
+        // remove a yet existing node at the target
+        try {
+            Node node = testRootNode.getNode(name);
+            node.remove();
+            session.save();
+        } catch (PathNotFoundException pnfe) {
+            // ok
+        }
+        // a referenceable node
+        Node n1 = testRootNode.addNode(name);
+        if (n1.canAddMixin(mixReferenceable)) {
+            n1.addMixin(mixReferenceable);
+            // make sure jcr:uuid is available
+            testRootNode.save();
+            return n1;
+        }
+        else {
+            return null;
+        }
+    }
+
+    /**
+     * Tests if the type of a created value is set correctly.
+     *
+     * @throws RepositoryException
+     */
+    public void testValueType() throws RepositoryException {
+        Value value = null;
+        int type = -1;
+        for (int i = 0; i < types.length; i++) {
+
+            switch (types[i]) {
+
+                case PropertyType.BINARY:
+                    try {
+                        ByteArrayInputStream in = new ByteArrayInputStream(binaryValue);
+                        value = valueFactory.createValue(in);
+                        session.save();
+                        type = value.getType();
+                        in.close();
+                    } catch (IOException ioe) {
+
+                    }
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.BINARY)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.BINARY == type);
+                    break;
+
+                case PropertyType.BOOLEAN:
+                    value = valueFactory.createValue(booleanValue);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.BOOLEAN)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.BOOLEAN == type);
+                    break;
+
+                case PropertyType.DATE:
+                    value = valueFactory.createValue(dateValue);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.DATE)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.DATE == type);
+                    break;
+
+                case PropertyType.DOUBLE:
+                    value = valueFactory.createValue(doubleValue);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.DOUBLE)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.DOUBLE == type);
+                    break;
+
+                case PropertyType.LONG:
+                    value = valueFactory.createValue(longValue);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.LONG)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.LONG == type);
+                    break;
+
+                case PropertyType.NAME:
+                    value = valueFactory.createValue(nameValue, PropertyType.NAME);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.NAME)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.NAME == type);
+                    break;
+
+                case PropertyType.PATH:
+                    value = valueFactory.createValue(pathValue, PropertyType.PATH);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.PATH)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.PATH == type);
+
+                    break;
+
+                case PropertyType.REFERENCE:
+                    if (referenceNode != null) {
+                        value = valueFactory.createValue(referenceNode);
+                        session.save();
+                        type = value.getType();
+                        assertTrue("Type of created value not correct: Expected: "
+                            + PropertyType.nameFromValue(PropertyType.REFERENCE)
+                            + " but was: " + PropertyType.nameFromValue(type),
+                            PropertyType.REFERENCE == type);
+                        // correct value?
+                        assertEquals("Reference value does not contain the UUID of the "
+
+                                "referenced node.", referenceNode.getUUID(), value.getString());
+                    }
+                    break;
+
+               case PropertyType.STRING:
+                    value = valueFactory.createValue(stringValue);
+                    session.save();
+                    type = value.getType();
+                    assertTrue("Type of created value not correct: Expected: "
+                        + PropertyType.nameFromValue(PropertyType.STRING)
+                        + " but was: " + PropertyType.nameFromValue(type),
+                        PropertyType.STRING == type);
+                    break;
+
+            }
+        }
+
+    }
+
+    /**
+     * Tests if a ValueFormatexception is thrown in case the passed string
+     * cannot be converted to the required value type.
+     * value creation.
+     * @throws RepositoryException
+     */
+    public void testValueFormatException() throws RepositoryException {
+        Value value = null;
+        for (int i = 0; i < types.length; i++) {
+
+            switch (types[i]) {
+
+                case PropertyType.DATE:
+                    try {
+                        value = valueFactory.createValue(dateValueFail,PropertyType.DATE);
+                        fail("Conversion from String " + dateValueFail
+                                + " to a Date value should throw ValueFormatException.");
+                    } catch (ValueFormatException vfe) {
+                        //ok
+                    }
+                    break;
+
+                case PropertyType.DOUBLE:
+                    try {
+                        value = valueFactory.createValue(doubleValueFail,PropertyType.DOUBLE);
+                        fail("Conversion from String " + doubleValueFail
+                            + " to a Date value should throw ValueFormatException.");
+                    } catch (ValueFormatException vfe) {
+                        //ok
+                    }
+                    break;
+
+                case PropertyType.LONG:
+                    try {
+                        value = valueFactory.createValue(longValueFail,PropertyType.LONG);
+                        fail("Conversion from String " + longValueFail
+                            + " to a Date value should throw ValueFormatException.");
+                    } catch (ValueFormatException vfe) {
+                        //ok
+                    }
+                    break;
+
+                case PropertyType.NAME:
+                    try {
+                        value = valueFactory.createValue(nameValueFail,PropertyType.NAME);
+                        fail("Conversion from String " + nameValueFail
+                            + " to a Date value should throw ValueFormatException.");
+                    } catch (ValueFormatException vfe) {
+                        //ok
+                    }
+                    break;
+
+                case PropertyType.PATH:
+                    try {
+                        value = valueFactory.createValue(pathValueFail,PropertyType.PATH);
+                        fail("Conversion from String " + pathValueFail
+                            + " to a Date value should throw ValueFormatException.");
+                    } catch (ValueFormatException vfe) {
+                        //ok
+                    }
+                    break;
+
+                default:
+                    break;
+            }
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ValueFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message