exo-jcr SVN: r505 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-11-09 06:37:43 -0500 (Mon, 09 Nov 2009)
New Revision: 505
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/IndexerCacheLoaderTest.java
Log:
EXOJCR-202 : base cache loader test
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 11:37:43 UTC (rev 505)
@@ -0,0 +1,98 @@
+/*
+ * 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.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class AbstractCacheLoaderTest extends TestCase
+{
+ protected Cache<Serializable, Object> cache;
+
+ protected JBossCacheStorageConnection jBossCacheStorageConnection;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ CacheFactory<Serializable, Object> factory = new DefaultCacheFactory<Serializable, Object>();
+ cache = factory.createCache(createCacheConfiguration());
+
+ Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+ // run cache
+ cache.create();
+ cache.start();
+ cache.startBatch();
+ // prepare cache structures
+ Node<Serializable, Object> nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
+ Node<Serializable, Object> props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
+
+ this.cache.endBatch(true);
+
+ // JCR connection
+ jBossCacheStorageConnection = new JBossCacheStorageConnection(cache, nodes, props);
+ }
+
+ /**
+ * Create cache configuration.
+ * @return
+ */
+ protected Configuration createCacheConfiguration()
+ {
+ Configuration config = new Configuration();
+ config.setInvocationBatchingEnabled(true);
+ config.setCacheLoaderConfig(createCacheLoaderConfig());
+ return config;
+ }
+
+ /**
+ * Create cache configuration.
+ * @return
+ */
+ protected CacheLoaderConfig createCacheLoaderConfig()
+ {
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.setPassivation(false);
+ cacheLoaderConfig.setShared(false);
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(createIndividualCacheLoaderConfig());
+ return cacheLoaderConfig;
+ };
+
+ protected abstract IndividualCacheLoaderConfig createIndividualCacheLoaderConfig();
+
+}
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
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderTest.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderTest.java 2009-11-09 11:37:43 UTC (rev 505)
@@ -0,0 +1,74 @@
+/*
+ * 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 org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class IndexerCacheLoaderTest extends AbstractCacheLoaderTest
+{
+ private final Log log = ExoLogger.getLogger(IndexerCacheLoaderTest.class.getName());
+
+ public void testAddRoot() throws Exception
+ {
+ // add root (/)
+ jBossCacheStorageConnection.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, null, new AccessControlList()));
+ jBossCacheStorageConnection.commit();
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractCacheLoaderTest#createIndividualCacheLoaderConfig()
+ */
+ @Override
+ protected IndividualCacheLoaderConfig createIndividualCacheLoaderConfig()
+ {
+ IndividualCacheLoaderConfig individualCacheLoaderConfig = new IndividualCacheLoaderConfig();
+ individualCacheLoaderConfig.setCacheLoader(new DummyCacheLoader());
+ return individualCacheLoaderConfig;
+ }
+
+ private class DummyCacheLoader extends AbstractWriteOnlyCacheLoader
+ {
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(java.util.List)
+ */
+ @Override
+ public void put(List<Modification> modifications) throws Exception
+ {
+ log.info("put:" + modifications);
+
+ }
+
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 8 months
exo-jcr SVN: r504 - in jcr/branches/1.12.0-JBC/component/core/src: main/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-11-09 06:17:36 -0500 (Mon, 09 Nov 2009)
New Revision: 504
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
Log:
EXOJCR-204:Observation cache loader update, test added.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-09 10:52:43 UTC (rev 503)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-09 11:17:36 UTC (rev 504)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.core.NamespaceAccessor;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -51,21 +52,22 @@
protected ActionLauncher launcher;
-
protected SessionRegistry sessionRegistry;
protected NamespaceAccessor namespaceAccessor;
protected NodeTypeDataManager nodeTypeDataManager;
+ protected WorkspacePersistentDataManager workspaceDataManager;
+
public ObservationManagerRegistry(WorkspacePersistentDataManager workspaceDataManager,
SessionRegistry sessionRegistry, NamespaceAccessor namespaceAccessor)
{
this.sessionRegistry = sessionRegistry;
this.listenersMap = new HashMap<EventListener, ListenerCriteria>();
- this.namespaceAccessor = namespaceAccessor;
- //this.nodeTypeDataManager = nodeTypeDataManager;
- this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager, sessionRegistry);
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.workspaceDataManager = workspaceDataManager;
+ //this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager, sessionRegistry);
}
public ObservationManagerImpl createObservationManager(SessionImpl session)
@@ -111,11 +113,23 @@
listenersMap.remove(listener);
}
}
-
- public ActionLauncher getLauncher()
+ // TODO: remove hardcode
+ public NodeTypeDataManager getNodeTypeDataManager()
{
- return launcher;
+ return nodeTypeDataManager;
}
+
+ // TODO: remove hardcode
+ public WorkspacePersistentDataManager getWorkspaceDataManager()
+ {
+ return workspaceDataManager;
+ }
+
+ // TODO: remove hardcode
+ public LocationFactory getLocationFactory()
+ {
+ return new LocationFactory(namespaceAccessor);
+ }
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09 10:52:43 UTC (rev 503)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09 11:17:36 UTC (rev 504)
@@ -31,6 +31,7 @@
import org.exoplatform.services.log.Log;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
+import org.jboss.cache.factories.annotations.Inject;
import java.util.List;
@@ -54,7 +55,7 @@
private final Fqn propFqn = Fqn.fromString(JBossCacheStorage.PROPS);
- private ObservationManagerRegistry observationManagerRegistry=null;
+ private ObservationManagerRegistry observationManagerRegistry = null;
/**
*
@@ -63,6 +64,12 @@
{
}
+ @Inject
+ public void insertObservationRegistry(ObservationManagerRegistry observationManagerRegistry)
+ {
+ this.observationManagerRegistry = observationManagerRegistry;
+ }
+
/**
* @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(java.util.List)
*/
@@ -70,6 +77,72 @@
public void put(List<Modification> modifications) throws Exception
{
+ // get SessionID from list
+ // TODO: get real user ID
+ String userId = "admin-dummy-id";
+
+ // get UserID from list
+ // TODO: get real session ID
+ String sessionId = "user-session-dummy-id";
+
+ // extract real list from list of modification
+ // real - means list with out fake modifications containing UserID & etc
+
+ // for each listener
+ // for each element from real list post and event, if filtering ok
+
+ if (observationManagerRegistry != null)
+ {
+
+ EventListenerIterator eventListeners = observationManagerRegistry.getEventListeners();
+ while (eventListeners.hasNext())
+ {
+ EventListener listener = eventListeners.nextEventListener();
+ ListenerCriteria criteria = observationManagerRegistry.getListenerFilter(listener);
+
+ EntityCollection events = new EntityCollection();
+
+ for (Modification m : modifications)
+ {
+
+ if (m.getFqn().isDirectChildOf(nodeFqn) || m.getFqn().isDirectChildOf(propFqn))
+ {
+ ItemData item = getItemData(m);
+ // TODO: remove hardcode
+ if (item == null)
+ {
+ break;
+ } // it wasn't able to retrive item's data
+ int eventType = eventType(m);
+ boolean result = true;
+ // check event type
+ result &= isTypeMatch(criteria, eventType);
+ // check Path
+ result &= isPathMatch(criteria, item);
+ // check UUID
+ result &= isIdentifierMatch(criteria, item);
+ // check NodeType
+ // TODO: FIX nodetype checks
+ //result &= isNodeTypeMatch(criteria, item, changesLog);
+ // check session
+ result &= isSessionMatch(criteria, sessionId);
+ if (result)
+ {
+ String path =
+ observationManagerRegistry.getLocationFactory().createJCRPath(item.getQPath()).getAsString(
+ false);
+ events.add(new EventImpl(eventType, path, userId));
+ }
+ }
+ }
+
+ if (events.size() > 0)
+ {
+ // no events - no onEvent() action
+ listener.onEvent(events);
+ }
+ }
+ }
}
private int eventType(Modification modification)
@@ -77,28 +150,32 @@
// TODO: REMOVE cache structure hardcode!
switch (modification.getType())
{
- case PUT_DATA :
- if (modification.getFqn().isDirectChildOf(nodeFqn))
+ case PUT_KEY_VALUE :
+ // put something to /$node/IDxxxx.ITEMDATA
+ if (modification.getKey().equals(JBossCacheStorage.ITEM_DATA))
{
- // node added
- return Event.NODE_ADDED;
- }
- else if (modification.getFqn().isDirectChildOf(propFqn))
- {
- // property added or changed
- if (modification.getOldValue() != null)
+ if (modification.getFqn().isDirectChildOf(nodeFqn))
{
- // property changed
- // TODO: possibly bad idea
- return Event.PROPERTY_CHANGED;
+ // node added
+ return Event.NODE_ADDED;
}
- else
+ else if (modification.getFqn().isDirectChildOf(propFqn))
{
- // property added
- return Event.PROPERTY_ADDED;
+ // property added or changed
+ if (modification.getOldValue() != null)
+ {
+ // property changed
+ return Event.PROPERTY_CHANGED;
+ }
+ else
+ {
+ // property added
+ return Event.PROPERTY_ADDED;
+ }
}
}
break;
+
case REMOVE_NODE :
if (modification.getFqn().isDirectChildOf(nodeFqn))
{
@@ -207,7 +284,7 @@
protected ItemData getItemData(Modification m)
{
- return (ItemData)m.getData().get(JBossCacheStorage.ITEM_DATA);
+ return (ItemData)m.getValue();
}
}
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java 2009-11-09 11:17:36 UTC (rev 504)
@@ -0,0 +1,163 @@
+/*
+ * 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.access.AccessControlList;
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.observation.ListenerCriteria;
+import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.Modification.ModificationType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: ObservationCacheLoaderTest.java 34360 2009-07-22 23:58:59Z aheritier $
+ *
+ */
+public class ObservationCacheLoaderTest extends TestCase
+{
+
+ private ObservationCacheLoader loader;
+
+ private ObservationManagerRegistry registry;
+
+ private LocationFactory lf;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ loader = new ObservationCacheLoader();
+ registry = new DummyObservationRegistry();
+ loader.insertObservationRegistry(registry);
+
+ final Map<String, String> ns = new HashMap<String, String>();
+
+ final Map<String, String> nss = new HashMap<String, String>();
+
+ ns.put("jcr", "http:jcr");
+ ns.put("", "");
+ nss.put("http:jcr", "jcr");
+ nss.put("", "");
+
+ this.lf = new LocationFactory(new NamespaceAccessor()
+ {
+
+ public String getNamespaceURIByPrefix(String prefix) throws NamespaceException, RepositoryException
+ {
+ return ns.get(prefix);
+ }
+
+ public String getNamespacePrefixByURI(String uri) throws NamespaceException, RepositoryException
+ {
+ return nss.get(uri);
+ }
+
+ public String[] getAllNamespacePrefixes() throws RepositoryException
+ {
+ return ns.keySet().toArray(new String[ns.keySet().size()]);
+ }
+ });
+ }
+
+ public void testAddNode() throws Exception
+ {
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ NodeData newNode =
+ new TransientNodeData(node1path, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList());
+ DummyListener listener = new DummyListener();
+ registry.addEventListener(listener, new ListenerCriteria(Event.NODE_ADDED,
+ lf.parseAbsPath("/").getInternalPath(), true, null, null, false, "asd"));
+
+ List<Modification> modifications = new ArrayList<Modification>();
+ modifications.add(addNode(newNode));
+ loader.put(modifications);
+ assertEquals(1, listener.eventList.size());
+ Event event = listener.eventList.get(0);
+ assertEquals(Event.NODE_ADDED, event.getType());
+ assertEquals(lf.createJCRPath(node1path).getAsString(false), event.getPath());
+ }
+
+ public Modification addNode(NodeData data)
+ {
+ // add in NODES
+ String fqn = "/" + JBossCacheStorage.NODES + "/" + data.getIdentifier();
+ return new Modification(ModificationType.PUT_KEY_VALUE, Fqn.fromString(fqn), (Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ //node.put(ITEM_DATA, data);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ class DummyObservationRegistry extends ObservationManagerRegistry
+ {
+ public DummyObservationRegistry()
+ {
+ super(null, null, null);
+ }
+
+ // TODO: remove hardcode
+ public LocationFactory getLocationFactory()
+ {
+ return lf;
+ }
+
+ }
+
+ class DummyListener implements EventListener
+ {
+
+ public List<Event> eventList = new ArrayList<Event>();
+
+ public void onEvent(EventIterator events)
+ {
+ while (events.hasNext())
+ {
+ eventList.add(events.nextEvent());
+ }
+ }
+
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 8 months
exo-jcr SVN: r503 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query: cacheloader and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2009-11-09 05:52:43 -0500 (Mon, 09 Nov 2009)
New Revision: 503
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java
Log:
EXOJCR-202: IndexerCacheLoader updated
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-11-09 09:54:44 UTC (rev 502)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-11-09 10:52:43 UTC (rev 503)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import java.io.IOException;
import java.util.Set;
import javax.jcr.Node;
@@ -90,4 +91,14 @@
*/
Set<String> getNodesByUri(final String uri) throws RepositoryException;
+ /**
+ * Update Index storege for next uuid lists.
+ *
+ * @param removedNodes - removed nodes uuid set
+ * @param addedNodes - added nodes uuid set
+ * @throws RepositoryException
+ * @throws IOException
+ */
+ public void updateIndex(Set<String> removedNodes, Set<String> addedNodes) throws RepositoryException, IOException;
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java 2009-11-09 09:54:44 UTC (rev 502)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java 2009-11-09 10:52:43 UTC (rev 503)
@@ -327,6 +327,40 @@
addedNodes.add(uuid);
}
+ try
+ {
+ updateIndex(removedNodes, addedNodes);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void updateIndex(final Set<String> removedNodes, final Set<String> addedNodes) throws RepositoryException,
+ IOException
+ {
Iterator<NodeData> addedStates = new Iterator<NodeData>()
{
private final Iterator<String> iter = addedNodes.iterator();
@@ -402,32 +436,9 @@
if (removedNodes.size() > 0 || addedNodes.size() > 0)
{
- try
- {
- handler.updateNodes(removedIds, addedStates);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(removedNodes, addedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
+ handler.updateNodes(removedIds, addedStates);
}
- if (log.isDebugEnabled())
- {
- log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
- }
}
public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java 2009-11-09 09:54:44 UTC (rev 502)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java 2009-11-09 10:52:43 UTC (rev 503)
@@ -16,48 +16,8 @@
*/
package org.exoplatform.services.jcr.impl.core.query.cacheloader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.WildcardQuery;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.exoplatform.container.configuration.ConfigurationManager;
-import org.exoplatform.services.document.DocumentReaderService;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerParams;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.dataflow.ItemState;
-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;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.LocationFactory;
-import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
-import org.exoplatform.services.jcr.impl.core.SessionDataManager;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import org.exoplatform.services.jcr.impl.core.query.AbstractQueryImpl;
-import org.exoplatform.services.jcr.impl.core.query.IndexException;
-import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
-import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
-import org.exoplatform.services.jcr.impl.core.query.QueryHandlerContext;
-import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
-import org.exoplatform.services.jcr.impl.core.query.SystemSearchManagerHolder;
-import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
-import org.exoplatform.services.jcr.impl.core.query.lucene.LuceneVirtualTableResolver;
-import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
-import org.exoplatform.services.jcr.impl.core.query.lucene.ScoreNode;
-import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
-import org.exoplatform.services.jcr.impl.core.value.NameValue;
-import org.exoplatform.services.jcr.impl.core.value.PathValue;
-import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
-import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -65,27 +25,12 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.StringTokenizer;
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.query.InvalidQueryException;
-import javax.jcr.query.Query;
-
/**
* Created by The eXo Platform SAS.
*
@@ -94,100 +39,23 @@
* @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
* @version $Id: CacheIndexer.java 111 2008-11-11 11:11:11Z serg $
*/
-public class IndexerCacheLoader extends AbstractWriteOnlyCacheLoader implements SearchManager
+public class IndexerCacheLoader extends AbstractWriteOnlyCacheLoader
{
+
/**
* Logger instance for this class
*/
private static final Log log = ExoLogger.getLogger(IndexerCacheLoader.class);
- protected QueryHandlerEntry config;
+ SearchManager searchManager = null;
- /**
- * Text extractor for extracting text content of binary properties.
- */
- protected DocumentReaderService extractor;
-
- /**
- * QueryHandler where query execution is delegated to
- */
- protected QueryHandler handler;
-
- /**
- * The shared item state manager instance for the workspace.
- */
- protected ItemDataConsumer itemMgr;
-
- /**
- * The namespace registry of the repository.
- */
- protected NamespaceRegistryImpl nsReg;
-
- /**
- * The node type registry.
- */
- protected NodeTypeDataManager nodeTypeDataManager;
-
- /**
- * QueryHandler of the parent search manager or <code>null</code> if there
- * is none.
- */
- protected SearchManager parentSearchManager;
-
- // protected QPath indexingRoot;
- //
- // protected List<QPath> excludedPaths = new ArrayList<QPath>();
-
- protected IndexingTree indexingTree;
-
- private ConfigurationManager cfm;
-
- protected LuceneVirtualTableResolver virtualTableResolver;
-
public IndexerCacheLoader()
{
- int i = 0;
- i++;
}
- /**
- * Creates a new <code>SearchManager</code>.
- *
- * @param config
- * the search configuration.
- * @param nsReg
- * the namespace registry.
- * @param ntReg
- * the node type registry.
- * @param itemMgr
- * the shared item state manager.
- * @param rootNodeId
- * the id of the root node.
- * @param parentMgr
- * the parent search manager or <code>null</code> if there is no
- * parent search manager.
- * @param excludedNodeId
- * id of the node that should be excluded from indexing. Any
- * descendant of that node will also be excluded from indexing.
- * @throws RepositoryException
- * if the search manager cannot be initialized
- * @throws RepositoryConfigurationException
- */
- public IndexerCacheLoader(QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
- WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
- DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
- throws RepositoryException, RepositoryConfigurationException
+ public void registerSearchManager(SearchManager manager)
{
-
- this.extractor = extractor;
- indexSearcherHolder.addIndexSearcher(this);
- this.config = config;
- this.nodeTypeDataManager = ntReg;
- this.nsReg = nsReg;
- this.itemMgr = itemMgr;
- this.cfm = cfm;
- this.virtualTableResolver = new LuceneVirtualTableResolver(nodeTypeDataManager, nsReg);
- this.parentSearchManager = parentSearchManager != null ? parentSearchManager.get() : null;
+ searchManager = manager;
}
private String parseUUID(Fqn fqn)
@@ -210,11 +78,9 @@
@Override
public void put(List<Modification> modifications) throws Exception
{
- if (handler == null)
+ if (searchManager == null)
return;
- long time = System.currentTimeMillis();
-
// nodes that need to be removed from the index.
final Set<String> removedNodes = new HashSet<String>();
// nodes that need to be added to the index.
@@ -373,607 +239,13 @@
// }
// }
- // TODO make quick changes
for (String uuid : updatedNodes.keySet())
{
removedNodes.add(uuid);
addedNodes.add(uuid);
}
- Iterator<NodeData> addedStates = new Iterator<NodeData>()
- {
- private final Iterator<String> iter = addedNodes.iterator();
+ searchManager.updateIndex(removedNodes, addedNodes);
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- public NodeData next()
- {
-
- // cycle till find a next or meet the end of set
- do
- {
- String id = iter.next();
- try
- {
- ItemData item = itemMgr.getItemData(id);
- if (item != null)
- {
- if (item.isNode())
- return (NodeData)item; // return node
- else
- log.warn("Node not found, but property " + id + ", " + item.getQPath().getAsString()
- + " found. ");
- }
- else
- log.warn("Unable to index node with id " + id + ", node does not exist.");
-
- }
- catch (RepositoryException e)
- {
- log.error("Can't read next node data " + id, e);
- }
- }
- while (iter.hasNext()); // get next if error or node not found
-
- return null; // we met the end of iterator set
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
-
- Iterator<String> removedIds = new Iterator<String>()
- {
- private final Iterator<String> iter = removedNodes.iterator();
-
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- public String next()
- {
- return nextNodeId();
- }
-
- public String nextNodeId() throws NoSuchElementException
- {
- return iter.next();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
-
- }
- };
-
- if (removedNodes.size() > 0 || addedNodes.size() > 0)
- {
- try
- {
- handler.updateNodes(removedIds, addedStates);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(removedNodes, addedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
-
- if (log.isDebugEnabled())
- {
- log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
- }
-
}
-
- /**
- * Creates a query object from a node that can be executed on the workspace.
- *
- * @param session
- * the session of the user executing the query.
- * @param itemMgr
- * the item manager of the user executing the query. Needed to
- * return <code>Node</code> instances in the result set.
- * @param node
- * a node of type nt:query.
- * @return a <code>Query</code> instance to execute.
- * @throws InvalidQueryException
- * if <code>absPath</code> is not a valid persisted query (that
- * is, a node of type nt:query)
- * @throws RepositoryException
- * if any other error occurs.
- */
- public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, Node node)
- throws InvalidQueryException, RepositoryException
- {
- AbstractQueryImpl query = createQueryInstance();
- query.init(session, sessionDataManager, handler, node);
- return query;
- }
-
- /**
- * Creates a query object that can be executed on the workspace.
- *
- * @param session
- * the session of the user executing the query.
- * @param itemMgr
- * the item manager of the user executing the query. Needed to
- * return <code>Node</code> instances in the result set.
- * @param statement
- * the actual query statement.
- * @param language
- * the syntax of the query statement.
- * @return a <code>Query</code> instance to execute.
- * @throws InvalidQueryException
- * if the query is malformed or the <code>language</code> is
- * unknown.
- * @throws RepositoryException
- * if any other error occurs.
- */
- public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, String statement,
- String language) throws InvalidQueryException, RepositoryException
- {
- AbstractQueryImpl query = createQueryInstance();
- query.init(session, sessionDataManager, handler, statement, language);
- return query;
- }
-
- /**
- * just for test use only
- */
- public QueryHandler getHandler()
- {
- return handler;
- }
-
- public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
- {
- List<ItemState> list = updatedNodes.get(key);
- if (list == null)
- {
- list = new ArrayList<ItemState>();
- updatedNodes.put(key, list);
- }
- list.add(state);
-
- }
-
- public void start()
- {
-
- if (log.isDebugEnabled())
- log.debug("start");
- try
- {
- if (indexingTree == null)
- {
- List<QPath> excludedPath = new ArrayList<QPath>();
- // Calculating excluded node identifiers
- excludedPath.add(Constants.JCR_SYSTEM_PATH);
-
- //if (config.getExcludedNodeIdentifers() != null)
- String excludedNodeIdentifer =
- config.getParameterValue(QueryHandlerParams.PARAM_EXCLUDED_NODE_IDENTIFERS, null);
- if (excludedNodeIdentifer != null)
- {
- StringTokenizer stringTokenizer = new StringTokenizer(excludedNodeIdentifer);
- while (stringTokenizer.hasMoreTokens())
- {
-
- try
- {
- ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
- if (excludeData != null)
- excludedPath.add(excludeData.getQPath());
- }
- catch (RepositoryException e)
- {
- log.warn(e.getLocalizedMessage());
- }
- }
- }
-
- NodeData indexingRootData = null;
- String rootNodeIdentifer = config.getParameterValue(QueryHandlerParams.PARAM_ROOT_NODE_ID, null);
- if (rootNodeIdentifer != null)
- {
- try
- {
- ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
- if (indexingRootDataItem != null && indexingRootDataItem.isNode())
- indexingRootData = (NodeData)indexingRootDataItem;
- }
- catch (RepositoryException e)
- {
- log.warn(e.getLocalizedMessage() + " Indexing root set to " + Constants.ROOT_PATH.getAsString());
-
- }
-
- }
- else
- {
- try
- {
- indexingRootData = (NodeData)itemMgr.getItemData(Constants.ROOT_UUID);
- }
- catch (RepositoryException e)
- {
- log.error("Fail to load root node data");
- }
- }
-
- indexingTree = new IndexingTree(indexingRootData, excludedPath);
- }
-
- initializeQueryHandler();
- }
- catch (RepositoryException e)
- {
- log.error(e.getLocalizedMessage());
- handler = null;
- throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
- }
- catch (RepositoryConfigurationException e)
- {
- log.error(e.getLocalizedMessage());
- handler = null;
- throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
- }
- }
-
- public void stop()
- {
- handler.close();
- log.info("Search manager stopped");
- }
-
- // /**
- // * Checks if the given event should be excluded based on the
- // * {@link #excludePath} setting.
- // *
- // * @param event
- // * observation event
- // * @return <code>true</code> if the event should be excluded,
- // * <code>false</code> otherwise
- // */
- // protected boolean isExcluded(ItemState event) {
- //
- // for (QPath excludedPath : excludedPaths) {
- // if (event.getData().getQPath().isDescendantOf(excludedPath)
- // || event.getData().getQPath().equals(excludedPath))
- // return true;
- // }
- //
- // return !event.getData().getQPath().isDescendantOf(indexingRoot)
- // && !event.getData().getQPath().equals(indexingRoot);
- // }
-
- protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
- throws RepositoryConfigurationException
- {
-
- QueryHandlerContext context =
- new QueryHandlerContext(itemMgr, indexingTree, nodeTypeDataManager, nsReg, parentHandler, getIndexDir(),
- extractor, true, virtualTableResolver);
- return context;
- }
-
- protected String getIndexDir() throws RepositoryConfigurationException
- {
- String dir = config.getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR, null);
- if (dir == null)
- {
- log.warn(QueryHandlerParams.PARAM_INDEX_DIR + " parameter not found. Using outdated parameter name "
- + QueryHandlerParams.OLD_PARAM_INDEX_DIR);
- dir = config.getParameterValue(QueryHandlerParams.OLD_PARAM_INDEX_DIR);
- }
- return dir;
- }
-
- /**
- * Initializes the query handler.
- *
- * @throws RepositoryException
- * if the query handler cannot be initialized.
- * @throws RepositoryConfigurationException
- * @throws ClassNotFoundException
- */
- protected void initializeQueryHandler() throws RepositoryException, RepositoryConfigurationException
- {
- // initialize query handler
- String className = config.getType();
- if (className == null)
- throw new RepositoryConfigurationException("Content hanler configuration fail");
-
- try
- {
- Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
- Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
- handler = (QueryHandler)constuctor.newInstance(config, cfm);
- QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
- QueryHandlerContext context = createQueryHandlerContext(parentHandler);
- handler.init(context);
-
- }
- catch (SecurityException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (IllegalArgumentException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (ClassNotFoundException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (NoSuchMethodException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (InstantiationException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (InvocationTargetException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (IOException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- }
-
- /**
- * Creates a new instance of an {@link AbstractQueryImpl} which is not
- * initialized.
- *
- * @return an new query instance.
- * @throws RepositoryException
- * if an error occurs while creating a new query instance.
- */
- protected AbstractQueryImpl createQueryInstance() throws RepositoryException
- {
- try
- {
- String queryImplClassName = handler.getQueryClass();
- Object obj = Class.forName(queryImplClassName).newInstance();
- if (obj instanceof AbstractQueryImpl)
- {
- return (AbstractQueryImpl)obj;
- }
- else
- {
- throw new IllegalArgumentException(queryImplClassName + " is not of type "
- + AbstractQueryImpl.class.getName());
- }
- }
- catch (Throwable t)
- {
- throw new RepositoryException("Unable to create query: " + t.toString(), t);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Set<String> getFieldNames() throws IndexException
- {
- final Set<String> fildsSet = new HashSet<String>();
- if (handler instanceof SearchIndex)
- {
- IndexReader reader = null;
- try
- {
- reader = ((SearchIndex)handler).getIndexReader();
- final Collection fields = reader.getFieldNames(IndexReader.FieldOption.ALL);
- for (final Object field : fields)
- {
- fildsSet.add((String)field);
- }
- }
- catch (IOException e)
- {
- throw new IndexException(e.getLocalizedMessage(), e);
- }
- finally
- {
- try
- {
- if (reader != null)
- reader.close();
- }
- catch (IOException e)
- {
- throw new IndexException(e.getLocalizedMessage(), e);
- }
- }
-
- }
- return fildsSet;
- }
-
- public Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException
- {
-
- return getNodes(virtualTableResolver.resolve(nodeType, true));
- }
-
- /**
- * Return set of uuid of nodes. Contains in names prefixes maped to the
- * given uri
- *
- * @param prefix
- * @return
- * @throws RepositoryException
- */
- public Set<String> getNodesByUri(final String uri) throws RepositoryException
- {
- Set<String> result;
- final int defaultClauseCount = BooleanQuery.getMaxClauseCount();
- try
- {
-
- // final LocationFactory locationFactory = new
- // LocationFactory(this);
- final ValueFactoryImpl valueFactory = new ValueFactoryImpl(new LocationFactory(nsReg));
- BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
- BooleanQuery query = new BooleanQuery();
-
- final String prefix = nsReg.getNamespacePrefixByURI(uri);
- query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
- // name of the property
- query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
-
- result = getNodes(query);
-
- // value of the property
-
- try
- {
- final Set<String> props = getFieldNames();
-
- query = new BooleanQuery();
- for (final String fieldName : props)
- {
- if (!FieldNames.PROPERTIES_SET.equals(fieldName))
- {
- query.add(new WildcardQuery(new Term(fieldName, "*" + prefix + ":*")), Occur.SHOULD);
- }
- }
- }
- catch (final IndexException e)
- {
- throw new RepositoryException(e.getLocalizedMessage(), e);
- }
-
- final Set<String> propSet = getNodes(query);
- // Manually check property values;
- for (final String uuid : propSet)
- {
- if (isPrefixMatch(valueFactory, uuid, prefix))
- {
- result.add(uuid);
- }
- }
- }
- finally
- {
- BooleanQuery.setMaxClauseCount(defaultClauseCount);
- }
-
- return result;
- }
-
- private boolean isPrefixMatch(final InternalQName value, final String prefix) throws RepositoryException
- {
- return value.getNamespace().equals(nsReg.getNamespaceURIByPrefix(prefix));
- }
-
- private boolean isPrefixMatch(final QPath value, final String prefix) throws RepositoryException
- {
- for (int i = 0; i < value.getEntries().length; i++)
- {
- if (isPrefixMatch(value.getEntries()[i], prefix))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * @param valueFactory
- * @param dm
- * @param uuid
- * @param prefix
- * @throws RepositoryException
- */
- private boolean isPrefixMatch(final ValueFactoryImpl valueFactory, final String uuid, final String prefix)
- throws RepositoryException
- {
-
- final ItemData node = itemMgr.getItemData(uuid);
- if (node != null && node.isNode())
- {
- final List<PropertyData> props = itemMgr.getChildPropertiesData((NodeData)node);
- for (final PropertyData propertyData : props)
- {
- if (propertyData.getType() == PropertyType.PATH || propertyData.getType() == PropertyType.NAME)
- {
- for (final ValueData vdata : propertyData.getValues())
- {
- final Value val =
- valueFactory.loadValue(((AbstractValueData)vdata).createTransientCopy(), propertyData.getType());
- if (propertyData.getType() == PropertyType.PATH)
- {
- if (isPrefixMatch(((PathValue)val).getQPath(), prefix))
- {
- return true;
- }
- }
- else if (propertyData.getType() == PropertyType.NAME)
- {
- if (isPrefixMatch(((NameValue)val).getQName(), prefix))
- {
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * @param query
- * @return
- * @throws RepositoryException
- */
- private Set<String> getNodes(final org.apache.lucene.search.Query query) throws RepositoryException
- {
- Set<String> result = new HashSet<String>();
- try
- {
- QueryHits hits = handler.executeQuery(query);
-
- ScoreNode sn;
-
- while ((sn = hits.nextScoreNode()) != null)
- {
- // Node node = session.getNodeById(sn.getNodeId());
- result.add(sn.getNodeId());
- }
- }
- catch (IOException e)
- {
- throw new RepositoryException(e.getLocalizedMessage(), e);
- }
- return result;
- }
-
}
16 years, 8 months
exo-jcr SVN: r502 - in jcr/branches/1.12.0-JBC/component/core/src: main/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-09 04:54:44 -0500 (Mon, 09 Nov 2009)
New Revision: 502
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-200: get childs impl, data container lifecycle rework
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java 2009-11-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java 2009-11-09 09:54:44 UTC (rev 502)
@@ -402,7 +402,6 @@
changesLog.add(new ItemState(exoNamespaces, ItemState.MIXIN_CHANGED, false, null));
}
- nsRoot = exoNamespaces;
dataManager.save(new TransactionChangesLog(changesLog));
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-09 09:54:44 UTC (rev 502)
@@ -27,12 +27,12 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import javax.jcr.InvalidItemStateException;
import javax.jcr.RepositoryException;
@@ -183,32 +183,36 @@
*/
public List<NodeData> getChildNodesData(NodeData parent) throws RepositoryException, IllegalStateException
{
- //Set<Object> childNames = cache.getChildrenNames(makeNodeFqn(parent.getQPath()));
- // Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
- // if (parentNode == null)
- // {
- // throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
- // }
- //
- // Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
- //
- // List<NodeData> childs = new ArrayList<NodeData>();
- // for (Node<Serializable, Object> child : childNodes)
- // {
- // String childId = (String)child.get(ITEM_ID);
- //
- // // TODO NodeData or PropertyData? As ItemData check then and cast.
- // NodeData node = (NodeData)cache.get(makeIdFqn(childId), ITEM_DATA);
- // if (node == null)
- // {
- // throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
- // }
- // childs.add(node);
- // }
- //
- // return childs;
- return null;
+ Node<Serializable, Object> parentNode = nodesRoot.getChild(makeNodeFqn(parent.getIdentifier()));
+ if (parentNode == null)
+ {
+ throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
+ }
+
+ Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
+
+ List<NodeData> childs = new ArrayList<NodeData>();
+ for (Node<Serializable, Object> child : childNodes)
+ {
+ String childId = (String)child.get(ITEM_ID);
+
+ // TODO NodeData or PropertyData? As ItemData check then and cast.
+ Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(childId));
+ if (node == null)
+ {
+ throw new RepositoryException("Child node is null. Parent " + parent.getQPath().getAsString());
+ }
+ NodeData nodeData = (NodeData)node.get(ITEM_DATA);
+ if (nodeData == null)
+ {
+ // TODO should not occurs by contract
+ throw new RepositoryException("Child node data is null. Parent " + parent.getQPath().getAsString());
+ }
+ childs.add(nodeData);
+ }
+
+ return childs;
}
private void treePrint(Node<Serializable, Object> node)
@@ -232,33 +236,40 @@
*/
public List<PropertyData> getChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
{
- // TODO treeRoot.getChild(f) possible if f not a direct child???
- // Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
- // if (parentNode == null)
- // {
- // throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
- // }
- //
- // List<PropertyData> childs = new ArrayList<PropertyData>();
- //
- // for (Serializable key : parentNode.getKeys())
- // {
- // if (!key.equals(ITEM_ID))
- // {
- // String propId = (String)parentNode.get(key);
- // // TODO NodeData or PropertyData? As ItemData check then and cast.
- // PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
- // if (property == null)
- // {
- // throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
- // }
- // childs.add(property);
- // }
- // }
- //
- // return childs;
+ //TODO treeRoot.getChild(f) possible if f not a direct child???
+ Node<Serializable, Object> parentNode = nodesRoot.getChild(makeNodeFqn(parent.getIdentifier()));
+ if (parentNode == null)
+ {
+ throw new IllegalStateException("Get child Properties error: parent not found "
+ + parent.getQPath().getAsString());
+ }
- return null;
+ List<PropertyData> childs = new ArrayList<PropertyData>();
+
+ for (Serializable key : parentNode.getKeys())
+ {
+ if (!key.equals(ITEM_ID))
+ {
+ String propId = (String)parentNode.get(key);
+
+ Node<Serializable, Object> prop = propsRoot.getChild(makePropFqn(propId));
+ if (prop == null)
+ {
+ throw new RepositoryException("Child property is null. Parent " + parent.getQPath().getAsString());
+ }
+
+ PropertyData propData = (PropertyData)prop.get(ITEM_DATA);
+ if (propData == null)
+ {
+ // TODO should not occurs by contract
+ throw new RepositoryException("Child property data is null. Parent " + parent.getQPath().getAsString());
+ }
+
+ childs.add(propData);
+ }
+ }
+
+ return childs;
}
/**
@@ -277,10 +288,21 @@
{
// try as Node
- Node<Serializable, Object> item = nodesRoot.getChild(makeChildNodeFqn(parentData.getIdentifier(), name));
- if (item != null)
+ // TODO validate ParentNotFound for both Node and Property
+ Node<Serializable, Object> childNode = nodesRoot.getChild(makeChildNodeFqn(parentData.getIdentifier(), name));
+ if (childNode != null)
{
- return (NodeData)item.get(ITEM_DATA);
+ String nodeId = (String)childNode.get(ITEM_ID);
+ Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(nodeId));
+ Object itemData = node.get(ITEM_DATA);
+ if (itemData != null)
+ {
+ return (NodeData)itemData;
+ }
+ else
+ {
+ throw new RepositoryException("FATAL NodeData empty " + parentData.getQPath() + name.getAsString(true));
+ }
}
else
{
@@ -295,6 +317,12 @@
return (PropertyData)propsRoot.get(makePropFqn(propId));
}
}
+ else
+ {
+ // TODO validation of ParentNotFound for Property
+ throw new RepositoryException("Parent not found " + parentData.getIdentifier() + ", "
+ + parentData.getQPath().getAsString());
+ }
}
return null;
@@ -306,28 +334,37 @@
public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
{
- Node<Serializable, Object> item = nodesRoot.getChild(makeNodeFqn(identifier));
- if (item == null)
+ Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(identifier));
+ if (node != null)
{
- item = propsRoot.getChild(makePropFqn(identifier));
- }
-
- if (item != null)
- {
- Object itemData = item.get(ITEM_DATA);
+ Object itemData = node.get(ITEM_DATA);
if (itemData != null)
{
- return (ItemData)itemData;
+ return (NodeData)itemData;
}
else
{
- throw new RepositoryException("FATAL ItemData empty " + item.getFqn());
+ throw new RepositoryException("FATAL NodeData empty " + identifier);
}
}
else
{
- return null;
+ Node<Serializable, Object> prop = propsRoot.getChild(makePropFqn(identifier));
+ if (prop != null)
+ {
+ Object itemData = prop.get(ITEM_DATA);
+ if (itemData != null)
+ {
+ return (PropertyData)itemData;
+ }
+ else
+ {
+ throw new RepositoryException("FATAL PropertyData empty " + identifier);
+ }
+ }
}
+
+ return null;
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-09 09:54:44 UTC (rev 502)
@@ -67,15 +67,16 @@
private final Cache<Serializable, Object> cache;
- private final Node<Serializable, Object> nodes;
- private final Node<Serializable, Object> properties;
+ private Node<Serializable, Object> nodes;
+ private Node<Serializable, Object> properties;
+
/**
* JBossWorkspaceDataContainer constructor.
*
*/
- public JBossCacheWorkspaceDataContainer(WorkspaceEntry wsConfig,
- RepositoryEntry repConfig, InitialContextInitializer contextInit, ValueStoragePluginProvider valueStorageProvider)
+ public JBossCacheWorkspaceDataContainer(WorkspaceEntry wsConfig, RepositoryEntry repConfig,
+ InitialContextInitializer contextInit, ValueStoragePluginProvider valueStorageProvider)
throws RepositoryConfigurationException, NamingException, RepositoryException, IOException
{
this.repositoryName = repConfig.getName();
@@ -89,6 +90,10 @@
// TODO hardcoded now
this.persistentContainer = new JDBCWorkspaceDataContainer(wsConfig, repConfig, contextInit, valueStorageProvider);
+ if (this.persistentContainer instanceof Startable)
+ {
+ ((Startable)this.persistentContainer).start();
+ }
// TODO configure CacheLoader here with this.persistentContainer
// for (IndividualCacheLoaderConfig loaderCfg : this.cache.getConfiguration().getCacheLoaderConfig()
@@ -99,7 +104,7 @@
// ((ExoJCRCacheLoader)loaderCfg.getCacheLoader()).initDataContainer(this.persistentContainer);
// }
// }
-
+
// inject JDBC DC via JBC ComponentRegistry
((CacheSPI<Serializable, Object>)cache).getComponentRegistry().registerComponent(this.persistentContainer,
WorkspaceDataContainer.class);
@@ -107,7 +112,8 @@
// TODO check lifecycle, might be we have to create in start(), with jdbc start.
// initializes configuration state, the root node, etc.
this.cache.create();
-
+ this.cache.start();
+
Node<Serializable, Object> cacheRoot = cache.getRoot();
//Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
@@ -118,10 +124,20 @@
public void start()
{
- if (persistentContainer instanceof Startable)
- {
- ((Startable)persistentContainer).start();
- }
+ // TODO started on init, due to RepositoryContainer logic
+// if (persistentContainer instanceof Startable)
+// {
+// ((Startable)persistentContainer).start();
+// }
+//
+// this.cache.start();
+//
+// Node<Serializable, Object> cacheRoot = cache.getRoot();
+// //Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
+//
+// // prepare cache structures
+// this.nodes = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.NODES));
+// this.properties = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.PROPS));
}
public void stop()
@@ -145,6 +161,12 @@
*/
public WorkspaceStorageConnection openConnection() throws RepositoryException
{
+ // TODO
+// if (nodes == null || properties == null)
+// {
+// throw new RepositoryException("Container is not started");
+// }
+
return new JBossCacheStorageConnection(cache, nodes, properties);
}
@@ -153,6 +175,12 @@
*/
public WorkspaceStorageConnection openConnection(boolean readOnly) throws RepositoryException
{
+ // TODO
+// if (nodes == null || properties == null)
+// {
+// throw new RepositoryException("Container is not started");
+// }
+
return new JBossCacheStorageConnection(cache, nodes, properties);
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml 2009-11-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml 2009-11-09 09:54:44 UTC (rev 502)
@@ -32,7 +32,7 @@
<!-- for system storage -->
<container class="org.exoplatform.services.jcr.impl.storage.jbosscache.JBossCacheWorkspaceDataContainer">
<properties>
- <property name="jbosscache-configuration" value="conf/portal/exojcr-jboss-cache-conf.xml" />
+ <property name="jbosscache-configuration" value="conf/standalone/test-jbosscache-config-jdbcloader.xml" />
<property name="source-name" value="jdbcjcr" />
<property name="dialect" value="hsqldb" />
<property name="multi-db" value="true" />
16 years, 8 months
exo-jcr SVN: r501 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-11-09 04:44:25 -0500 (Mon, 09 Nov 2009)
New Revision: 501
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
Log:
EXOJCR-204:Observation manager updated/logic excluded.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09 09:19:00 UTC (rev 500)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09 09:44:25 UTC (rev 501)
@@ -18,11 +18,27 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+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.QPath;
+import org.exoplatform.services.jcr.impl.core.observation.EventImpl;
+import org.exoplatform.services.jcr.impl.core.observation.ListenerCriteria;
import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
+import org.exoplatform.services.jcr.impl.util.EntityCollection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import java.util.List;
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventListenerIterator;
+
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: ObservationCacheLoader.java 34360 2009-07-22 23:58:59Z aheritier $
@@ -30,14 +46,21 @@
*/
public class ObservationCacheLoader extends AbstractWriteOnlyCacheLoader
{
- private final ObservationManagerRegistry observationManagerRegistry;
+ public final int SKIP_EVENT = Integer.MIN_VALUE;
+ private Log log = ExoLogger.getLogger(this.getClass().getName());
+
+ private final Fqn nodeFqn = Fqn.fromString(JBossCacheStorage.NODES);
+
+ private final Fqn propFqn = Fqn.fromString(JBossCacheStorage.PROPS);
+
+ private ObservationManagerRegistry observationManagerRegistry=null;
+
/**
*
*/
- public ObservationCacheLoader(ObservationManagerRegistry observationManagerRegistry)
+ public ObservationCacheLoader()
{
- this.observationManagerRegistry = observationManagerRegistry;
}
/**
@@ -46,8 +69,145 @@
@Override
public void put(List<Modification> modifications) throws Exception
{
- // TODO Auto-generated method stub
}
+ private int eventType(Modification modification)
+ {
+ // TODO: REMOVE cache structure hardcode!
+ switch (modification.getType())
+ {
+ case PUT_DATA :
+ if (modification.getFqn().isDirectChildOf(nodeFqn))
+ {
+ // node added
+ return Event.NODE_ADDED;
+ }
+ else if (modification.getFqn().isDirectChildOf(propFqn))
+ {
+ // property added or changed
+ if (modification.getOldValue() != null)
+ {
+ // property changed
+ // TODO: possibly bad idea
+ return Event.PROPERTY_CHANGED;
+ }
+ else
+ {
+ // property added
+ return Event.PROPERTY_ADDED;
+ }
+ }
+ break;
+ case REMOVE_NODE :
+ if (modification.getFqn().isDirectChildOf(nodeFqn))
+ {
+ // node removed
+ return Event.NODE_REMOVED;
+ }
+ else if (modification.getFqn().isDirectChildOf(propFqn))
+ {
+ // property removed
+ return Event.PROPERTY_REMOVED;
+ }
+ break;
+ }
+ return SKIP_EVENT;
+ }
+
+ private boolean isTypeMatch(ListenerCriteria criteria, int eventType)
+ {
+ return (criteria.getEventTypes() & eventType) > 0;
+ }
+
+ private boolean isSessionMatch(ListenerCriteria criteria, String sessionId)
+ {
+ if (criteria.getNoLocal() && criteria.getSessionId().equals(sessionId))
+ return false;
+ return true;
+ }
+
+ private boolean isIdentifierMatch(ListenerCriteria criteria, ItemData item)
+ {
+
+ if (criteria.getIdentifier() == null)
+ return true;
+ // for each uuid in list
+ for (int i = 0; i < criteria.getIdentifier().length; i++)
+ {
+ // if it is a direct child of nodeFqn or propertyFqn - get their parent
+ if (criteria.getIdentifier()[i].equals(item.getParentIdentifier()))
+ return true;
+ }
+ return false;
+
+ }
+
+ private boolean isPathMatch(ListenerCriteria criteria, ItemData item)
+ {
+ if (criteria.getAbsPath() == null)
+ return true;
+ // 8.3.3 Only events whose associated parent node is at absPath (or
+ // within its subtree, if isDeep is true) will be received.
+ QPath itemPath = item.getQPath();
+ return itemPath.isDescendantOf(criteria.getAbsPath(), !criteria.isDeep());
+ }
+
+ @Deprecated
+ private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, List<Modification> modifications)
+ throws RepositoryException
+ {
+ if (criteria.getNodeTypeName() == null)
+ return true;
+
+ // TODO: IT IS IMPOSSIBLE TO ACCESS CACHE ON CACHELOADER.PUT()!!!
+ NodeData node =
+ (NodeData)observationManagerRegistry.getWorkspaceDataManager().getItemData(item.getParentIdentifier());
+ if (node == null)
+ {
+ // check if parent exists in changes log
+ for (int i = modifications.size() - 1; i >= 0; i--)
+ {
+ ItemData data = getItemData(modifications.get(i));
+ if (data.getIdentifier().equals(item.getParentIdentifier()))
+ {
+ // parent found
+ node = (NodeData)data;
+ break;
+ }
+ }
+
+ if (node == null)
+ {
+ log.warn("Item's " + item.getQPath().getAsString() + " associated parent (" + item.getParentIdentifier()
+ + ") can't be found nor in workspace nor in current changes. Nodetype filter is rejected.");
+ return false;
+ }
+ }
+
+ for (int i = 0; i < criteria.getNodeTypeName().length; i++)
+ {
+ NodeTypeData criteriaNT =
+ observationManagerRegistry.getNodeTypeDataManager().getNodeType(criteria.getNodeTypeName()[i]);
+ InternalQName[] testQNames;
+ if (criteriaNT.isMixin())
+ {
+ testQNames = node.getMixinTypeNames();
+ }
+ else
+ {
+ testQNames = new InternalQName[1];
+ testQNames[0] = node.getPrimaryTypeName();
+ }
+ if (observationManagerRegistry.getNodeTypeDataManager().isNodeType(criteriaNT.getName(), testQNames))
+ return true;
+ }
+ return false;
+ }
+
+ protected ItemData getItemData(Modification m)
+ {
+ return (ItemData)m.getData().get(JBossCacheStorage.ITEM_DATA);
+ }
+
}
16 years, 8 months
exo-jcr SVN: r500 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr: impl/dataflow and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-09 04:19:00 -0500 (Mon, 09 Nov 2009)
New Revision: 500
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
Log:
EXOJCR-201 :Add serialization mechanism to PersistentItemData, PersistentNodeData, etc.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -18,8 +18,15 @@
*/
package org.exoplatform.services.jcr.dataflow.persistent;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.exoplatform.services.jcr.datamodel.IllegalPathException;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
/**
* Created by The eXo Platform SAS. </br>
@@ -30,17 +37,34 @@
* @version $Id$
*/
-public abstract class PersistedItemData implements ItemData
+public abstract class PersistedItemData implements ItemData, Externalizable
{
- protected final String id;
+ /**
+ * SerialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = -3845740801904303663L;
- protected final QPath qpath;
+ protected String id;
- protected final String parentId;
+ protected QPath qpath;
- protected final int version;
+ protected String parentId;
+ protected int version;
+
+ private final int NOT_NULL_VALUE = 1;
+
+ private final int NULL_VALUE = -1;
+
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public PersistedItemData()
+ {
+ }
+
public PersistedItemData(String id, QPath qpath, String parentId, int version)
{
this.id = id;
@@ -104,4 +128,67 @@
return false;
}
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ byte[] buf;
+
+ try
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ String sQPath = new String(buf, Constants.DEFAULT_ENCODING);
+ qpath = QPath.parse(sQPath);
+ }
+ catch (final IllegalPathException e)
+ {
+ throw new IOException("Deserialization error. " + e)
+ {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ id = new String(buf);
+
+ int isNull = in.readInt();
+ if (isNull == NOT_NULL_VALUE)
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ parentId = new String(buf);
+ }
+
+ version = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ byte[] buf = qpath.getAsString().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ out.writeInt(id.getBytes().length);
+ out.write(id.getBytes());
+
+ if (parentId != null)
+ {
+ out.writeInt(NOT_NULL_VALUE);
+ out.writeInt(parentId.getBytes().length);
+ out.write(parentId.getBytes());
+ }
+ else
+ out.writeInt(NULL_VALUE);
+
+ out.writeInt(version);
+ }
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -18,14 +18,21 @@
*/
package org.exoplatform.services.jcr.dataflow.persistent;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.jcr.RepositoryException;
+
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.dataflow.ItemDataVisitor;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
-import javax.jcr.RepositoryException;
-
/**
* Created by The eXo Platform SAS.</br>
*
@@ -35,15 +42,23 @@
* @version $Id$
*/
-public class PersistedNodeData extends PersistedItemData implements NodeData
+public class PersistedNodeData extends PersistedItemData implements NodeData, Externalizable
{
- protected final int orderNumber;
+ /**
+ * serialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = 3033563403958948338L;
- protected final InternalQName primaryTypeName;
+ //TODO remove final
+ protected int orderNumber;
- protected final InternalQName[] mixinTypeNames;
+ //TODO remove final
+ protected InternalQName primaryTypeName;
+ //TODO remove final
+ protected InternalQName[] mixinTypeNames;
+
protected AccessControlList acl;
public PersistedNodeData(String id, QPath qpath, String parentId, int version, int orderNumber,
@@ -123,4 +138,94 @@
return true;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ super.readExternal(in);
+
+ orderNumber = in.readInt();
+
+ // primary type
+ byte[] buf;
+ try
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ primaryTypeName = InternalQName.parse(new String(buf, Constants.DEFAULT_ENCODING));
+ }
+ catch (final IllegalNameException e)
+ {
+ throw new IOException(e.getMessage())
+ {
+ private static final long serialVersionUID = 3489809179234435267L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+
+ // mixins
+ int count = in.readInt();
+ mixinTypeNames = new InternalQName[count];
+ for (int i = 0; i < count; i++)
+ {
+ try
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ mixinTypeNames[i] = InternalQName.parse(new String(buf, Constants.DEFAULT_ENCODING));
+ }
+ catch (final IllegalNameException e)
+ {
+ throw new IOException(e.getMessage())
+ {
+ private static final long serialVersionUID = 3489809179234435268L; // eclipse
+
+ // gen
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+ }
+
+ // acl
+ acl.readExternal(in);
+
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ super.writeExternal(out);
+
+ out.writeInt(orderNumber);
+
+ // primary type
+ byte[] ptbuf = primaryTypeName.getAsString().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(ptbuf.length);
+ out.write(ptbuf);
+
+ // mixins
+ out.writeInt(mixinTypeNames.length);
+ for (int i = 0; i < mixinTypeNames.length; i++)
+ {
+ byte[] buf = mixinTypeNames[i].getAsString().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+ }
+
+ acl.writeExternal(out);
+ }
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -23,6 +23,11 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.ValueData;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
import java.util.List;
import javax.jcr.RepositoryException;
@@ -36,15 +41,30 @@
* @version $Id$
*/
-public class PersistedPropertyData extends PersistedItemData implements PropertyData
+public class PersistedPropertyData extends PersistedItemData implements PropertyData, Externalizable
{
+ /**
+ * serialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = 2035566403758848232L;
+
+ protected final static int NULL_VALUES = -1;
+
protected List<ValueData> values;
- protected final int type;
+ protected int type;
- protected final boolean multiValued;
+ protected boolean multiValued;
+ /**
+ * Empty constructor to serialization.
+ */
+ public PersistedPropertyData()
+ {
+ super();
+ }
+
public PersistedPropertyData(String id, QPath qpath, String parentId, int version, int type, boolean multiValued)
{
super(id, qpath, parentId, version);
@@ -119,5 +139,42 @@
else
throw new RuntimeException("The values can not be changed ");
}
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ super.writeExternal(out);
+ out.writeInt(type);
+ out.writeBoolean(multiValued);
+
+ if (values != null)
+ {
+ int listSize = values.size();
+ out.writeInt(listSize);
+ for (int i = 0; i < listSize; i++)
+ out.writeObject(values.get(i));
+ }
+ else
+ {
+ out.writeInt(NULL_VALUES);
+ }
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ super.readExternal(in);
+
+ type = in.readInt();
+
+ multiValued = in.readBoolean();
+
+ int listSize = in.readInt();
+ if (listSize != NULL_VALUES)
+ {
+ values = new ArrayList<ValueData>();
+ for (int i = 0; i < listSize; i++)
+ values.add((ValueData)in.readObject());
+ }
+ }
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -18,13 +18,14 @@
*/
package org.exoplatform.services.jcr.impl.dataflow;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
@@ -34,11 +35,28 @@
import javax.jcr.RepositoryException;
-public class EditableValueData extends TransientValueData
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+public class EditableValueData extends TransientValueData implements Externalizable
{
- protected final int maxIOBuffSize;
+ /**
+ * SerialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = -5280857006905550884L;
+
+ protected int maxIOBuffSize;
+ /**
+ * Empty constructor to serialization.
+ */
+ public EditableValueData()
+ {
+ super();
+ maxIOBuffSize = 0;
+ }
+
+
public EditableValueData(byte[] bytes, int orderNumber, FileCleaner fileCleaner, int maxBufferSize,
File tempDirectory) throws IOException
{
@@ -437,4 +455,14 @@
}
}
}
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ maxIOBuffSize = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(maxIOBuffSize);
+ }
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.io.Serializable;
import javax.jcr.RepositoryException;
@@ -39,6 +40,10 @@
public class ByteArrayPersistedValueData extends AbstractValueData implements Externalizable
{
+ /**
+ * The serialVersionUID.
+ */
+ private static final long serialVersionUID = -9131328056670315388L;
protected byte[] data;
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -18,15 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent;
-import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.jcr.impl.util.io.SwapFile;
-
+import java.io.Externalizable;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.jcr.RepositoryException;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.SwapFile;
+
/**
* Created by The eXo Platform SAS. Implementation of FileStream ValueData secures deleting file in
* object finalization
@@ -35,10 +36,23 @@
* @version $Id$
*/
-public class CleanableFileStreamValueData extends FileStreamPersistedValueData
+public class CleanableFileStreamValueData extends FileStreamPersistedValueData implements Externalizable
{
protected final FileCleaner cleaner;
+
+
+ /**
+ * Empty constructor to serialization.
+ *
+ * @throws FileNotFoundException
+ */
+ public CleanableFileStreamValueData() throws FileNotFoundException
+ {
+ super();
+ //TODO
+ cleaner = null;
+ }
/**
* CleanableFileStreamValueData constructor.
@@ -76,7 +90,7 @@
if (log.isDebugEnabled())
{
- log.debug("�ould not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+ log.debug("�ould not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+ file.getAbsolutePath());
}
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java 2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java 2009-11-09 09:19:00 UTC (rev 500)
@@ -21,10 +21,14 @@
import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
import javax.jcr.RepositoryException;
@@ -35,10 +39,24 @@
* @version $Id$
*/
-public class FileStreamPersistedValueData extends AbstractValueData
+public class FileStreamPersistedValueData extends AbstractValueData implements Externalizable
{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -2668587716865690994L;
+
protected final File file;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public FileStreamPersistedValueData()
+ {
+ super(0);
+ file = null;
+ }
/**
* FileStreamPersistedValueData constructor.
@@ -109,6 +127,18 @@
return false;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
// TODO cleanup
// protected void finalize() throws Throwable {
// try {
16 years, 8 months
exo-jcr SVN: r499 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl: storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2009-11-09 02:13:07 -0500 (Mon, 09 Nov 2009)
New Revision: 499
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
Log:
EXOJCR-205: LockManager refactored
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2009-11-08 22:04:52 UTC (rev 498)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2009-11-09 07:13:07 UTC (rev 499)
@@ -709,8 +709,10 @@
* @param sessionId
* @param nodeIdentifier
* @throws LockException
+ *
+ * TODO: Changed from private to public. Need for LockCacheLoader.
*/
- private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
+ public synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
{
LockData lData = locks.get(nodeIdentifier);
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java 2009-11-08 22:04:52 UTC (rev 498)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java 2009-11-09 07:13:07 UTC (rev 499)
@@ -16,17 +16,25 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.lock.LockManager;
import org.exoplatform.services.jcr.impl.core.lock.LockManagerImpl;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.jboss.cache.CacheException;
import org.jboss.cache.Modification;
+import org.jboss.cache.Modification.ModificationType;
import java.util.ArrayList;
import java.util.List;
+import javax.jcr.lock.LockException;
+
/**
* Created by The eXo Platform SAS.
*
@@ -38,25 +46,33 @@
public class LockCacheLoader extends AbstractWriteOnlyCacheLoader
{
+ /**
+ * Lock manager.
+ */
private LockManagerImpl lockManager;
/**
+ * Logger.
+ */
+ private final Log log = ExoLogger.getLogger("jcr.LockCacheLoader");
+
+ /**
* {@inheritDoc}
*/
@Override
public void put(List<Modification> modifications) throws Exception
{
- LockChanges lockChanges = new LockChanges();
+ List<Modification> lockChanges = new ArrayList<Modification>();
for (Modification m : modifications)
{
- // TODO $properties
if (m.getFqn().hasElement(JBossCacheStorage.PROPS))
{
switch (m.getType())
{
case PUT_DATA :
break;
+
case PUT_KEY_VALUE :
if (m.getKey().equals(JBossCacheStorage.ITEM_DATA))
{
@@ -65,51 +81,124 @@
if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
{
+ lockChanges.add(m);
}
}
break;
+
case REMOVE_DATA :
break;
+
case REMOVE_KEY_VALUE :
+ PropertyData propertyData = (PropertyData)m.getValue();
+ InternalQName propertyName = propertyData.getQPath().getName();
+
+ if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
+ {
+ lockChanges.add(m);
+ }
break;
+
case REMOVE_NODE :
break;
+
case MOVE :
break;
+
default :
throw new CacheException("Unknown modification " + m.getType());
}
}
+
+ if (lockChanges.size() == 2)
+ {
+ if (lockChanges.get(0).getType() == ModificationType.PUT_KEY_VALUE
+ && lockChanges.get(1).getType() == ModificationType.PUT_KEY_VALUE)
+ {
+ performLock(lockChanges);
+ }
+ else if (lockChanges.get(0).getType() == ModificationType.REMOVE_KEY_VALUE
+ && lockChanges.get(1).getType() == ModificationType.REMOVE_KEY_VALUE)
+ {
+ performUnLock(lockChanges);
+ }
+ else
+ {
+
+ }
+ }
+
+ lockChanges = new ArrayList<Modification>();
}
+
+ if (lockChanges.size() != 0)
+ {
+ log.error("Incorrect changes log size for lock or unlock operation");
+ }
}
- private void processLock()
+ /**
+ * Perform lock operation.
+ *
+ * @param lockChanges
+ * @throws LockException
+ */
+ private void performLock(List<Modification> lockChanges) throws Exception
{
- // String nodeIdentifier = data.getParentIdentifier();
- // if (lockManager.hasPendingLocks(nodeIdentifier))
- // {
- // lockManager.internalLock(nodeIdentifier);
- // }
- // else
- // {
- //
- // }
+ String nodeIdentifier = ((PropertyData)lockChanges.get(0).getValue()).getParentIdentifier();
+
+ if (lockManager.hasPendingLocks(nodeIdentifier))
+ {
+ lockManager.internalLock(nodeIdentifier);
+ }
+ else
+ {
+ log.warn("No lock in pendingLocks for identifier " + nodeIdentifier + " Probably lock come from replication.");
+
+ String lockToken = IdGenerator.generate();
+ Modification ownerModification = getModification(lockChanges, Constants.JCR_LOCKOWNER);
+ Modification isDeepModification = getModification(lockChanges, Constants.JCR_LOCKISDEEP);
+
+ if (ownerModification != null && isDeepModification != null)
+ {
+
+ String owner =
+ new String(((((TransientPropertyData)(ownerModification.getValue())).getValues()).get(0))
+ .getAsByteArray(), Constants.DEFAULT_ENCODING);
+
+ boolean isDeep =
+ Boolean.valueOf(
+ new String(((((TransientPropertyData)(isDeepModification.getValue())).getValues()).get(0))
+ .getAsByteArray(), Constants.DEFAULT_ENCODING)).booleanValue();
+
+ // TODO sessionId
+ lockManager.createRemoteLock("sessionId", nodeIdentifier, lockToken, isDeep, false, owner);
+ }
+ }
}
- private void processUnLock()
+ private void performUnLock(List<Modification> lockChanges) throws Exception
{
-
+ // TODO sessionId
+ // TODO nodeIdentifier
+ lockManager.internalUnLock("sessionId", "nodeIdentifier");
}
/**
+ * Search item with name <code>itemName<code> in modification list
*
+ * @param changes
+ * @param itemName
+ * @return Item
*/
- private class LockChanges
+ private Modification getModification(List<Modification> changes, InternalQName itemName)
{
- PropertyData lockIsDeepData;
-
- PropertyData lockOwnerData;
-
+ for (Modification m : changes)
+ {
+ if (((PropertyData)changes.get(0).getValue()).getQPath().getName().equals(itemName))
+ return m;
+ }
+ return null;
}
}
16 years, 8 months
exo-jcr SVN: r498 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-08 17:04:52 -0500 (Sun, 08 Nov 2009)
New Revision: 498
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-200: conn tests
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-08 13:19:25 UTC (rev 497)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-08 22:04:52 UTC (rev 498)
@@ -137,6 +137,53 @@
}
}
+ 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 checkChildNode(Node<Serializable, Object> rootNode, String childId, QPath childPath)
+ {
+ checkChildNode(rootNode, childId, childPath, null, null);
+ }
+
+ private void checkChildNode(Node<Serializable, Object> rootNode, String childId, QPath childPath, Integer orderNum,
+ Integer 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 = props.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 != null)
+ {
+ //assertEquals("Node order number wrong", orderNum, childNodeData.getOrderNumber());
+ }
+
+ if (version != null)
+ {
+ //assertEquals("Node persisted version wrong", version, childNodeData.getPersistedVersion());
+ }
+ }
+
public void testAddNode() throws Exception
{
// add root (/)
@@ -161,47 +208,12 @@
assertNotNull("Node expected", rootNode);
// check root Node
- Object dataObject = rootNode.get(JBossCacheStorageConnection.ITEM_DATA);
- assertTrue("Node item data is not a Node", dataObject instanceof NodeData);
+ checkNode(rootNode, Constants.ROOT_UUID, Constants.ROOT_PATH);
- NodeData data = (NodeData)dataObject;
- assertEquals("Node id wrong", node1id, data.getIdentifier());
- assertEquals("Node path wrong", node1path, data.getQPath());
-
- // cehck childs
+ // cechk childs
assertEquals("Childs expected", 2, rootNode.getChildren().size());
-
- for (Node<Serializable, Object> child : rootNode.getChildren())
- {
- // check id and name
- String nodeName = child.getFqn().getLastElementAsString();
- String nodeId = (String)child.get(JBossCacheStorageConnection.ITEM_ID);
- if (nodeName.equals(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)))
- {
- assertEquals("Node id wrong", node1id, nodeId);
- }
- else if (nodeName
- .equals(Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1]
- .getAsString(true)))
- {
- assertEquals("Node id wrong", Constants.SYSTEM_UUID, nodeId);
- }
- else
- {
- fail("Wrong Node name " + nodeName);
- }
-
- // check data
- Node<Serializable, Object> childNode = nodes.getChild(Fqn.fromElements(nodeId));
- assertNotNull("Node expected", childNode);
-
- Object childData = childNode.get(JBossCacheStorageConnection.ITEM_DATA);
- assertTrue("Child Node item data is not a Node", childData instanceof NodeData);
-
- assertEquals("Node id wrong", nodeId, ((NodeData)childData).getIdentifier());
- assertEquals("Node path wrong", nodeName,
- data.getQPath().getEntries()[data.getQPath().getEntries().length - 1].getAsString(true));
- }
+ checkChildNode(rootNode, node1id, node1path);
+ checkChildNode(rootNode, Constants.SYSTEM_UUID, Constants.JCR_SYSTEM_PATH);
}
public void testAddProperty() throws Exception
@@ -228,7 +240,6 @@
// check in nodes
treePrint(nodes);
- treePrint(props);
Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
@@ -251,7 +262,7 @@
}
// check in props
- treePrint(nodes);
+ treePrint(props);
Node<Serializable, Object> itemsProp1 = props.getChild(Fqn.fromElements(propId1));
Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
@@ -373,39 +384,98 @@
// add node (/node)
String node1id = "1";
- QPath node1path = QPath.parse("[]:1[]node:1");
- conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ QPath node1path = QPath.parse("[]:1[]snsNode:1");
+ int node1OrderNumb = 0;
+ int node1version = 1;
+ conn.add(new TransientNodeData(node1path, node1id, node1version, Constants.NT_UNSTRUCTURED, new InternalQName[0],
+ node1OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ String node2id = "2";
+ QPath node2path = QPath.parse("[]:1[]snsNode:2");
+ int node2OrderNumb = 1;
+ conn.add(new TransientNodeData(node2path, node2id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0],
+ node2OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ String node3id = "3";
+ QPath node3path = QPath.parse("[]:1[]baseNode:1");
+ int node3OrderNumb = 2;
+ conn.add(new TransientNodeData(node3path, node3id, 1, Constants.NT_BASE, new InternalQName[0], node3OrderNumb,
Constants.ROOT_UUID, new AccessControlList()));
// get root node ([]:1)
Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
- // update /node (order number)
- int nodeOrderNumb = 1;
- conn.update(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0],
- nodeOrderNumb, Constants.ROOT_UUID, new AccessControlList()));
-
- // check in tree
+ // before
treePrint(nodes);
- Node<Serializable, Object> node =
- rootNode.getChild(Fqn
- .fromElements(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)));
+ // do Node.orderBefore("/snsNode:1", null) behaviour: order /snsNode:1 at the end
+ // update /snsNode:1 (order number, version and index) to /snsNode:2
+ QPath newNode1path = QPath.parse("[]:1[]snsNode:2");
+ int newNode1OrderNumb = 2;
+ int newNode1version = 2;
+ conn.update(new TransientNodeData(newNode1path, node1id, newNode1version, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], newNode1OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
- assertNotNull("Node should exists", node);
- assertEquals("Child expected", 1, rootNode.getChildren().size());
+ // update /snsNode:2 (order number, version and index) to /snsNode:1
+ QPath newNode2path = QPath.parse("[]:1[]snsNode:1");
+ int newNode2OrderNumb = 0;
+ int newNode2version = 2;
+ conn.update(new TransientNodeData(newNode2path, node2id, newNode2version, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], newNode2OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
- // check in items
+ // update /baseNode:1 (order number and version) to /baseNode:1
+ int newNode3OrderNumb = 1;
+ int newNode3version = 2;
+ conn.update(new TransientNodeData(node3path, node3id, newNode3version, Constants.NT_BASE, new InternalQName[0],
+ newNode3OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ // after
treePrint(nodes);
- Node<Serializable, Object> itemNode = nodes.getChild(Fqn.fromElements(node1id));
- assertNotNull("Node item data should exists", itemNode);
+ // get /snsNode:1 from childs of root /
+ checkChildNode(rootNode, node1id, node2path);
+ checkChildNode(rootNode, node2id, node1path);
+ checkChildNode(rootNode, node3id, node3path);
- Object dataObject = itemNode.get(JBossCacheStorageConnection.ITEM_DATA);
- assertTrue("Node item data should be a NodeData", dataObject instanceof NodeData);
- assertEquals("Node id wrong", node1id, ((NodeData)dataObject).getIdentifier());
- assertEquals("Node path wrong", node1path, ((NodeData)dataObject).getQPath());
- assertEquals("Node order number wrong", nodeOrderNumb, ((NodeData)dataObject).getOrderNumber());
+// Node<Serializable, Object> childNode1 =
+// rootNode.getChild(Fqn
+// .fromElements(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)));
+//
+// assertNotNull("Child Node should exists", childNode1);
+// String childNode1id = (String)childNode1.get(JBossCacheStorage.ITEM_ID);
+// Node<Serializable, Object> node1 = props.getChild(Fqn.fromElements(childNode1id));
+// assertNotNull("Node by ID should exists", node1);
+//
+// Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
+// assertTrue("Node item data is not a Node", childNode1Object instanceof NodeData);
+// assertEquals("Node id wrong", node2id, ((NodeData)childNode1Object).getIdentifier());
+// assertEquals("Node path wrong", node2path, ((NodeData)childNode1Object).getQPath());
+//
+// // get /snsNode:2 from childs of root /
+// Node<Serializable, Object> childNode2 =
+// rootNode.getChild(Fqn
+// .fromElements(node2path.getEntries()[node2path.getEntries().length - 1].getAsString(true)));
+//
+// assertNotNull("Child Node should exists", childNode2);
+// String childNode2id = (String)childNode2.get(JBossCacheStorage.ITEM_ID);
+// Node<Serializable, Object> node2 = props.getChild(Fqn.fromElements(childNode2id));
+// assertNotNull("Node by ID should exists", node2);
+//
+// Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
+// assertTrue("Node item data is not a Node", childNode1Object instanceof NodeData);
+// assertEquals("Node id wrong", node2id, ((NodeData)childNode1Object).getIdentifier());
+// assertEquals("Node path wrong", node2path, ((NodeData)childNode1Object).getQPath());
+//
+// assertEquals("Child expected", 3, rootNode.getChildren().size());
+//
+// Node<Serializable, Object> itemNode = nodes.getChild(Fqn.fromElements(node1id));
+// assertNotNull("Node item data should exists", itemNode);
+//
+// Object dataObject = itemNode.get(JBossCacheStorageConnection.ITEM_DATA);
+// assertTrue("Node item data should be a NodeData", dataObject instanceof NodeData);
+// assertEquals("Node id wrong", node1id, ((NodeData)dataObject).getIdentifier());
+// assertEquals("Node path wrong", node1path, ((NodeData)dataObject).getQPath());
+// assertEquals("Node order number wrong", nodeOrderNumb, ((NodeData)dataObject).getOrderNumber());
}
public void testUpdateProperty() throws Exception
16 years, 8 months
exo-jcr SVN: r497 - in ws/branches/2.2.x/exo.ws.rest.core/src: main/java/org/exoplatform/services/rest/tools and 4 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2009-11-08 08:19:25 -0500 (Sun, 08 Nov 2009)
New Revision: 497
Added:
ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
Removed:
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java
Modified:
ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java
ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java
Log:
EXOJCR-230 :
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/MultipartFormDataEntityProvider.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -28,7 +28,6 @@
import org.exoplatform.services.rest.impl.FileCollector;
import org.exoplatform.services.rest.provider.EntityProvider;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Copied: ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java (from rev 496, ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java)
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java (rev 0)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -0,0 +1,103 @@
+/*
+ * 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.rest.tools;
+
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.exoplatform.services.rest.ContainerResponseWriter;
+import org.exoplatform.services.rest.RequestHandler;
+import org.exoplatform.services.rest.impl.ContainerRequest;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
+import org.exoplatform.services.rest.impl.InputHeadersMap;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+
+/**
+ * This class may be useful for running test and should not be used for launching
+ * services in real environment, Servlet Container for example.
+ *
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class ResourceLauncher
+{
+
+ private final RequestHandler requestHandler;
+
+ public ResourceLauncher(RequestHandler requestHandler)
+ {
+ this.requestHandler = requestHandler;
+ }
+
+ /**
+ * @param method HTTP method
+ * @param requestURI full requested URI
+ * @param baseURI base requested URI
+ * @param headers HTTP headers
+ * @param data data
+ * @param writer response writer
+ * @param env environment context
+ * @return response
+ * @throws Exception if any error occurs
+ */
+ public ContainerResponse service(String method, String requestURI, String baseURI,
+ Map<String, List<String>> headers, byte[] data, ContainerResponseWriter writer, EnvironmentContext env)
+ throws Exception
+ {
+
+ if (headers == null)
+ headers = new MultivaluedMapImpl();
+
+ ByteArrayInputStream in = null;
+ if (data != null)
+ in = new ByteArrayInputStream(data);
+
+ if (env == null)
+ env = new EnvironmentContext();
+ EnvironmentContext.setCurrent(env);
+
+ ContainerRequest request =
+ new ContainerRequest(method, new URI(requestURI), new URI(baseURI), in, new InputHeadersMap(headers));
+ ContainerResponse response = new ContainerResponse(writer);
+ requestHandler.handleRequest(request, response);
+ return response;
+ }
+
+ /**
+ * @param method HTTP method
+ * @param requestURI full requested URI
+ * @param baseURI base requested URI
+ * @param headers HTTP headers
+ * @param data data
+ * @param env environment context
+ * @return response
+ * @throws Exception if any error occurs
+ */
+ public ContainerResponse service(String method, String requestURI, String baseURI,
+ MultivaluedMap<String, String> headers, byte[] data, EnvironmentContext env) throws Exception
+ {
+ return service(method, requestURI, baseURI, headers, data, new DummyContainerResponseWriter(), env);
+ }
+
+}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -1,79 +0,0 @@
-/*
- * 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.rest.impl;
-
-import org.exoplatform.services.rest.ContainerResponseWriter;
-import org.exoplatform.services.rest.impl.ContainerRequest;
-import org.exoplatform.services.rest.impl.ContainerResponse;
-import org.exoplatform.services.rest.impl.EnvironmentContext;
-import org.exoplatform.services.rest.impl.InputHeadersMap;
-import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
-import org.exoplatform.services.rest.tools.DummyContainerResponseWriter;
-import org.exoplatform.services.test.mock.MockHttpServletRequest;
-
-import java.io.ByteArrayInputStream;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.MultivaluedMap;
-
-/**
- * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
- */
-public abstract class AbstractResourceTest extends BaseTest
-{
-
- // public void setUp() throws Exception {
- // super.setUp();
- // }
-
- public ContainerResponse service(String method, String requestURI, String baseURI,
- Map<String, List<String>> headers, byte[] data, ContainerResponseWriter writer) throws Exception
- {
-
- if (headers == null)
- headers = new MultivaluedMapImpl();
-
- ByteArrayInputStream in = null;
- if (data != null)
- in = new ByteArrayInputStream(data);
-
- EnvironmentContext envctx = new EnvironmentContext();
- HttpServletRequest httpRequest =
- new MockHttpServletRequest("", in, in != null ? in.available() : 0, method, headers);
- envctx.put(HttpServletRequest.class, httpRequest);
- EnvironmentContext.setCurrent(envctx);
- ContainerRequest request =
- new ContainerRequest(method, new URI(requestURI), new URI(baseURI), in, new InputHeadersMap(headers));
- ContainerResponse response = new ContainerResponse(writer);
- requestHandler.handleRequest(request, response);
- return response;
- }
-
- public ContainerResponse service(String method, String requestURI, String baseURI,
- MultivaluedMap<String, String> headers, byte[] data) throws Exception
- {
- return service(method, requestURI, baseURI, headers, data, new DummyContainerResponseWriter());
-
- }
-
-}
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,6 +18,10 @@
*/
package org.exoplatform.services.rest.impl;
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.List;
+
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
@@ -34,14 +38,18 @@
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.Inject;
import org.exoplatform.services.rest.Property;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class RequestDispatcherTest extends AbstractResourceTest
+public class RequestDispatcherTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
public void setUp() throws Exception
{
resources = new ResourceBinderImpl();
@@ -50,12 +58,13 @@
depInjector.put(InjectableComponent2.class, new InjectableComponent2());
requestHandler = new RequestHandlerImpl(resources, depInjector);
-
+
// reset providers to be sure it is clean
ProviderBinder.setInstance(new ProviderBinder());
providers = ProviderBinder.getInstance();
+ this.launcher = new ResourceLauncher(requestHandler);
}
-
+
@Path("/a")
public static class Resource1
{
@@ -121,12 +130,12 @@
{
Resource1 r1 = new Resource1();
registry(r1);
- assertEquals("m0", service("POST", "/a", "", null, null).getEntity());
- assertEquals("m1", service("POST", "/a/b", "", null, null).getEntity());
- assertEquals("m2.0", service("POST", "/a/b/c", "", null, null).getEntity());
- assertEquals("m2.1", service("POST", "/a/b/c/d", "", null, null).getEntity());
- assertEquals("m3.0", service("POST", "/a/b/c/d/e", "", null, null).getEntity());
- assertEquals("m3.1", service("POST", "/a/b/c/d/e/f", "", null, null).getEntity());
+ assertEquals("m0", launcher.service("POST", "/a", "", null, null, null).getEntity());
+ assertEquals("m1", launcher.service("POST", "/a/b", "", null, null, null).getEntity());
+ assertEquals("m2.0", launcher.service("POST", "/a/b/c", "", null, null, null).getEntity());
+ assertEquals("m2.1", launcher.service("POST", "/a/b/c/d", "", null, null, null).getEntity());
+ assertEquals("m3.0", launcher.service("POST", "/a/b/c/d/e", "", null, null, null).getEntity());
+ assertEquals("m3.1", launcher.service("POST", "/a/b/c/d/e/f", "", null, null, null).getEntity());
unregistry(r1);
}
@@ -167,10 +176,11 @@
{
Resource2 r2 = new Resource2();
registry(r2);
- assertEquals("m0", service("POST", "/", "", null, null).getEntity());
- assertEquals("m1", service("POST", "/a", "", null, null).getEntity());
- assertEquals("#x y", service("POST", "/1/a/b%20/c/%23x%20y", "", null, null).getEntity());
- assertEquals("%23x%20y", service("POST", "/2/a/b%20/c/%23x%20y", "", null, null).getEntity());
+ assertEquals("m0", launcher.service("POST", "/", "", null, null, null).getEntity());
+ assertEquals("m1", launcher.service("POST", "/a", "", null, null, null).getEntity());
+ assertEquals("#x y", launcher.service("POST", "/1/a/b%20/c/%23x%20y", "", null, null, null).getEntity());
+ assertEquals("%23x%20y", launcher.service("POST", "/2/a/b%20/c/%23x%20y", "", null, null, null)
+ .getEntity());
unregistry(r2);
}
@@ -222,9 +232,9 @@
public void testResourceConstructorAndFields() throws Exception
{
registry(Resource3.class);
- assertEquals("/a/b/c/d/m0", service("GET", "/a/b/c/d/m0", "", null, null).getEntity());
- assertEquals("c", service("GET", "/a/b/c/d/m1", "", null, null).getEntity());
- assertEquals("d", service("GET", "/a/b/c/d/m2", "", null, null).getEntity());
+ assertEquals("/a/b/c/d/m0", launcher.service("GET", "/a/b/c/d/m0", "", null, null, null).getEntity());
+ assertEquals("c", launcher.service("GET", "/a/b/c/d/m1", "", null, null, null).getEntity());
+ assertEquals("d", launcher.service("GET", "/a/b/c/d/m2", "", null, null, null).getEntity());
unregistry(Resource3.class);
}
@@ -248,7 +258,7 @@
private HttpServletRequest request;
private InjectableComponent1 ic1;
-
+
@Inject
private InjectableComponent2 ic2;
@@ -279,7 +289,10 @@
public void testResourceConstructorsDependencyInjection() throws Exception
{
registry(Resource4.class);
- assertEquals(204, service("GET", "/aaa/bbb", "", null, null).getStatus());
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(new byte[0]), 0, "GET",
+ new HashMap<String, List<String>>()));
+ assertEquals(204, launcher.service("GET", "/aaa/bbb", "", null, null, env).getStatus());
unregistry(Resource4.class);
}
@@ -308,7 +321,7 @@
public void testResourceConstructorDependencyInjectionFail() throws Exception
{
registry(ResourceFail.class);
- GenericContainerResponse resp = service("GET", "/_a/b/c/d/m0", "", null, null);
+ GenericContainerResponse resp = launcher.service("GET", "/_a/b/c/d/m0", "", null, null, null);
String entity = (String)resp.getEntity();
assertTrue(entity.startsWith("Can't instantiate resource "));
assertEquals(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus());
@@ -350,7 +363,7 @@
public void testQuery() throws Exception
{
registry(Resource5.class);
- service("GET", "/a/b/c/d?q1=q1&q2=q2", "", null, null);
+ launcher.service("GET", "/a/b/c/d?q1=q1&q2=q2", "", null, null, null);
unregistry(Resource5.class);
}
@@ -359,7 +372,7 @@
public void testFieldSuperClass() throws Exception
{
registry(EndResource.class);
- service("GET", "/a", "", null, null);
+ launcher.service("GET", "/a", "", null, null, null);
unregistry(EndResource.class);
}
@@ -412,7 +425,7 @@
registry(Resource6.class);
RequestHandlerImpl.setProperty("prop1", "hello");
RequestHandlerImpl.setProperty("prop2", "test");
- service("GET", "/a", "", null, null);
+ launcher.service("GET", "/a", "", null, null, null);
unregistry(Resource6.class);
}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,9 +18,15 @@
*/
package org.exoplatform.services.rest.impl;
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.List;
+
import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.RequestFilter;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
@@ -34,11 +40,19 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class RequestFilterTest extends AbstractResourceTest
+public class RequestFilterTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Filter
public static class RequestFilter1 implements RequestFilter
{
@@ -53,18 +67,15 @@
private HttpServletRequest httpRequest;
-// private ResourceBinder binder; // exo container component
-
- public RequestFilter1(@Context Providers providers, @Context HttpServletRequest httpRequest/*, ResourceBinder binder*/)
+ public RequestFilter1(@Context Providers providers, @Context HttpServletRequest httpRequest)
{
this.providers = providers;
this.httpRequest = httpRequest;
-// this.binder = binder;
}
public void doFilter(GenericContainerRequest request)
{
- if (uriInfo != null && httpHeaders != null && providers != null && httpRequest != null/* && binder != null*/)
+ if (uriInfo != null && httpHeaders != null && providers != null && httpRequest != null)
request.setMethod("POST");
}
@@ -109,7 +120,7 @@
public void testWithoutFilter1() throws Exception
{
registry(Resource1.class);
- ContainerResponse resp = service("GET", "/a", "", null, null);
+ ContainerResponse resp = launcher.service("GET", "/a", "", null, null, null);
assertEquals(405, resp.getStatus());
assertEquals(1, resp.getHttpHeaders().get("allow").size());
assertTrue(resp.getHttpHeaders().get("allow").get(0).toString().contains("POST"));
@@ -122,9 +133,12 @@
// add filter that can change method
providers.addRequestFilter(RequestFilter1.class);
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(new byte[0]), 0,
+ "GET", new HashMap<String, List<String>>()));
// should get status 204
- ContainerResponse resp = service("GET", "/a", "", null, null);
+ ContainerResponse resp = launcher.service("GET", "/a", "", null, null, env);
assertEquals(204, resp.getStatus());
unregistry(Resource1.class);
@@ -134,7 +148,7 @@
public void testFilter2() throws Exception
{
registry(Resource1.class);
- ContainerResponse resp = service("GET", "/a/b/c/d/e", "", null, null);
+ ContainerResponse resp = launcher.service("GET", "/a/b/c/d/e", "", null, null, null);
assertEquals(405, resp.getStatus());
assertEquals(1, resp.getHttpHeaders().get("allow").size());
assertTrue(resp.getHttpHeaders().get("allow").get(0).toString().contains("DELETE"));
@@ -143,7 +157,7 @@
providers.addRequestFilter(new RequestFilter2());
// not should get status 204
- resp = service("GET", "/a/b/c/d/e", "", null, null);
+ resp = launcher.service("GET", "/a/b/c/d/e", "", null, null, null);
assertEquals(204, resp.getStatus());
unregistry(Resource1.class);
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,9 +18,15 @@
*/
package org.exoplatform.services.rest.impl;
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.List;
+
import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.ResponseFilter;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
@@ -34,11 +40,19 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class ResponseFilterTest extends AbstractResourceTest
+public class ResponseFilterTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Filter
public static class ResponseFilter1 implements ResponseFilter
{
@@ -53,19 +67,15 @@
private HttpServletRequest httpRequest;
-// private ResourceBinder binder; // exo container component
-
- public ResponseFilter1(@Context Providers providers, @Context HttpServletRequest httpRequest/*,
- ResourceBinder binder*/)
+ public ResponseFilter1(@Context Providers providers, @Context HttpServletRequest httpRequest)
{
this.providers = providers;
this.httpRequest = httpRequest;
-// this.binder = binder;
}
public void doFilter(GenericContainerResponse response)
{
- if (uriInfo != null && httpHeaders != null && providers != null && httpRequest != null /*&& binder != null*/)
+ if (uriInfo != null && httpHeaders != null && providers != null && httpRequest != null)
response.setResponse(Response.status(200).entity("to be or not to be").type("text/plain").build());
}
@@ -110,18 +120,21 @@
{
Resource1 r = new Resource1();
registry(r);
- ContainerResponse resp = service("POST", "/a", "", null, null);
+ ContainerResponse resp = launcher.service("POST", "/a", "", null, null, null);
assertEquals(204, resp.getStatus());
// should not be any changes after add this
providers.addResponseFilter(new ResponseFilter2());
- resp = service("POST", "/a", "", null, null);
+ resp = launcher.service("POST", "/a", "", null, null, null);
assertEquals(204, resp.getStatus());
// add response filter and try again
providers.addResponseFilter(ResponseFilter1.class);
- resp = service("POST", "/a", "", null, null);
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(new byte[0]), 0,
+ "POST", new HashMap<String, List<String>>()));
+ resp = launcher.service("POST", "/a", "", null, null, env);
assertEquals(200, resp.getStatus());
assertEquals("text/plain", resp.getContentType().toString());
assertEquals("to be or not to be", resp.getEntity());
@@ -133,7 +146,7 @@
{
Resource1 r = new Resource1();
registry(r);
- ContainerResponse resp = service("POST", "/a/b/c/d/e", "", null, null);
+ ContainerResponse resp = launcher.service("POST", "/a/b/c/d/e", "", null, null, null);
assertEquals(200, resp.getStatus());
assertEquals("text/plain", resp.getContentType().toString());
assertEquals("{\"name\":\"andrew\", \"password\":\"hello\"}", resp.getEntity());
@@ -141,7 +154,7 @@
// add response filter and try again
providers.addResponseFilter(new ResponseFilter2());
- resp = service("POST", "/a/b/c/d/e", "", null, null);
+ resp = launcher.service("POST", "/a/b/c/d/e", "", null, null, null);
assertEquals(200, resp.getStatus());
assertEquals("application/json", resp.getContentType().toString());
assertEquals("{\"name\":\"andrew\", \"password\":\"hello\"}", resp.getEntity());
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,7 +18,8 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
@@ -31,7 +32,7 @@
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
* @version $Id: HeadMethodTest.java
*/
-public class HeadMethodTest extends AbstractResourceTest
+public class HeadMethodTest extends BaseTest
{
@Path("/a")
@@ -64,13 +65,21 @@
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testHeadMethod() throws Exception
{
Resource1 resource1 = new Resource1();
registry(resource1);
- assertEquals("get", service("GET", "/a", "", null, null).getEntity());
- assertEquals(200, service("HEAD", "/a", "", null, null).getStatus());
+ assertEquals("get", launcher.service("GET", "/a", "", null, null, null).getEntity());
+ assertEquals(200, launcher.service("HEAD", "/a", "", null, null, null).getStatus());
unregistry(resource1);
@@ -78,9 +87,9 @@
registry(resource2);
- assertEquals("get", service("GET", "/b", "", null, null).getEntity());
- assertEquals(200, service("HEAD", "/b", "", null, null).getStatus());
- assertNull(service("HEAD", "/b", "", null, null).getEntity());
+ assertEquals("get", launcher.service("GET", "/b", "", null, null, null).getEntity());
+ assertEquals(200, launcher.service("HEAD", "/b", "", null, null, null).getStatus());
+ assertNull(launcher.service("HEAD", "/b", "", null, null, null).getEntity());
unregistry(resource2);
}
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,8 +18,9 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -38,9 +39,17 @@
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
* @version $Id: MediaTypeTest.java
*/
-public class MediaTypeTest extends AbstractResourceTest
+public class MediaTypeTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Path("/a")
public static class Resource1
{
@@ -90,21 +99,25 @@
registry(resource1);
registry(resource2);
- assertEquals(200, service("GET", "/a", "", null, null).getStatus());
- assertEquals("m0", service("GET", "/a", "", null, null).getEntity());
- assertEquals(MediaType.WILDCARD_TYPE, service("GET", "/a", "", null, null).getContentType());
+ assertEquals(200, launcher.service("GET", "/a", "", null, null, null).getStatus());
+ assertEquals("m0", launcher.service("GET", "/a", "", null, null, null).getEntity());
+ assertEquals(MediaType.WILDCARD_TYPE, launcher.service("GET", "/a", "", null, null, null)
+ .getContentType());
- assertEquals(200, service("GET", "/b/c", "", null, null).getStatus());
- assertEquals(MediaType.TEXT_PLAIN_TYPE, service("GET", "/b/c", "", null, null).getContentType());
+ assertEquals(200, launcher.service("GET", "/b/c", "", null, null, null).getStatus());
+ assertEquals(MediaType.TEXT_PLAIN_TYPE, launcher.service("GET", "/b/c", "", null, null, null)
+ .getContentType());
- assertEquals(200, service("GET", "/b/d", "", null, null).getStatus());
- assertEquals(MediaType.TEXT_XML_TYPE, service("GET", "/b/d", "", null, null).getContentType());
+ assertEquals(200, launcher.service("GET", "/b/d", "", null, null, null).getStatus());
+ assertEquals(MediaType.TEXT_XML_TYPE, launcher.service("GET", "/b/d", "", null, null, null)
+ .getContentType());
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
- assertEquals(406, service("GET", "/b/d", "", headers, null).getStatus());
- assertEquals(MediaType.TEXT_XML_TYPE, service("GET", "/b/d", "", null, null).getContentType());
+ assertEquals(406, launcher.service("GET", "/b/d", "", headers, null, null).getStatus());
+ assertEquals(MediaType.TEXT_XML_TYPE, launcher.service("GET", "/b/d", "", null, null, null)
+ .getContentType());
unregistry(resource1);
unregistry(resource2);
@@ -144,19 +157,19 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
- assertEquals(200, service("GET", "/d/e", "", headers, null).getStatus());
- assertEquals("m0", service("GET", "/d/e", "", headers, null).getEntity());
+ assertEquals(200, launcher.service("GET", "/d/e", "", headers, null, null).getStatus());
+ assertEquals("m0", launcher.service("GET", "/d/e", "", headers, null, null).getEntity());
headers = new MultivaluedMapImpl();
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
- assertEquals(200, service("GET", "/d/f", "", headers, null).getStatus());
- assertEquals("m1", service("GET", "/d/f", "", headers, null).getEntity());
+ assertEquals(200, launcher.service("GET", "/d/f", "", headers, null, null).getStatus());
+ assertEquals("m1", launcher.service("GET", "/d/f", "", headers, null, null).getEntity());
headers = new MultivaluedMapImpl();
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
- assertEquals(415, service("GET", "/d/f", "", headers, null).getStatus());
+ assertEquals(415, launcher.service("GET", "/d/f", "", headers, null, null).getStatus());
unregistry(resource4);
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,8 +18,9 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.UnhandledException;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -33,7 +34,7 @@
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
* @version $Id: TestMethodException.java
*/
-public class MethodExceptionTest extends AbstractResourceTest
+public class MethodExceptionTest extends BaseTest
{
@SuppressWarnings("serial")
@@ -79,16 +80,24 @@
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testExceptionProcessing() throws Exception
{
Resource1 resource = new Resource1();
registry(resource);
- assertEquals(500, service("GET", "/a/0", "", null, null).getStatus());
- assertEquals(500, service("GET", "/a/1", "", null, null).getStatus());
+ assertEquals(500, launcher.service("GET", "/a/0", "", null, null, null).getStatus());
+ assertEquals(500, launcher.service("GET", "/a/1", "", null, null, null).getStatus());
try
{
- assertEquals(500, service("GET", "/a/2", "", null, null).getStatus());
+ assertEquals(500, launcher.service("GET", "/a/2", "", null, null, null).getStatus());
fail();
}
catch (UnhandledException e)
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,12 +18,19 @@
*/
package org.exoplatform.services.rest.impl.method;
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.List;
+
import org.exoplatform.services.rest.Filter;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.method.MethodInvokerFilter;
import org.exoplatform.services.rest.resource.GenericMethodResource;
import org.exoplatform.services.rest.resource.ResourceMethodDescriptor;
import org.exoplatform.services.rest.resource.SubResourceMethodDescriptor;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
@@ -39,7 +46,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class MethodInvokerFilterTest extends AbstractResourceTest
+public class MethodInvokerFilterTest extends BaseTest
{
@Filter
@@ -56,18 +63,15 @@
@Context
private HttpServletRequest httpRequest;
-// private ResourceBinder binder; // exo container component
-
- public MethodInvokerFilter1(@Context UriInfo uriInfo, @Context HttpHeaders httpHeaders/*, ResourceBinder binder*/)
+ public MethodInvokerFilter1(@Context UriInfo uriInfo, @Context HttpHeaders httpHeaders)
{
this.uriInfo = uriInfo;
this.httpHeaders = httpHeaders;
-// this.binder = binder;
}
public void accept(GenericMethodResource genericMethodResource)
{
- if (uriInfo != null && httpHeaders != null && providers != null && httpRequest != null/* && binder != null*/)
+ if (uriInfo != null && httpHeaders != null && providers != null && httpRequest != null)
{
if (genericMethodResource instanceof SubResourceMethodDescriptor)
// not invoke sub-resource method
@@ -127,15 +131,26 @@
}
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testInvokerFilter() throws Exception
{
Resource1 r = new Resource1();
registry(r);
- assertEquals(204, service("GET", "/a/b", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a", "", null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/b", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a", "", null, null, null).getStatus());
providers.addMethodInvokerFilter(MethodInvokerFilter1.class);
- assertEquals(400, service("GET", "/a/b", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a", "", null, null).getStatus());
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(new byte[0]), 0,
+ "GET", new HashMap<String, List<String>>()));
+ assertEquals(400, launcher.service("GET", "/a/b", "", null, null, env).getStatus());
+ assertEquals(204, launcher.service("GET", "/a", "", null, null, env).getStatus());
unregistry(r);
}
@@ -143,11 +158,11 @@
{
Resource2 r = new Resource2();
registry(r);
- assertEquals(204, service("GET", "/b/c", "", null, null).getStatus());
- assertEquals(204, service("GET", "/b/d", "", null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/b/c", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/b/d", "", null, null, null).getStatus());
providers.addMethodInvokerFilter(new MethodInvokerFilter2());
- assertEquals(400, service("GET", "/b/c", "", null, null).getStatus());
- assertEquals(204, service("GET", "/b/d", "", null, null).getStatus());
+ assertEquals(400, launcher.service("GET", "/b/c", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/b/d", "", null, null, null).getStatus());
unregistry(r);
}
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,7 +18,8 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import java.util.List;
@@ -34,7 +35,7 @@
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
* @version $Id: ResourceReturnTypeTest.java
*/
-public class MethodReturnTypeTest extends AbstractResourceTest
+public class MethodReturnTypeTest extends BaseTest
{
@Path("/a")
@@ -86,36 +87,44 @@
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testResourceMethodReturnType() throws Exception
{
Resource1 r = new Resource1();
registry(r);
// void Results in an empty entity body with a 204 status code.
- assertEquals(204, service("GET", "/a/0", "", null, null).getStatus());
- assertNull(service("GET", "/a/o", "", null, null).getEntity());
+ assertEquals(204, launcher.service("GET", "/a/0", "", null, null, null).getStatus());
+ assertNull(launcher.service("GET", "/a/o", "", null, null, null).getEntity());
// Response Results in an entity body mapped from the entity property of the
// Response
// with the status code specified by the status property of the Response.
- assertEquals(200, service("GET", "/a/1", "", null, null).getStatus());
- assertEquals("body", service("GET", "/a/1", "", null, null).getEntity());
+ assertEquals(200, launcher.service("GET", "/a/1", "", null, null, null).getStatus());
+ assertEquals("body", launcher.service("GET", "/a/1", "", null, null, null).getEntity());
// GenericEntity Results: null return value results in a 204 status code
- assertEquals(204, service("GET", "/a/2", "", null, null).getStatus());
- assertNull(service("GET", "/a/2", "", null, null).getEntity());
+ assertEquals(204, launcher.service("GET", "/a/2", "", null, null, null).getStatus());
+ assertNull(launcher.service("GET", "/a/2", "", null, null, null).getEntity());
// a null return value results in a 204 status code.
- assertEquals(204, service("GET", "/a/3", "", null, null).getStatus());
- assertNull(service("GET", "/a/3", "", null, null).getEntity());
+ assertEquals(204, launcher.service("GET", "/a/3", "", null, null, null).getStatus());
+ assertNull(launcher.service("GET", "/a/3", "", null, null, null).getEntity());
// Other Results: null return value results in a 204 status code
- assertEquals(204, service("GET", "/a/5", "", null, null).getStatus());
- assertNull(service("GET", "/a/5", "", null, null).getEntity());
+ assertEquals(204, launcher.service("GET", "/a/5", "", null, null, null).getStatus());
+ assertNull(launcher.service("GET", "/a/5", "", null, null, null).getEntity());
// Other Results: null return value results in a 204 status code
- assertEquals(200, service("GET", "/a/6", "", null, null).getStatus());
- assertNotNull(service("GET", "/a/6", "", null, null).getEntity());
+ assertEquals(200, launcher.service("GET", "/a/6", "", null, null, null).getStatus());
+ assertNotNull(launcher.service("GET", "/a/6", "", null, null, null).getEntity());
unregistry(r);
}
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,7 +18,8 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -36,7 +37,7 @@
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
* @version $Id: OptionsMethodTest.java
*/
-public class OptionsMethodTest extends AbstractResourceTest
+public class OptionsMethodTest extends BaseTest
{
@Target(ElementType.METHOD)
@@ -70,17 +71,25 @@
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testOptionsMethod() throws Exception
{
Resource1 resource1 = new Resource1();
registry(resource1);
- assertEquals("options", service("OPTIONS", "/a", "", null, null).getEntity());
+ assertEquals("options", launcher.service("OPTIONS", "/a", "", null, null, null).getEntity());
unregistry(resource1);
Resource2 resource2 = new Resource2();
registry(resource2);
- assertEquals(200, service("OPTIONS", "/b", "", null, null).getStatus());
- assertNotNull(service("OPTIONS", "/b", "", null, null).getResponse().getMetadata());
+ assertEquals(200, launcher.service("OPTIONS", "/b", "", null, null, null).getStatus());
+ assertNotNull(launcher.service("OPTIONS", "/b", "", null, null, null).getResponse().getMetadata());
}
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -19,9 +19,10 @@
package org.exoplatform.services.rest.impl.method;
import org.exoplatform.services.rest.Property;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import java.util.List;
import java.util.Set;
@@ -46,7 +47,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ParametersInjectionTest extends AbstractResourceTest
+public class ParametersInjectionTest extends BaseTest
{
@Path("/a/{x}")
@@ -218,50 +219,58 @@
}
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testParameterTypes() throws Exception
{
Resource1 r1 = new Resource1();
registry(r1);
- assertEquals(204, service("GET", "/a/test/0/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/1/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/2/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/3/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/3333/4/2222", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/5555/5/4444", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/6/test", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a/test/7/test?x=1&y=2&x=3&y=4&x=5", "", null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/0/test", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/1/test", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/2/test", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/3/test", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/3333/4/2222", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/5555/5/4444", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/6/test", "", null, null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/7/test?x=1&y=2&x=3&y=4&x=5", "", null, null, null).getStatus());
MultivaluedMap<String, String> h = new MultivaluedMapImpl();
h.putSingle("foo", "to be or not to be");
h.putSingle("bar", "to be or not to be");
- assertEquals(204, service("GET", "/a/test/8/test", "", h, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/8/test", "", h, null, null).getStatus());
h.clear();
h.putSingle("Content-Type", "application/x-www-form-urlencoded");
- assertEquals(204, service("POST", "/a/test/9/test", "", h,
- "bar=to%20be%20or%20not%20to%20be&foo=to%20be%20or%20not%20to%20be".getBytes("UTF-8")).getStatus());
+ assertEquals(204, launcher.service("POST", "/a/test/9/test", "", h,
+ "bar=to%20be%20or%20not%20to%20be&foo=to%20be%20or%20not%20to%20be".getBytes("UTF-8"), null).getStatus());
h.clear();
h.putSingle("Cookie",
"$Version=1;foo=foo;$Domain=exo.com;$Path=/exo,$Version=1;bar=ar;$Domain=exo.com;$Path=/exo");
- assertEquals(204, service("GET", "/a/test/11/test", "", h, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/test/11/test", "", h, null, null).getStatus());
- assertEquals(204, service("GET", "/a/111/12/222", "", null, null).getStatus());
+ assertEquals(204, launcher.service("GET", "/a/111/12/222", "", null, null, null).getStatus());
- assertEquals("111", service("GET", "/a/111/13", "", null, null).getEntity());
- assertEquals("222", service("GET", "/a/111/13?query=222", "", null, null).getEntity());
+ assertEquals("111", launcher.service("GET", "/a/111/13", "", null, null, null).getEntity());
+ assertEquals("222", launcher.service("GET", "/a/111/13?query=222", "", null, null, null).getEntity());
try
{
- assertEquals("hello", service("GET", "/a/111/14", "", null, null).getEntity());
+ assertEquals("hello", launcher.service("GET", "/a/111/14", "", null, null, null).getEntity());
RequestHandlerImpl.setProperty("prop1", "to be or not to be");
- assertEquals("to be or not to be", service("GET", "/a/111/14", "", null, null).getEntity());
+ assertEquals("to be or not to be", launcher.service("GET", "/a/111/14", "", null, null, null).getEntity());
}
finally
{
RequestHandlerImpl.setProperty("prop1", null);
}
-
+
unregistry(r1);
}
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -22,11 +22,13 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
+import org.exoplatform.services.rest.impl.BaseTest;
+
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class ContextResolverTest extends org.exoplatform.services.rest.impl.AbstractResourceTest
+public class ContextResolverTest extends BaseTest
{
@Provider
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,8 +18,9 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -29,9 +30,9 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class ExceptionMapperTest extends AbstractResourceTest
+public class ExceptionMapperTest extends BaseTest
{
public static class ExceptionMapper1 implements ExceptionMapper<IllegalArgumentException>
@@ -81,6 +82,8 @@
}
+ private ResourceLauncher launcher;
+
public void setUp() throws Exception
{
super.setUp();
@@ -88,6 +91,7 @@
providers.addExceptionMapper(ExceptionMapper2.class);
providers.addExceptionMapper(ExceptionMapper3.class);
providers.addExceptionMapper(ExceptionMapper4.class);
+ this.launcher = new ResourceLauncher(requestHandler);
}
@Path("a")
@@ -136,24 +140,24 @@
{
registry(Resource1.class);
- ContainerResponse resp = service("GET", "/a/1", "", null, null);
+ ContainerResponse resp = launcher.service("GET", "/a/1", "", null, null, null);
assertEquals(200, resp.getStatus());
assertEquals("IllegalArgumentException", resp.getEntity());
- resp = service("GET", "/a/2", "", null, null);
+ resp = launcher.service("GET", "/a/2", "", null, null, null);
assertEquals(200, resp.getStatus());
assertEquals("RuntimeException", resp.getEntity());
- resp = service("GET", "/a/3", "", null, null);
+ resp = launcher.service("GET", "/a/3", "", null, null, null);
assertEquals(200, resp.getStatus());
assertEquals("WebApplicationException", resp.getEntity());
- resp = service("GET", "/a/4", "", null, null);
+ resp = launcher.service("GET", "/a/4", "", null, null, null);
// WebApplicationException with entity - must not be overridden
assertEquals(500, resp.getStatus());
assertEquals("this exception must not be hidden by any ExceptionMapper", resp.getEntity());
- resp = service("GET", "/a/5", "", null, null);
+ resp = launcher.service("GET", "/a/5", "", null, null, null);
assertEquals(200, resp.getStatus());
assertEquals("MockException", resp.getEntity());
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -19,15 +19,21 @@
package org.exoplatform.services.rest.impl.provider;
import org.apache.commons.fileupload.FileItem;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
@@ -36,11 +42,19 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class FormEntityTest extends AbstractResourceTest
+public class FormEntityTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Path("/")
public static class Resource1
{
@@ -72,8 +86,8 @@
MultivaluedMap<String, String> h = new MultivaluedMapImpl();
h.putSingle("content-type", "application/x-www-form-urlencoded");
h.putSingle("content-length", "" + data.length);
- assertEquals(204, service("POST", "/a", "", h, data).getStatus());
- assertEquals(204, service("POST", "/b", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/a", "", h, data, null).getStatus());
+ assertEquals(204, launcher.service("POST", "/b", "", h, data, null).getStatus());
unregistry(r1);
}
@@ -190,7 +204,12 @@
h.putSingle("content-type", "multipart/form-data; boundary=abcdef");
byte[] data = out.toByteArray();
- assertEquals(204, service("POST", "/", "", h, data).getStatus());
+ // NOTE In this test data will be red from HttpServletRequest, not from
+ // byte array. See MultipartFormDataEntityProvider.
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(data), data.length,
+ "POST", (Map<String, List<String>>)h));
+ assertEquals(204, launcher.service("POST", "/", "", h, data, env).getStatus());
unregistry(r2);
}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -19,10 +19,11 @@
package org.exoplatform.services.rest.impl.provider;
import org.exoplatform.services.rest.generated.Book;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -34,11 +35,19 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class JAXBEntityTest extends AbstractResourceTest
+public class JAXBEntityTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Path("/")
public static class Resource1
{
@@ -111,10 +120,10 @@
h.putSingle("content-type", "application/xml");
byte[] data = XML_DATA.getBytes("UTF-8");
h.putSingle("content-length", "" + data.length);
- assertEquals(204, service("POST", "/a", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/a", "", h, data, null).getStatus());
// Object transfered via XML (JAXB)
- assertEquals(204, service("POST", "/b", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/b", "", h, data, null).getStatus());
unregistry(r1);
}
@@ -127,7 +136,7 @@
// Resource2#m1()
h.putSingle("accept", "application/xml");
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = service("GET", "/", "", h, null, writer);
+ ContainerResponse response = launcher.service("GET", "/", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/xml", response.getContentType().toString());
Book book = (Book)response.getEntity();
@@ -137,7 +146,7 @@
// Resource2#m2()
writer = new ByteArrayContainerResponseWriter();
- response = service("POST", "/", "", h, null, writer);
+ response = launcher.service("POST", "/", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/xml", response.getContentType().toString());
book = (Book)response.getEntity();
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -19,10 +19,11 @@
package org.exoplatform.services.rest.impl.provider;
import org.exoplatform.services.rest.generated.Book;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -33,9 +34,9 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class JsonEntityTest extends AbstractResourceTest
+public class JsonEntityTest extends BaseTest
{
@Path("/")
@@ -79,11 +80,14 @@
private byte[] jsonData;
+ private ResourceLauncher launcher;
+
public void setUp() throws Exception
{
super.setUp();
jsonData =
("{\"title\":\"Hamlet\"," + "\"author\":\"William Shakespeare\"," + "\"sendByPost\":true}").getBytes("UTF-8");
+ this.launcher = new ResourceLauncher(requestHandler);
}
public void testJsonEntityParameter() throws Exception
@@ -96,7 +100,7 @@
// with JSON transformation for Book have restriction can't pass BigDecimal
// (has not simple constructor and it is not in JSON known types)
h.putSingle("content-length", "" + jsonData.length);
- assertEquals(204, service("POST", "/", "", h, jsonData).getStatus());
+ assertEquals(204, launcher.service("POST", "/", "", h, jsonData, null).getStatus());
unregistry(r1);
}
@@ -109,7 +113,7 @@
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
// Resource2#m1()
- ContainerResponse response = service("GET", "/", "", h, null, writer);
+ ContainerResponse response = launcher.service("GET", "/", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/json", response.getContentType().toString());
Book book = (Book)response.getEntity();
@@ -118,7 +122,7 @@
assertTrue(book.isSendByPost());
// Resource2#m2()
- response = service("POST", "/", "", h, null, writer);
+ response = launcher.service("POST", "/", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/json", response.getContentType().toString());
book = (Book)response.getEntity();
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,10 +18,11 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
@@ -50,11 +51,19 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class OtherEntityTest extends AbstractResourceTest
+public class OtherEntityTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Path("/")
public static class Resource1
{
@@ -136,24 +145,24 @@
// next types allowed for any content-type
// h.putSingle("content-type", "application/octet-stream");
- assertEquals(204, service("POST", "/bytes", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/bytes", "", h, data, null).getStatus());
- assertEquals(204, service("POST", "/string", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/string", "", h, data, null).getStatus());
- assertEquals(204, service("POST", "/stream", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/stream", "", h, data, null).getStatus());
- assertEquals(204, service("POST", "/reader", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/reader", "", h, data, null).getStatus());
// next types required application/xml, text/xml or
// application/xhtml+xml content-type
h.putSingle("content-type", "application/xml");
data = XML_DATA.getBytes("UTF-8");
h.putSingle("content-length", "" + data.length);
- assertEquals(204, service("POST", "/dom", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/dom", "", h, data, null).getStatus());
- assertEquals(204, service("POST", "/sax", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/sax", "", h, data, null).getStatus());
- assertEquals(204, service("POST", "/ss", "", h, data).getStatus());
+ assertEquals(204, launcher.service("POST", "/ss", "", h, data, null).getStatus());
unregistry(r1);
}
@@ -249,24 +258,24 @@
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
h.putSingle("accept", "text/plain");
- ContainerResponse response = service("GET", "/bytes", "", h, null, writer);
+ ContainerResponse response = launcher.service("GET", "/bytes", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/octet-stream", response.getContentType().toString());
assertEquals("to be or not to be".getBytes("UTF-8").length + "", response.getHttpHeaders().getFirst(
HttpHeaders.CONTENT_LENGTH).toString());
assertEquals("to be or not to be", new String(writer.getBody()));
- response = service("GET", "/string", "", h, null, writer);
+ response = launcher.service("GET", "/string", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("text/plain", response.getContentType().toString());
assertEquals("to be or not to be", new String(writer.getBody()));
- response = service("GET", "/stream", "", h, null, writer);
+ response = launcher.service("GET", "/stream", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/octet-stream", response.getContentType().toString());
assertEquals("to be or not to be", new String(writer.getBody()));
- response = service("GET", "/reader", "", h, null, writer);
+ response = launcher.service("GET", "/reader", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("text/plain", response.getContentType().toString());
assertEquals("to be or not to be", new String(writer.getBody()));
@@ -275,33 +284,33 @@
String xml = pattern.matcher(XML_DATA).replaceFirst("");
h.putSingle("accept", "application/xml");
- response = service("GET", "/dom", "", h, null, writer);
+ response = launcher.service("GET", "/dom", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/xml", response.getContentType().toString());
String result = new String(writer.getBody());
result = pattern.matcher(result).replaceFirst("");
assertEquals(xml, result);
- response = service("GET", "/sax", "", h, null, writer);
+ response = launcher.service("GET", "/sax", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/xml", response.getContentType().toString());
result = new String(writer.getBody());
result = pattern.matcher(result).replaceFirst("");
assertEquals(xml, result);
- response = service("GET", "/ss", "", h, null, writer);
+ response = launcher.service("GET", "/ss", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/xml", response.getContentType().toString());
result = new String(writer.getBody());
result = pattern.matcher(result).replaceFirst("");
assertEquals(xml, result);
- response = service("GET", "/so", "", h, null, writer);
+ response = launcher.service("GET", "/so", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("application/octet-stream", response.getContentType().toString());
assertEquals("to be or not to be", new String(writer.getBody()));
- response = service("GET", "/response", "", h, null, writer);
+ response = launcher.service("GET", "/response", "", h, null, writer, null);
assertEquals(200, response.getStatus());
assertEquals("text/plain", response.getContentType().toString());
assertEquals("to be or not to be".getBytes("UTF-8").length + "", response.getHttpHeaders().getFirst(
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,15 +18,21 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.provider.EntityProvider;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
@@ -47,9 +53,9 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class ProviderContextParameterInjectionTest extends AbstractResourceTest
+public class ProviderContextParameterInjectionTest extends BaseTest
{
public static class MockEntity
@@ -170,6 +176,8 @@
}
+ private ResourceLauncher launcher;
+
public void setUp() throws Exception
{
super.setUp();
@@ -177,6 +185,7 @@
providers.addMessageBodyWriter(EntityProviderChecker.class);
providers.addExceptionMapper(ExceptionMapperChecker.class);
providers.addContextResolver(ContextResolverChecker.class);
+ this.launcher = new ResourceLauncher(requestHandler);
}
public void tearDown() throws Exception
@@ -217,17 +226,20 @@
}
}
- public void test0() throws Exception
+ public void testParameterInjection() throws Exception
{
registry(Resource1.class);
- ContainerResponse resp = service("GET", "/a/1", "", null, "to be or not to be".getBytes());
+ EnvironmentContext env = new EnvironmentContext();
+ env.put(HttpServletRequest.class, new MockHttpServletRequest("", new ByteArrayInputStream(new byte[0]), 0, "GET",
+ new HashMap<String, List<String>>()));
+ ContainerResponse resp = launcher.service("GET", "/a/1", "", null, "to be or not to be".getBytes(), env);
assertEquals("to be", ((MockEntity)resp.getEntity()).entity);
- resp = service("GET", "/a/2", "", null, null);
+ resp = launcher.service("GET", "/a/2", "", null, null, env);
assertEquals(200, resp.getStatus());
- resp = service("GET", "/a/3", "", null, null);
+ resp = launcher.service("GET", "/a/3", "", null, null, env);
assertEquals(200, resp.getStatus());
assertEquals("to be to not to be", resp.getEntity());
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,8 +18,9 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -30,9 +31,9 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class AcceptResourceTest extends AbstractResourceTest
+public class AcceptResourceTest extends BaseTest
{
@Path("/a")
@@ -146,6 +147,14 @@
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testContentType() throws Exception
{
Resource1 r1 = new Resource1();
@@ -204,14 +213,14 @@
{
MultivaluedMap<String, String> h = new MultivaluedMapImpl();
h.putSingle("content-type", contentType);
- return (String)service("POST", "/a", "", h, null).getEntity();
+ return (String)launcher.service("POST", "/a", "", h, null, null).getEntity();
}
private String testAcceptedMediaType(String acceptMediaType) throws Exception
{
MultivaluedMap<String, String> h = new MultivaluedMapImpl();
h.putSingle("accept", acceptMediaType);
- return (String)service("GET", "/a", "", h, null).getEntity();
+ return (String)launcher.service("GET", "/a", "", h, null, null).getEntity();
}
private String testComplex(String contentType, String acceptMediaType) throws Exception
@@ -219,6 +228,6 @@
MultivaluedMap<String, String> h = new MultivaluedMapImpl();
h.putSingle("content-type", contentType);
h.putSingle("accept", acceptMediaType);
- return (String)service("POST", "/a", "", h, null).getEntity();
+ return (String)launcher.service("POST", "/a", "", h, null, null).getEntity();
}
}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -19,7 +19,8 @@
package org.exoplatform.services.rest.impl.resource;
import org.exoplatform.services.rest.ComponentLifecycleScope;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -33,7 +34,7 @@
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
* @version $Id: AnnotationInheritanceTest.java
*/
-public class AnnotationInheritanceTest extends AbstractResourceTest
+public class AnnotationInheritanceTest extends BaseTest
{
public static interface ResourceInterface
@@ -84,6 +85,14 @@
}
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testFailedInheritance()
{
try
@@ -103,16 +112,18 @@
registry(resource1);
- assertEquals(200, service("GET", "/a", "", null, null).getStatus());
- assertEquals("m0", service("GET", "/a", "", null, null).getEntity());
- assertEquals(MediaType.TEXT_XML_TYPE, service("GET", "/a", "", null, null).getContentType());
+ assertEquals(200, launcher.service("GET", "/a", "", null, null, null).getStatus());
+ assertEquals("m0", launcher.service("GET", "/a", "", null, null, null).getEntity());
+ assertEquals(MediaType.TEXT_XML_TYPE, launcher.service("GET", "/a", "", null, null, null)
+ .getContentType());
unregistry(resource1);
registry(resource2);
- assertEquals(200, service("GET", "/a", "", null, null).getStatus());
- assertEquals("m0", service("GET", "/a", "", null, null).getEntity());
- assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, service("GET", "/a", "", null, null).getContentType());
+ assertEquals(200, launcher.service("GET", "/a", "", null, null, null).getStatus());
+ assertEquals("m0", launcher.service("GET", "/a", "", null, null, null).getEntity());
+ assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, launcher.service("GET", "/a", "", null, null, null)
+ .getContentType());
unregistry(resource2);
}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -23,11 +23,12 @@
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.RequestFilter;
import org.exoplatform.services.rest.ResponseFilter;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.ApplicationPublisher;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.method.MethodInvokerFilter;
import org.exoplatform.services.rest.resource.GenericMethodResource;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import java.util.HashSet;
import java.util.Set;
@@ -40,9 +41,9 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class ApplicationTest extends AbstractResourceTest
+public class ApplicationTest extends BaseTest
{
public static class Application1 extends javax.ws.rs.core.Application
@@ -202,36 +203,44 @@
private static boolean responseFilter = false;
private static boolean invFilter = false;
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testAsResources() throws Exception
{
ApplicationPublisher deployer = new ApplicationPublisher(resources, providers);
deployer.publish(new Application1());
// per-request
- ContainerResponse resp = service("GET", "/a", "", null, null);
+ ContainerResponse resp = launcher.service("GET", "/a", "", null, null, null);
assertEquals(200, resp.getStatus());
String hash10 = (String)resp.getEntity();
- resp = service("GET", "/a", "", null, null);
+ resp = launcher.service("GET", "/a", "", null, null, null);
String hash11 = (String)resp.getEntity();
// new instance of resource for each request
assertFalse(hash10.equals(hash11));
// singleton
- resp = service("GET", "/c", "", null, null);
+ resp = launcher.service("GET", "/c", "", null, null, null);
assertEquals(200, resp.getStatus());
String hash20 = (String)resp.getEntity();
- resp = service("GET", "/c", "", null, null);
+ resp = launcher.service("GET", "/c", "", null, null, null);
String hash21 = (String)resp.getEntity();
// singleton resource
assertTrue(hash20.equals(hash21));
// check per-request ExceptionMapper as example of provider
- resp = service("GET", "/b", "", null, null);
+ resp = launcher.service("GET", "/b", "", null, null, null);
// should be 200 status instead 500 if ExceptionMapper works correct
assertEquals(200, resp.getStatus());
assertEquals("test Runtime Exception", resp.getEntity());
// check singleton ExceptionMapper as example of provider
- resp = service("GET", "/d", "", null, null);
+ resp = launcher.service("GET", "/d", "", null, null, null);
// should be 200 status instead 500 if ExceptionMapper works correct
assertEquals(200, resp.getStatus());
assertEquals("test Illegal State Exception", resp.getEntity());
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -19,9 +19,10 @@
package org.exoplatform.services.rest.impl.resource;
import org.exoplatform.services.rest.InitialProperties;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.impl.header.HeaderHelper;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import java.util.List;
@@ -36,11 +37,19 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class ContextParametersInjectionTest extends AbstractResourceTest
+public class ContextParametersInjectionTest extends BaseTest
{
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
@Path("/a/b")
public static class Resource1
{
@@ -231,17 +240,19 @@
private void injectionTest() throws Exception
{
- assertEquals("http://localhost/test/a/b/c", service("GET", "http://localhost/test/a/b/c",
- "http://localhost/test", null, null).getEntity());
+ assertEquals("http://localhost/test/a/b/c", launcher.service("GET", "http://localhost/test/a/b/c",
+ "http://localhost/test", null, null, null).getEntity());
MultivaluedMap<String, String> h = new MultivaluedMapImpl();
h.add("Accept", "text/xml");
h.add("Accept", "text/plain;q=0.7");
- assertEquals("text/xml,text/plain;q=0.7", service("GET", "http://localhost/test/a/b/d", "http://localhost/test",
- h, null).getEntity());
- assertEquals("GET", service("GET", "http://localhost/test/a/b/e", "http://localhost/test", null, null)
- .getEntity());
- assertEquals(204, service("GET", "http://localhost/test/a/b/f", "http://localhost/test", null, null).getStatus());
- assertEquals(204, service("GET", "http://localhost/test/a/b/g", "http://localhost/test", null, null).getStatus());
+ assertEquals("text/xml,text/plain;q=0.7", launcher.service("GET", "http://localhost/test/a/b/d",
+ "http://localhost/test", h, null, null).getEntity());
+ assertEquals("GET", launcher.service("GET", "http://localhost/test/a/b/e", "http://localhost/test", null, null,
+ null).getEntity());
+ assertEquals(204, launcher.service("GET", "http://localhost/test/a/b/f", "http://localhost/test", null, null,
+ null).getStatus());
+ assertEquals(204, launcher.service("GET", "http://localhost/test/a/b/g", "http://localhost/test", null, null,
+ null).getStatus());
}
}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java 2009-11-06 17:08:38 UTC (rev 496)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java 2009-11-08 13:19:25 UTC (rev 497)
@@ -18,8 +18,9 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.BaseTest;
import org.exoplatform.services.rest.impl.header.HeaderHelper;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import java.util.ArrayList;
import java.util.List;
@@ -31,9 +32,9 @@
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: $
+ * @version $Id$
*/
-public class MatchedURIsAndResourcesTest extends AbstractResourceTest
+public class MatchedURIsAndResourcesTest extends BaseTest
{
@Path("/a/b")
@@ -110,14 +111,22 @@
}
}
+ private ResourceLauncher launcher;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.launcher = new ResourceLauncher(requestHandler);
+ }
+
public void testLevel1() throws Exception
{
Resource1 r1 = new Resource1();
registry(r1);
- assertEquals("/1,/a/b", service("GET", "http://localhost/test/a/b/1", "http://localhost/test", null, null)
- .getEntity());
- assertEquals("Resource1", service("GET", "http://localhost/test/a/b/2", "http://localhost/test", null, null)
- .getEntity());
+ assertEquals("/1,/a/b", launcher.service("GET", "http://localhost/test/a/b/1", "http://localhost/test", null,
+ null, null).getEntity());
+ assertEquals("Resource1", launcher.service("GET", "http://localhost/test/a/b/2", "http://localhost/test", null,
+ null, null).getEntity());
unregistry(r1);
}
@@ -125,10 +134,10 @@
{
Resource1 r1 = new Resource1();
registry(r1);
- assertEquals("/1,/sub,/a/b", service("GET", "http://localhost/test/a/b/sub/1", "http://localhost/test", null,
- null).getEntity());
- assertEquals("SubResource1,Resource1", service("GET", "http://localhost/test/a/b/sub/2", "http://localhost/test",
- null, null).getEntity());
+ assertEquals("/1,/sub,/a/b", launcher.service("GET", "http://localhost/test/a/b/sub/1", "http://localhost/test",
+ null, null, null).getEntity());
+ assertEquals("SubResource1,Resource1", launcher.service("GET", "http://localhost/test/a/b/sub/2",
+ "http://localhost/test", null, null, null).getEntity());
unregistry(r1);
}
@@ -136,10 +145,10 @@
{
Resource1 r1 = new Resource1();
registry(r1);
- assertEquals("/1,/sub-sub,/sub,/a/b", service("GET", "http://localhost/test/a/b/sub/sub-sub/1",
- "http://localhost/test", null, null).getEntity());
- assertEquals("SubResource2,SubResource1,Resource1", service("GET", "http://localhost/test/a/b/sub/sub-sub/2",
- "http://localhost/test", null, null).getEntity());
+ assertEquals("/1,/sub-sub,/sub,/a/b", launcher.service("GET", "http://localhost/test/a/b/sub/sub-sub/1",
+ "http://localhost/test", null, null, null).getEntity());
+ assertEquals("SubResource2,SubResource1,Resource1", launcher.service("GET",
+ "http://localhost/test/a/b/sub/sub-sub/2", "http://localhost/test", null, null, null).getEntity());
unregistry(r1);
}
}
Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
16 years, 8 months
exo-jcr SVN: r496 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/dataflow and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-06 12:08:38 -0500 (Fri, 06 Nov 2009)
New Revision: 496
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
Log:
EXOJCR-201 :Add serialization mechanism to ByteArrayPersistentValuData and added test TestByteArrayPersistentValueDataSerialization.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-11-06 16:55:26 UTC (rev 495)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-11-06 17:08:38 UTC (rev 496)
@@ -22,8 +22,11 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import javax.jcr.RepositoryException;
@@ -33,10 +36,18 @@
* @author Gennady Azarenkov
* @version $Id$
*/
-public class ByteArrayPersistedValueData extends AbstractValueData
+public class ByteArrayPersistedValueData extends AbstractValueData implements Externalizable
{
protected byte[] data;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public ByteArrayPersistedValueData()
+ {
+ super(0);
+ }
/**
* ByteArrayPersistedValueData constructor.
@@ -108,4 +119,20 @@
return false;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ orderNumber = in.readInt();
+
+ data = new byte[in.readInt()];
+ in.readFully(data);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(orderNumber);
+
+ out.writeInt(data.length);
+ out.write(data);
+ }
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java 2009-11-06 16:55:26 UTC (rev 495)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java 2009-11-06 17:08:38 UTC (rev 496)
@@ -52,7 +52,7 @@
File out = File.createTempFile("test", ".data");
- f.deleteOnExit();
+ out.deleteOnExit();
//serialize
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
@@ -82,7 +82,7 @@
tvd.setFileCleaner(new FileCleaner());
File out = File.createTempFile("test", ".data");
- f.deleteOnExit();
+ out.deleteOnExit();
//serialize
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java 2009-11-06 17:08:38 UTC (rev 496)
@@ -0,0 +1,73 @@
+/*
+ * 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.dataflow.persistent;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestByteArrayPersistedValueDataSerialization
+ extends JcrImplBaseTest
+{
+ public void testBAPVDSerialization() throws Exception
+ {
+
+ byte []buf = new byte[124578];
+
+ for (int i = 0; i< buf.length; i++)
+ buf[i] = (byte) (Math.random()*256);
+
+ // Create ValueData instants
+ ByteArrayPersistedValueData vd = new ByteArrayPersistedValueData(buf, 11);
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(vd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ ByteArrayPersistedValueData deserializedValueData = (ByteArrayPersistedValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedValueData);
+ assertEquals(vd.getLength(), deserializedValueData.getLength());
+ assertEquals(vd.getOrderNumber(), deserializedValueData.getOrderNumber());
+
+ for (int j = 0; j < vd.getAsByteArray().length; j++)
+ assertEquals(vd.getAsByteArray()[j], deserializedValueData.getAsByteArray()[j]);
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
16 years, 8 months