Author: areshetnyak
Date: 2009-11-12 08:33:43 -0500 (Thu, 12 Nov 2009)
New Revision: 596
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201 : The JDBCCacheLoaderTest was changed.
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12
13:18:52 UTC (rev 595)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12
13:33:43 UTC (rev 596)
@@ -18,20 +18,31 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
import org.apache.commons.dbcp.BasicDataSourceFactory;
import org.exoplatform.services.idgenerator.impl.IDGeneratorServiceImpl;
import org.exoplatform.services.jcr.access.AccessControlList;
-import org.exoplatform.services.jcr.config.CacheEntry;
import org.exoplatform.services.jcr.config.ContainerEntry;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
-import org.exoplatform.services.jcr.config.LockPersisterEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.ValueStorageEntry;
import org.exoplatform.services.jcr.config.ValueStorageFilterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
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.ValueData;
@@ -47,19 +58,6 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
/**
* @author <a href="mailto:reshetnyak.alex@gmail.com">Alex
Reshetnyak</a>
* @version $Id$
@@ -248,7 +246,7 @@
WorkspaceStorageConnection conn = persistentContainer.openConnection();
// add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED);
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED, null);
// add property (/jcr:mixinTypes)
List<InternalQName> mixins = new ArrayList<InternalQName>();
@@ -266,7 +264,7 @@
WorkspaceStorageConnection conn = persistentContainer.openConnection();
// add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED);
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED, null);
// add property (/jcr:mixinTypes)
List<InternalQName> mixins = new ArrayList<InternalQName>();
@@ -279,7 +277,7 @@
}
/**
- * Add Property to the connection but doesn't save it.
+ * Add Node to the connection but doesn't save it.
*
* @param conn WorkspaceStorageConnection
* @param root QPath
@@ -287,15 +285,44 @@
* @param primaryType InternalQName
* @throws Exception
*/
- private void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId,
InternalQName primaryType)
+ private void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId,
InternalQName primaryType, InternalQName[] mixinTypeNames)
throws Exception
{
- // add root (/)
- conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0],
0, null,
+ // create node with property jcr:primaryType
+ List<ItemData> list = createNode(root, nodeId, primaryType, mixinTypeNames);
+
+ // add node with property jcr:primaryType
+ for (ItemData itemData : list)
+ {
+ if (itemData instanceof NodeData)
+ conn.add((NodeData)itemData);
+ else
+ conn.add((PropertyData)itemData);
+ }
+ }
+
+ /**
+ * Create Node to the connection but doesn't save it.
+ *
+ * @param path QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @param mixinTypeNames InternalQName
+ * @throws Exception
+ */
+ private List<ItemData> createNode(QPath path, String nodeId, InternalQName
primaryType, InternalQName[] mixinTypeNames)
+ throws Exception
+ {
+ List<ItemData> list = new ArrayList<ItemData>();
+
+ // add node
+ list.add(new TransientNodeData(path, nodeId, 1, primaryType, (mixinTypeNames ==
null ? new InternalQName[0] : null), 0, null,
new AccessControlList()));
// add property (/jcr:primaryType)
- addDbProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE,
primaryType, false);
+ list.add(createProperty(path, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE,
primaryType, false));
+
+ return list;
}
/**
@@ -400,7 +427,6 @@
// tests
WorkspaceStorageConnection conn = persistentContainer.openConnection();
- //??? Map<Serializable, Object> data =
cache.getData(Fqn.fromString("/"+JBossCacheStorage.NODES + "/" +
Constants.ROOT_UUID));
}
public void testAddProperty() throws Exception
@@ -506,15 +532,24 @@
connection.commit();
// tests it
- connection = persistentContainer.openConnection();
+ Map<Object, Object> attrebutes =
loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" +
propData.getIdentifier()));
- PropertyData destPropData = (PropertyData)
connection.getItemData(propData.getIdentifier());
+ assertNotNull(attrebutes);
- Map<Object, Object> attrebutes =
loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" +
propData.getIdentifier()));
+ PropertyData destPropData = (PropertyData)
attrebutes.get(JBossCacheStorage.ITEM_DATA);
- assertNotNull(attrebutes);
+ 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 testGetPropertyByName() throws Exception