[exo-jcr-commits] exo-jcr SVN: r610 - 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 10:55:39 EST 2009


Author: sergiykarpenko
Date: 2009-11-12 10:55:39 -0500 (Thu, 12 Nov 2009)
New Revision: 610

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 15:46:23 UTC (rev 609)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java	2009-11-12 15:55:39 UTC (rev 610)
@@ -117,96 +117,102 @@
 
    public void setUp() throws Exception
    {
-      try
-      {
-         super.setUp();
+      super.setUp();
 
-         initPersistence();
+      initPersistence();
 
-         loader = new IndexerCacheLoader();
-         loader.injectDependencies(manager);
+      loader = new IndexerCacheLoader();
+      loader.injectDependencies(manager);
 
-         initJCRRoot();
+      initJCRRoot();
 
-         //         // JBossCache 
-         //         initJBCConfig();
-         //
-         //         cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig, false);
-         //
-         //         initJBC();
-
-         //         // run cache
-         //         cache.create();
-         //         cache.start();
-         //
-         //         Node<Serializable, Object> cacheRoot = cache.getRoot();
-         //
-         //         // prepare cache structures
-         //
-         //         nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
-         //         props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
-         //         session = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.SESSION));
-         //
-         //         // JCR connection
-         //         conn = new JBossCacheStorageConnection(cache, nodes, props, session);
-         //         // add root (/)
-         //         conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
-         //            new InternalQName[0], 0, null, new AccessControlList()));
-         //
-         //         String propId1 = "rootf111111";
-         //         QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
-         //         TransientPropertyData propData1 =
-         //            new TransientPropertyData(propPath1, propId1, 1, PropertyType.NAME, Constants.ROOT_UUID, false);
-         //         propData1.setValue(new TransientValueData(Constants.NT_UNSTRUCTURED));
-         //         conn.add(propData1);
-         //
-         //         conn.commit();
-         manager.start();
-      }
-      catch (Exception e)
-      {
-         e.printStackTrace();
-         throw e;
-      }
+      manager.start();
    }
 
    public void testAddNode() 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 root (/) with jcr:primaryType
-      addDbNode(conn, node1path, node1id, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
+      // 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);
 
-      List<ItemData> node = this.createNode(node1path, node1id, Constants.NT_UNSTRUCTURED, new InternalQName[0]);
+      // 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());
+
+   }
+
+   public void testRemoveNode() throws Exception
+   {
       List<Modification> modifications = new ArrayList<Modification>();
 
-      for (ItemData data : node)
-      {
-         if (data.isNode())
-         {
-            modifications.addAll(addNode((NodeData)data));
-         }
-         else
-         {
-            modifications.addAll(addProperty((PropertyData)data));
-         }
-      }
+      // 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
-      WorkspaceStorageConnection connection = persistentContainer.openConnection();
-
-      NodeData nd = (NodeData)connection.getItemData(node1id);
+      // 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();
@@ -216,6 +222,39 @@
       Query query = new TermQuery(new Term("_:UUID", node1id));
       Hits hit = searcher.search(query);
       assertEquals(1, hit.length());
+
+      // remove node1
+      modifications.clear();
+
+      //   PropertyData prop = (PropertyData)node.get(1);
+      //   NodeData n = (NodeData)node.get(0);
+
+      conn.delete(pd);
+      modifications.addAll(removeProperty(pd));
+      conn.delete(nd);
+      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);
+      assertNull(nd);
+
+      loader.put(modifications);
+
+      // check index;
+      reader = index.getIndexReader();
+
+      searcher = new IndexSearcher(reader);
+      hit = searcher.search(query);
+      assertEquals(0, hit.length());
+
    }
 
    //   public void testAddProperty() throws Exception



More information about the exo-jcr-commits mailing list