/*
 * 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.oak.jcr.security.authorization;

import javax.jcr.AccessDeniedException;
import javax.jcr.Node;
import javax.jcr.security.Privilege;

import org.apache.jackrabbit.api.JackrabbitNode;
import org.junit.Ignore;
import org.junit.Test;

/**
 * Permission evaluation tests related to {@link JackrabbitNode#rename(String)}.
 */
@Ignore("OAK-770 : NodeImpl doesn't implement JackrabbitNode#rename")
public class RenameTest extends AbstractEvaluationTest {

    @Test
    public void testRename() throws Exception {
        Node child = testSession.getNode(childNPath);
        try {
            ((JackrabbitNode) child).rename("rename");
            testSession.save();
            fail("test session must not be allowed to rename nodes.");
        } catch (AccessDeniedException e) {
            // success.
        }

        // give 'add_child_nodes' and 'nt-management' privilege
        // -> not sufficient privileges for a renaming of the child
        allow(path, privilegesFromNames(new String[] {Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT}));
        try {
            ((JackrabbitNode) child).rename("rename");
            testSession.save();
            fail("test session must not be allowed to rename nodes.");
        } catch (AccessDeniedException e) {
            // success.
        }

        // add 'remove_child_nodes' at 'path
        // -> rename of child must now succeed
        allow(path, privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES));
        ((JackrabbitNode) child).rename("rename");
        testSession.save();
    }
}
@@ -1013,33 +1013,8 @@
 de;%0A
-import org.junit.Ignore;%0A
 impo
@@ -1126,78 +1126,8 @@
  */%0A
-@Ignore(%22OAK-770 : NodeImpl doesn't implement JackrabbitNode#rename%22)%0A
 publ
@@ -1534,32 +1534,97 @@
 cess.%0A        %7D%0A
+    %7D%0A%0A    @Test%0A    public void testRename2() throws Exception %7B
 %0A        // give
@@ -1863,16 +1863,71 @@
 MENT%7D));
+%0A%0A        Node child = testSession.getNode(childNPath);
 %0A       
@@ -2173,173 +2173,692 @@
   %7D%0A
-%0A        // add 'remove_child_nodes' at 'path%0A        // -%3E rename of child must now succeed%0A        allow(path, privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES)
+    %7D%0A%0A    /**%0A     * @since OAK 1.0 : Renaming a node requires the same permission as moving it%0A     * around. This behavior differs from Jackrabbit 2.x where renaming just%0A     * required the ability to change the child collection of the parent.%0A     */%0A    @Test%0A    public void testRename3() throws Exception %7B%0A        // grant 'add_child_nodes', 'nt-management' and remove_child_nodes' at 'path%0A        // -%3E rename of child must now succeed%0A        allow(path, privilegesFromNames(new String%5B%5D %7BPrivilege.JCR_ADD_CHILD_NODES, Privilege.JCR_NODE_TYPE_MANAGEMENT, Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_REMOVE_NODE%7D));%0A%0A        Node child = testSession.getNode(childNPath
 );%0A 

clean up test cases and remove @Ignore