1 17 package org.alfresco.service.cmr.repository; 18 19 import org.alfresco.service.namespace.QName; 20 21 import junit.framework.TestCase; 22 23 28 public class PathTest extends TestCase 29 { 30 private Path absolutePath; 31 private Path relativePath; 32 private QName typeQName; 33 private QName qname; 34 private StoreRef storeRef; 35 private NodeRef parentRef; 36 private NodeRef childRef; 37 38 public PathTest(String name) 39 { 40 super(name); 41 } 42 43 public void setUp() throws Exception 44 { 45 super.setUp(); 46 absolutePath = new Path(); 47 relativePath = new Path(); 48 typeQName = QName.createQName("http://www.alfresco.org/PathTest/1.0", "testType"); 49 qname = QName.createQName("http://www.google.com", "documentx"); 50 storeRef = new StoreRef("x", "y"); 51 parentRef = new NodeRef(storeRef, "P"); 52 childRef = new NodeRef(storeRef, "C"); 53 } 54 55 public void testQNameElement() throws Exception 56 { 57 Path.Element element = new Path.ChildAssocElement(new ChildAssociationRef(typeQName, parentRef, qname, childRef)); 59 assertEquals("Element string incorrect", 60 qname.toString(), 61 element.getElementString()); 62 element = new Path.ChildAssocElement(new ChildAssociationRef(typeQName, parentRef, qname, childRef, true, 5)); 64 assertEquals("Element string incorrect", "{http://www.google.com}documentx[5]", element.getElementString()); 65 } 66 67 public void testElementTypes() throws Exception 68 { 69 Path.Element element = new Path.DescendentOrSelfElement(); 70 assertEquals("DescendentOrSelf element incorrect", 71 "descendant-or-self::node()", 72 element.getElementString()); 73 74 element = new Path.ParentElement(); 75 assertEquals("Parent element incorrect", "..", element.getElementString()); 76 77 element = new Path.SelfElement(); 78 assertEquals("Self element incorrect", ".", element.getElementString()); 79 } 80 81 public void testAppendingAndPrepending() throws Exception 82 { 83 Path.Element element0 = new Path.ChildAssocElement(new ChildAssociationRef(null, null, null, parentRef)); 84 Path.Element element1 = new Path.ChildAssocElement(new ChildAssociationRef(typeQName, parentRef, qname, childRef, true, 4)); 85 Path.Element element2 = new Path.DescendentOrSelfElement(); 86 Path.Element element3 = new Path.ParentElement(); 87 Path.Element element4 = new Path.SelfElement(); 88 absolutePath.append(element0).append(element1).append(element2).append(element3).append(element4); 90 relativePath.append(element1).append(element2).append(element3).append(element4); 91 assertEquals("Path appending didn't work", 93 "/{http://www.google.com}documentx[4]/descendant-or-self::node()/../.", 94 absolutePath.toString()); 95 96 Path copy = new Path(); 98 copy.append(relativePath).append(relativePath); 99 assertEquals("Path appending didn't work", 101 relativePath.toString() + "/" + relativePath.toString(), 102 copy.toString()); 103 104 relativePath.prepend(element2); 106 assertEquals("Prepending didn't work", 108 "descendant-or-self::node()/{http://www.google.com}documentx[4]/descendant-or-self::node()/../.", 109 relativePath.toString()); 110 } 111 } | Popular Tags |