Files
alfresco-community-repo/source/test-java/org/alfresco/repo/virtual/ref/NumericPathHasherTest.java
Raluca Munteanu 8674e2bfc8 Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
      125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-04-26 12:48:49 +00:00

101 lines
3.0 KiB
Java

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<String, String> h1 = nph.hash("/1/2/3");
assertEquals(new Pair<String, String>("123",
null),
h1);
Pair<String, String> h2 = nph.hash("/a/2/3");
String xc2 = new String(Base64.encodeBase64("/a/2/3".getBytes(),
false));
assertEquals(new Pair<String, String>(null,
xc2),
h2);
Pair<String, String> h3 = nph.hash("/1/2/a/1/3");
String xc3 = new String(Base64.encodeBase64("a/1/3".getBytes(),
false));
assertEquals(new Pair<String, String>("12",
xc3),
h3);
}
@Test
public void testHashRoot() throws Exception
{
NumericPathHasher nph = new NumericPathHasher();
Pair<String, String> h1 = nph.hash("/");
assertEquals(new Pair<String, String>(null,
""),
h1);
}
@Test
public void testLookupRoot() throws Exception
{
NumericPathHasher nph = new NumericPathHasher();
String p = nph.lookup(new Pair<String, String>(null,
""));
assertEquals("/",
p);
}
@Test
public void testLookup() throws Exception
{
NumericPathHasher nph = new NumericPathHasher();
Pair<String, String> h = nph.hash("/1/2/3");
assertEquals(new Pair<String, String>("123",
null),
h);
String xc2 = new String(Base64.encodeBase64("/a/2/3".getBytes(),
false));
String p2 = nph.lookup(new Pair<String, String>(null,
xc2));
assertEquals("/a/2/3",
p2);
String xc3 = new String(Base64.encodeBase64("a/1/3".getBytes(),
false));
String p3 = nph.lookup(new Pair<String, String>("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
}
}
}