[exo-jcr-commits] exo-jcr SVN: r631 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 13 05:03:38 EST 2009


Author: sergiykarpenko
Date: 2009-11-13 05:03:37 -0500 (Fri, 13 Nov 2009)
New Revision: 631

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java
Log:
EXOJCR-202: IndexerCacheLoaderRuntimeTest test updated

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java	2009-11-13 10:00:05 UTC (rev 630)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java	2009-11-13 10:03:37 UTC (rev 631)
@@ -236,12 +236,6 @@
       modifications.addAll(removeNode(nd));
       conn.commit();
 
-      //      NodeData data =
-      //         new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, null,
-      //            new AccessControlList());
-      //      conn.delete(data);
-      //conn.commit();
-
       // check removing
       conn = persistentContainer.openConnection();
       nd = (NodeData)conn.getItemData(node1id);
@@ -255,9 +249,67 @@
       searcher = new IndexSearcher(reader);
       hit = searcher.search(query);
       assertEquals(0, hit.length());
-
    }
 
+   //   public void testRenameNode() throws Exception
+   //   {
+   //      List<Modification> modifications = new ArrayList<Modification>();
+   //
+   //      // prepare add node to storage
+   //      WorkspaceStorageConnection conn = persistentContainer.openConnection();
+   //
+   //      String node1id = IdGenerator.generate();
+   //      QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
+   //
+   //      // add node (/) with jcr:primaryType
+   //      NodeData nodeData =
+   //         new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+   //            Constants.ROOT_UUID, new AccessControlList());
+   //      conn.add(nodeData);
+   //      modifications.addAll(this.addNode(nodeData));
+   //
+   //      // add property (/jcr:primaryType)
+   //      TransientPropertyData propData =
+   //         createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE, Constants.NT_UNSTRUCTURED, false);
+   //      conn.add(propData);
+   //      modifications.addAll(this.addProperty(propData));
+   //
+   //      conn.commit();
+   //      loader.put(modifications);
+   //
+   //      // check do we really have node and its property
+   //      conn = persistentContainer.openConnection();
+   //      NodeData nd = (NodeData)conn.getItemData(node1id);
+   //      assertNotNull(nd);
+   //      assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
+   //
+   //      PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
+   //      assertNotNull(pd);
+   //      assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
+   //
+   //      // find node by search engine
+   //      SearchIndex index = ((SearchIndex)manager.getHandler());
+   //      IndexReader reader = index.getIndexReader();
+   //
+   //      IndexSearcher searcher = new IndexSearcher(reader);
+   //
+   //      Query query = new TermQuery(new Term("_:UUID", node1id));
+   //      Hits hit = searcher.search(query);
+   //      assertEquals(1, hit.length());
+   //
+   //      modifications.clear();
+   //
+   //      conn = persistentContainer.openConnection();
+   //
+   //      QPath newnode1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
+   //      NodeData newnodeData =
+   //         new TransientNodeData(newnode1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+   //            Constants.ROOT_UUID, new AccessControlList());
+   //
+   //      conn.rename(newnodeData);
+   //
+   //   }
+
    public void testUpdateAddProperty() throws Exception
    {
 
@@ -349,6 +401,194 @@
 
    }
 
+   public void testUpdateRemoveProperty() throws Exception
+   {
+
+      List<Modification> modifications = new ArrayList<Modification>();
+
+      // prepare add node to storage
+      WorkspaceStorageConnection conn = persistentContainer.openConnection();
+
+      String node1id = IdGenerator.generate();
+      QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
+
+      // add node (/) with jcr:primaryType
+      NodeData nodeData =
+         new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+            Constants.ROOT_UUID, new AccessControlList());
+      conn.add(nodeData);
+      modifications.addAll(this.addNode(nodeData));
+
+      // add property (/jcr:primaryType)
+      TransientPropertyData propData =
+         createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE, Constants.NT_UNSTRUCTURED, false);
+      conn.add(propData);
+      modifications.addAll(this.addProperty(propData));
+
+      // add additonal property
+      TransientPropertyData propData2 =
+         createProperty(node1path, node1id, new InternalQName(Constants.NS_DEFAULT_URI, "myProp2"), "JCR DATA VALUE",
+            false);
+      conn.add(propData2);
+      modifications.addAll(addProperty(propData2));
+
+      conn.commit();
+      loader.put(modifications);
+
+      // check do we really have node and its property
+      conn = persistentContainer.openConnection();
+      NodeData nd = (NodeData)conn.getItemData(node1id);
+      assertNotNull(nd);
+      assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
+
+      PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
+      assertNotNull(pd);
+      assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
+
+      // find node by search engine
+      SearchIndex index = ((SearchIndex)manager.getHandler());
+      IndexReader reader = index.getIndexReader();
+
+      IndexSearcher searcher = new IndexSearcher(reader);
+
+      Query query = new TermQuery(new Term("_:UUID", node1id));
+      Hits hit = searcher.search(query);
+      assertEquals(1, hit.length());
+
+      query = new TermQuery(new Term("FULL:myProp2", "data"));
+      hit = searcher.search(query);
+      assertEquals(1, hit.length());
+
+      modifications.clear();
+
+      // remove property
+      conn = persistentContainer.openConnection();
+      conn.delete(propData2);
+      modifications.addAll(removeProperty(propData2));
+      conn.commit();
+
+      loader.put(modifications);
+
+      // tests it
+      WorkspaceStorageConnection connection = persistentContainer.openConnection();
+
+      PropertyData destPropData = (PropertyData)connection.getItemData(propData2.getIdentifier());
+
+      assertNull(destPropData);
+
+      reader = index.getIndexReader();
+
+      searcher = new IndexSearcher(reader);
+
+      query = new TermQuery(new Term("_:UUID", node1id));
+      hit = searcher.search(query);
+      assertEquals(1, hit.length());
+
+      query = new TermQuery(new Term("FULL:myProp2", "data"));
+      hit = searcher.search(query);
+      assertEquals(0, hit.length());
+
+   }
+
+   public void testUpdateProperty() throws Exception
+   {
+
+      List<Modification> modifications = new ArrayList<Modification>();
+
+      // prepare add node to storage
+      WorkspaceStorageConnection conn = persistentContainer.openConnection();
+
+      String node1id = IdGenerator.generate();
+      QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
+
+      // add node (/) with jcr:primaryType
+      NodeData nodeData =
+         new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+            Constants.ROOT_UUID, new AccessControlList());
+      conn.add(nodeData);
+      modifications.addAll(this.addNode(nodeData));
+
+      // add property (/jcr:primaryType)
+      TransientPropertyData propData =
+         createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE, Constants.NT_UNSTRUCTURED, false);
+      conn.add(propData);
+      modifications.addAll(this.addProperty(propData));
+
+      // add additonal property
+      TransientPropertyData propData2 =
+         createProperty(node1path, node1id, new InternalQName(Constants.NS_DEFAULT_URI, "myProp2"), "JCR DATA VALUE",
+            false);
+      conn.add(propData2);
+      modifications.addAll(addProperty(propData2));
+
+      conn.commit();
+      loader.put(modifications);
+
+      // check do we really have node and its property
+      conn = persistentContainer.openConnection();
+      NodeData nd = (NodeData)conn.getItemData(node1id);
+      assertNotNull(nd);
+      assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
+
+      PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
+      assertNotNull(pd);
+      assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
+
+      // find node by search engine
+      SearchIndex index = ((SearchIndex)manager.getHandler());
+      IndexReader reader = index.getIndexReader();
+
+      IndexSearcher searcher = new IndexSearcher(reader);
+
+      Query query = new TermQuery(new Term("_:UUID", node1id));
+      Hits hit = searcher.search(query);
+      assertEquals(1, hit.length());
+
+      query = new TermQuery(new Term("FULL:myProp2", "data"));
+      hit = searcher.search(query);
+      assertEquals(1, hit.length());
+
+      modifications.clear();
+
+      // update property
+      conn = persistentContainer.openConnection();
+
+      TransientPropertyData newpropData2 =
+         new TransientPropertyData(propData2.getQPath(), propData2.getIdentifier(), propData2.getPersistedVersion(),
+            propData2.getType(), propData2.getParentIdentifier(), propData2.isMultiValued());
+
+      newpropData2.setValue(new TransientValueData("newvalue"));
+
+      conn.update(newpropData2);
+      modifications.addAll(updateProperty(newpropData2));
+      conn.commit();
+
+      loader.put(modifications);
+
+      // tests it
+      WorkspaceStorageConnection connection = persistentContainer.openConnection();
+
+      PropertyData destPropData = (PropertyData)connection.getItemData(propData2.getIdentifier());
+
+      assertNotNull(destPropData);
+
+      reader = index.getIndexReader();
+
+      searcher = new IndexSearcher(reader);
+
+      query = new TermQuery(new Term("_:UUID", node1id));
+      hit = searcher.search(query);
+      assertEquals(1, hit.length());
+
+      query = new TermQuery(new Term("FULL:myProp2", "data"));
+      hit = searcher.search(query);
+      assertEquals(0, hit.length());
+
+      query = new TermQuery(new Term("FULL:myProp2", "newvalue"));
+      hit = searcher.search(query);
+      assertEquals(1, hit.length());
+   }
+
    /**
     * Add Property to the connection but doesn't save it.
     *



More information about the exo-jcr-commits mailing list