/*
 * 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.id;

import junit.framework.TestCase;

public class NodeIdTest extends TestCase {

    private static final NodeId[] ids = {
        new NodeId(), // random id
        new NodeId(0, 0),
        new NodeId(-1, -1),
        new NodeId("cafebabe-cafe-babe-cafe-babecafebabe")
    };

    public void testDenotesNode() {
        for (NodeId id : ids) {
            assertTrue(id.denotesNode());
        }
    }

    public void testGetMostAndLeastSignificantBits() {
        for (NodeId id : ids) {
            long msb = id.getMostSignificantBits();
            long lsb = id.getLeastSignificantBits();
            assertEquals(id, new NodeId(msb, lsb));
        }
    }

    public void testGetRawBytes() {
        for (NodeId id : ids) {
            assertEquals(id, new NodeId(id.getRawBytes()));
        }
    }

    public void testToString() {
        for (NodeId id : ids) {
            assertEquals(id, new NodeId(id.toString()));
        }
    }

    public void testCompareTo() {
        for (NodeId id : ids) {
            assertEquals(0, id.compareTo(id));
        }

        NodeId[] ordered = {
                new NodeId(-1, -1),
                new NodeId(-1, 0),
                new NodeId(0, -1),
                new NodeId(0, 0),
                new NodeId(0, 1),
                new NodeId(1, 0),
                new NodeId(1, 1)
        };
        for (int i = 0; i < ordered.length; i++) {
            for (int j = 0; j < i; j++) {
                assertEquals(1, ordered[i].compareTo(ordered[j]));
            }
            assertEquals(0, ordered[i].compareTo(ordered[i]));
            for (int j = i + 1; j < ordered.length; j++) {
                assertEquals(-1, ordered[i].compareTo(ordered[j]));
            }
        }
    }

}

@@ -2664,11 +2664,1120 @@
    %7D%0D%0A%0D%0A
+    public void testUuidFormat() %7B%0D%0A        long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;%0D%0A        for (int i = 0; i %3C 100; i++) %7B%0D%0A            NodeId id = new NodeId();%0D%0A            assertUuidFormat(id);%0D%0A            maxHigh %7C= id.getMostSignificantBits();%0D%0A            maxLow %7C= id.getLeastSignificantBits();%0D%0A            minHigh &= id.getMostSignificantBits();%0D%0A            minLow &= id.getLeastSignificantBits();%0D%0A        %7D%0D%0A        NodeId max = new NodeId(maxHigh, maxLow);%0D%0A        assertEquals(%22ffffffff-ffff-4fff-bfff-ffffffffffff%22, max.toString());%0D%0A        NodeId min = new NodeId(minHigh, minLow);%0D%0A        assertEquals(%2200000000-0000-4000-8000-000000000000%22, min.toString());%0D%0A    %7D%0D%0A%0D%0A    private void assertUuidFormat(NodeId id) %7B%0D%0A        long high = id.getMostSignificantBits();%0D%0A        long low = id.getLeastSignificantBits();%0D%0A        long high2 = (high & (~0xf000L)) %7C 0x4000L; // version 4 (random)%0D%0A        assertEquals(high, high2);%0D%0A        long low2 = (low & 0x3fffffffffffffffL) %7C 0x8000000000000000L; // variant (Leach-Salz)%0D%0A        assertEquals(low, low2);%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

Merge UUID to NodeId