[exo-jcr-commits] exo-jcr SVN: r494 - in jcr/branches/1.12.0-JBC/component/core: src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 6 11:41:21 EST 2009


Author: pnedonosko
Date: 2009-11-06 11:41:20 -0500 (Fri, 06 Nov 2009)
New Revision: 494

Added:
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Modified:
   jcr/branches/1.12.0-JBC/component/core/pom.xml
Log:
EXOJCR-200: new impl tests 

Modified: jcr/branches/1.12.0-JBC/component/core/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/pom.xml	2009-11-06 16:18:11 UTC (rev 493)
+++ jcr/branches/1.12.0-JBC/component/core/pom.xml	2009-11-06 16:41:20 UTC (rev 494)
@@ -571,7 +571,7 @@
                         <include>**/**/JBossCacheServiceTest__.java</include>
                         <include>**/**/TestItem__.java</include>
                         
-                        <include>**/**/JBossCacheTreeStorageConnectionTest.java</include>
+                        <include>**/**/JBossCacheStorageConnectionTest.java</include>
                      </includes>
                   </configuration>
                </plugin>

Added: 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	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java	2009-11-06 16:41:20 UTC (rev 494)
@@ -0,0 +1,668 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 25.10.2009
+ *
+ * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a> 
+ * @version $Id$
+ */
+public class JBossCacheStorageConnectionTest extends TestCase
+{
+
+   protected JBossCacheStorageConnection conn;
+
+   protected Cache<Serializable, Object> cache;
+
+   protected Node<Serializable, Object> nodes;
+
+   protected Node<Serializable, Object> props;
+
+   protected String jbcConfig;
+
+   /**
+    * {@inheritDoc}
+    */
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      // JBossCache 
+      initJBCConfig();
+
+      cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig);
+
+      Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+      // prepare cache structures
+      nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
+      props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
+
+      // run cache
+      cache.create();
+      cache.start();
+
+      // JCR connection
+      conn = new JBossCacheStorageConnection(cache, nodes, props);
+   }
+
+   protected void initJBCConfig()
+   {
+      jbcConfig = "conf/standalone/test-jbosscache-config-jdbcloader.xml";
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   protected void tearDown() throws Exception
+   {
+
+      cache.stop();
+      cache.destroy();
+
+      super.tearDown();
+   }
+
+   private void treePrint(Node<Serializable, Object> node)
+   {
+      for (Node<Serializable, Object> child : node.getChildren())
+      {
+         System.out.println(child.toString());
+         for (Serializable key : child.getKeys())
+         {
+            System.out.println("\t" + key + "=" + child.get(key));
+         }
+         if (!child.isLeaf())
+         {
+            treePrint(child);
+         }
+      }
+   }
+
+   public void testAddNode() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // 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,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // add /jcr:system
+      conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+      // check in nodes
+      treePrint(nodes);
+
+      // get root node ([]:1)
+      Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+      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);
+
+      NodeData data = (NodeData)dataObject;
+      assertEquals("Node id wrong", node1id, data.getIdentifier());
+      assertEquals("Node path wrong", node1path, data.getQPath());
+
+      // cehck 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));
+      }
+   }
+
+   public void testAddProperty() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/jcr:primaryType)
+      String propId1 = "1";
+      QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+      TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+      String propValue1 = "Property value #1";
+      propData1.setValue(new TransientValueData(propValue1));
+      conn.add(propData1);
+
+      // add property (/jcr:mixinTypes)
+      String propId2 = "2";
+      QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+      TransientPropertyData propData2 = new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false);
+      String propValue2 = "Property value #2";
+      propData2.setValue(new TransientValueData(propValue2));
+      conn.add(propData2);
+
+      // check in nodes
+      treePrint(nodes);
+      treePrint(props);
+
+      Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+      assertEquals("Attributes ammount wrong", 3, rootNode.getKeys().size());
+
+      String pid1 = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
+      assertNotNull("Property ID should exists", pid1);
+      assertEquals("Property ID wrong", propId1, pid1);
+
+      String pid2 = (String)rootNode.get(Constants.JCR_MIXINTYPES.getAsString());
+      assertNotNull("Property ID should exists", pid2);
+      assertEquals("Property ID wrong", propId2, pid2);
+
+      // TODO check order
+      int index = 0;
+      for (Serializable key : rootNode.getKeys())
+      {
+         //System.out.println(key);
+         //index++;
+      }
+
+      // check in props
+      treePrint(nodes);
+
+      Node<Serializable, Object> itemsProp1 = props.getChild(Fqn.fromElements(propId1));
+      Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertNotNull("Property item data should exists", data1Object);
+      assertTrue("Property item data is not a Property", data1Object instanceof PropertyData);
+
+      PropertyData data1 = (PropertyData)data1Object;
+      assertEquals("Property id wrong", propId1, data1.getIdentifier());
+      assertEquals("Property path wrong", propPath1, data1.getQPath());
+      assertEquals("Property Value wrong", propValue1, new String(data1.getValues().get(0).getAsByteArray(),
+         Constants.DEFAULT_ENCODING));
+
+      Node<Serializable, Object> itemsProp2 = props.getChild(Fqn.fromElements(propId2));
+      Object data2Object = itemsProp2.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertNotNull("Property item data should exists", data2Object);
+      assertTrue("Property item data is not a Property", data2Object instanceof PropertyData);
+
+      PropertyData data2 = (PropertyData)data2Object;
+      assertEquals("Property id wrong", propId2, data2.getIdentifier());
+      assertEquals("Property path wrong", propPath2, data2.getQPath());
+      assertEquals("Property Value wrong", propValue2, new String(data2.getValues().get(0).getAsByteArray(),
+         Constants.DEFAULT_ENCODING));
+   }
+
+   public void testDeleteNode() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // 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,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // add /jcr:system
+      conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+      // get root node ([]:1)
+      Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+      assertEquals("Number of childs wrong", 2, rootNode.getChildren().size());
+
+      // delete /node
+      conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // check in nodes
+      treePrint(nodes);
+
+      // check childs
+      assertEquals("Childs expected", 1, rootNode.getChildren().size());
+
+      assertNull("Child Node should be deleted", rootNode.getChild(Fqn.fromElements(node1path.getEntries()[node1path
+         .getEntries().length - 1].getAsString(true))));
+
+      assertNotNull("Child Node should be not deleted", rootNode.getChild(Fqn.fromElements(Constants.JCR_SYSTEM_PATH
+         .getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1].getAsString(true))));
+
+      // to be sure ;)
+      Node<Serializable, Object> child = rootNode.getChildren().iterator().next();
+      assertEquals("Node name wrong",
+         Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1].getAsString(true),
+         child.getFqn().getLastElementAsString());
+
+      assertEquals("Node id wrong", Constants.SYSTEM_UUID, (String)child.get(JBossCacheStorageConnection.ITEM_ID));
+
+      // check nodes 
+      assertNull("Node item data should not exists", nodes.getChild(Fqn.fromElements(node1id)));
+
+      Node<Serializable, Object> system = nodes.getChild(Fqn.fromElements(Constants.SYSTEM_UUID));
+      assertNotNull("Node item data should exists", system);
+   }
+
+   public void testDeleteProperty() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/jcr:primaryType)
+      String propId1 = "1";
+      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
+         1, 1, Constants.ROOT_UUID, false));
+
+      // add property (/jcr:mixinTypes)
+      String propId2 = "2";
+      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES), propId2,
+         1, 1, Constants.ROOT_UUID, false));
+
+      // get root node ([]:1)
+      Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+      // delete /jcr:primaryType
+      conn.delete(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE),
+         propId1, 1, 1, Constants.ROOT_UUID, false));
+
+      // check in nodes
+      treePrint(nodes);
+
+      assertEquals("Number of childs wrong", 2, rootNode.getKeys().size());
+      assertNull("Property should be deleted", rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString()));
+      assertNotNull("Property should exists", rootNode.get(Constants.JCR_MIXINTYPES.getAsString()));
+
+      // check in props
+      treePrint(props);
+
+      assertNull("Property item data should not exists", props.getChild(Fqn.fromElements(propId1)));
+      assertNotNull("Property item data should exists", props.getChild(Fqn.fromElements(propId2)));
+   }
+
+   public void testUpdateNode() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // 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,
+         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
+      treePrint(nodes);
+
+      Node<Serializable, Object> node =
+         rootNode.getChild(Fqn
+            .fromElements(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)));
+
+      assertNotNull("Node should exists", node);
+      assertEquals("Child expected", 1, rootNode.getChildren().size());
+
+      // check in items
+      treePrint(nodes);
+
+      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
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/prop1)
+      String propId1 = "1";
+      QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+      TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+      String propValue1 = "Property value #1";
+      propData1.setValue(new TransientValueData(propValue1));
+      conn.add(propData1);
+
+      // update property (/prop1) with new value
+      TransientPropertyData propDataU = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+      String propValueU = "Updated Property value #1";
+      propDataU.setValue(new TransientValueData(propValueU));
+      conn.update(propDataU);
+
+      // check in tree
+      treePrint(nodes);
+
+      Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+      assertEquals("Attributes ammount wrong", 2, rootNode.getKeys().size());
+
+      String pid = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
+      assertEquals("Property ID wrong", propId1, pid);
+
+      // check in items
+      treePrint(nodes);
+
+      Node<Serializable, Object> itemsProp1 = props.getChild(Fqn.fromElements(propId1));
+      Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertNotNull("Property item data should exists", data1Object);
+      assertTrue("Property item data is not a Property", data1Object instanceof PropertyData);
+
+      PropertyData data1 = (PropertyData)data1Object;
+      assertEquals("Property id wrong", propId1, data1.getIdentifier());
+      assertEquals("Property path wrong", propPath1, data1.getQPath());
+      assertEquals("Property Value wrong", propValueU, new String(data1.getValues().get(0).getAsByteArray(),
+         Constants.DEFAULT_ENCODING));
+   }
+
+   public void testGetNodeByName() throws Exception
+   {
+      // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // 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,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // add /jcr:system
+      conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+      // check 
+      ItemData nodeItem =
+         conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+            new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()),
+            node1path.getEntries()[node1path.getEntries().length - 1]);
+
+      assertTrue("Node expected", nodeItem.isNode());
+      assertEquals("Node id wrong", node1id, nodeItem.getIdentifier());
+      assertEquals("Node path wrong", node1path, nodeItem.getQPath());
+   }
+
+   public void testGetPropertyByName() throws Exception
+   {
+      // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/jcr:primaryType)
+      String propId1 = "1";
+      QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+      conn.add(new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false));
+
+      // add property (/jcr:mixinTypes)
+      String propId2 = "2";
+      QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+      conn.add(new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false));
+
+      // check 
+      ItemData propItem =
+         conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+            new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()),
+            propPath1.getEntries()[propPath1.getEntries().length - 1]);
+
+      assertFalse("Proeprty expected", propItem.isNode());
+      assertEquals("Proeprty id wrong", propId1, propItem.getIdentifier());
+      assertEquals("Proeprty path wrong", propPath1, propItem.getQPath());
+   }
+
+   public void testGetNodeById() throws Exception
+   {
+      // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // 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,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // add /jcr:system
+      conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+      // check 
+      ItemData nodeItem = conn.getItemData(node1id);
+
+      assertTrue("Node expected", nodeItem.isNode());
+      assertEquals("Node id wrong", node1id, nodeItem.getIdentifier());
+      assertEquals("Node path wrong", node1path, nodeItem.getQPath());
+   }
+
+   public void testGetPropertyById() throws Exception
+   {
+      // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/jcr:primaryType)
+      String propId1 = "1";
+      QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+      conn.add(new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false));
+
+      // add property (/jcr:mixinTypes)
+      String propId2 = "2";
+      QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+      conn.add(new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false));
+
+      // check 
+      ItemData propItem = conn.getItemData(propId1);
+
+      assertFalse("Proeprty expected", propItem.isNode());
+      assertEquals("Proeprty id wrong", propId1, propItem.getIdentifier());
+      assertEquals("Proeprty path wrong", propPath1, propItem.getQPath());
+   }
+
+   public void _testGetChildNodes() throws Exception
+   {
+      // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // 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,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // add /jcr:system
+      conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+      // check in tree
+      treePrint(nodes);
+
+      List<NodeData> childs =
+         conn.getChildNodesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+            Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      assertEquals("Childs amount wrong", 2, childs.size());
+
+      for (NodeData child : childs)
+      {
+         if (child.getQPath().equals(node1path))
+         {
+            assertEquals("Node id wrong", node1id, child.getIdentifier());
+         }
+         else if (child.getQPath().equals(Constants.JCR_SYSTEM_PATH))
+         {
+            assertEquals("Node id wrong", Constants.SYSTEM_UUID, child.getIdentifier());
+         }
+         else
+         {
+            fail("Wrong Node found");
+         }
+      }
+   }
+
+   public void _testGetChildProperties() throws Exception
+   {
+      // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/jcr:primaryType)
+      String propId1 = "1";
+      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
+         1, 1, Constants.ROOT_UUID, false));
+
+      // add property (/jcr:mixinTypes)
+      String propId2 = "2";
+      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES), propId2,
+         1, 1, Constants.ROOT_UUID, false));
+
+      // add property (/a)
+      String propId3 = "3";
+      InternalQName propName3 = InternalQName.parse("[]a");
+      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, propName3), propId3, 1, 1,
+         Constants.ROOT_UUID, false));
+
+      // add property (/b)
+      String propId4 = "4";
+      InternalQName propName4 = InternalQName.parse("[]b");
+      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, propName4), propId4, 1, 1,
+         Constants.ROOT_UUID, false));
+
+      // check
+      treePrint(nodes);
+
+      List<PropertyData> childs =
+         conn.getChildPropertiesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+            Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      assertEquals("Childs amount wrong", 4, childs.size());
+
+      for (PropertyData child : childs)
+      {
+         if (child.getQPath().getName().equals(Constants.JCR_PRIMARYTYPE))
+         {
+            assertEquals("Property id wrong", propId1, child.getIdentifier());
+         }
+         else if (child.getQPath().getName().equals(Constants.JCR_MIXINTYPES))
+         {
+            assertEquals("Property id wrong", propId2, child.getIdentifier());
+         }
+         else if (child.getQPath().getName().equals(propName3))
+         {
+            assertEquals("Property id wrong", propId3, child.getIdentifier());
+         }
+         else if (child.getQPath().getName().equals(propName4))
+         {
+            assertEquals("Property id wrong", propId4, child.getIdentifier());
+         }
+         else
+         {
+            fail("Wrong Property found");
+         }
+      }
+   }
+
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id



More information about the exo-jcr-commits mailing list