exo-jcr SVN: r174 - jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl.
by do-not-reply@jboss.org
Author: tolusha
Date: 2009-09-15 10:32:02 -0400 (Tue, 15 Sep 2009)
New Revision: 174
Modified:
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
Log:
EXOJCR-158: registration NS and NT in RepositoryContainer
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2009-09-15 07:17:59 UTC (rev 173)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2009-09-15 14:32:02 UTC (rev 174)
@@ -19,6 +19,8 @@
package org.exoplatform.services.jcr.impl;
import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.component.ComponentPlugin;
+import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.jmx.MX4JComponentAdapterFactory;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
@@ -29,6 +31,7 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
@@ -61,10 +64,13 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.io.InputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Map;
+import javax.jcr.NamespaceException;
import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeTypeManager;
@@ -99,19 +105,33 @@
private final Log log = ExoLogger.getLogger("jcr.RepositoryContainer");
/**
+ * NodeType plugins list.
+ */
+ private final List<ComponentPlugin> addNodeTypePlugins;
+
+ /**
+ * NameSpace plugins list.
+ */
+ private final List<ComponentPlugin> addNamespacesPlugins;
+
+ /**
* RepositoryContainer constructor.
*
* @param parent
* container
* @param config
* Repository configuration
+ * @param addNodeTypePlugins
+ * NodeType plugins list
+ * @param addNamespacesPlugins
+ * NameSpace plugins list
* @throws RepositoryException
* container initialization error
* @throws RepositoryConfigurationException
* configuration error
*/
- public RepositoryContainer(ExoContainer parent, RepositoryEntry config) throws RepositoryException,
- RepositoryConfigurationException
+ public RepositoryContainer(ExoContainer parent, RepositoryEntry config, List<ComponentPlugin> addNodeTypePlugins,
+ List<ComponentPlugin> addNamespacesPlugins) throws RepositoryException, RepositoryConfigurationException
{
super(new MX4JComponentAdapterFactory(), parent);
@@ -121,6 +141,8 @@
config.setAccessControl(AccessControlPolicy.OPTIONAL);
this.config = config;
+ this.addNamespacesPlugins = addNamespacesPlugins;
+ this.addNodeTypePlugins = addNodeTypePlugins;
registerComponents();
}
@@ -483,6 +505,99 @@
registerRepositoryComponents();
}
+ private void addNamespaces() throws RepositoryException
+ {
+ NamespaceRegistry nsRegistry = (NamespaceRegistry)this.getComponentInstanceOfType(NamespaceRegistryImpl.class);
+ this.getComponentInstanceOfType(IdGenerator.class);
+
+ for (int j = 0; j < addNamespacesPlugins.size(); j++)
+ {
+ AddNamespacesPlugin plugin = (AddNamespacesPlugin)addNamespacesPlugins.get(j);
+ Map<String, String> namespaces = plugin.getNamespaces();
+ try
+ {
+ for (Map.Entry<String, String> namespace : namespaces.entrySet())
+ {
+
+ String prefix = namespace.getKey();
+ String uri = namespace.getValue();
+
+ // register namespace if not found
+ try
+ {
+ nsRegistry.getURI(prefix);
+ }
+ catch (NamespaceException e)
+ {
+ nsRegistry.registerNamespace(prefix, uri);
+ }
+ if (log.isDebugEnabled())
+ log.debug("Namespace is registered " + prefix + " = " + uri);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Error load namespaces ", e);
+ }
+ }
+ }
+
+ private void registerNodeTypes() throws RepositoryException
+ {
+ ConfigurationManager configService =
+ (ConfigurationManager)this.getParent().getComponentInstanceOfType(ConfigurationManager.class);
+
+ NodeTypeDataManagerImpl ntManager =
+ (NodeTypeDataManagerImpl)this.getComponentInstanceOfType(NodeTypeDataManagerImpl.class);
+ //
+ for (int j = 0; j < addNodeTypePlugins.size(); j++)
+ {
+ AddNodeTypePlugin plugin = (AddNodeTypePlugin)addNodeTypePlugins.get(j);
+ List<String> autoNodeTypesFiles = plugin.getNodeTypesFiles(AddNodeTypePlugin.AUTO_CREATED);
+ if (autoNodeTypesFiles != null && autoNodeTypesFiles.size() > 0)
+ {
+ for (String nodeTypeFilesName : autoNodeTypesFiles)
+ {
+
+ InputStream inXml;
+ try
+ {
+ inXml = configService.getInputStream(nodeTypeFilesName);
+ }
+ catch (Exception e)
+ {
+ throw new RepositoryException(e);
+ }
+ if (log.isDebugEnabled())
+ log.debug("Trying register node types from xml-file " + nodeTypeFilesName);
+ ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
+ if (log.isDebugEnabled())
+ log.debug("Node types is registered from xml-file " + nodeTypeFilesName);
+ }
+ List<String> defaultNodeTypesFiles = plugin.getNodeTypesFiles(this.getName());
+ if (defaultNodeTypesFiles != null && defaultNodeTypesFiles.size() > 0)
+ {
+ for (String nodeTypeFilesName : defaultNodeTypesFiles)
+ {
+
+ InputStream inXml;
+ try
+ {
+ inXml = configService.getInputStream(nodeTypeFilesName);
+ }
+ catch (Exception e)
+ {
+ throw new RepositoryException(e);
+ }
+ log.info("Trying register node types (" + this.getName() + ") from xml-file " + nodeTypeFilesName);
+ ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
+ log.info("Node types is registered (" + this.getName() + ") from xml-file " + nodeTypeFilesName);
+ }
+ }
+ }
+ }
+ }
+
private void registerRepositoryComponents() throws RepositoryConfigurationException, RepositoryException
{
@@ -491,6 +606,8 @@
registerComponentImplementation(NamespaceDataPersister.class);
registerComponentImplementation(NamespaceRegistryImpl.class);
+ addNamespaces();
+
registerComponentImplementation(WorkspaceFileCleanerHolder.class);
registerComponentImplementation(LocationFactory.class);
registerComponentImplementation(ValueFactoryImpl.class);
@@ -499,6 +616,8 @@
registerComponentImplementation(NodeTypeManagerImpl.class);
registerComponentImplementation(NodeTypeDataManagerImpl.class);
+ registerNodeTypes();
+
registerComponentImplementation(DefaultAccessManagerImpl.class);
registerComponentImplementation(SessionRegistry.class);
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2009-09-15 07:17:59 UTC (rev 173)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2009-09-15 14:32:02 UTC (rev 174)
@@ -145,7 +145,9 @@
if (repositoryContainers.containsKey(rEntry.getName()))
throw new RepositoryConfigurationException("Repository container " + rEntry.getName() + " already started");
- RepositoryContainer repositoryContainer = new RepositoryContainer(parentContainer, rEntry);
+ RepositoryContainer repositoryContainer =
+ new RepositoryContainer(parentContainer, rEntry, addNodeTypePlugins, addNamespacesPlugins);
+
// Storing and starting the repository container under
// key=repository_name
repositoryContainers.put(rEntry.getName(), repositoryContainer);
@@ -156,9 +158,9 @@
{
config.getRepositoryConfigurations().add(rEntry);
}
- addNamespaces(rEntry.getName());
- registerNodeTypes(rEntry.getName());
+ // registration Namespaces and NodeTypes moved to RepositoryContainer [AB]
+
// turn on Repository ONLINE
ManageableRepository mr =
(ManageableRepository)repositoryContainer.getComponentInstanceOfType(ManageableRepository.class);
@@ -281,53 +283,6 @@
managerStartChanges.cleanup();
}
- private void addNamespaces() throws RepositoryException
- {
-
- for (RepositoryEntry repoConfig : config.getRepositoryConfigurations())
- {
- addNamespaces(repoConfig.getName());
- }
- }
-
- private void addNamespaces(String repositoryName) throws RepositoryException
- {
-
- ManageableRepository repository = getRepository(repositoryName);
- NamespaceRegistry nsRegistry = repository.getNamespaceRegistry();
-
- for (int j = 0; j < addNamespacesPlugins.size(); j++)
- {
- AddNamespacesPlugin plugin = (AddNamespacesPlugin)addNamespacesPlugins.get(j);
- Map<String, String> namespaces = plugin.getNamespaces();
- try
- {
- for (Map.Entry<String, String> namespace : namespaces.entrySet())
- {
-
- String prefix = namespace.getKey();
- String uri = namespace.getValue();
-
- // register namespace if not found
- try
- {
- nsRegistry.getURI(prefix);
- }
- catch (NamespaceException e)
- {
- nsRegistry.registerNamespace(prefix, uri);
- }
- if (log.isDebugEnabled())
- log.debug("Namespace is registered " + prefix + " = " + uri);
- }
- }
- catch (Exception e)
- {
- log.error("Error load namespaces ", e);
- }
- }
- }
-
private void init(ExoContainer container) throws RepositoryConfigurationException, RepositoryException
{
this.parentContainer = container;
@@ -340,69 +295,6 @@
}
}
- private void registerNodeTypes() throws RepositoryException
- {
- for (RepositoryEntry repoConfig : config.getRepositoryConfigurations())
- {
- registerNodeTypes(repoConfig.getName());
- }
- }
-
- private void registerNodeTypes(String repositoryName) throws RepositoryException
- {
- ConfigurationManager configService =
- (ConfigurationManager)parentContainer.getComponentInstanceOfType(ConfigurationManager.class);
-
- ExtendedNodeTypeManager ntManager = getRepository(repositoryName).getNodeTypeManager();
- //
- for (int j = 0; j < addNodeTypePlugins.size(); j++)
- {
- AddNodeTypePlugin plugin = (AddNodeTypePlugin)addNodeTypePlugins.get(j);
- List<String> autoNodeTypesFiles = plugin.getNodeTypesFiles(AddNodeTypePlugin.AUTO_CREATED);
- if (autoNodeTypesFiles != null && autoNodeTypesFiles.size() > 0)
- {
- for (String nodeTypeFilesName : autoNodeTypesFiles)
- {
-
- InputStream inXml;
- try
- {
- inXml = configService.getInputStream(nodeTypeFilesName);
- }
- catch (Exception e)
- {
- throw new RepositoryException(e);
- }
- if (log.isDebugEnabled())
- log.debug("Trying register node types from xml-file " + nodeTypeFilesName);
- ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
- if (log.isDebugEnabled())
- log.debug("Node types is registered from xml-file " + nodeTypeFilesName);
- }
- List<String> defaultNodeTypesFiles = plugin.getNodeTypesFiles(repositoryName);
- if (defaultNodeTypesFiles != null && defaultNodeTypesFiles.size() > 0)
- {
- for (String nodeTypeFilesName : defaultNodeTypesFiles)
- {
-
- InputStream inXml;
- try
- {
- inXml = configService.getInputStream(nodeTypeFilesName);
- }
- catch (Exception e)
- {
- throw new RepositoryException(e);
- }
- log.info("Trying register node types (" + repositoryName + ") from xml-file " + nodeTypeFilesName);
- ntManager.registerNodeTypes(inXml, ExtendedNodeTypeManager.IGNORE_IF_EXISTS);
- log.info("Node types is registered (" + repositoryName + ") from xml-file " + nodeTypeFilesName);
- }
- }
- }
- }
- }
-
/**
* Manager start changes plugins.
*/
14 years, 7 months
exo-jcr SVN: r173 - jcr/trunk/component/core.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-09-15 03:17:59 -0400 (Tue, 15 Sep 2009)
New Revision: 173
Modified:
jcr/trunk/component/core/TCK.sh
Log:
SWF-194: use exo.test.skip instead of maven.test.skip
Modified: jcr/trunk/component/core/TCK.sh
===================================================================
--- jcr/trunk/component/core/TCK.sh 2009-09-14 13:29:17 UTC (rev 172)
+++ jcr/trunk/component/core/TCK.sh 2009-09-15 07:17:59 UTC (rev 173)
@@ -1,2 +1,2 @@
-MAVEN_OPTS="-Duser.language=en -Duser.region=us -Dmaven.test.skip=true -Dexo.devtest.skip=true -Dexo.tck.skip=false -DforkMode=never -Dorg.exoplatform.jcr.monitor.jdbcMonitor $MAVEN_OPTS "
+MAVEN_OPTS="-Duser.language=en -Duser.region=us -Dexo.test.skip=true -Dexo.devtest.skip=true -Dexo.tck.skip=false -DforkMode=never -Dorg.exoplatform.jcr.monitor.jdbcMonitor $MAVEN_OPTS "
mvn $MAVEN_OPTS clean install
\ No newline at end of file
14 years, 7 months
exo-jcr SVN: r172 - jcr/trunk/component/core.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-09-14 09:29:17 -0400 (Mon, 14 Sep 2009)
New Revision: 172
Modified:
jcr/trunk/component/core/TCK.cmd
Log:
SWF-194: JCR core cmd files cleanup
Modified: jcr/trunk/component/core/TCK.cmd
===================================================================
--- jcr/trunk/component/core/TCK.cmd 2009-09-14 13:28:05 UTC (rev 171)
+++ jcr/trunk/component/core/TCK.cmd 2009-09-14 13:29:17 UTC (rev 172)
@@ -1,5 +1,3 @@
@set MAVEN_OPTS=-Duser.language=en -Duser.region=us -Dexo.test.skip=true -Dexo.devtest.skip=true -Dexo.tck.skip=false -DforkMode=never -Dorg.exoplatform.jcr.monitor.jdbcMonitor %MAVEN_OPTS%
@start mvn clean install
-
-@rem start mvn -Dexo.tck.skip=false help:effective-pom
\ No newline at end of file
14 years, 7 months
exo-jcr SVN: r171 - in jcr/trunk: component/core and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-09-14 09:28:05 -0400 (Mon, 14 Sep 2009)
New Revision: 171
Modified:
jcr/trunk/component/core/TCK.cmd
jcr/trunk/component/core/pom.xml
jcr/trunk/component/core/test-dev.cmd
jcr/trunk/component/core/test.cmd
jcr/trunk/pom.xml
Log:
SWF-194: exo.test.skip default value removed from JCR root POM; exo.devtest.skip removed from JCR core POM; use exo.test.skip instead of maven.test.skip
Modified: jcr/trunk/component/core/TCK.cmd
===================================================================
--- jcr/trunk/component/core/TCK.cmd 2009-09-10 13:45:09 UTC (rev 170)
+++ jcr/trunk/component/core/TCK.cmd 2009-09-14 13:28:05 UTC (rev 171)
@@ -1,3 +1,5 @@
-@set MAVEN_OPTS=-Duser.language=en -Duser.region=us -Dmaven.test.skip=true -Dexo.devtest.skip=true -Dexo.tck.skip=false -DforkMode=never -Dorg.exoplatform.jcr.monitor.jdbcMonitor %MAVEN_OPTS%
+@set MAVEN_OPTS=-Duser.language=en -Duser.region=us -Dexo.test.skip=true -Dexo.devtest.skip=true -Dexo.tck.skip=false -DforkMode=never -Dorg.exoplatform.jcr.monitor.jdbcMonitor %MAVEN_OPTS%
-@start mvn clean install
\ No newline at end of file
+@start mvn clean install
+
+@rem start mvn -Dexo.tck.skip=false help:effective-pom
\ No newline at end of file
Modified: jcr/trunk/component/core/pom.xml
===================================================================
--- jcr/trunk/component/core/pom.xml 2009-09-10 13:45:09 UTC (rev 170)
+++ jcr/trunk/component/core/pom.xml 2009-09-14 13:28:05 UTC (rev 171)
@@ -35,7 +35,6 @@
<properties>
<jcr.test.configuration.file>/conf/standalone/test-configuration.xml</jcr.test.configuration.file>
- <exo.devtest.skip>true</exo.devtest.skip>
</properties>
<dependencies>
@@ -395,7 +394,7 @@
<goal>test</goal>
</goals>
<configuration>
- <skip>${maven.test.skip}</skip>
+ <skip>${exo.test.skip}</skip>
<argLine>-Xmx512M</argLine>
<systemProperties>
<property>
Modified: jcr/trunk/component/core/test-dev.cmd
===================================================================
--- jcr/trunk/component/core/test-dev.cmd 2009-09-10 13:45:09 UTC (rev 170)
+++ jcr/trunk/component/core/test-dev.cmd 2009-09-14 13:28:05 UTC (rev 171)
@@ -1,3 +1,3 @@
-@set MAVEN_OPTS=-Duser.language=en -Duser.region=us %MAVEN_OPTS% -Dmaven.test.skip=true -Dexo.tck.skip=true -Dexo.devtest.skip=false -DforkMode=never
+@set MAVEN_OPTS=-Duser.language=en -Duser.region=us %MAVEN_OPTS% -Dexo.test.skip=true -Dexo.tck.skip=true -Dexo.devtest.skip=false -DforkMode=never
@start mvn clean test
\ No newline at end of file
Modified: jcr/trunk/component/core/test.cmd
===================================================================
--- jcr/trunk/component/core/test.cmd 2009-09-10 13:45:09 UTC (rev 170)
+++ jcr/trunk/component/core/test.cmd 2009-09-14 13:28:05 UTC (rev 171)
@@ -1,3 +1,3 @@
-@set MAVEN_OPTS=-Duser.language=en -Duser.region=us %MAVEN_OPTS% -Dmaven.test.skip=false -Dexo.tck.skip=true -Dexo.devtest.skip=true -DforkMode=never
+@set MAVEN_OPTS=-Duser.language=en -Duser.region=us %MAVEN_OPTS% -Dexo.test.skip=false -Dexo.tck.skip=true -Dexo.devtest.skip=true -DforkMode=never
@start mvn clean test
\ No newline at end of file
Modified: jcr/trunk/pom.xml
===================================================================
--- jcr/trunk/pom.xml 2009-09-10 13:45:09 UTC (rev 170)
+++ jcr/trunk/pom.xml 2009-09-14 13:28:05 UTC (rev 171)
@@ -42,8 +42,6 @@
<org.exoplatform.kernel.version>2.2.0-Beta01</org.exoplatform.kernel.version>
<org.exoplatform.core.version>2.3.0-Beta01</org.exoplatform.core.version>
<org.exoplatform.ws.version>2.1.0-Beta01</org.exoplatform.ws.version>
-
- <exo.tck.skip>true</exo.tck.skip>
</properties>
<scm>
14 years, 7 months
exo-jcr SVN: r170 - ws/trunk/testframework.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-10 09:45:09 -0400 (Thu, 10 Sep 2009)
New Revision: 170
Modified:
ws/trunk/testframework/pom.xml
Log:
EXOJCR-155
Modified: ws/trunk/testframework/pom.xml
===================================================================
--- ws/trunk/testframework/pom.xml 2009-09-10 13:38:05 UTC (rev 169)
+++ ws/trunk/testframework/pom.xml 2009-09-10 13:45:09 UTC (rev 170)
@@ -30,7 +30,7 @@
<artifactId>exo.ws.testframework</artifactId>
- <name>eXo WS HTTP testframework</name>
+ <name>eXo WS :: HTTP :: testframework</name>
<dependencies>
<dependency>
14 years, 7 months
exo-jcr SVN: r169 - ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-10 09:38:05 -0400 (Thu, 10 Sep 2009)
New Revision: 169
Modified:
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
Log:
EXOJCR-152
Modified: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2009-09-10 13:37:40 UTC (rev 168)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2009-09-10 13:38:05 UTC (rev 169)
@@ -24,7 +24,7 @@
import org.exoplatform.services.rest.impl.InputHeadersMap;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.tools.DummyContainerResponseWriter;
-import org.exoplatform.testframework.MockHttpServletRequest;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import java.io.ByteArrayInputStream;
import java.net.URI;
14 years, 7 months
exo-jcr SVN: r168 - in ws/trunk/testframework/src/main/java/org/exoplatform: services and 2 other directories.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-10 09:37:40 -0400 (Thu, 10 Sep 2009)
New Revision: 168
Added:
ws/trunk/testframework/src/main/java/org/exoplatform/services/
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensetiveMap.java
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensitiveMultivaluedMap.java
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletRequest.java
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletResponse.java
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpSession.java
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockPrincipal.java
ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockServletContext.java
Removed:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/
Log:
EXOJCR-152
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensetiveMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensetiveMap.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensetiveMap.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,76 @@
+/*
+ * 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.test.mock;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id: CaseInsensetiveMap.java 167 2009-09-10 13:14:45Z max_shaposhnik $
+ */
+public class CaseInsensetiveMap<T> extends java.util.HashMap<String, T>
+{
+
+ private static final long serialVersionUID = -8562529039657285360L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return super.containsKey(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T get(Object key)
+ {
+ return super.get(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T put(String key, T value)
+ {
+ return super.put(getKey(key), value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T remove(Object key)
+ {
+ return super.remove(getKey(key));
+ }
+
+ private String getKey(Object key)
+ {
+ if (key == null)
+ {
+ return null;
+ }
+ return key.toString().toLowerCase();
+ }
+
+}
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensitiveMultivaluedMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensitiveMultivaluedMap.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/CaseInsensitiveMultivaluedMap.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,97 @@
+/*
+ * 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.test.mock;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id: CaseInsensitiveMap.java 2822 2009-08-27 14:14:41Z andrew00x $
+ */
+public class CaseInsensitiveMultivaluedMap<T> extends HashMap<String, List<T>>
+{
+
+ private static final long serialVersionUID = 6637313979061607685L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return super.containsKey(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<T> get(Object key)
+ {
+ return getList(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<T> put(String key, List<T> value)
+ {
+ return super.put(getKey(key), value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<T> remove(Object key)
+ {
+ return super.remove(getKey(key));
+ }
+
+ public T getFirst(String key)
+ {
+ List<T> l = getList(key);
+ if (l.size() == 0)
+ return null;
+ return l.get(0);
+ }
+
+ private List<T> getList(String key)
+ {
+ List<T> l = super.get(getKey(key));
+ if (l == null)
+ l = new ArrayList<T>();
+ put(key, l);
+ return l;
+ }
+
+ private String getKey(Object key)
+ {
+ if (key == null)
+ {
+ return null;
+ }
+ return key.toString().toLowerCase();
+ }
+
+}
\ No newline at end of file
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletRequest.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletRequest.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,720 @@
+/*
+ * 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.test.mock;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * The Class MockHttpServletRequest.
+ *
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id: $
+ */
+
+@SuppressWarnings("unchecked")
+public class MockHttpServletRequest implements HttpServletRequest
+{
+
+ /** HTTP method. */
+ private String method;
+
+ /** Length. */
+ private int length;
+
+ /** Request url. */
+ private String requestURL;
+
+ /** Data. */
+ private InputStream data;
+
+ /** Headers. */
+ private CaseInsensitiveMultivaluedMap<String> headers = new CaseInsensitiveMultivaluedMap<String>();
+
+ /** The parameters. */
+ private Map<String, List<String>> parameters = new HashMap<String, List<String>>();
+
+ /** The session. */
+ private HttpSession session;
+
+ /** The locale. */
+ private Locale locale;
+
+ /** The secure. */
+ private boolean secure;
+
+ /** The Constant p. */
+ private static final Pattern p = Pattern.compile("http://([^:]+?):([^/]+?)/([^/]+?)/(.*?)");
+
+ /** The attributes. */
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ private Principal principal;
+
+ /**
+ * Instantiates a new mock http servlet request.
+ *
+ * @param url
+ * the url
+ * @param data
+ * the data
+ * @param length
+ * the length
+ * @param method
+ * the method
+ * @param headers
+ * the headers
+ */
+ public MockHttpServletRequest(String url, InputStream data, int length, String method,
+ Map<String, List<String>> headers)
+ {
+ this.requestURL = url;
+ this.data = data;
+ this.length = length;
+ this.method = method;
+ if (headers != null)
+ this.headers.putAll(headers);
+ String queryString = getQueryString();
+ if (queryString != null)
+ {
+ parameters.putAll(parseQueryString(queryString));
+ }
+ session = new MockHttpSession();
+ }
+
+ /**
+ * Reset.
+ */
+ public void reset()
+ {
+ parameters = new HashMap();
+ attributes = new HashMap();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getAttribute(String name)
+ {
+ return attributes.get(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getAttributeNames()
+ {
+ return new EnumerationImpl(attributes.keySet().iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getAuthType()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCharacterEncoding()
+ {
+ return "UTF-8";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getContentLength()
+ {
+ return length;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getContentType()
+ {
+ return headers.getFirst("content-type");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getContextPath()
+ {
+ Matcher m = p.matcher(requestURL);
+ if (!m.matches())
+ throw new RuntimeException("Unable determine context path.");
+ return '/' + m.group(3);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Cookie[] getCookies()
+ {
+ return new Cookie[0];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getDateHeader(String name)
+ {
+ if (headers.get(name) != null)
+ return Long.valueOf(headers.getFirst(name));
+ return -1L;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getHeader(String name)
+ {
+ return headers.getFirst(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getHeaderNames()
+ {
+ return new EnumerationImpl(headers.keySet().iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getHeaders(String name)
+ {
+ ArrayList values = (ArrayList)headers.get(name);
+ if (values.size() > 0)
+ return new EnumerationImpl(values.iterator());
+
+ return new EnumerationImpl(Collections.EMPTY_LIST.iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ServletInputStream getInputStream() throws IOException
+ {
+ return new MockServletInputStream(data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getIntHeader(String name)
+ {
+ if (headers.get(name).size() > 0)
+ return Integer.parseInt(headers.getFirst(name));
+ return -1;
+ }
+
+ /**
+ * Gets the local addr.
+ *
+ * @return the local addr
+ */
+ public String getLocalAddr()
+ {
+ return "127.0.0.1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Locale getLocale()
+ {
+ return Locale.US;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getLocales()
+ {
+ return null;
+ }
+
+ /**
+ * Gets the local name.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return "localhost";
+ }
+
+ /**
+ * Gets the local port.
+ *
+ * @return the local port
+ */
+ public int getLocalPort()
+ {
+ return 80;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getMethod()
+ {
+ return method;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getParameter(String name)
+ {
+ Iterator<String> it = parameters.keySet().iterator();
+ while (it.hasNext())
+ {
+ String key = it.next();
+ if (key.equalsIgnoreCase(name))
+ {
+ ArrayList values = (ArrayList)parameters.get(key);
+ if (values != null)
+ return (String)values.get(0);
+ }
+ }
+ return (null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Map getParameterMap()
+ {
+ return parameters;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getParameterNames()
+ {
+ return new EnumerationImpl(parameters.keySet().iterator());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getParameterValues(String name)
+ {
+ ArrayList<String> arr = new ArrayList<String>();
+ Iterator it = parameters.keySet().iterator();
+ while (it.hasNext())
+ {
+
+ String pname = (String)it.next();
+ if (pname.equalsIgnoreCase(name))
+ arr.add((String)parameters.get(name).get(0));
+ }
+ return arr.toArray(new String[arr.size()]);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPathInfo()
+ {
+ Matcher m = p.matcher(requestURL);
+ if (!m.matches())
+ throw new RuntimeException("Unable determine pathInfo.");
+ String p = m.group(4);
+ int q = p.indexOf('?');
+ if (q > 0)
+ {
+ p = p.substring(0, q);
+ }
+ return '/' + p;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPathTranslated()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getProtocol()
+ {
+ return "HTTP/1.1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getQueryString()
+ {
+ if (requestURL == null)
+ return null;
+ int sep = requestURL.lastIndexOf('?');
+ if (sep == -1)
+ return null;
+ return requestURL.substring(sep + 1);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BufferedReader getReader() throws IOException
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRealPath(String arg0)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRemoteAddr()
+ {
+ return "127.0.0.1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRemoteHost()
+ {
+ return "localhost";
+ }
+
+ /**
+ * Gets the remote port.
+ *
+ * @return the remote port
+ */
+ public int getRemotePort()
+ {
+ return 8080;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRemoteUser()
+ {
+ return "root";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RequestDispatcher getRequestDispatcher(String s)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRequestedSessionId()
+ {
+ return "sessionId";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRequestURI()
+ {
+ return getContextPath() + getServletPath() + getPathInfo();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StringBuffer getRequestURL()
+ {
+ if (requestURL == null)
+ return null;
+ return new StringBuffer(requestURL);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getScheme()
+ {
+ return "http";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getServerName()
+ {
+ Matcher m = p.matcher(requestURL);
+ if (!m.matches())
+ throw new RuntimeException("Unable determine server name.");
+ return m.group(1);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getServerPort()
+ {
+ Matcher m = p.matcher(requestURL);
+ if (!m.matches())
+ throw new RuntimeException("Unable determine request URI.");
+ return Integer.valueOf(m.group(2));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getServletPath()
+ {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public HttpSession getSession()
+ {
+ return session;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public HttpSession getSession(boolean b)
+ {
+ return session;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Principal getUserPrincipal()
+ {
+ return principal == null ? principal = new MockPrincipal("root") : principal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRequestedSessionIdFromCookie()
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRequestedSessionIdFromUrl()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRequestedSessionIdFromURL()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRequestedSessionIdValid()
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSecure()
+ {
+ return secure;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isUserInRole(String role)
+ {
+ return "admin".equals(role);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeAttribute(String name)
+ {
+ attributes.remove(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setAttribute(String name, Object object)
+ {
+ attributes.put(name, object);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCharacterEncoding(String enc) throws UnsupportedEncodingException
+ {
+ }
+
+ /**
+ * Sets the parameter.
+ *
+ * @param name
+ * the name
+ * @param value
+ * the value
+ */
+ public void setParameter(String name, String value)
+ {
+ ArrayList arr = new ArrayList<String>();
+ arr.add(value);
+ parameters.put(name, arr);
+ }
+
+ public static Map<String, List<String>> parseQueryString(String rawQuery)
+ {
+ HashMap<String, List<String>> m = new HashMap<String, List<String>>();
+ if (rawQuery == null || rawQuery.length() == 0)
+ return m;
+ int p = 0;
+ int n = 0;
+ while (n < rawQuery.length())
+ {
+ n = rawQuery.indexOf('&', p);
+ if (n == -1)
+ n = rawQuery.length();
+
+ String pair = rawQuery.substring(p, n);
+ if (pair.length() == 0)
+ continue;
+
+ String name;
+ String value = ""; // default value
+ int eq = pair.indexOf('=');
+ if (eq == -1) // no value, default is ""
+ name = pair;
+ else
+ {
+ name = pair.substring(0, eq);
+ value = pair.substring(eq + 1);
+ }
+
+ if (m.get(name) == null)
+ {
+ List<String> arr = new ArrayList<String>();
+ arr.add(value);
+ m.put(name, arr);
+ }
+ else
+ {
+ List<String> arr = m.get(name);
+ arr.add(value);
+ }
+ p = n + 1;
+ }
+ return m;
+ }
+}
+
+@SuppressWarnings("unchecked")
+class EnumerationImpl implements Enumeration
+{
+
+ private final Iterator iter;
+
+ public EnumerationImpl(Iterator iter)
+ {
+ this.iter = iter;
+ }
+
+ public boolean hasMoreElements()
+ {
+ return iter.hasNext();
+ }
+
+ public Object nextElement()
+ {
+ return iter.next();
+ }
+}
+
+class MockServletInputStream extends ServletInputStream
+{
+
+ private final InputStream data;
+
+ public MockServletInputStream(InputStream data)
+ {
+ this.data = data;
+ }
+
+ @Override
+ public int read() throws IOException
+ {
+ return data.read();
+ }
+}
\ No newline at end of file
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletResponse.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletResponse.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpServletResponse.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,445 @@
+/*
+ * 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.test.mock;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * The Class MockHttpServletResponse.
+ *
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id: $
+ */
+
+public class MockHttpServletResponse implements HttpServletResponse
+{
+
+ /** The writer. */
+ private PrintWriter writer;
+
+ /** The stream. */
+ private ByteArrayOutputStream stream;
+
+ /** The output. */
+ private ByteArrayServletOutputStream output;
+
+ /** The buffer. */
+ private byte[] buffer = new byte[1024];
+
+ /** The buffer count. */
+ private int bufferCount = 0;
+
+ /** The cookies. */
+ private List<Cookie> cookies = new ArrayList<Cookie>();
+
+ /** The headers. */
+ private HashMap<String, List<String>> headers = new CaseInsensitiveMultivaluedMap<String>();
+
+ /** The status. */
+ private int status = HttpServletResponse.SC_OK;
+
+ /** The message. */
+ private String message = "";
+
+ /** The locale. */
+ private Locale locale = Locale.getDefault();
+
+ /** The content type. */
+ private String contentType = null;
+
+ /** The content length. */
+ protected int contentLength = -1;
+
+ /** The encoding. */
+ protected String encoding = null;
+
+ /** The date format we will use for creating date headers. */
+ protected static final SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+ static
+ {
+ format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ };
+
+ /**
+ * Instantiates a new mock http servlet response.
+ */
+ public MockHttpServletResponse()
+ {
+ stream = new ByteArrayOutputStream();
+ writer = new PrintWriter(stream);
+ output = new ByteArrayServletOutputStream(stream);
+ }
+
+ /**
+ * Gets the output content.
+ *
+ * @return the output content
+ */
+ public String getOutputContent()
+ {
+ return new String(stream.toByteArray());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void flushBuffer() throws IOException
+ {
+ if (bufferCount > 0)
+ {
+ try
+ {
+ output.write(buffer, 0, bufferCount);
+ }
+ finally
+ {
+ bufferCount = 0;
+ }
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getBufferSize()
+ {
+ return (buffer.length);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ServletOutputStream getOutputStream() throws IOException
+ {
+ return this.output;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PrintWriter getWriter() throws IOException
+ {
+ return this.writer;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isCommitted()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void reset()
+ {
+ bufferCount = 0;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resetBuffer()
+ {
+ bufferCount = 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addCookie(Cookie cookie)
+ {
+ cookies.add(cookie);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addDateHeader(String name, long value)
+ {
+ addHeader(name, format.format(new Date(value)));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addHeader(String name, String value)
+ {
+ Iterator it = headers.keySet().iterator();
+ while (it.hasNext())
+ {
+ String key = (String)it.next();
+ if (key.equals(name))
+ {
+ List<String> values = (ArrayList<String>)headers.get(key);
+ if (values != null)
+ {
+ values = new ArrayList<String>();
+ headers.put(name, values);
+ }
+ values.add(value);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addIntHeader(String name, int value)
+ {
+ addHeader(name, "" + value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean containsHeader(String name)
+ {
+ return (headers.get(name) != null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String encodeRedirectURL(String url)
+ {
+ return url; // TODO encode
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String encodeRedirectUrl(String url)
+ {
+ return url;// TODO encode
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String encodeURL(String url)
+ {
+ return url;// TODO encode
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String encodeUrl(String url)
+ {
+ return url;// TODO encode
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void sendError(int status) throws IOException
+ {
+ sendError(status, "");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void sendError(int status, String message) throws IOException
+ {
+ this.status = status;
+ this.message = message;
+ resetBuffer();
+ try
+ {
+ flushBuffer();
+ }
+ catch (IOException e)
+ {
+
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void sendRedirect(String location) throws IOException
+ {
+ resetBuffer();
+ setStatus(SC_MOVED_TEMPORARILY);
+ setHeader("Location", location);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDateHeader(String name, long value)
+ {
+ setHeader(name, format.format(new Date(value)));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setHeader(String name, String value)
+ {
+ List<String> values = new ArrayList<String>();
+ values.add(value);
+ headers.put(name, values);
+
+ String match = name.toLowerCase();
+ if (match.equals("content-length"))
+ {
+ int contentLength = -1;
+ contentLength = Integer.parseInt(value);
+ if (contentLength >= 0)
+ setContentLength(contentLength);
+ }
+ else if (match.equals("content-type"))
+ {
+ setContentType(value);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setIntHeader(String name, int value)
+ {
+ setHeader(name, "" + value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setStatus(int status)
+ {
+ this.status = status;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setStatus(int status, String message)
+ {
+ this.status = status;
+ this.message = message;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCharacterEncoding()
+ {
+ if (encoding == null)
+ return ("UTF-8");
+ else
+ return (encoding);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setBufferSize(int size)
+ {
+ if (buffer.length >= size)
+ return;
+ buffer = new byte[size];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setContentLength(int length)
+ {
+ this.contentLength = length;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setContentType(String type)
+ {
+ this.contentType = type;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setLocale(Locale locale)
+ {
+ this.locale = locale;
+ }
+
+ /**
+ * The Class ByteArrayServletOutputStream.
+ */
+ private static class ByteArrayServletOutputStream extends ServletOutputStream
+ {
+
+ /** The baos. */
+ ByteArrayOutputStream baos;
+
+ /**
+ * Instantiates a new byte array servlet output stream.
+ *
+ * @param baos
+ * the baos
+ */
+ public ByteArrayServletOutputStream(ByteArrayOutputStream baos)
+ {
+ this.baos = baos;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void write(int i) throws IOException
+ {
+ baos.write(i);
+ }
+ }
+
+}
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpSession.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpSession.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockHttpSession.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,221 @@
+/*
+ * 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.test.mock;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class MockHttpSession.
+ *
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id: $
+ */
+public class MockHttpSession implements HttpSession
+{
+
+ /** The attributes map. */
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ /** The servlet context. */
+ private ServletContext servletContext;
+
+ /** The is valid. */
+ private boolean isValid = true;
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getCreationTime()
+ {
+ return 0L;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getId()
+ {
+ return "MockSessionId";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getLastAccessedTime()
+ {
+ return 0L;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setMaxInactiveInterval(int i)
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMaxInactiveInterval()
+ {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public HttpSessionContext getSessionContext()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getAttribute(String s)
+ {
+
+ if (!isValid)
+ {
+ throw new IllegalStateException("Cannot call getAttribute() on invalidated session");
+ }
+ return attributes.get(s);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getValue(String s)
+ {
+ return getAttribute(s);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getAttributeNames()
+ {
+ if (!isValid)
+ {
+ throw new IllegalStateException("Cannot call getAttribute() on invalidated session");
+ }
+ return new Vector<String>(attributes.keySet()).elements();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getValueNames()
+ {
+ if (!isValid)
+ {
+ throw new IllegalStateException("Cannot call getAttribute() on invalidated session");
+ }
+ String results[] = new String[0];
+ return ((String[])attributes.keySet().toArray(results));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setAttribute(String s, Object o)
+ {
+ attributes.put(s, o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void putValue(String s, Object o)
+ {
+ setAttribute(s, o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeAttribute(String s)
+ {
+ attributes.remove(s);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeValue(String s)
+ {
+ removeAttribute(s);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void invalidate()
+ {
+ if (!isValid)
+ {
+ throw new IllegalStateException("Cannot call invalidate() on invalidated session");
+ }
+ this.isValid = false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isNew()
+ {
+ return false;
+ }
+
+ /**
+ * Checks if is valid.
+ *
+ * @return true, if is valid
+ */
+ public boolean isValid()
+ {
+ return this.isValid;
+ }
+
+ /**
+ * Sets the valid.
+ *
+ * @param isValid the new valid
+ */
+ public void setValid(boolean isValid)
+ {
+ this.isValid = isValid;
+ }
+}
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockPrincipal.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockPrincipal.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockPrincipal.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,41 @@
+/*
+ * 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.test.mock;
+
+/**
+ * @author Mestrallet Benjamin benjmestrallet(a)users.sourceforge.net
+ */
+public class MockPrincipal implements java.security.Principal
+{
+
+ private final String username;
+
+ public MockPrincipal(String username)
+ {
+ this.username = username;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName()
+ {
+ return username;
+ }
+}
Added: ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockServletContext.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockServletContext.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/services/test/mock/MockServletContext.java 2009-09-10 13:37:40 UTC (rev 168)
@@ -0,0 +1,378 @@
+/*
+ * 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.test.mock;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+
+/**
+ * The Class MockServletContext.
+ *
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id: $
+ */
+public class MockServletContext implements ServletContext
+{
+
+ /** The name. */
+ private String name;
+
+ /** The init params. */
+ private HashMap<String, String> initParams;
+
+ /** The attributes. */
+ private HashMap<String, Object> attributes;
+
+ /** The context path. */
+ private String contextPath;
+
+ /** The log buffer. */
+ private StringBuffer logBuffer = new StringBuffer();
+
+ /**
+ * Instantiates a new mock servlet context.
+ */
+ public MockServletContext()
+ {
+ this("MockServletContext1");
+ }
+
+ /**
+ * Instantiates a new mock servlet context.
+ *
+ * @param name the name
+ */
+ public MockServletContext(String name)
+ {
+ this.name = name;
+ this.initParams = new HashMap<String, String>();
+ this.attributes = new HashMap<String, Object>();
+ }
+
+ /**
+ * Instantiates a new mock servlet context.
+ *
+ * @param name the name
+ * @param path the path
+ */
+ public MockServletContext(String name, String path)
+ {
+ this(name);
+ contextPath = path;
+ attributes.put("javax.servlet.context.tempdir", path);
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name the new name
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Gets the log buffer.
+ *
+ * @return the log buffer
+ */
+ public String getLogBuffer()
+ {
+ try
+ {
+ return logBuffer.toString();
+ }
+ finally
+ {
+ logBuffer = new StringBuffer();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ServletContext getContext(String s)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMajorVersion()
+ {
+ return 2;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMinorVersion()
+ {
+ return 4;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getMimeType(String s)
+ {
+ return "text/html";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set getResourcePaths(String s)
+ {
+
+ if (!s.endsWith("/"))
+ s = s + "/";
+
+ Set<String> set = new HashSet<String>();
+ set.add("/WEB-INF/");
+
+ try
+ {
+ URL url = getResource(s);
+ File dir = new File(url.getPath());
+ if (dir.isDirectory())
+ {
+ File[] arr = dir.listFiles();
+ for (int i = 0; i < arr.length; i++)
+ {
+ File tmp = arr[i];
+ if (tmp.isDirectory())
+ set.add(s + "/" + tmp.getName() + "/");
+ else
+ set.add(s + "/" + tmp.getName());
+ }
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ }
+ return set;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URL getResource(String s) throws MalformedURLException
+ {
+ String path = "file:" + contextPath + s;
+ URL url = new URL(path);
+ return url;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public InputStream getResourceAsStream(String s)
+ {
+ try
+ {
+ return getResource(s).openStream();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RequestDispatcher getRequestDispatcher(String s)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RequestDispatcher getNamedDispatcher(String s)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Deprecated
+ public Servlet getServlet(String s) throws ServletException
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Deprecated
+ public Enumeration getServlets()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Deprecated
+ public Enumeration getServletNames()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log(String s)
+ {
+ logBuffer.append(s);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Deprecated
+ public void log(Exception e, String s)
+ {
+ logBuffer.append(s + e.getMessage());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log(String s, Throwable throwable)
+ {
+ logBuffer.append(s + throwable.getMessage());
+ }
+
+ /**
+ * Sets the context path.
+ *
+ * @param s the new context path
+ */
+ public void setContextPath(String s)
+ {
+ contextPath = s;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRealPath(String s)
+ {
+ return contextPath + s;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getServerInfo()
+ {
+ return null;
+ }
+
+ /**
+ * Sets the init parameter.
+ *
+ * @param name the name
+ * @param value the value
+ */
+ public void setInitParameter(String name, String value)
+ {
+ initParams.put(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getInitParameter(String name)
+ {
+ return (String)initParams.get(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getInitParameterNames()
+ {
+ Vector<String> keys = new Vector<String>(initParams.keySet());
+ return keys.elements();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getAttribute(String name)
+ {
+ return attributes.get(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getAttributeNames()
+ {
+ Vector<String> keys = new Vector<String>(attributes.keySet());
+ return keys.elements();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setAttribute(String name, Object value)
+ {
+ attributes.put(name, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeAttribute(String name)
+ {
+ attributes.remove(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getServletContextName()
+ {
+ return name;
+ }
+
+}
14 years, 7 months
exo-jcr SVN: r167 - ws/trunk/testframework/src/main/java/org/exoplatform/testframework.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2009-09-10 09:14:45 -0400 (Thu, 10 Sep 2009)
New Revision: 167
Modified:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpSession.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletContext.java
Log:
EXOJCR-152 :
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java 2009-09-10 11:21:37 UTC (rev 166)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java 2009-09-10 13:14:45 UTC (rev 167)
@@ -1,18 +1,20 @@
/*
- * Copyright (C) 2003-2008 eXo Platform SAS.
+ * Copyright (C) 2009 eXo Platform SAS.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
+ * 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ * 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.testframework;
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java 2009-09-10 11:21:37 UTC (rev 166)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java 2009-09-10 13:14:45 UTC (rev 167)
@@ -78,7 +78,7 @@
private List<T> getList(String key)
{
- List<T> l = super.get(key);
+ List<T> l = super.get(getKey(key));
if (l == null)
l = new ArrayList<T>();
put(key, l);
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-10 11:21:37 UTC (rev 166)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-10 13:14:45 UTC (rev 167)
@@ -65,7 +65,7 @@
private InputStream data;
/** Headers. */
- private Map<String, List<String>> headers = new CaseInsensitiveMultivaluedMap<String>();
+ private CaseInsensitiveMultivaluedMap<String> headers = new CaseInsensitiveMultivaluedMap<String>();
/** The parameters. */
private Map<String, List<String>> parameters = new HashMap<String, List<String>>();
@@ -172,9 +172,7 @@
*/
public String getContentType()
{
- if (headers.get("content-type") != null)
- return headers.get("content-type").get(0);
- return (null);
+ return headers.getFirst("content-type");
}
/**
@@ -202,7 +200,7 @@
public long getDateHeader(String name)
{
if (headers.get(name) != null)
- return Long.valueOf(headers.get(name).get(0));
+ return Long.valueOf(headers.getFirst(name));
return -1L;
}
@@ -211,9 +209,7 @@
*/
public String getHeader(String name)
{
- if (headers.get(name) != null)
- return headers.get(name).get(0);
- return (null);
+ return headers.getFirst(name);
}
/**
@@ -229,21 +225,10 @@
*/
public Enumeration getHeaders(String name)
{
- // return new EnumerationImpl(headers.get(name).iterator());
- synchronized (headers)
- {
- Iterator<String> it = headers.keySet().iterator();
- while (it.hasNext())
- {
- String key = it.next();
- if (key.equalsIgnoreCase(name))
- {
- ArrayList values = (ArrayList)headers.get(key);
- if (values != null)
- return new EnumerationImpl(values.iterator());
- }
- }
- }
+ ArrayList values = (ArrayList)headers.get(name);
+ if (values.size() > 0)
+ return new EnumerationImpl(values.iterator());
+
return new EnumerationImpl(Collections.EMPTY_LIST.iterator());
}
@@ -260,8 +245,8 @@
*/
public int getIntHeader(String name)
{
- if (headers.get(name) != null)
- return Integer.parseInt(headers.get(name).get(0));
+ if (headers.get(name).size() > 0)
+ return Integer.parseInt(headers.getFirst(name));
return -1;
}
@@ -324,18 +309,15 @@
*/
public String getParameter(String name)
{
- synchronized (parameters)
+ Iterator<String> it = parameters.keySet().iterator();
+ while (it.hasNext())
{
- Iterator<String> it = parameters.keySet().iterator();
- while (it.hasNext())
+ String key = it.next();
+ if (key.equalsIgnoreCase(name))
{
- String key = it.next();
- if (key.equalsIgnoreCase(name))
- {
- ArrayList values = (ArrayList)parameters.get(key);
- if (values != null)
- return (String)values.get(0);
- }
+ ArrayList values = (ArrayList)parameters.get(key);
+ if (values != null)
+ return (String)values.get(0);
}
}
return (null);
@@ -362,8 +344,6 @@
*/
public String[] getParameterValues(String name)
{
- // List<String> values = parameters.get(name);
- // return values.toArray(new String[values.size()]);
ArrayList<String> arr = new ArrayList<String>();
Iterator it = parameters.keySet().iterator();
while (it.hasNext())
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java 2009-09-10 11:21:37 UTC (rev 166)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java 2009-09-10 13:14:45 UTC (rev 167)
@@ -34,7 +34,6 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
-
/**
* The Class MockHttpServletResponse.
*
@@ -184,11 +183,7 @@
*/
public void addCookie(Cookie cookie)
{
- synchronized (cookies)
- {
cookies.add(cookie);
- }
-
}
/**
@@ -204,24 +199,23 @@
*/
public void addHeader(String name, String value)
{
- synchronized (headers) {
Iterator it = headers.keySet().iterator();
- while (it.hasNext()){
+ while (it.hasNext())
+ {
String key = (String)it.next();
- if (key.equals(name)){
- ArrayList values = (ArrayList) headers.get(key);
- if (values != null){
- values = new ArrayList();
- headers.put(name, values);
+ if (key.equals(name))
+ {
+ List<String> values = (ArrayList<String>)headers.get(key);
+ if (values != null)
+ {
+ values = new ArrayList<String>();
+ headers.put(name, values);
}
- values.add(value);
+ values.add(value);
}
}
- }
}
-
-
/**
* {@inheritDoc}
*/
@@ -235,10 +229,7 @@
*/
public boolean containsHeader(String name)
{
- synchronized (headers)
- {
return (headers.get(name) != null);
- }
}
/**
@@ -322,25 +313,15 @@
*/
public void setHeader(String name, String value)
{
- ArrayList values = new ArrayList();
+ List<String> values = new ArrayList<String>();
values.add(value);
- synchronized (headers)
- {
- headers.put(name, values);
- }
+ headers.put(name, values);
String match = name.toLowerCase();
if (match.equals("content-length"))
{
int contentLength = -1;
- try
- {
- contentLength = Integer.parseInt(value);
- }
- catch (NumberFormatException e)
- {
- ;
- }
+ contentLength = Integer.parseInt(value);
if (contentLength >= 0)
setContentLength(contentLength);
}
@@ -437,14 +418,15 @@
*/
private static class ByteArrayServletOutputStream extends ServletOutputStream
{
-
+
/** The baos. */
ByteArrayOutputStream baos;
/**
* Instantiates a new byte array servlet output stream.
*
- * @param baos the baos
+ * @param baos
+ * the baos
*/
public ByteArrayServletOutputStream(ByteArrayOutputStream baos)
{
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpSession.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpSession.java 2009-09-10 11:21:37 UTC (rev 166)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpSession.java 2009-09-10 13:14:45 UTC (rev 167)
@@ -38,7 +38,7 @@
{
/** The attributes map. */
- private Map attributes = new HashMap();
+ private Map<String, Object> attributes = new HashMap<String, Object>();
/** The servlet context. */
private ServletContext servletContext;
@@ -131,7 +131,7 @@
{
throw new IllegalStateException("Cannot call getAttribute() on invalidated session");
}
- return new Vector(attributes.keySet()).elements();
+ return new Vector<String>(attributes.keySet()).elements();
}
/**
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletContext.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletContext.java 2009-09-10 11:21:37 UTC (rev 166)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockServletContext.java 2009-09-10 13:14:45 UTC (rev 167)
@@ -44,17 +44,17 @@
public class MockServletContext implements ServletContext
{
- /** The name_. */
- private String name_;
+ /** The name. */
+ private String name;
/** The init params. */
- private HashMap initParams_;
+ private HashMap<String, String> initParams;
/** The attributes. */
- private HashMap attributes_;
+ private HashMap<String, Object> attributes;
/** The context path. */
- private String contextPath_;
+ private String contextPath;
/** The log buffer. */
private StringBuffer logBuffer = new StringBuffer();
@@ -74,9 +74,9 @@
*/
public MockServletContext(String name)
{
- name_ = name;
- initParams_ = new HashMap();
- attributes_ = new HashMap();
+ this.name = name;
+ this.initParams = new HashMap<String, String>();
+ this.attributes = new HashMap<String, Object>();
}
/**
@@ -88,8 +88,8 @@
public MockServletContext(String name, String path)
{
this(name);
- contextPath_ = path;
- attributes_.put("javax.servlet.context.tempdir", path);
+ contextPath = path;
+ attributes.put("javax.servlet.context.tempdir", path);
}
/**
@@ -99,7 +99,7 @@
*/
public void setName(String name)
{
- name_ = name;
+ this.name = name;
}
/**
@@ -160,7 +160,7 @@
if (!s.endsWith("/"))
s = s + "/";
- Set set = new HashSet<String>();
+ Set<String> set = new HashSet<String>();
set.add("/WEB-INF/");
try
@@ -191,7 +191,7 @@
*/
public URL getResource(String s) throws MalformedURLException
{
- String path = "file:" + contextPath_ + s;
+ String path = "file:" + contextPath + s;
URL url = new URL(path);
return url;
}
@@ -287,7 +287,7 @@
*/
public void setContextPath(String s)
{
- contextPath_ = s;
+ contextPath = s;
}
/**
@@ -295,7 +295,7 @@
*/
public String getRealPath(String s)
{
- return contextPath_ + s;
+ return contextPath + s;
}
/**
@@ -314,7 +314,7 @@
*/
public void setInitParameter(String name, String value)
{
- initParams_.put(name, value);
+ initParams.put(name, value);
}
/**
@@ -322,7 +322,7 @@
*/
public String getInitParameter(String name)
{
- return (String)initParams_.get(name);
+ return (String)initParams.get(name);
}
/**
@@ -330,7 +330,7 @@
*/
public Enumeration getInitParameterNames()
{
- Vector keys = new Vector(initParams_.keySet());
+ Vector<String> keys = new Vector<String>(initParams.keySet());
return keys.elements();
}
@@ -339,7 +339,7 @@
*/
public Object getAttribute(String name)
{
- return attributes_.get(name);
+ return attributes.get(name);
}
/**
@@ -347,7 +347,7 @@
*/
public Enumeration getAttributeNames()
{
- Vector keys = new Vector(attributes_.keySet());
+ Vector<String> keys = new Vector<String>(attributes.keySet());
return keys.elements();
}
@@ -356,7 +356,7 @@
*/
public void setAttribute(String name, Object value)
{
- attributes_.put(name, value);
+ attributes.put(name, value);
}
/**
@@ -364,7 +364,7 @@
*/
public void removeAttribute(String name)
{
- attributes_.remove(name);
+ attributes.remove(name);
}
/**
@@ -372,7 +372,7 @@
*/
public String getServletContextName()
{
- return name_;
+ return name;
}
}
14 years, 7 months
exo-jcr SVN: r166 - ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2009-09-10 07:21:37 -0400 (Thu, 10 Sep 2009)
New Revision: 166
Modified:
ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
Log:
EXOJCR-152 :
Modified: ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
===================================================================
--- ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2009-09-10 11:21:01 UTC (rev 165)
+++ ws/trunk/rest/core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2009-09-10 11:21:37 UTC (rev 166)
@@ -23,14 +23,13 @@
import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.impl.InputHeadersMap;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
-import org.exoplatform.testframework.MockHttpServletRequest;
import org.exoplatform.services.rest.tools.DummyContainerResponseWriter;
+import org.exoplatform.testframework.MockHttpServletRequest;
import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.net.URI;
-import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MultivaluedMap;
@@ -47,7 +46,7 @@
// }
public ContainerResponse service(String method, String requestURI, String baseURI,
- MultivaluedMap<String, String> headers, byte[] data, ContainerResponseWriter writer) throws Exception
+ Map<String, List<String>> headers, byte[] data, ContainerResponseWriter writer) throws Exception
{
if (headers == null)
@@ -57,17 +56,13 @@
if (data != null)
in = new ByteArrayInputStream(data);
- HashMap<String, List> map = new HashMap();
- map.putAll((HashMap)headers);
-
-
EnvironmentContext envctx = new EnvironmentContext();
HttpServletRequest httpRequest =
- new MockHttpServletRequest("",in, in != null ? in.available() : 0, method, map);
+ 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, headers);
+ new ContainerRequest(method, new URI(requestURI), new URI(baseURI), in, new InputHeadersMap(headers));
ContainerResponse response = new ContainerResponse(writer);
requestHandler.handleRequest(request, response);
return response;
14 years, 7 months
exo-jcr SVN: r165 - ws/trunk/testframework/src/main/java/org/exoplatform/testframework.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2009-09-10 07:21:01 -0400 (Thu, 10 Sep 2009)
New Revision: 165
Added:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java
Removed:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java
Modified:
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java
Log:
EXOJCR-152 :
Added: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java 2009-09-10 11:21:01 UTC (rev 165)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2003-2008 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+
+package org.exoplatform.testframework;
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class CaseInsensetiveMap<T> extends java.util.HashMap<String, T>
+{
+
+ private static final long serialVersionUID = -8562529039657285360L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return super.containsKey(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T get(Object key)
+ {
+ return super.get(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T put(String key, T value)
+ {
+ return super.put(getKey(key), value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T remove(Object key)
+ {
+ return super.remove(getKey(key));
+ }
+
+ private String getKey(Object key)
+ {
+ if (key == null)
+ {
+ return null;
+ }
+ return key.toString().toLowerCase();
+ }
+
+}
Property changes on: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java 2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java 2009-09-10 11:21:01 UTC (rev 165)
@@ -1,78 +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.testframework;
-
-import java.util.HashMap;
-
-
-/**
- * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
- * @version $Id: CaseInsensitiveMap.java 2822 2009-08-27 14:14:41Z andrew00x $
- */
-public class CaseInsensitiveMap extends HashMap<String, String>
-{
-
- private static final long serialVersionUID = 6637313979061607685L;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean containsKey(Object key)
- {
- return super.containsKey(getKey(key));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String get(Object key)
- {
- return super.get(getKey(key));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String put(String key, String value)
- {
- return super.put(getKey(key), value);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String remove(Object key)
- {
- return super.remove(getKey(key));
- }
-
- private String getKey(Object key)
- {
- if (key == null)
- {
- return null;
- }
- return key.toString().toLowerCase();
- }
-
-}
\ No newline at end of file
Copied: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java (from rev 160, ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java)
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java 2009-09-10 11:21:01 UTC (rev 165)
@@ -0,0 +1,97 @@
+/*
+ * 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.testframework;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
+ * @version $Id: CaseInsensitiveMap.java 2822 2009-08-27 14:14:41Z andrew00x $
+ */
+public class CaseInsensitiveMultivaluedMap<T> extends HashMap<String, List<T>>
+{
+
+ private static final long serialVersionUID = 6637313979061607685L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return super.containsKey(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<T> get(Object key)
+ {
+ return getList(getKey(key));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<T> put(String key, List<T> value)
+ {
+ return super.put(getKey(key), value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<T> remove(Object key)
+ {
+ return super.remove(getKey(key));
+ }
+
+ public T getFirst(String key)
+ {
+ List<T> l = getList(key);
+ if (l.size() == 0)
+ return null;
+ return l.get(0);
+ }
+
+ private List<T> getList(String key)
+ {
+ List<T> l = super.get(key);
+ if (l == null)
+ l = new ArrayList<T>();
+ put(key, l);
+ return l;
+ }
+
+ private String getKey(Object key)
+ {
+ if (key == null)
+ {
+ return null;
+ }
+ return key.toString().toLowerCase();
+ }
+
+}
\ No newline at end of file
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java 2009-09-10 11:21:01 UTC (rev 165)
@@ -1,18 +1,20 @@
-/**
- * Copyright (C) 2003-2009 eXo Platform SAS.
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
+ * 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ * 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.testframework;
@@ -63,10 +65,10 @@
private InputStream data;
/** Headers. */
- private Map headers = new CaseInsensitiveMap();
+ private Map<String, List<String>> headers = new CaseInsensitiveMultivaluedMap<String>();
/** The parameters. */
- private Map<String, ArrayList> parameters = new HashMap();
+ private Map<String, List<String>> parameters = new HashMap<String, List<String>>();
/** The session. */
private HttpSession session;
@@ -83,6 +85,8 @@
/** The attributes. */
private Map<String, Object> attributes = new HashMap<String, Object>();
+ private Principal principal;
+
/**
* Instantiates a new mock http servlet request.
*
@@ -97,18 +101,21 @@
* @param headers
* the headers
*/
- public MockHttpServletRequest(String url, InputStream data, int length, String method, HashMap<String, List> headers)
+ public MockHttpServletRequest(String url, InputStream data, int length, String method,
+ Map<String, List<String>> headers)
{
this.requestURL = url;
this.data = data;
this.length = length;
this.method = method;
- this.headers = headers;
+ if (headers != null)
+ this.headers.putAll(headers);
String queryString = getQueryString();
if (queryString != null)
{
parameters.putAll(parseQueryString(queryString));
}
+ session = new MockHttpSession();
}
/**
@@ -165,12 +172,8 @@
*/
public String getContentType()
{
- // return headers.getFirst("content-type");
- synchronized (headers)
- {
- if (headers.get("content-type") != null)
- return (String)headers.get("content-type");
- }
+ if (headers.get("content-type") != null)
+ return headers.get("content-type").get(0);
return (null);
}
@@ -198,12 +201,8 @@
*/
public long getDateHeader(String name)
{
- // return Long.valueOf(headers.get(name));
- synchronized (headers)
- {
- if (headers.get(name) != null)
- return (Long)headers.get(0);
- }
+ if (headers.get(name) != null)
+ return Long.valueOf(headers.get(name).get(0));
return -1L;
}
@@ -212,12 +211,8 @@
*/
public String getHeader(String name)
{
- // return headers.get(name);
- synchronized (headers)
- {
- if (headers.get(name) != null)
- return (String)headers.get(name);
- }
+ if (headers.get(name) != null)
+ return headers.get(name).get(0);
return (null);
}
@@ -265,18 +260,8 @@
*/
public int getIntHeader(String name)
{
- // return Integer.valueOf(headers.get(name));
- synchronized (headers)
- {
- if (headers.get(name) != null)
- try
- {
- return Integer.parseInt((String)headers.get(name));
- }
- catch (NumberFormatException e)
- {
- }
- }
+ if (headers.get(name) != null)
+ return Integer.parseInt(headers.get(name).get(0));
return -1;
}
@@ -565,7 +550,7 @@
*/
public HttpSession getSession()
{
- return null;
+ return session;
}
/**
@@ -573,7 +558,7 @@
*/
public HttpSession getSession(boolean b)
{
- return null;
+ return session;
}
/**
@@ -581,14 +566,7 @@
*/
public Principal getUserPrincipal()
{
- return new Principal()
- {
-
- public String getName()
- {
- return "root";
- }
- };
+ return principal == null ? principal = new MockPrincipal("root") : principal;
}
/**
@@ -628,7 +606,7 @@
*/
public boolean isSecure()
{
- return false;
+ return secure;
}
/**
@@ -677,9 +655,9 @@
parameters.put(name, arr);
}
- public static Map<String, ArrayList> parseQueryString(String rawQuery)
+ public static Map<String, List<String>> parseQueryString(String rawQuery)
{
- HashMap<String, ArrayList> m = new HashMap();
+ HashMap<String, List<String>> m = new HashMap<String, List<String>>();
if (rawQuery == null || rawQuery.length() == 0)
return m;
int p = 0;
@@ -707,13 +685,13 @@
if (m.get(name) == null)
{
- ArrayList<String> arr = new ArrayList<String>();
+ List<String> arr = new ArrayList<String>();
arr.add(value);
m.put(name, arr);
}
else
{
- ArrayList<String> arr = m.get(name);
+ List<String> arr = m.get(name);
arr.add(value);
}
p = n + 1;
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java 2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java 2009-09-10 11:21:01 UTC (rev 165)
@@ -26,6 +26,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
@@ -60,10 +61,10 @@
private int bufferCount = 0;
/** The cookies. */
- private ArrayList cookies = new ArrayList();
+ private List<Cookie> cookies = new ArrayList<Cookie>();
/** The headers. */
- private HashMap headers = new CaseInsensitiveMap();
+ private HashMap<String, List<String>> headers = new CaseInsensitiveMultivaluedMap<String>();
/** The status. */
private int status = HttpServletResponse.SC_OK;
Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java 2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java 2009-09-10 11:21:01 UTC (rev 165)
@@ -23,11 +23,19 @@
*/
public class MockPrincipal implements java.security.Principal
{
+
+ private final String username;
+
+ public MockPrincipal(String username)
+ {
+ this.username = username;
+ }
+
/**
* {@inheritDoc}
*/
public String getName()
{
- return "PrincipalMackName";
+ return username;
}
}
14 years, 7 months