[exo-jcr-commits] exo-jcr SVN: r615 - 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
Thu Nov 12 11:30:44 EST 2009


Author: sergiykarpenko
Date: 2009-11-12 11:30:44 -0500 (Thu, 12 Nov 2009)
New Revision: 615

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-12 16:28:45 UTC (rev 614)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java	2009-11-12 16:30:44 UTC (rev 615)
@@ -41,6 +41,7 @@
 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.ValueData;
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.core.LocationFactory;
 import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
@@ -257,37 +258,97 @@
 
    }
 
-   //   public void testAddProperty() throws Exception
-   //   {
-   //      // prepare
-   //      TransientPropertyData propData =
-   //         createProperty(Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
-   //
-   //      List<Modification> modifications = new ArrayList<Modification>();
-   //
-   //      modifications.addAll(addProperty(propData));
-   //
-   //      loader.put(modifications);
-   //
-   //      // tests it
-   //      WorkspaceStorageConnection connection = persistentContainer.openConnection();
-   //
-   //      PropertyData destPropData = (PropertyData)connection.getItemData(propData.getIdentifier());
-   //
-   //      assertNotNull(destPropData);
-   //      assertEquals(propData.getIdentifier(), destPropData.getIdentifier());
-   //      assertEquals(propData.getParentIdentifier(), destPropData.getParentIdentifier());
-   //      assertEquals(propData.getPersistedVersion(), destPropData.getPersistedVersion());
-   //      assertEquals(propData.getType(), destPropData.getType());
-   //      assertEquals(propData.getQPath(), destPropData.getQPath());
-   //      assertEquals(propData.getValues().size(), destPropData.getValues().size());
-   //      assertEquals(1, destPropData.getValues().size());
-   //
-   //      ValueData valueData = destPropData.getValues().get(0);
-   //      assertEquals("JCR DATA VALUE", new String(valueData.getAsByteArray(), "UTF-8"));
-   //
-   //   }
+   public void testUpdateAddProperty() 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();
+      // prepare
+      TransientPropertyData newPropData =
+         createProperty(node1path, node1id, new InternalQName(Constants.NS_DEFAULT_URI, "myProp"), "JCR DATA VALUE",
+            false);
+
+      conn = persistentContainer.openConnection();
+      conn.add(newPropData);
+      modifications.addAll(addProperty(newPropData));
+      conn.commit();
+
+      loader.put(modifications);
+
+      // tests it
+      WorkspaceStorageConnection connection = persistentContainer.openConnection();
+
+      PropertyData destPropData = (PropertyData)connection.getItemData(newPropData.getIdentifier());
+
+      assertNotNull(destPropData);
+      assertEquals(newPropData.getIdentifier(), destPropData.getIdentifier());
+      assertEquals(newPropData.getParentIdentifier(), destPropData.getParentIdentifier());
+      assertEquals(newPropData.getPersistedVersion(), destPropData.getPersistedVersion());
+      assertEquals(newPropData.getType(), destPropData.getType());
+      assertEquals(newPropData.getQPath(), destPropData.getQPath());
+      assertEquals(newPropData.getValues().size(), destPropData.getValues().size());
+      assertEquals(1, destPropData.getValues().size());
+
+      ValueData valueData = destPropData.getValues().get(0);
+      assertEquals("JCR DATA VALUE", new String(valueData.getAsByteArray(), "UTF-8"));
+
+      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:myProp", "data"));
+      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