[exo-jcr-commits] exo-jcr SVN: r771 - 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 19 08:59:33 EST 2009
Author: pnedonosko
Date: 2009-11-19 08:59:33 -0500 (Thu, 19 Nov 2009)
New Revision: 771
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-203: conn tests
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java 2009-11-19 13:59:33 UTC (rev 771)
@@ -0,0 +1,200 @@
+/*
+ * 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.datamodel.InternalQName;
+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.impl.Constants;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * 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 abstract class AbstractJBossCacheStorageConnectionTest extends TestCase
+{
+
+ protected JBossCacheStorageConnection conn;
+
+ protected Cache<Serializable, Object> cache;
+
+ protected Node<Serializable, Object> nodes;
+
+ protected Node<Serializable, Object> props;
+
+ protected Node<Serializable, Object> locks;
+
+ protected String jbcConfig;
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // 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));
+ locks = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.LOCKS));
+
+ // JCR connection
+ conn = new JBossCacheStorageConnection(cache, nodes, props, locks);
+ }
+
+ protected void initJBCConfig()
+ {
+ jbcConfig = "conf/standalone/test-jbosscache-config-exoloader.xml";
+ }
+
+ protected void initJBC() throws Exception
+ {
+ // empty here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void tearDown() throws Exception
+ {
+
+ cache.stop();
+ cache.destroy();
+
+ super.tearDown();
+ }
+
+ protected 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);
+ }
+ }
+ }
+
+ protected 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());
+ }
+
+ protected void checkProp(String propId, QPath propPath, Object propValue) throws UnsupportedEncodingException,
+ IllegalStateException, IOException
+ {
+ Node<Serializable, Object> prop = props.getChild(Fqn.fromElements(propId));
+ Object dataObject = prop.get(JBossCacheStorage.ITEM_DATA);
+ assertNotNull("Property item data should exists", dataObject);
+ assertTrue("Property item data is not a Property", dataObject instanceof PropertyData);
+
+ PropertyData propData = (PropertyData)dataObject;
+ assertEquals("Property id wrong", propId, propData.getIdentifier());
+ assertEquals("Property path wrong", propPath, propData.getQPath());
+ assertEquals("Property Value wrong", propValue, new String(propData.getValues().get(0).getAsByteArray(),
+ Constants.DEFAULT_ENCODING));
+ }
+
+ protected void checkChildProp(Node<Serializable, Object> node, InternalQName propName, String propId, QPath propPath,
+ Object propValue) throws UnsupportedEncodingException, IllegalStateException, IOException
+ {
+ String pid = (String)node.get(propName.getAsString());
+
+ assertNotNull("Property ID should exists", pid);
+ assertEquals("Property ID wrong", propId, pid);
+
+ checkProp(propId, propPath, propValue);
+ }
+
+ protected void checkChildNode(Node<Serializable, Object> rootNode, String childId, QPath childPath)
+ {
+ checkChildNode(rootNode, childId, childPath, -1, -1);
+ }
+
+ protected void checkChildNode(Node<Serializable, Object> rootNode, String childId, QPath childPath, int orderNum,
+ int 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 = nodes.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 >= 0)
+ {
+ assertEquals("Node order number wrong", orderNum, childNodeData.getOrderNumber());
+ }
+
+ if (version >= 0)
+ {
+ assertEquals("Node persisted version wrong", version, childNodeData.getPersistedVersion());
+ }
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
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-19 12:53:34 UTC (rev 770)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 13:59:33 UTC (rev 771)
@@ -51,161 +51,9 @@
* @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a>
* @version $Id$
*/
-public class JBossCacheStorageConnectionTest extends TestCase
+public class JBossCacheStorageConnectionTest extends AbstractJBossCacheStorageConnectionTest
{
- protected JBossCacheStorageConnection conn;
-
- protected Cache<Serializable, Object> cache;
-
- protected Node<Serializable, Object> nodes;
-
- protected Node<Serializable, Object> props;
-
- protected Node<Serializable, Object> locks;
-
- protected String jbcConfig;
-
- /**
- * {@inheritDoc}
- */
- protected void setUp() throws Exception
- {
- super.setUp();
-
- // 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));
- locks = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.LOCKS));
-
- // JCR connection
- conn = new JBossCacheStorageConnection(cache, nodes, props, locks);
- }
-
- protected void initJBCConfig()
- {
- jbcConfig = "conf/standalone/test-jbosscache-config-jdbcloader.xml";
- }
-
- protected void initJBC() throws Exception
- {
- // empty here
- }
-
- /**
- * {@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);
- }
- }
- }
-
- 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 checkProp(String propId, QPath propPath, Object propValue) throws UnsupportedEncodingException,
- IllegalStateException, IOException
- {
- Node<Serializable, Object> prop = props.getChild(Fqn.fromElements(propId));
- Object dataObject = prop.get(JBossCacheStorage.ITEM_DATA);
- assertNotNull("Property item data should exists", dataObject);
- assertTrue("Property item data is not a Property", dataObject instanceof PropertyData);
-
- PropertyData propData = (PropertyData)dataObject;
- assertEquals("Property id wrong", propId, propData.getIdentifier());
- assertEquals("Property path wrong", propPath, propData.getQPath());
- assertEquals("Property Value wrong", propValue, new String(propData.getValues().get(0).getAsByteArray(),
- Constants.DEFAULT_ENCODING));
- }
-
- private void checkChildProp(Node<Serializable, Object> node, InternalQName propName, String propId, QPath propPath,
- Object propValue) throws UnsupportedEncodingException, IllegalStateException, IOException
- {
- String pid = (String)node.get(propName.getAsString());
-
- assertNotNull("Property ID should exists", pid);
- assertEquals("Property ID wrong", propId, pid);
-
- checkProp(propId, propPath, propValue);
- }
-
- private void checkChildNode(Node<Serializable, Object> rootNode, String childId, QPath childPath)
- {
- checkChildNode(rootNode, childId, childPath, -1, -1);
- }
-
- private void checkChildNode(Node<Serializable, Object> rootNode, String childId, QPath childPath, int orderNum,
- int 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 = nodes.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 >= 0)
- {
- assertEquals("Node order number wrong", orderNum, childNodeData.getOrderNumber());
- }
-
- if (version >= 0)
- {
- assertEquals("Node persisted version wrong", version, childNodeData.getPersistedVersion());
- }
- }
-
public void testAddNode() throws Exception
{
// add root (/)
More information about the exo-jcr-commits
mailing list