1 5 6 package org.exoplatform.services.jcr.impl; 7 8 import org.exoplatform.services.jcr.BaseTest; 9 import org.exoplatform.services.jcr.core.ItemLocation; 10 import org.exoplatform.services.jcr.util.PathUtil; 11 12 13 19 20 public class TestPath extends BaseTest { 21 22 23 public void testPathUtil() throws Exception { 24 int test = PathUtil.getDepth("/"); 25 assertTrue(test == 0); 26 test = PathUtil.getDepth("/node1"); 27 assertTrue(test == 1); 28 test = PathUtil.getDepth("/node1/"); 29 assertTrue(test == 1); 30 test = PathUtil.getDepth("/node1/jcr:uuid"); 31 assertTrue(test == 2); 32 assertFalse(PathUtil.isDescendant("/node1/jcr:uuid", "/", true)); 33 assertTrue(PathUtil.isDescendant("/node1/jcr:uuid", "/", false)); 34 assertTrue(PathUtil.isDescendant("/node1/jcr:uuid", "/node1", false)); 35 assertTrue(PathUtil.isDescendant("/node1/jcr:uuid", "/node1", true)); 36 37 assertFalse(PathUtil.isDescendant("/node11", "/node1", true)); 38 assertFalse(PathUtil.isDescendant("/node11", "/node1", false)); 39 40 assertFalse(PathUtil.isDescendant("/testNode1/node11", "/testNode", true)); 41 assertFalse(PathUtil.isDescendant("/testNode1/node11", "/testNode", false)); 42 43 44 } 45 46 public void testItemLocation() throws Exception { 47 ItemLocation loc = new ItemLocation("/root/node1", "node2"); 48 assertEquals("/root/node1/node2", loc.getPath()); 49 assertEquals("node2", loc.getName()); 50 assertEquals("/root/node1", loc.getParentPath()); 51 assertEquals("/", loc.getAncestorPath(3)); 52 assertTrue(loc.getDepth() == 3); 53 } 54 } 55 | Popular Tags |