package org.alfresco.repo.virtual.ref; import junit.framework.TestCase; import org.alfresco.util.Pair; import org.apache.commons.codec.binary.Base64; import org.junit.Test; public class NumericPathHasherTest extends TestCase { @Test public void testHash() throws Exception { NumericPathHasher nph = new NumericPathHasher(); Pair h1 = nph.hash("/1/2/3"); assertEquals(new Pair("123", null), h1); Pair h2 = nph.hash("/a/2/3"); String xc2 = new String(Base64.encodeBase64("/a/2/3".getBytes(), false)); assertEquals(new Pair(null, xc2), h2); Pair h3 = nph.hash("/1/2/a/1/3"); String xc3 = new String(Base64.encodeBase64("a/1/3".getBytes(), false)); assertEquals(new Pair("12", xc3), h3); } @Test public void testHashRoot() throws Exception { NumericPathHasher nph = new NumericPathHasher(); Pair h1 = nph.hash("/"); assertEquals(new Pair(null, ""), h1); } @Test public void testLookupRoot() throws Exception { NumericPathHasher nph = new NumericPathHasher(); String p = nph.lookup(new Pair(null, "")); assertEquals("/", p); } @Test public void testLookup() throws Exception { NumericPathHasher nph = new NumericPathHasher(); Pair h = nph.hash("/1/2/3"); assertEquals(new Pair("123", null), h); String xc2 = new String(Base64.encodeBase64("/a/2/3".getBytes(), false)); String p2 = nph.lookup(new Pair(null, xc2)); assertEquals("/a/2/3", p2); String xc3 = new String(Base64.encodeBase64("a/1/3".getBytes(), false)); String p3 = nph.lookup(new Pair("12", xc3)); assertEquals("/1/2/a/1/3", p3); } @Test public void testHashEmpty() throws Exception { NumericPathHasher nph = new NumericPathHasher(); try { nph.hash(""); fail("Should not be able to hash empty String"); } catch (IllegalArgumentException e) { // as expected } } }