Author: nzamosenchuk
Date: 2009-11-09 10:30:08 -0500 (Mon, 09 Nov 2009)
New Revision: 519
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java
Log:
EXOJCR-204: Added abstract test-class
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java 2009-11-09
15:30:08 UTC (rev 519)
@@ -0,0 +1,144 @@
+/*
+ * 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.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.Modification.ModificationType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This abstract class contains only methods for creating a fake {@link Modification}
instances. It doesn't use real cache.
+ *
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: AbstractCacheLoaderClass.java 34360 2009-07-22 23:58:59Z aheritier $
+ *
+ */
+public abstract class AbstractCacheLoaderTest extends TestCase
+{
+
+ /**
+ * Returns {@link Modification} like as node added. NodeData is written to
/$NODE/IDxxxx as an attribute by key ITEM_DATA.
+ *
+ * @param data
+ * @return
+ */
+ public Modification addNode(NodeData data)
+ {
+ String fqn = "/" + JBossCacheStorage.NODES + "/" +
data.getIdentifier();
+ return new Modification(ModificationType.PUT_KEY_VALUE, Fqn.fromString(fqn),
(Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ }
+
+ /**
+ * Returns {@link Modification} like as node removed. But it is thought, that list is
already modified by JDBC loader,
+ * so {@link Modification} instance contains additional data: Key=ITEM_DATA,
value=NodeData - data of already removed
+ * node.
+ *
+ * @param data
+ * @return
+ */
+ public Modification removeNode(NodeData data)
+ {
+ String fqn = "/" + JBossCacheStorage.NODES + "/" +
data.getIdentifier();
+ return new Modification(ModificationType.REMOVE_NODE, Fqn.fromString(fqn),
(Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ }
+
+ /**
+ * Returns {@link Modification} like as property added. PropertyData is written to
/$PROPERTY/IDxxxx as an attribute by key ITEM_DATA.
+ *
+ * @param data
+ * @return
+ */
+ public Modification addProperty(PropertyData data)
+ {
+ String fqn = "/" + JBossCacheStorage.PROPS + "/" +
data.getIdentifier();
+ return new Modification(ModificationType.PUT_KEY_VALUE, Fqn.fromString(fqn),
(Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ }
+
+ /**
+ * Returns {@link Modification} like as property updated. PropertyData is written to
/$PROPERTY/IDxxxx as an attribute by key ITEM_DATA.
+ * But it is thought, that list is already modified by JDBC loader,so {@link
Modification} instance contains additional data: Old_Value
+ * filed of {@link Modification} instance contains same PropertyData (meaning that
there was an old value, so this is an update, no add
+ * action)
+ *
+ * @param data
+ * @return
+ */
+ public Modification updateProperty(PropertyData data)
+ {
+ String fqn = "/" + JBossCacheStorage.PROPS + "/" +
data.getIdentifier();
+ Modification modification =
+ new Modification(ModificationType.PUT_KEY_VALUE, Fqn.fromString(fqn),
(Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ modification.setOldValue(data);
+ return modification;
+ }
+
+ /**
+ * Returns {@link Modification} like as property removed. But it is thought, that list
is already modified by JDBC loader,
+ * so {@link Modification} instance contains additional data: Key=ITEM_DATA,
value=PropertyData - data of already removed
+ * node.
+ *
+ * @param data
+ * @return
+ */
+ public Modification removeProperty(PropertyData data)
+ {
+ String fqn = "/" + JBossCacheStorage.PROPS + "/" +
data.getIdentifier();
+ Modification modification =
+ new Modification(ModificationType.REMOVE_NODE, Fqn.fromString(fqn),
(Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ modification.setOldValue(data);
+ return modification;
+ }
+
+ /**
+ * Generates list of {@link Modification}-s, containing add to /$SESSION attribute
sessionId and userId with corresponding values.
+ * This imitates situation when WorkspaceDataManager walks thought transaction changes
log, and on the beginning of each plain
+ * changes log, such sequence is generated.
+ *
+ * @param sessionId
+ * @param userId
+ * @return
+ */
+ public List<Modification> setSession(String sessionId, String userId)
+ {
+ List<Modification> list = new ArrayList<Modification>();
+ // add SessionID by the key SESSION_ID
+ list.add(new Modification(ModificationType.PUT_KEY_VALUE,
Fqn.fromString("/" + JBossCacheStorage.SESSION),
+ JBossCacheStorage.SESSION_ID, sessionId));
+ // add UserID by the key USER_ID
+ list.add(new Modification(ModificationType.PUT_KEY_VALUE,
Fqn.fromString("/" + JBossCacheStorage.SESSION),
+ JBossCacheStorage.USER_ID, userId));
+ // remove all the attributes from /$SESSION
+ list.add(new Modification(ModificationType.REMOVE_DATA,
Fqn.fromString("/" + JBossCacheStorage.SESSION)));
+ // return
+ return list;
+ }
+
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain