<commit_before>/*
 * 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.spi.commit;

import java.util.LinkedHashMap;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.apache.jackrabbit.oak.api.Tree;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * MoveTrackerTest... TODO
 */
public class MoveTrackerTest {

    @Test
    public void testIsEmpty() {
        assertTrue(new MoveTracker().isEmpty());
    }

    @Test
    public void testNotEmpty() {
        for (Tree.Status st : Tree.Status.values()) {
            MoveTracker mt = new MoveTracker();
            mt.addMove("/a/b/c", "/d/e/f", st);
            assertFalse(mt.isEmpty());
        }
    }

    @Test
    public void testSingleMove() {
        Map<String, String> moves = ImmutableMap.of(
                "/a/b/c", "/d/e/f",
                "/aa/bb/cc", "/aa/f/cc"
        );

        for (String src : moves.keySet()) {
            MoveTracker mt = new MoveTracker();
            String dest = moves.get(src);
            mt.addMove(src, dest);

            assertEquals(src, mt.getOriginalSourcePath(dest));
            assertEquals(dest, mt.getDestPath(src));
        }
    }
<commit_msg>OAK-710: PermissionValidator: Proper permission evaluation for moving/renaming nodes More MoveTracker tests: ported the relevant cases from http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup line 222 and forward.<commit_after>/*
 * 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.spi.commit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.LinkedHashMap;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.apache.jackrabbit.oak.api.Tree;
import org.junit.Ignore;
import org.junit.Test;

/**
 * MoveTrackerTest... TODO
 */
public class MoveTrackerTest {

    @Test
    public void testIsEmpty() {
        assertTrue(new MoveTracker().isEmpty());
    }

    /**
     * 1.   >/a:/b >/c:/d     =  >/c:/d >/a:b
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 222
     */
    @Test
    public void test1() {
        MoveTracker mt = new MoveTracker();
        mt.addMove("/a", "/b");
        mt.addMove("/c", "/d");

        assertEquals("/a", mt.getOriginalSourcePath("/b"));
        assertEquals("/c", mt.getOriginalSourcePath("/d"));
        assertEquals("/b", mt.getDestPath("/a"));
        assertEquals("/d", mt.getDestPath("/c"));
    }

    /**
     * 4.   >/a/b:/c >/a:/d   =  >/a:/d >/d/b:/c
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 225
     */
    @Test
    public void test4() {
        MoveTracker mt1 = new MoveTracker();
        mt1.addMove("/a/b", "/c");
        mt1.addMove("/a", "/d");

        assertEquals("/a/b", mt1.getOriginalSourcePath("/c"));
        assertEquals("/a", mt1.getOriginalSourcePath("/d"));
        assertEquals("/c", mt1.getDestPath("/a/b"));
        assertEquals("/d", mt1.getDestPath("/a"));
    }

    /**
     * 4.   >/a/b:/c >/a:/c/d    does not commute  (q < s)
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 226
     */
    @Test
    public void test4a() {
        MoveTracker mt2 = new MoveTracker();
        mt2.addMove("/a/b", "/c");
        mt2.addMove("/a", "/c/d");

        assertEquals("/a/b", mt2.getOriginalSourcePath("/c"));
        assertEquals("/a", mt2.getOriginalSourcePath("/c/d"));
        assertEquals("/c", mt2.getDestPath("/a/b"));
        assertEquals("/c/d", mt2.getDestPath("/a"));
    }

    /**
     * 7.   >/a:/b >/c:/a        does not commute
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 231
     */
    @Test
    public void test7() {
        MoveTracker mt3 = new MoveTracker();
        mt3.addMove("/a", "/b");
        mt3.addMove("/c", "/a");

        assertEquals("/a", mt3.getOriginalSourcePath("/b"));
        assertEquals("/c", mt3.getOriginalSourcePath("/a"));
        assertEquals("/b", mt3.getDestPath("/a"));
        assertEquals("/a", mt3.getDestPath("/c"));
    }

    /**
     * 10.  >/a:/b >/b/c:/d   =  >/a/c:/d >/a:/b
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 234
     */
    @Test
    public void test10() {
        MoveTracker mt = new MoveTracker();
        mt.addMove("/a", "/b");
        mt.addMove("/b/c", "/d");

        assertEquals("/a", mt.getOriginalSourcePath("/b"));
        assertEquals("/a/c", mt.getOriginalSourcePath("/d"));
        assertEquals("/b", mt.getDestPath("/a"));
        assertEquals("/d", mt.getDestPath("/a/c"));
    }

    /**
     * 11.  >/a:/b >/b:/c     =  >/a:/c
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 236
     */
    @Test
    public void test11() {
        MoveTracker mt = new MoveTracker();
        mt.addMove("/a", "/b");
        mt.addMove("/b", "/c");

        assertEquals("/a", mt.getOriginalSourcePath("/c"));
        assertEquals("/c", mt.getDestPath("/a"));
    }

    /**
     * 12.  >/a:/b/c >/b:/d   =  >/b:/d >/a:/d/c
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 237
     */
    @Test
    @Ignore("OAK-710")  // FIXME see OAK-710
    public void test12() {
        MoveTracker mt4 = new MoveTracker();
        mt4.addMove("/a", "/b/c");
        mt4.addMove("/b", "/d");

        assertEquals("/a", mt4.getOriginalSourcePath("/d/c"));
        assertEquals("/b", mt4.getOriginalSourcePath("/d"));
        assertEquals("/d/c", mt4.getDestPath("/a"));
        assertEquals("/d", mt4.getDestPath("/b"));
    }

    /**
     * 14.  >/a:/b >/c:/b/d   =  >/c:/a/d >/a:/b
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 240
     */
    @Test
    public void test14() {
        MoveTracker mt5 = new MoveTracker();
        mt5.addMove("/a", "/b");
        mt5.addMove("/c", "/b/d");

        assertEquals("/a", mt5.getOriginalSourcePath("/b"));
        assertEquals("/c", mt5.getOriginalSourcePath("/b/d"));
        assertEquals("/b", mt5.getDestPath("/a"));
        assertEquals("/b/d", mt5.getDestPath("/c"));
    }

    /**
     * 14.  >/a/b:/b >/a:/b/d    does not commute  (p > r)
     * See http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeLog.java?view=markup
     * Line 241
     */
    @Test
    public void test14a() {
        MoveTracker mt6 = new MoveTracker();
        mt6.addMove("/a/b", "/b");
        mt6.addMove("/a", "/b/d");

        assertEquals("/a/b", mt6.getOriginalSourcePath("/b"));
        assertEquals("/a", mt6.getOriginalSourcePath("/b/d"));
        assertEquals("/b", mt6.getDestPath("/a/b"));
        assertEquals("/b/d", mt6.getDestPath("/a"));
    }

    @Test
    public void testNotEmpty() {
        for (Tree.Status st : Tree.Status.values()) {
            MoveTracker mt = new MoveTracker();
            mt.addMove("/a/b/c", "/d/e/f", st);
            assertFalse(mt.isEmpty());
        }
    }

    @Test
    public void testSingleMove() {
        Map<String, String> moves = ImmutableMap.of(
                "/a/b/c", "/d/e/f",
                "/aa/bb/cc", "/aa/f/cc"
        );

        for (String src : moves.keySet()) {
            MoveTracker mt = new MoveTracker();
            String dest = moves.get(src);
            mt.addMove(src, dest);

            assertEquals(src, mt.getOriginalSourcePath(dest));
            assertEquals(dest, mt.getDestPath(src));
        }
    }

{'fraction_non_alphanumeric': 0.16469051446945338, 'fraction_numerical': 0.011756430868167203, 'mean_word_length': 2.5058119056005634, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7663528', 'n_tokens_mistral': 3264, 'n_tokens_neox': 3080, 'n_words': 669}