KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > reading > fs > TestNode


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5
6 package org.exoplatform.services.jcr.api.reading.fs;
7
8
9 import javax.jcr.DoubleValue;
10 import javax.jcr.LongValue;
11 import javax.jcr.Node;
12 import javax.jcr.Property;
13 import javax.jcr.PropertyIterator;
14 import javax.jcr.Repository;
15 import javax.jcr.RepositoryException;
16 import javax.jcr.StringValue;
17 import javax.jcr.Ticket;
18
19 import org.exoplatform.services.jcr.api.reading.NodeTest;
20
21 /**
22  * Created y the eXo platform team
23  * User: Benjamin Mestrallet
24  * Date: 21 juil. 2004
25  */

26 public class TestNode extends NodeTest{
27
28   public void setUp() throws Exception JavaDoc {
29     super.setUp();
30     repository = (Repository) repositoryService.getRepository("fs1");
31     ticket = repository.login(credentials, "ws");
32     initRepository();
33   }
34   public void testGetProperties() throws RepositoryException {
35     ticket = repository.login(credentials, WORKSPACE);
36     Node root = ticket.getRootNode();
37     Node node = root.getNode("/childNode");
38
39     PropertyIterator iterator = node.getProperties();
40     while(iterator.hasNext()){
41       Property property = iterator.nextProperty();
42       if(!("jcr:primaryType".equals(property.getName()) || "jcr:created".equals(property.getName()) ||
43           "jcr:lastModified".equals(property.getName())))
44         fail("returned non expected nodes");
45     }
46
47     Ticket ticket2 = repository.login(credentials, WORKSPACE);
48     Node root2 = ticket2.getRootNode();
49     Node node2 = root2.getNode("/childNode/childNode2/jcr:content");
50     node2.setProperty("exo:content", new StringValue("hehe"));
51     ticket2.save();
52
53     ticket.revert();
54     node = root.getNode("/childNode/childNode2/jcr:content");
55     iterator = node.getProperties();
56     while(iterator.hasNext()){
57       Property property = iterator.nextProperty();
58       if(!("jcr:primaryType".equals(property.getName()) || "jcr:created".equals(property.getName()) ||
59           "jcr:lastModified".equals(property.getName()) ||
60           "exo:content".equals(property.getName()) || "jcr:uuid".equals(property.getName())))
61         fail("returned non expected properties");
62     }
63   }
64
65   public void testGetPropertiesWithNamePattern() throws RepositoryException {
66     ticket = repository.login(credentials, WORKSPACE);
67     Node root = ticket.getRootNode();
68     Node node = root.getNode("/childNode/childNode2/jcr:content");
69     node.setProperty("exo:content", "prop1Value");
70 // node.setProperty("property2", "prop2Value");
71

72     PropertyIterator iterator = node.getProperties("property1 | property2");
73     while(iterator.hasNext()){
74       Property property = iterator.nextProperty();
75       if(!("exo:content".equals(property.getName()) ))
76         fail("returned non expected properties");
77     }
78
79     iterator = node.getProperties("property1 | jcr:*");
80     while(iterator.hasNext()){
81       Property property = iterator.nextProperty();
82       if(!("property1".equals(property.getName()) || "jcr:primaryType".equals(property.getName())
83           || "jcr:created".equals(property.getName()) || "jcr:lastModified".equals(property.getName()) ||
84           "exo:content".equals(property.getName()) || "jcr:uuid".equals(property.getName()) ))
85         fail("returned non expected properties");
86     }
87
88     Ticket ticket2 = repository.login(credentials, WORKSPACE);
89     Node root2 = ticket2.getRootNode();
90     Node node2 = root2.getNode("/childNode/childNode2/jcr:content");
91     node2.setProperty("exo:content", new StringValue("hehe"));
92     ticket2.save();
93
94     ticket.revert();
95     node = root.getNode("/childNode/childNode2/jcr:content");
96     iterator = node.getProperties("exo:* | property1");
97     while(iterator.hasNext()){
98       Property property = iterator.nextProperty();
99       if(!("property1".equals(property.getName()) || "exo:prop".equals(property.getName()) ||
100           "exo:content".equals(property.getName()) ))
101         fail("returned non expected properties");
102     }
103   }
104
105   public void testFindProperties() throws RepositoryException {
106     Node root = ticket.getRootNode();
107     Node node = root.getNode("/childNode/childNode2/jcr:content");
108     node.setProperty("exo:content", "prop1Value");
109     int i = 0;
110     PropertyIterator iterator = node.findProperties(new StringValue("prop1Value"));
111     while(iterator.hasNext()){
112       Property property = iterator.nextProperty();
113       if( !"exo:content".equals(property.getName()) )
114         fail("returned non expected properties");
115       i++;
116     }
117     assertEquals(1, i);
118   }
119
120   public void testFindProperty() throws RepositoryException {
121     ticket = repository.login(credentials, WORKSPACE);
122     Node root = ticket.getRootNode();
123     Node node = root.getNode("/childNode/childNode2/jcr:content");
124     node.setProperty("exo:content", "prop1Value");
125     assertEquals("exo:content", node.findProperty(new StringValue("prop1Value")).getName());
126     assertNull(node.findProperty(new StringValue("prop2Value")));
127 // node.setProperty("property2", "prop1Value");
128
// assertEquals("property1", node.findProperty(new StringValue("prop1Value")).getName());
129
ticket.save();
130
131     ticket = repository.login(credentials, WORKSPACE);
132     root = ticket.getRootNode();
133     node = root.getNode("/childNode/childNode2/jcr:content");
134     assertNotNull(node.findProperty(new StringValue("prop1Value")));
135     assertEquals("exo:content", node.findProperty(new StringValue("prop1Value")).getName());
136
137     assertNull(node.findProperty(new LongValue(15)));
138     node.setProperty("longProp", new LongValue(15));
139     assertEquals("longProp", node.findProperty(new LongValue(15)).getName());
140
141     assertNull(node.findProperty(new DoubleValue(16)));
142     node.setProperty("doubleProp", new DoubleValue(16));
143     assertEquals("doubleProp", node.findProperty(new DoubleValue(16)).getName());
144
145     Ticket ticket2 = repository.login(credentials, WORKSPACE);
146     Node root2 = ticket2.getRootNode();
147     Node node2 = root2.getNode("/childNode/childNode2/jcr:content");
148     node2.setProperty("exo:content", new StringValue("hehe"));
149     ticket2.save();
150
151     ticket.revert();
152     node = root.getNode("/childNode/childNode2/jcr:content");
153     PropertyIterator iterator = node.getProperties();
154     while(iterator.hasNext()){
155       Property property = iterator.nextProperty();
156       if(!( "exo:content".equals(property.getName())
157           || "jcr:created".equals(property.getName()) || "jcr:lastModified".equals(property.getName())
158           || "jcr:primaryType".equals(property.getName()) || "jcr:uuid".equals(property.getName()) ) )
159         fail("returned non expected properties");
160     }
161   }
162
163   public void testHasNodes() throws RepositoryException {
164     Node root = ticket.getRootNode();
165     assertTrue(root.hasNodes());
166   }
167
168 }
169
Popular Tags