Author: pnedonosko
Date: 2009-11-12 04:44:59 -0500 (Thu, 12 Nov 2009)
New Revision: 587
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201: test for JDBC loader
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
09:28:28 UTC (rev 586)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12
09:44:59 UTC (rev 587)
@@ -18,17 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-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;
@@ -57,6 +46,18 @@
import org.exoplatform.services.jcr.util.IdGenerator;
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.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$
@@ -228,33 +229,94 @@
PreparedStatement st = connection.prepareStatement("create database " +
dbName);
st.executeQuery();
}
-
-
- private void initJCRRoot() throws Exception {
+
+ private void initJCRRoot() throws Exception
+ {
// prepare
WorkspaceStorageConnection conn = persistentContainer.openConnection();
+ // add root (/) with jcr:primaryType
+ addNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED);
+
+ // add property (/jcr:mixinTypes)
+ List<InternalQName> mixins = new ArrayList<InternalQName>();
+ mixins.add(Constants.MIX_REFERENCEABLE);
+ mixins.add(Constants.EXO_PRIVILEGEABLE);
+ mixins.add(Constants.EXO_OWNEABLE);
+ addProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.JCR_MIXINTYPES, mixins, true);
+
+ conn.commit();
+ }
+
+ /**
+ * Add Property to the connection but doesn't save it.
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param root QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @throws Exception
+ */
+ private void addNode(WorkspaceStorageConnection conn, QPath root, String nodeId,
InternalQName primaryType)
+ throws Exception
+ {
// add root (/)
- conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, null, new AccessControlList()));
+ conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0],
0, null,
+ new AccessControlList()));
// add property (/jcr:primaryType)
- String propId1 = "1";
- QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH,
Constants.JCR_PRIMARYTYPE);
- TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1,
1, Constants.ROOT_UUID, false);
- String propValue1 = "Property value #1";
- propData1.setValue(new TransientValueData(propValue1));
- conn.add(propData1);
+ addProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE,
primaryType, false);
+ }
- // add property (/jcr:mixinTypes)
- String propId2 = "2";
- QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH,
Constants.JCR_MIXINTYPES);
- TransientPropertyData propData2 = new TransientPropertyData(propPath2, propId2, 1,
1, Constants.ROOT_UUID, false);
- String propValue2 = "Property value #2";
- propData2.setValue(new TransientValueData(propValue2));
- conn.add(propData2);
+ /**
+ * Add Property to the connection but doesn't save it.
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param nodePath QPath
+ * @param nodeId String
+ * @param propertyName InternalQName
+ * @param propertyValue Object
+ * @return TransientPropertyData
+ * @throws Exception
+ */
+ private TransientPropertyData addProperty(WorkspaceStorageConnection conn, QPath
nodePath, String nodeId,
+ InternalQName propertyName, Object propertyValue, boolean multiValued) throws
Exception
+ {
+ String propId = IdGenerator.generate();
+ QPath propPath = QPath.makeChildPath(Constants.ROOT_PATH,
Constants.JCR_MIXINTYPES);
+ TransientPropertyData propData =
+ new TransientPropertyData(propPath, propId, 1, 1, Constants.ROOT_UUID,
multiValued);
- conn.commit();
+ List<Object> values = new ArrayList<Object>();
+ if (multiValued)
+ {
+ if (propertyValue instanceof List)
+ {
+ values.addAll((List<Object>)propertyValue);
+ }
+ else
+ throw new Exception("propertyValue should be a List");
+ }
+
+ for (Object value : values)
+ {
+ if (value instanceof InternalQName)
+ {
+ propData.setValue(new TransientValueData((InternalQName)value));
+ }
+ else if (value instanceof String)
+ {
+ propData.setValue(new TransientValueData((String)value));
+ }
+ else if (value instanceof InputStream)
+ {
+ propData.setValue(new TransientValueData((InputStream)value));
+ }
+ }
+
+ conn.add(propData);
+
+ return propData;
}
// ============= TESTS =============
@@ -263,8 +325,7 @@
{
// prepare
initJCRRoot();
-
-
+
// tests
WorkspaceStorageConnection conn = persistentContainer.openConnection();