Author: pnedonosko
Date: 2009-11-08 17:04:52 -0500 (Sun, 08 Nov 2009)
New Revision: 498
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-200: conn tests
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-08
13:19:25 UTC (rev 497)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-08
22:04:52 UTC (rev 498)
@@ -137,6 +137,53 @@
}
}
+ private void checkNode(Node<Serializable, Object> rootNode, String nodeId, QPath
nodePath)
+ {
+ Node<Serializable, Object> node = nodes.getChild(Fqn.fromElements(nodeId));
+
+ // check Node
+ Object dataObject = node.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertTrue("Node item data is not a Node", dataObject instanceof
NodeData);
+
+ NodeData data = (NodeData)dataObject;
+ assertEquals("Node id wrong", nodeId, data.getIdentifier());
+ assertEquals("Node path wrong", nodePath, data.getQPath());
+ }
+
+ private void checkChildNode(Node<Serializable, Object> rootNode, String childId,
QPath childPath)
+ {
+ checkChildNode(rootNode, childId, childPath, null, null);
+ }
+
+ private void checkChildNode(Node<Serializable, Object> rootNode, String childId,
QPath childPath, Integer orderNum,
+ Integer version)
+ {
+ Node<Serializable, Object> childNode =
+ rootNode.getChild(Fqn
+ .fromElements(childPath.getEntries()[childPath.getEntries().length -
1].getAsString(true)));
+
+ assertNotNull("Child Node should exists", childNode);
+ String childNodeId = (String)childNode.get(JBossCacheStorage.ITEM_ID);
+ Node<Serializable, Object> node =
props.getChild(Fqn.fromElements(childNodeId));
+ assertNotNull("Node by ID should exists", node);
+
+ Object childNodeObject = node.get(JBossCacheStorage.ITEM_DATA);
+ assertTrue("Node item data is not a Node", childNodeObject instanceof
NodeData);
+ NodeData childNodeData = (NodeData)childNodeObject;
+ assertEquals("Node id wrong", childId, childNodeData.getIdentifier());
+ assertEquals("Node path wrong", childPath, childNodeData.getQPath());
+
+ if (orderNum != null)
+ {
+ //assertEquals("Node order number wrong", orderNum,
childNodeData.getOrderNumber());
+ }
+
+ if (version != null)
+ {
+ //assertEquals("Node persisted version wrong", version,
childNodeData.getPersistedVersion());
+ }
+ }
+
public void testAddNode() throws Exception
{
// add root (/)
@@ -161,47 +208,12 @@
assertNotNull("Node expected", rootNode);
// check root Node
- Object dataObject = rootNode.get(JBossCacheStorageConnection.ITEM_DATA);
- assertTrue("Node item data is not a Node", dataObject instanceof
NodeData);
+ checkNode(rootNode, Constants.ROOT_UUID, Constants.ROOT_PATH);
- NodeData data = (NodeData)dataObject;
- assertEquals("Node id wrong", node1id, data.getIdentifier());
- assertEquals("Node path wrong", node1path, data.getQPath());
-
- // cehck childs
+ // cechk childs
assertEquals("Childs expected", 2, rootNode.getChildren().size());
-
- for (Node<Serializable, Object> child : rootNode.getChildren())
- {
- // check id and name
- String nodeName = child.getFqn().getLastElementAsString();
- String nodeId = (String)child.get(JBossCacheStorageConnection.ITEM_ID);
- if (nodeName.equals(node1path.getEntries()[node1path.getEntries().length -
1].getAsString(true)))
- {
- assertEquals("Node id wrong", node1id, nodeId);
- }
- else if (nodeName
-
.equals(Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length
- 1]
- .getAsString(true)))
- {
- assertEquals("Node id wrong", Constants.SYSTEM_UUID, nodeId);
- }
- else
- {
- fail("Wrong Node name " + nodeName);
- }
-
- // check data
- Node<Serializable, Object> childNode =
nodes.getChild(Fqn.fromElements(nodeId));
- assertNotNull("Node expected", childNode);
-
- Object childData = childNode.get(JBossCacheStorageConnection.ITEM_DATA);
- assertTrue("Child Node item data is not a Node", childData instanceof
NodeData);
-
- assertEquals("Node id wrong", nodeId,
((NodeData)childData).getIdentifier());
- assertEquals("Node path wrong", nodeName,
- data.getQPath().getEntries()[data.getQPath().getEntries().length -
1].getAsString(true));
- }
+ checkChildNode(rootNode, node1id, node1path);
+ checkChildNode(rootNode, Constants.SYSTEM_UUID, Constants.JCR_SYSTEM_PATH);
}
public void testAddProperty() throws Exception
@@ -228,7 +240,6 @@
// check in nodes
treePrint(nodes);
- treePrint(props);
Node<Serializable, Object> rootNode =
nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
@@ -251,7 +262,7 @@
}
// check in props
- treePrint(nodes);
+ treePrint(props);
Node<Serializable, Object> itemsProp1 =
props.getChild(Fqn.fromElements(propId1));
Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
@@ -373,39 +384,98 @@
// add node (/node)
String node1id = "1";
- QPath node1path = QPath.parse("[]:1[]node:1");
- conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0], 0,
+ QPath node1path = QPath.parse("[]:1[]snsNode:1");
+ int node1OrderNumb = 0;
+ int node1version = 1;
+ conn.add(new TransientNodeData(node1path, node1id, node1version,
Constants.NT_UNSTRUCTURED, new InternalQName[0],
+ node1OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ String node2id = "2";
+ QPath node2path = QPath.parse("[]:1[]snsNode:2");
+ int node2OrderNumb = 1;
+ conn.add(new TransientNodeData(node2path, node2id, 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0],
+ node2OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ String node3id = "3";
+ QPath node3path = QPath.parse("[]:1[]baseNode:1");
+ int node3OrderNumb = 2;
+ conn.add(new TransientNodeData(node3path, node3id, 1, Constants.NT_BASE, new
InternalQName[0], node3OrderNumb,
Constants.ROOT_UUID, new AccessControlList()));
// get root node ([]:1)
Node<Serializable, Object> rootNode =
nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
- // update /node (order number)
- int nodeOrderNumb = 1;
- conn.update(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0],
- nodeOrderNumb, Constants.ROOT_UUID, new AccessControlList()));
-
- // check in tree
+ // before
treePrint(nodes);
- Node<Serializable, Object> node =
- rootNode.getChild(Fqn
- .fromElements(node1path.getEntries()[node1path.getEntries().length -
1].getAsString(true)));
+ // do Node.orderBefore("/snsNode:1", null) behaviour: order /snsNode:1 at
the end
+ // update /snsNode:1 (order number, version and index) to /snsNode:2
+ QPath newNode1path = QPath.parse("[]:1[]snsNode:2");
+ int newNode1OrderNumb = 2;
+ int newNode1version = 2;
+ conn.update(new TransientNodeData(newNode1path, node1id, newNode1version,
Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], newNode1OrderNumb, Constants.ROOT_UUID, new
AccessControlList()));
- assertNotNull("Node should exists", node);
- assertEquals("Child expected", 1, rootNode.getChildren().size());
+ // update /snsNode:2 (order number, version and index) to /snsNode:1
+ QPath newNode2path = QPath.parse("[]:1[]snsNode:1");
+ int newNode2OrderNumb = 0;
+ int newNode2version = 2;
+ conn.update(new TransientNodeData(newNode2path, node2id, newNode2version,
Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], newNode2OrderNumb, Constants.ROOT_UUID, new
AccessControlList()));
- // check in items
+ // update /baseNode:1 (order number and version) to /baseNode:1
+ int newNode3OrderNumb = 1;
+ int newNode3version = 2;
+ conn.update(new TransientNodeData(node3path, node3id, newNode3version,
Constants.NT_BASE, new InternalQName[0],
+ newNode3OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ // after
treePrint(nodes);
- Node<Serializable, Object> itemNode =
nodes.getChild(Fqn.fromElements(node1id));
- assertNotNull("Node item data should exists", itemNode);
+ // get /snsNode:1 from childs of root /
+ checkChildNode(rootNode, node1id, node2path);
+ checkChildNode(rootNode, node2id, node1path);
+ checkChildNode(rootNode, node3id, node3path);
- Object dataObject = itemNode.get(JBossCacheStorageConnection.ITEM_DATA);
- assertTrue("Node item data should be a NodeData", dataObject instanceof
NodeData);
- assertEquals("Node id wrong", node1id,
((NodeData)dataObject).getIdentifier());
- assertEquals("Node path wrong", node1path,
((NodeData)dataObject).getQPath());
- assertEquals("Node order number wrong", nodeOrderNumb,
((NodeData)dataObject).getOrderNumber());
+// Node<Serializable, Object> childNode1 =
+// rootNode.getChild(Fqn
+// .fromElements(node1path.getEntries()[node1path.getEntries().length -
1].getAsString(true)));
+//
+// assertNotNull("Child Node should exists", childNode1);
+// String childNode1id = (String)childNode1.get(JBossCacheStorage.ITEM_ID);
+// Node<Serializable, Object> node1 =
props.getChild(Fqn.fromElements(childNode1id));
+// assertNotNull("Node by ID should exists", node1);
+//
+// Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
+// assertTrue("Node item data is not a Node", childNode1Object instanceof
NodeData);
+// assertEquals("Node id wrong", node2id,
((NodeData)childNode1Object).getIdentifier());
+// assertEquals("Node path wrong", node2path,
((NodeData)childNode1Object).getQPath());
+//
+// // get /snsNode:2 from childs of root /
+// Node<Serializable, Object> childNode2 =
+// rootNode.getChild(Fqn
+// .fromElements(node2path.getEntries()[node2path.getEntries().length -
1].getAsString(true)));
+//
+// assertNotNull("Child Node should exists", childNode2);
+// String childNode2id = (String)childNode2.get(JBossCacheStorage.ITEM_ID);
+// Node<Serializable, Object> node2 =
props.getChild(Fqn.fromElements(childNode2id));
+// assertNotNull("Node by ID should exists", node2);
+//
+// Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
+// assertTrue("Node item data is not a Node", childNode1Object instanceof
NodeData);
+// assertEquals("Node id wrong", node2id,
((NodeData)childNode1Object).getIdentifier());
+// assertEquals("Node path wrong", node2path,
((NodeData)childNode1Object).getQPath());
+//
+// assertEquals("Child expected", 3, rootNode.getChildren().size());
+//
+// Node<Serializable, Object> itemNode =
nodes.getChild(Fqn.fromElements(node1id));
+// assertNotNull("Node item data should exists", itemNode);
+//
+// Object dataObject = itemNode.get(JBossCacheStorageConnection.ITEM_DATA);
+// assertTrue("Node item data should be a NodeData", dataObject instanceof
NodeData);
+// assertEquals("Node id wrong", node1id,
((NodeData)dataObject).getIdentifier());
+// assertEquals("Node path wrong", node1path,
((NodeData)dataObject).getQPath());
+// assertEquals("Node order number wrong", nodeOrderNumb,
((NodeData)dataObject).getOrderNumber());
}
public void testUpdateProperty() throws Exception