jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d.@apache.org
Subject svn commit: r1700942 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ test/java/org/apache/jackrabbit/core/integration/ test/java/org/apache/jackrabbit/core/security/user/
Date Thu, 03 Sep 2015 07:45:56 GMT
Author: dj
Date: Thu Sep  3 07:45:55 2015
New Revision: 1700942

URL: http://svn.apache.org/r1700942
Log:
JCR-3870 : Export SessionImpl#getItemOrNull in JackrabbitSession

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/GetOrNullTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=1700942&r1=1700941&r2=1700942&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Thu Sep  3 07:45:55 2015
@@ -706,6 +706,36 @@ public class SessionImpl extends Abstrac
         return userManager;
     }
 
+    @Override
+    public Item getItemOrNull(String absPath) throws RepositoryException {
+        // TODO optimise, reduce to a single read operation
+        if (itemExists(absPath)) {
+            return getItem(absPath);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public Property getPropertyOrNull(String absPath) throws RepositoryException {
+        // TODO optimise, reduce to a single read operation
+        if (propertyExists(absPath)) {
+            return getProperty(absPath);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public Node getNodeOrNull(String absPath) throws RepositoryException {
+        // TODO optimise, reduce to a single read operation
+        if (nodeExists(absPath)) {
+            return getNode(absPath);
+        } else {
+            return null;
+        }
+    }
+
     //--------------------------------------------------------------< Session >
     /**
      * {@inheritDoc}

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/GetOrNullTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/GetOrNullTest.java?rev=1700942&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/GetOrNullTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/GetOrNullTest.java
Thu Sep  3 07:45:55 2015
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.core.integration;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+/**
+ * @see <a href="https://issues.apache.org/jira/browse/JCR-3870">JCR-3870</a>
+ */
+public class GetOrNullTest extends AbstractJCRTest {
+
+    public static String NAME_EXISTING_PROPERTY = "property1";
+    public static String PATH_EXISTING_NODE = "/node1";
+    public static String PATH_NON_EXISTING_NODE = "/non-existing-node";
+    public static String PATH_EXISTING_PROPERTY = PATH_EXISTING_NODE + "/" + NAME_EXISTING_PROPERTY;
+    public static String PATH_NON_EXISTING_PROPERTY = PATH_EXISTING_NODE + "/non-existing-property";
+
+    public void setUp() throws Exception {
+        super.setUp();
+
+        Node node = JcrUtils.getOrCreateByPath(PATH_EXISTING_NODE, "nt:unstructured", superuser);
+        node.setProperty(NAME_EXISTING_PROPERTY, "value");
+        superuser.save();
+    }
+
+    public void testGetItemOrNullExistingNode() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Item item = js.getItemOrNull(PATH_EXISTING_NODE);
+        assertNotNull(item);
+        assertTrue(item instanceof Node);
+        assertEquals(item.getPath(), PATH_EXISTING_NODE);
+    }
+
+    public void testGetItemOrNullNonExistingNode() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Item item = js.getItemOrNull(PATH_NON_EXISTING_NODE);
+        assertNull(item);
+    }
+
+    public void testGetItemOrNullExistingProperty() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Item item = js.getItemOrNull(PATH_EXISTING_PROPERTY);
+        assertNotNull(item);
+        assertTrue(item instanceof Property);
+        assertEquals(item.getPath(), PATH_EXISTING_PROPERTY);
+    }
+
+    public void testGetItemOrNullNonExistingProperty() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Item item = js.getItemOrNull(PATH_NON_EXISTING_PROPERTY);
+        assertNull(item);
+    }
+
+    public void testGetNodeOrNullExisting() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Node node = js.getNodeOrNull(PATH_EXISTING_NODE);
+        assertNotNull(node);
+        assertEquals(node.getPath(), PATH_EXISTING_NODE);
+    }
+
+    public void testGetNodeOrNullNonExisting() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Node node = js.getNodeOrNull(PATH_NON_EXISTING_NODE);
+        assertNull(node);
+    }
+
+    public void testGetPropertyOrNullExisting() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Property property = js.getPropertyOrNull(PATH_EXISTING_PROPERTY);
+        assertNotNull(property);
+        assertEquals(property.getPath(), PATH_EXISTING_PROPERTY);
+    }
+
+    public void testGetPropertyOrNullNonExisting() throws RepositoryException {
+        JackrabbitSession js = (JackrabbitSession) superuser;
+        Property property = js.getPropertyOrNull(PATH_NON_EXISTING_PROPERTY);
+        assertNull(property);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/GetOrNullTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java?rev=1700942&r1=1700941&r2=1700942&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImporterTest.java
Thu Sep  3 07:45:55 2015
@@ -1659,6 +1659,18 @@ public class UserImporterTest extends Ab
             };
         }
 
+        public Item getItemOrNull(String absPath) throws RepositoryException {
+            return null;
+        }
+
+        public Property getPropertyOrNull(String absPath) throws RepositoryException {
+            return null;
+        }
+
+        public Node getNodeOrNull(String absPath) throws RepositoryException {
+            return null;
+        }
+
         public Repository getRepository() {
             return null;
         }



Mime
View raw message