jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1344187 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test: AbstractJCRTest.java api/NodeDiscoveringNodeTypesTest.java
Date Wed, 30 May 2012 10:27:42 GMT
Author: reschke
Date: Wed May 30 10:27:42 2012
New Revision: 1344187

URL: http://svn.apache.org/viewvc?rev=1344187&view=rev
Log:
JCR-3322: test case coverage for isNodeType(expandedName)

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?rev=1344187&r1=1344186&r2=1344187&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Wed May 30 10:27:42 2012
@@ -589,21 +589,54 @@ public abstract class AbstractJCRTest ex
     }
 
     /**
-     * Returns the local name for the given <code>name</code>.
-     *
-     * @param name the name.
+     * Returns the local name for the given <code>jcrName</code>.
+     * 
+     * @param jcrName
+     *            the name.
      * @return the local name part.
      */
-    protected static String getLocalName(String name) {
-        int idx = name.indexOf(':');
+    protected static String getLocalName(String jcrName) {
+        int idx = jcrName.indexOf(':');
+        if (idx != -1) {
+            return jcrName.substring(idx + 1);
+        } else {
+            return jcrName;
+        }
+    }
+
+    /**
+     * Returns the prefix for the given <code>jcrName</code>.
+     * 
+     * @param jcrName
+     *            the name.
+     * @return the prefix part (empty string when not prefixed)
+     */
+    protected static String getPrefix(String jcrName) {
+        int idx = jcrName.indexOf(':');
         if (idx != -1) {
-            return name.substring(idx + 1);
+            return jcrName.substring(0, idx);
         } else {
-            return name;
+            return "";
         }
     }
 
     /**
+     * Returns the expanded name for the given <code>jcrName</code>.
+     * 
+     * @param jcrName
+     *            the name.
+     * @return the expanded name representation
+     * @throws RepositoryException
+     * @throws NamespaceException
+     */
+    protected static String getQualifiedName(Session session, String jcrName) throws RepositoryException
{
+        String prefix = getPrefix(jcrName);
+        String namespace = session.getNamespaceURI(prefix);
+        String localname = getLocalName(jcrName);
+        return (!namespace.isEmpty() ? "{" + namespace + "}" : "") + localname;
+    }
+
+    /**
      * Returns the name of a workspace that is not accessible from
      * <code>session</code>.
      * @param session the session.

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java?rev=1344187&r1=1344186&r2=1344187&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java
Wed May 30 10:27:42 2012
@@ -66,7 +66,7 @@ public class NodeDiscoveringNodeTypesTes
     }
 
     /**
-     * Releases the session aquired in {@link #setUp()}.
+     * Releases the session acquired in {@link #setUp()}.
      */
     protected void tearDown() throws Exception {
         if (session != null) {
@@ -103,7 +103,7 @@ public class NodeDiscoveringNodeTypesTes
 
     /**
      * Test if getMixinNodeType returns the node types according to the property
-     * "jcr:mixinTypes". Therefor a node with mixin types is located recursively
+     * "jcr:mixinTypes". Therefore a node with mixin types is located recursively
      * in the entire repository. A NotExecutableException is thrown when no such
      * node is found.
      */
@@ -165,22 +165,29 @@ public class NodeDiscoveringNodeTypesTes
                 "nodeTypeName is the name of the primary node type",
                 testRootNode.isNodeType(nodeTypeName));
 
+        String expNodeTypeName = getQualifiedName(testRootNode.getSession(), nodeTypeName);
+        assertTrue("isNodeType(String expNodeTypeName) must return true if "
+                + "expNodeTypeName is the name of the primary node type", testRootNode.isNodeType(expNodeTypeName));
+
         // test with mixin node's name
         // (if such a node is available)
         Node nodeWithMixin = locateNodeWithMixinNodeTypes(testRootNode);
         if (nodeWithMixin != null) {
             NodeType types[] = nodeWithMixin.getMixinNodeTypes();
             nodeTypeName = types[0].getName();
-            assertTrue("isNodeType(String nodeTypeName) must return true if " +
-                    "nodeTypeName is the name of one of the " +
-                    "mixin node types",
-                    nodeWithMixin.isNodeType(nodeTypeName));
+            expNodeTypeName = getQualifiedName(testRootNode.getSession(), nodeTypeName);
+            assertTrue("isNodeType(String nodeTypeName) must return true if " + "nodeTypeName
is the name of one of the "
+                    + "mixin node types", nodeWithMixin.isNodeType(nodeTypeName));
+            assertTrue("isNodeType(String expNodeTypeName) must return true if " + "expNodeTypeName
is the name of one of the "
+                    + "mixin node types", nodeWithMixin.isNodeType(expNodeTypeName));
         }
 
         // test with the name of predefined supertype "nt:base"
         assertTrue("isNodeType(String nodeTypeName) must return true if " +
                 "nodeTypeName is the name of a node type of a supertype",
                 testRootNode.isNodeType(ntBase));
+        assertTrue("isNodeType(String nodeTypeName) must return true if "
+                + "nodeTypeName is the name of a node type of a supertype", testRootNode.isNodeType(NodeType.NT_BASE));
     }
 
     //-----------------------< internal >---------------------------------------



Mime
View raw message