KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > cmr > repository > PathTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.service.cmr.repository;
18
19 import org.alfresco.service.namespace.QName;
20
21 import junit.framework.TestCase;
22
23 /**
24  * @see org.alfresco.service.cmr.repository.Path
25  *
26  * @author Derek Hulley
27  */

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 JavaDoc name)
39     {
40         super(name);
41     }
42     
43     public void setUp() throws Exception JavaDoc
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 JavaDoc
56     {
57         // plain
58
Path.Element element = new Path.ChildAssocElement(new ChildAssociationRef(typeQName, parentRef, qname, childRef));
59         assertEquals("Element string incorrect",
60                 qname.toString(),
61                 element.getElementString());
62         // sibling
63
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 JavaDoc
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 JavaDoc
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         // append them all to the path
89
absolutePath.append(element0).append(element1).append(element2).append(element3).append(element4);
90         relativePath.append(element1).append(element2).append(element3).append(element4);
91         // check
92
assertEquals("Path appending didn't work",
93                 "/{http://www.google.com}documentx[4]/descendant-or-self::node()/../.",
94                 absolutePath.toString());
95         
96         // copy the path
97
Path copy = new Path();
98         copy.append(relativePath).append(relativePath);
99         // check
100
assertEquals("Path appending didn't work",
101                 relativePath.toString() + "/" + relativePath.toString(),
102                 copy.toString());
103         
104         // prepend
105
relativePath.prepend(element2);
106         // check
107
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