exo-jcr SVN: r2706 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-06-25 09:15:29 -0400 (Fri, 25 Jun 2010)
New Revision: 2706
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
Log:
EXOJCR-797 resp.getText replaced with resp.getData().
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-06-25 08:53:00 UTC (rev 2705)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-06-25 13:15:29 UTC (rev 2706)
@@ -79,7 +79,7 @@
if (resp.getStatusCode() >= 300)
{
LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
+ LOG.error(new String(resp.getData()));
}
return resp;
}
@@ -105,7 +105,7 @@
if (resp.getStatusCode() >= 300)
{
LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
+ LOG.error(new String(resp.getData()));
}
return resp;
}
@@ -131,7 +131,7 @@
if (resp.getStatusCode() >= 300)
{
LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
+ LOG.error(new String(resp.getData()));
}
return resp;
}
@@ -154,7 +154,7 @@
if (resp.getStatusCode() >= 300)
{
LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
+ LOG.error(new String(resp.getData()));
}
return resp;
}
13 years, 10 months
exo-jcr SVN: r2705 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-25 04:53:00 -0400 (Fri, 25 Jun 2010)
New Revision: 2705
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
Log:
EXOJCR-230 : simlify test by using ResourceLauncher
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-25 08:51:18 UTC (rev 2704)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-25 08:53:00 UTC (rev 2705)
@@ -24,17 +24,18 @@
import org.exoplatform.services.jcr.ext.registry.RESTRegistryTest.DummyContainerResponseWriter;
import org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoader.ScriptMetadata;
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.InputHeadersMap;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.impl.ResourceBinder;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
import org.exoplatform.services.security.ConversationState;
import org.exoplatform.services.security.Identity;
import java.io.ByteArrayInputStream;
-import java.net.URI;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Calendar;
import javax.jcr.Node;
@@ -54,6 +55,7 @@
private ResourceBinder binder;
+ @Deprecated
private RequestHandler handler;
private ThreadLocalSessionProviderService sesProv;
@@ -66,6 +68,8 @@
private int resourceNumber = 0;
+ private ResourceLauncher launcher;
+
/**
* {@inheritDoc}
*/
@@ -93,6 +97,8 @@
// repository for groovy dependencies
groovyRepo = root.addNode("repo", "nt:folder");
+ launcher = new ResourceLauncher(handler);
+
session.save();
}
@@ -121,68 +127,47 @@
{
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.putSingle("Accept", MediaType.APPLICATION_JSON);
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/meta/db1/ws/testRoot/script"), new URI(""), null,
- new InputHeadersMap(headers));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
-
- assertEquals(200, cres.getStatus());
- ScriptMetadata data = (ScriptMetadata)cres.getEntity();
+ ContainerResponse response =
+ launcher.service("POST", "/script/groovy/meta/db1/ws/testRoot/script", "", headers, null, null);
+ assertEquals(200, response.getStatus());
+ ScriptMetadata data = (ScriptMetadata)response.getEntity();
assertEquals("script/groovy", data.getMediaType());
assertTrue(Boolean.valueOf(data.getLoad()));
}
public void testRemoteAccessAutoload() throws Exception
{
- MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/autoload/db1/ws/testRoot/script?state=false"),
- new URI(""), null, new InputHeadersMap(headers));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/autoload/db1/ws/testRoot/script?state=false", "", null, null, null);
+
assertEquals(204, cres.getStatus());
assertFalse(script.getProperty("exo:autoload").getBoolean());
- creq =
- new ContainerRequest("POST", new URI("/script/groovy/autoload/db1/ws/testRoot/script"), new URI(""), null,
- new InputHeadersMap(headers));
- cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+ cres = launcher.service("POST", "/script/groovy/autoload/db1/ws/testRoot/script", "", null, null, null);
+
assertEquals(204, cres.getStatus());
assertTrue(script.getProperty("exo:autoload").getBoolean());
}
public void testRemoteAccessLoad() throws Exception
{
- MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/load/db1/ws/testRoot/script?state=false"), new URI(""),
- null, new InputHeadersMap(headers));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/load/db1/ws/testRoot/script?state=false", "", null, null, null);
assertEquals(204, cres.getStatus());
assertEquals(resourceNumber, binder.getSize());
- creq =
- new ContainerRequest("POST", new URI("/script/groovy/load/db1/ws/testRoot/script"), new URI(""), null,
- new InputHeadersMap(headers));
- cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+ launcher.service("POST", "/script/groovy/load/db1/ws/testRoot/script", "", null, null, null);
+
assertEquals(204, cres.getStatus());
assertEquals(resourceNumber + 1, binder.getSize());
}
public void testRemoteAccessDelete() throws Exception
{
- MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/delete/db1/ws/testRoot/script"), new URI(""), null,
- new InputHeadersMap(headers));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/delete/db1/ws/testRoot/script", "", null, null, null);
assertEquals(204, cres.getStatus());
assertEquals(resourceNumber, binder.getSize());
@@ -192,13 +177,9 @@
{
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.putSingle("Accept", "script/groovy");
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/src/db1/ws/testRoot/script"), new URI(""), null,
- new InputHeadersMap(headers));
ByteArrayContainerResponseWriter wr = new ByteArrayContainerResponseWriter();
- ContainerResponse cres = new ContainerResponse(wr);
- handler.handleRequest(creq, cres);
-
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/src/db1/ws/testRoot/script", "", headers, null, wr, null);
assertEquals(200, cres.getStatus());
compareStream(script.getProperty("jcr:data").getStream(), new ByteArrayInputStream(wr.getBody()));
}
@@ -209,26 +190,18 @@
session.save();
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.putSingle("Content-type", "script/groovy");
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/add/db1/ws/testRoot/script"), new URI(""), Thread
- .currentThread().getContextClassLoader().getResourceAsStream("test1.groovy"), new InputHeadersMap(headers));
- ByteArrayContainerResponseWriter wr = new ByteArrayContainerResponseWriter();
- ContainerResponse cres = new ContainerResponse(wr);
- handler.handleRequest(creq, cres);
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/add/db1/ws/testRoot/script", "", headers,
+ getResourceAsBytes("test1.groovy"), null, null);
+
assertEquals(201, cres.getStatus());
}
public void testDispatchScript() throws Exception
{
- ContainerRequest creq =
- new ContainerRequest("GET", new URI("/groovy-test/groovy1/test"), new URI(""), null, new InputHeadersMap(
- new MultivaluedMapImpl()));
+ ContainerResponse cres = launcher.service("GET", "/groovy-test/groovy1/test", "", null, null, null);
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
-
- handler.handleRequest(creq, cres);
-
assertEquals(200, cres.getStatus());
assertEquals("Hello from groovy to test", cres.getEntity());
@@ -239,12 +212,9 @@
// must be rebounded , not created other one
assertEquals(resourceNumber + 1, binder.getSize());
- creq =
- new ContainerRequest("GET", new URI("/groovy-test/groovy2/test"), new URI(""), null, new InputHeadersMap(
- new MultivaluedMapImpl()));
cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+ cres = launcher.service("GET", "/groovy-test/groovy2/test", "", null, null, null);
assertEquals(200, cres.getStatus());
assertEquals("Hello from groovy to >>>>> test", cres.getEntity());
}
@@ -254,20 +224,14 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.putSingle("Content-Type", "script/groovy");
String script = "public class Test { def a = 0\ndef =\n}\n";
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/validate/%5Bno-name%5D"), new URI(""),
- new ByteArrayInputStream(script.getBytes()), new InputHeadersMap(headers));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/validate/%5Bno-name%5D", "", headers, script.getBytes(), null);
assertEquals(400, cres.getStatus());
System.out.println(cres.getEntity());
- // cres.setResponse(null); //reset response
script = "public class Test { def a = 0\ndef b = 1\n }\n";
- creq =
- new ContainerRequest("POST", new URI("/script/groovy/validate/%5Bno-name%5D"), new URI(""),
- new ByteArrayInputStream(script.getBytes()), new InputHeadersMap(headers));
- handler.handleRequest(creq, cres);
+ cres = launcher.service("POST", "/script/groovy/validate/%5Bno-name%5D", "", headers, script.getBytes(), null);
assertEquals(200, cres.getStatus());
}
@@ -276,21 +240,16 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.putSingle("Content-Type", "script/groovy");
String script = "public class Test { def a = 0\ndef =\n}\n";
- ContainerRequest creq =
- new ContainerRequest("POST", new URI("/script/groovy/validate/"), new URI(""), new ByteArrayInputStream(script
- .getBytes()), new InputHeadersMap(headers));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+
+ ContainerResponse cres =
+ launcher.service("POST", "/script/groovy/validate/", "", headers, script.getBytes(), null);
assertEquals(400, cres.getStatus());
System.out.println(cres.getEntity());
- // cres.setResponse(null); //reset response
script = "public class Test { def a = 0\ndef b = 1\n }\n";
- creq =
- new ContainerRequest("POST", new URI("/script/groovy/validate/"), new URI(""), new ByteArrayInputStream(script
- .getBytes()), new InputHeadersMap(headers));
- handler.handleRequest(creq, cres);
+ cres = launcher.service("POST", "/script/groovy/validate/", "", headers, script.getBytes(), null);
assertEquals(200, cres.getStatus());
+
}
public void testGroovyDependency() throws Exception
@@ -312,13 +271,29 @@
// must be rebounded , not created other one
assertEquals(resourceNumber + 1, binder.getSize());
- ContainerRequest creq =
- new ContainerRequest("GET", new URI("/groovy-test-dependency"), new URI(""), null, new InputHeadersMap(
- new MultivaluedMapImpl()));
- ContainerResponse cres = new ContainerResponse(new DummyContainerResponseWriter());
- handler.handleRequest(creq, cres);
+
+ ContainerResponse cres = launcher.service("GET", "/groovy-test-dependency", "", null, null, null);
assertEquals(200, cres.getStatus());
assertEquals("dependencies.Dep1", cres.getEntity());
}
+
+ private byte[] getResourceAsBytes(String resource) throws IOException
+ {
+ byte[] data = null;
+ InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ if (stream != null)
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ byte[] buf = new byte[1024];
+ int r = -1;
+ while ((r = stream.read(buf)) != -1)
+ {
+ bout.write(buf, 0, r);
+ }
+ data = bout.toByteArray();
+ }
+ return data;
+ }
+
}
13 years, 10 months
exo-jcr SVN: r2704 - ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-25 04:51:18 -0400 (Fri, 25 Jun 2010)
New Revision: 2704
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
Log:
EXOJCR-230
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java 2010-06-25 05:28:07 UTC (rev 2703)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java 2010-06-25 08:51:18 UTC (rev 2704)
@@ -33,6 +33,8 @@
import java.util.Map;
/**
+ * Request launcher. It can be useful for testing services.
+ *
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id$
*/
13 years, 10 months
exo-jcr SVN: r2703 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-25 01:28:07 -0400 (Fri, 25 Jun 2010)
New Revision: 2703
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
Log:
EXOJCR-482
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-06-24 19:19:47 UTC (rev 2702)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/groovy/DefaultGroovyResourceLoader.java 2010-06-25 05:28:07 UTC (rev 2703)
@@ -21,7 +21,6 @@
import groovy.lang.GroovyResourceLoader;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -72,7 +71,7 @@
*/
public final URL loadGroovySource(String classname) throws MalformedURLException
{
- final String filename = classname.replace('.', File.separatorChar) + ".groovy";
+ final String filename = classname.replace('.', '/') + ".groovy";
try
{
return AccessController.doPrivileged(new PrivilegedExceptionAction<URL>()
13 years, 10 months
exo-jcr SVN: r2702 - in jcr/trunk/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/core/security and 3 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-06-24 15:19:47 -0400 (Thu, 24 Jun 2010)
New Revision: 2702
Modified:
jcr/trunk/exo.jcr.component.core/pom.xml
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java
jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
Log:
EXOJCR-764: To definitively fix the issue I had to check the permission in SessionFactory.createSession
What has been done:
1. Re-add the security test for the profile run-all
2. Move the permission check from RepositoryImpl.getSystemSession(..) to SessionFactory.createSession
3. The related unit test added
4. Fix the other tests
5. Renamed the permission "getJCRSystemSession" to "createSystemSession"
Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml 2010-06-24 19:19:31 UTC (rev 2701)
+++ jcr/trunk/exo.jcr.component.core/pom.xml 2010-06-24 19:19:47 UTC (rev 2702)
@@ -728,8 +728,6 @@
<exclude>org/apache/jackrabbit/test/api/TestAll.java</exclude>
<exclude>org/apache/jackrabbit/test/api/**/Abstract*.java</exclude>
<exclude>org/apache/jackrabbit/test/api/**/FrozenNodeTest.java</exclude>
- <!-- security -->
- <exclude>org/exoplatform/services/jcr/impl/core/security/Test*.java</exclude>
</excludes>
</configuration>
</plugin>
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java 2010-06-24 19:19:31 UTC (rev 2701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java 2010-06-24 19:19:47 UTC (rev 2702)
@@ -25,7 +25,7 @@
public class JCRRuntimePermissions
{
- public static final RuntimePermission GET_SYSTEM_SESSION_PERMISSION = new RuntimePermission("getJCRSystemSession");
+ public static final RuntimePermission CREATE_SYSTEM_SESSION_PERMISSION = new RuntimePermission("createSystemSession");
public static final RuntimePermission MANAGE_REPOSITORY_PERMISSION = new RuntimePermission("manageRepository");
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2010-06-24 19:19:31 UTC (rev 2701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2010-06-24 19:19:47 UTC (rev 2702)
@@ -400,12 +400,6 @@
*/
public SessionImpl getSystemSession(String workspaceName) throws RepositoryException
{
- // Need privileges to get system session.
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- {
- security.checkPermission(JCRRuntimePermissions.GET_SYSTEM_SESSION_PERMISSION);
- }
if (getState() == OFFLINE)
LOG.warn("Repository " + getName() + " is OFFLINE.");
@@ -574,9 +568,9 @@
ConversationState state;
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ PrivilegedExceptionAction<ConversationState> action = new PrivilegedExceptionAction<ConversationState>()
{
- public Object run() throws Exception
+ public ConversationState run() throws Exception
{
if (credentials != null)
return authenticationPolicy.authenticate(credentials);
@@ -586,7 +580,7 @@
};
try
{
- state = (ConversationState)AccessController.doPrivileged(action);
+ state = AccessController.doPrivileged(action);
}
catch (PrivilegedActionException pae)
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-06-24 19:19:31 UTC (rev 2701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-06-24 19:19:47 UTC (rev 2702)
@@ -21,11 +21,13 @@
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.dataflow.session.TransactionableResourceManager;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.ConversationState;
+import org.exoplatform.services.security.IdentityConstants;
import org.exoplatform.services.transaction.TransactionService;
import javax.jcr.LoginException;
@@ -116,11 +118,20 @@
* Creates Session object by given Credentials
*
* @param credentials
- * @return XASessionImpl if TransactionService present or SessionImpl otherwice
+ * @return XASessionImpl if TransactionService present or SessionImpl otherwise
* @throws RepositoryException
*/
SessionImpl createSession(ConversationState user) throws RepositoryException, LoginException
{
+ if (IdentityConstants.SYSTEM.equals(user.getIdentity().getUserId()))
+ {
+ // Need privileges to get system session.
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(JCRRuntimePermissions.CREATE_SYSTEM_SESSION_PERMISSION);
+ }
+ }
if (tService == null)
{
if (SessionReference.isStarted())
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java 2010-06-24 19:19:31 UTC (rev 2701)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java 2010-06-24 19:19:47 UTC (rev 2702)
@@ -20,8 +20,10 @@
package org.exoplatform.services.jcr.impl.core.security;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.CredentialsImpl;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.impl.dataflow.serialization.TesterItemsPersistenceListener;
+import org.exoplatform.services.security.IdentityConstants;
import java.security.AccessControlException;
import java.security.PrivilegedExceptionAction;
@@ -85,6 +87,32 @@
}
}
+ public void testGetSystemSessionFail2()
+ {
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ repository.login(new CredentialsImpl(IdentityConstants.SYSTEM, "".toCharArray()), repository.getSystemWorkspaceName());
+ return null;
+ }
+
+ };
+ try
+ {
+ doPrivilegedAction(action);
+ fail("Must not be able get system session.");
+ }
+ catch (AccessControlException ace)
+ {
+ // OK
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ fail();
+ }
+ }
public void testAddItemPersistenceListenerSuccess()
{
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
@@ -174,9 +202,30 @@
fail();
}
- // remove configured workspace
- repository.createWorkspace("testConfigWorkspaceSuccess");
- repository.internalRemoveWorkspace("testConfigWorkspaceSuccess");
+ action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ // remove configured workspace
+ repository.createWorkspace("testConfigWorkspaceSuccess");
+ repository.internalRemoveWorkspace("testConfigWorkspaceSuccess");
+ return null;
+ }
+
+ };
+ try
+ {
+ doPrivilegedActionStaticPermissions(action);
+ }
+ catch (AccessControlException ace)
+ {
+ fail("Must be able config workspace. We are under static permissions");
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ fail();
+ }
}
public void testConfigWorkspaceFail() throws Exception
@@ -223,7 +272,7 @@
WorkspaceEntry defConfig =
(WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
- WorkspaceEntry wsConfig = new WorkspaceEntry();
+ final WorkspaceEntry wsConfig = new WorkspaceEntry();
wsConfig.setName("testCreateWorkspaceSuccess");
wsConfig.setAccessManager(defConfig.getAccessManager());
@@ -231,12 +280,11 @@
wsConfig.setContainer(defConfig.getContainer());
wsConfig.setLockManager(defConfig.getLockManager());
- repository.configWorkspace(wsConfig);
-
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
{
+ repository.configWorkspace(wsConfig);
repository.createWorkspace("testCreateWorkspaceSuccess");
return null;
}
@@ -255,9 +303,30 @@
t.printStackTrace();
fail();
}
+ action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ // remove configured workspace
+ repository.internalRemoveWorkspace("testCreateWorkspaceSuccess");
+ return null;
+ }
- // remove configured workspace
- repository.internalRemoveWorkspace("testCreateWorkspaceSuccess");
+ };
+ try
+ {
+ doPrivilegedActionStaticPermissions(action);
+ }
+ catch (AccessControlException ace)
+ {
+ fail("Must be able config workspace. We are under static permissions");
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ fail();
+ }
+
}
public void testCreateWorkspaceFail()
@@ -293,7 +362,7 @@
WorkspaceEntry defConfig =
(WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
- WorkspaceEntry wsConfig = new WorkspaceEntry();
+ final WorkspaceEntry wsConfig = new WorkspaceEntry();
wsConfig.setName("testInternalRemoveWorkspaceSuccess");
wsConfig.setAccessManager(defConfig.getAccessManager());
@@ -301,13 +370,13 @@
wsConfig.setContainer(defConfig.getContainer());
wsConfig.setLockManager(defConfig.getLockManager());
- repository.configWorkspace(wsConfig);
- repository.createWorkspace("testInternalRemoveWorkspaceSuccess");
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
{
+ repository.configWorkspace(wsConfig);
+ repository.createWorkspace("testInternalRemoveWorkspaceSuccess");
repository.internalRemoveWorkspace("testInternalRemoveWorkspaceSuccess");
return null;
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-24 19:19:31 UTC (rev 2701)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-24 19:19:47 UTC (rev 2702)
@@ -7,6 +7,6 @@
};
grant codeBase "@TEST_CLASSES@-"{
- permission java.lang.RuntimePermission "getJCRSystemSession";
+ permission java.lang.RuntimePermission "createSystemSession";
permission java.lang.RuntimePermission "manageRepository";
};
13 years, 10 months
exo-jcr SVN: r2701 - core/trunk/exo.core.component.document/src/test/resources.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-06-24 15:19:31 -0400 (Thu, 24 Jun 2010)
New Revision: 2701
Modified:
core/trunk/exo.core.component.document/src/test/resources/test.policy
Log:
EXOJCR-764: To definitively fix the issue I had to check the permission in SessionFactory.createSession
What has been done:
1. Re-add the security test for the profile run-all
2. Move the permission check from RepositoryImpl.getSystemSession(..) to SessionFactory.createSession
3. The related unit test added
4. Fix the other tests
5. Renamed the permission "getJCRSystemSession" to "createSystemSession"
Modified: core/trunk/exo.core.component.document/src/test/resources/test.policy
===================================================================
--- core/trunk/exo.core.component.document/src/test/resources/test.policy 2010-06-24 15:19:13 UTC (rev 2700)
+++ core/trunk/exo.core.component.document/src/test/resources/test.policy 2010-06-24 19:19:31 UTC (rev 2701)
@@ -7,6 +7,6 @@
};
grant codeBase "@TEST_CLASSES@-"{
- permission java.lang.RuntimePermission "getJCRSystemSession";
+ permission java.lang.RuntimePermission "createSystemSession";
permission java.lang.RuntimePermission "manageRepository";
};
13 years, 10 months
exo-jcr SVN: r2700 - in jcr/branches/1.12.x/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/usecases and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-06-24 11:19:13 -0400 (Thu, 24 Jun 2010)
New Revision: 2700
Added:
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
Log:
EXOJCR-813: ItemImpl.getParent method return session pooled parent
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-06-24 15:17:59 UTC (rev 2699)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-06-24 15:19:13 UTC (rev 2700)
@@ -224,7 +224,7 @@
if (isRoot())
throw new ItemNotFoundException("Root node does not have a parent");
- return parent();
+ return parent(true);
}
/**
@@ -723,27 +723,32 @@
return getData().getQPath().getName();
}
- protected ItemImpl item(String identifier) throws RepositoryException
+ /**
+ * Get parent node item. Session pool is ignored.
+ *
+ * @return parent item
+ * @throws RepositoryException if parent item is null
+ */
+ protected NodeImpl parent() throws RepositoryException
{
- return dataManager.getItemByIdentifier(identifier, false);
+ return parent(false);
}
/**
- * Get parent node item.
+ * Get parent node item.
*
+ * @param pool - take a parent from session pool
* @return parent item
- * @throws RepositoryException
- * if parent item is null
+ * @throws RepositoryException if parent item is null
*/
- protected NodeImpl parent() throws RepositoryException
+ protected NodeImpl parent(final boolean pool) throws RepositoryException
{
- NodeImpl parent = (NodeImpl)item(getParentIdentifier());
+ NodeImpl parent = (NodeImpl)dataManager.getItemByIdentifier(getParentIdentifier(), pool);
if (parent == null)
{
throw new ItemNotFoundException("FATAL: Parent is null for " + getPath() + " parent UUID: "
+ getParentIdentifier());
}
-
return parent;
}
Added: jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java (rev 0)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java 2010-06-24 15:19:13 UTC (rev 2700)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2003-2010 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.services.jcr.usecases;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestMixin.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestMixin extends BaseUsecasesTest
+{
+
+ public void testMixin() throws Exception
+ {
+ Node a = session.getRootNode().addNode("a");
+ a.addMixin("mix:referenceable");
+
+ Property p = a.setProperty("prop", "string");
+ Node a1 = p.getParent();
+
+ a1.addMixin("mix:lockable");
+ a.addMixin("mix:versionable");
+ session.save();
+
+ //check result
+ Node a2 = session.getRootNode().getNode("a");
+ assertTrue(a2.isNodeType("mix:referenceable"));
+ assertTrue(a2.isNodeType("mix:versionable"));
+ assertTrue(a2.isNodeType("mix:lockable"));
+ }
+}
13 years, 10 months
exo-jcr SVN: r2699 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/usecases and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-06-24 11:17:59 -0400 (Thu, 24 Jun 2010)
New Revision: 2699
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
Log:
EXOJCR-813: ItemImpl.getParent method return session pooled parent
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-06-24 15:06:31 UTC (rev 2698)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-06-24 15:17:59 UTC (rev 2699)
@@ -223,7 +223,7 @@
if (isRoot())
throw new ItemNotFoundException("Root node does not have a parent");
- return parent();
+ return parent(true);
}
/**
@@ -726,26 +726,32 @@
return getData().getQPath().getName();
}
- protected ItemImpl item(String identifier) throws RepositoryException
+ /**
+ * Get parent node item. Session pool is ignored.
+ *
+ * @return parent item
+ * @throws RepositoryException if parent item is null
+ */
+ protected NodeImpl parent() throws RepositoryException
{
- return dataManager.getItemByIdentifier(identifier, false);
+ return parent(false);
}
/**
- * Get parent node item.
+ * Get parent node item.
*
+ * @param pool - take a parent from session pool
* @return parent item
* @throws RepositoryException if parent item is null
*/
- protected NodeImpl parent() throws RepositoryException
+ protected NodeImpl parent(final boolean pool) throws RepositoryException
{
- NodeImpl parent = (NodeImpl)item(getParentIdentifier());
+ NodeImpl parent = (NodeImpl)dataManager.getItemByIdentifier(getParentIdentifier(), pool);
if (parent == null)
{
throw new ItemNotFoundException("FATAL: Parent is null for " + getPath() + " parent UUID: "
+ getParentIdentifier());
}
-
return parent;
}
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestMixin.java 2010-06-24 15:17:59 UTC (rev 2699)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2003-2010 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.services.jcr.usecases;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestMixin.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestMixin extends BaseUsecasesTest
+{
+
+ /**
+ * There is usecase when changes in NodeImpl fetched with getParent() do not
+ * cause on other NodeImpl objects.
+ *
+ * @throws Exception
+ */
+ public void testMixin() throws Exception
+ {
+ Node a = session.getRootNode().addNode("a");
+ a.addMixin("mix:referenceable");
+
+ Property p = a.setProperty("prop", "string");
+ Node a1 = p.getParent();
+
+ a1.addMixin("mix:lockable");
+ a.addMixin("mix:versionable");
+ session.save();
+
+ //check result
+ Node a2 = session.getRootNode().getNode("a");
+ assertTrue(a2.isNodeType("mix:referenceable"));
+ assertTrue(a2.isNodeType("mix:versionable"));
+ assertTrue(a2.isNodeType("mix:lockable"));
+ }
+}
13 years, 10 months
exo-jcr SVN: r2698 - in ws/trunk: exo.ws.rest.core/src/test/java/org/exoplatform/services/rest and 6 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-24 11:06:31 -0400 (Thu, 24 Jun 2010)
New Revision: 2698
Added:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
Removed:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
Modified:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ExceptionsTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java
ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java
Log:
EXOJCR-230 :
Added: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java (rev 0)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -0,0 +1,101 @@
+/**
+ * Copyright (C) 2010 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 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;
+
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @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);
+
+ if (writer == null)
+ writer = new DummyContainerResponseWriter();
+
+ 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,
+ Map<String, List<String>> headers, byte[] data, EnvironmentContext env) throws Exception
+ {
+ return service(method, requestURI, baseURI, headers, data, new DummyContainerResponseWriter(), env);
+ }
+
+}
Property changes on: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/tools/ResourceLauncher.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/AbstractResourceTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -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.services.rest;
-
-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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -25,6 +25,7 @@
import org.exoplatform.services.rest.impl.ProviderBinder;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
import org.exoplatform.services.rest.impl.ResourceBinder;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
@@ -41,6 +42,8 @@
protected RequestHandlerImpl requestHandler;
+ protected ResourceLauncher launcher;
+
public void setUp() throws Exception
{
StandaloneContainer.setConfigurationPath("src/test/resources/conf/standalone/test-configuration.xml");
@@ -53,6 +56,7 @@
// System.out.println("##########################"+providers);
ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers));
binder.clear();
+ launcher = new ResourceLauncher(requestHandler);
}
public void tearDown() throws Exception
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ExceptionsTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ExceptionsTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ExceptionsTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.ExtHttpHeaders;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
@@ -34,7 +34,7 @@
* @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
* @version $Id: ExceptionsTest
*/
-public class ExceptionsTest extends AbstractResourceTest
+public class ExceptionsTest extends BaseTest
{
@Path("a")
@@ -100,7 +100,7 @@
public void testErrorResponse() throws Exception
{
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = service("GET", "/a/4", "", null, null, writer);
+ ContainerResponse response = launcher.service("GET", "/a/4", "", null, null, writer, null);
assertEquals(500, response.getStatus());
String entity = new String(writer.getBody());
assertEquals(errorMessage, entity);
@@ -110,7 +110,7 @@
public void testUncheckedException() throws Exception
{
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = service("GET", "/a/3", "", null, null, writer);
+ ContainerResponse response = launcher.service("GET", "/a/3", "", null, null, writer, null);
assertEquals(500, response.getStatus());
String entity = new String(writer.getBody());
assertEquals(errorMessage, entity);
@@ -120,7 +120,7 @@
public void testWebApplicationExceptionWithCause() throws Exception
{
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = service("GET", "/a/0", "", null, null, writer);
+ ContainerResponse response = launcher.service("GET", "/a/0", "", null, null, writer, null);
assertEquals(500, response.getStatus());
String entity = new String(writer.getBody());
assertEquals(new Exception(errorMessage).toString(), entity);
@@ -130,7 +130,7 @@
public void testWebApplicationExceptionWithoutCause() throws Exception
{
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = service("GET", "/a/2", "", null, null, writer);
+ ContainerResponse response = launcher.service("GET", "/a/2", "", null, null, writer, null);
assertEquals(500, response.getStatus());
assertNull(response.getEntity());
assertNull(response.getHttpHeaders().getFirst(ExtHttpHeaders.JAXRS_BODY_PROVIDED));
@@ -139,7 +139,7 @@
public void testWebApplicationExceptionWithResponse() throws Exception
{
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse response = service("GET", "/a/1", "", null, null, writer);
+ ContainerResponse response = launcher.service("GET", "/a/1", "", null, null, writer, null);
assertEquals(500, response.getStatus());
String entity = new String(writer.getBody());
assertEquals(errorMessage, entity);
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestDispatcherTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,9 +18,10 @@
*/
package org.exoplatform.services.rest.impl;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.Property;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Encoded;
@@ -39,7 +40,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class RequestDispatcherTest extends AbstractResourceTest
+public class RequestDispatcherTest extends BaseTest
{
@Path("/a")
@@ -107,12 +108,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);
}
@@ -153,10 +154,10 @@
{
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);
}
@@ -208,9 +209,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);
}
@@ -258,7 +259,14 @@
{
container.registerComponentInstance(TestContainerComponent.class.getName(), new TestContainerComponent());
registry(Resource4.class);
- service("GET", "/aaa/bbb", "", null, null);
+
+ EnvironmentContext envctx = new EnvironmentContext();
+
+ HttpServletRequest httpRequest = new MockHttpServletRequest("/aaa/bbb", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+
+ launcher.service("GET", "/aaa/bbb", "", null, null, envctx);
+
unregistry(Resource4.class);
}
@@ -287,12 +295,13 @@
public void testResourceConstructorFail() 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());
unregistry(ResourceFail.class);
}
+
//--------------------------------------
@Path("a/{b}/{c}")
@@ -328,16 +337,16 @@
public void testResource5() 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);
}
//--------------------------------------
-
+
public void testFieldSuperClass() throws Exception
{
registry(EndResource.class);
- service("GET", "/a", "", null, null);
+ launcher.service("GET", "/a", "", null, null, null);
unregistry(EndResource.class);
}
@@ -348,7 +357,7 @@
@Context
public Request request;
-
+
@Context
protected UriInfo something;
}
@@ -365,7 +374,7 @@
{
@Context
private HttpHeaders header;
-
+
@Context
private SecurityContext something;
@@ -382,40 +391,40 @@
assertNotNull(header);
}
}
-
+
// -----------------------------------------------
-
+
public void testPropertyInjection() throws Exception
{
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);
-
+
}
@Path("a")
public static class Resource6
{
-
+
@Property("prop1")
private String prop1;
-
+
private final String prop2;
-
+
public Resource6(@Property("prop2") String cProp)
{
this.prop2 = cProp;
}
-
+
@GET
public void m1()
{
assertEquals("hello", prop1);
assertEquals("test", prop2);
}
-
+
}
-
+
}
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/RequestFilterTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,10 +18,11 @@
*/
package org.exoplatform.services.rest.impl;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.RequestFilter;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
@@ -37,7 +38,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class RequestFilterTest extends AbstractResourceTest
+public class RequestFilterTest extends BaseTest
{
@Filter
@@ -110,7 +111,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"));
@@ -124,8 +125,12 @@
// add filter that can change method
providers.addRequestFilter(RequestFilter1.class);
+ EnvironmentContext envctx = new EnvironmentContext();
+ HttpServletRequest httpRequest = new MockHttpServletRequest("/a", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+
// should get status 204
- ContainerResponse resp = service("GET", "/a", "", null, null);
+ ContainerResponse resp = launcher.service("GET", "/a", "", null, null, envctx);
assertEquals(204, resp.getStatus());
unregistry(Resource1.class);
@@ -135,7 +140,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"));
@@ -144,7 +149,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);
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/ResponseFilterTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,10 +18,11 @@
*/
package org.exoplatform.services.rest.impl;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.GenericContainerResponse;
import org.exoplatform.services.rest.ResponseFilter;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
@@ -37,7 +38,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ResponseFilterTest extends AbstractResourceTest
+public class ResponseFilterTest extends BaseTest
{
@Filter
@@ -99,7 +100,7 @@
@Produces("text/plain")
public String m1()
{
- // text/plain will be overridden in response filter
+ // text/plain will be overridden in response filter
return "{\"name\":\"andrew\", \"password\":\"hello\"}";
}
@@ -111,18 +112,23 @@
{
Resource1 r = new Resource1();
registry(r);
- ContainerResponse resp = service("POST", "/a", "", null, null);
+
+ EnvironmentContext envctx = new EnvironmentContext();
+ HttpServletRequest httpRequest = new MockHttpServletRequest("/a", null, 0, "POST", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+
+ ContainerResponse resp = launcher.service("POST", "/a", "", null, null, envctx);
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, envctx);
assertEquals(204, resp.getStatus());
// add response filter and try again
providers.addResponseFilter(ResponseFilter1.class);
- resp = service("POST", "/a", "", null, null);
+ resp = launcher.service("POST", "/a", "", null, null, envctx);
assertEquals(200, resp.getStatus());
assertEquals("text/plain", resp.getContentType().toString());
assertEquals("to be or not to be", resp.getEntity());
@@ -134,7 +140,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());
@@ -142,7 +148,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());
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/HeadMethodTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
@@ -27,11 +27,11 @@
/**
* Created by The eXo Platform SAS. <br/>
* Date: 21 Jan 2009
- *
+ *
* @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")
@@ -69,8 +69,8 @@
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 +78,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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MediaTypeTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import javax.ws.rs.Consumes;
@@ -32,13 +32,13 @@
/**
* Created by The eXo Platform SAS.
- *
+ *
* <br/>Date: 22 Jan 2009
*
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro Katayev</a>
- * @version $Id: MediaTypeTest.java
+ * @version $Id: MediaTypeTest.java
*/
-public class MediaTypeTest extends AbstractResourceTest
+public class MediaTypeTest extends BaseTest
{
@Path("/a")
@@ -90,21 +90,21 @@
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 +144,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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodInvokerFilterTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,13 +18,15 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.Filter;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.impl.ResourceBinder;
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.test.mock.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
@@ -40,7 +42,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class MethodInvokerFilterTest extends AbstractResourceTest
+public class MethodInvokerFilterTest extends BaseTest
{
@Filter
@@ -132,11 +134,26 @@
{
Resource1 r = new Resource1();
registry(r);
- assertEquals(204, service("GET", "/a/b", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a", "", null, null).getStatus());
+
+ EnvironmentContext envctx = new EnvironmentContext();
+
+ HttpServletRequest httpRequest = new MockHttpServletRequest("/a/b", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+ assertEquals(204, launcher.service("GET", "/a/b", "", null, null, envctx).getStatus());
+
+ httpRequest = new MockHttpServletRequest("/a", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+ assertEquals(204, launcher.service("GET", "/a", "", null, null, envctx).getStatus());
+
providers.addMethodInvokerFilter(MethodInvokerFilter1.class);
- assertEquals(400, service("GET", "/a/b", "", null, null).getStatus());
- assertEquals(204, service("GET", "/a", "", null, null).getStatus());
+
+ httpRequest = new MockHttpServletRequest("/a/b", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+ assertEquals(400, launcher.service("GET", "/a/b", "", null, null, envctx).getStatus());
+
+ httpRequest = new MockHttpServletRequest("/a", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+ assertEquals(204, launcher.service("GET", "/a", "", null, null, envctx).getStatus());
unregistry(r);
}
@@ -144,11 +161,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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import java.util.List;
@@ -34,7 +34,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")
@@ -92,30 +92,30 @@
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/0", "", null, null).getEntity());
+ assertEquals(204, launcher.service("GET", "/a/0", "", null, null, null).getStatus());
+ assertNull(launcher.service("GET", "/a/0", "", 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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/OptionsMethodTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -32,11 +32,11 @@
/**
* Created by The eXo Platform SAS. <br/>
* Date: 21 Jan 2009
- *
+ *
* @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)
@@ -74,13 +74,13 @@
{
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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/ParametersInjectionTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.method;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.Property;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
@@ -46,7 +46,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}")
@@ -222,46 +222,46 @@
{
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/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ContextResolverTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.rest.impl.provider;
+import org.exoplatform.services.rest.BaseTest;
+
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
@@ -26,7 +28,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ContextResolverTest extends org.exoplatform.services.rest.AbstractResourceTest
+public class ContextResolverTest extends BaseTest
{
@Provider
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ExceptionMapperTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
import javax.ws.rs.GET;
@@ -31,7 +31,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ExceptionMapperTest extends AbstractResourceTest
+public class ExceptionMapperTest extends BaseTest
{
public static class ExceptionMapper1 implements ExceptionMapper<IllegalArgumentException>
@@ -136,24 +136,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);
- // WebApplicationException with entity - must not be overridden
+ 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());
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/FormEntityTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -19,15 +19,19 @@
package org.exoplatform.services.rest.impl.provider;
import org.apache.commons.fileupload.FileItem;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+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 javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
@@ -38,7 +42,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class FormEntityTest extends AbstractResourceTest
+public class FormEntityTest extends BaseTest
{
@Path("/")
@@ -72,8 +76,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 +194,15 @@
h.putSingle("content-type", "multipart/form-data; boundary=abcdef");
byte[] data = out.toByteArray();
- assertEquals(204, service("POST", "/", "", h, data).getStatus());
+
+ EnvironmentContext envctx = new EnvironmentContext();
+
+ HttpServletRequest httpRequest =
+ new MockHttpServletRequest("/", new ByteArrayInputStream(data), data.length, "POST", h);
+ envctx.put(HttpServletRequest.class, httpRequest);
+
+ assertEquals(204, launcher.service("POST", "/", "", h, data, envctx).getStatus());
+
unregistry(r2);
}
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JAXBEntityTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.generated.Book;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
@@ -36,7 +36,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class JAXBEntityTest extends AbstractResourceTest
+public class JAXBEntityTest extends BaseTest
{
@Path("/")
@@ -79,7 +79,7 @@
book.setAuthor("William Shakespeare");
book.setTitle("Hamlet");
book.setSendByPost(true);
- // ignore some fields
+ // ignore some fields
return book;
}
@@ -91,7 +91,7 @@
book.setAuthor("William Shakespeare\n");
book.setTitle("Hamlet\n");
book.setSendByPost(false);
- // ignore some fields
+ // ignore some fields
return book;
}
}
@@ -111,10 +111,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 +127,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 +137,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();
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.generated.Book;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
@@ -35,7 +35,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class JsonEntityTest extends AbstractResourceTest
+public class JsonEntityTest extends BaseTest
{
@Path("/")
@@ -96,7 +96,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 +109,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 +118,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();
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/OtherEntityTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
@@ -52,7 +52,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class OtherEntityTest extends AbstractResourceTest
+public class OtherEntityTest extends BaseTest
{
@Path("/")
@@ -136,24 +136,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 +249,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 +275,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(
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/ProviderContextParameterInjectionTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,10 +18,13 @@
*/
package org.exoplatform.services.rest.impl.provider;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.provider.EntityProvider;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -30,6 +33,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
@@ -49,7 +53,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ProviderContextParameterInjectionTest extends AbstractResourceTest
+public class ProviderContextParameterInjectionTest extends BaseTest
{
public static class MockEntity
@@ -191,7 +195,7 @@
@Context
private Providers providers;
- @GET
+ @POST
@Path("1")
public MockEntity m0(MockEntity me)
{
@@ -221,13 +225,23 @@
{
registry(Resource1.class);
- ContainerResponse resp = service("GET", "/a/1", "", null, "to be or not to be".getBytes());
+ EnvironmentContext envctx = new EnvironmentContext();
+
+ HttpServletRequest httpRequest =
+ new MockHttpServletRequest("/a/1", new ByteArrayInputStream("to be or not to be".getBytes()), 18, "POST", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+
+ ContainerResponse resp = launcher.service("POST", "/a/1", "", null, "to be or not to be".getBytes(), envctx);
assertEquals("to be", ((MockEntity)resp.getEntity()).entity);
- resp = service("GET", "/a/2", "", null, null);
+ httpRequest = new MockHttpServletRequest("/a/2", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+ resp = launcher.service("GET", "/a/2", "", null, null, envctx);
assertEquals(200, resp.getStatus());
- resp = service("GET", "/a/3", "", null, null);
+ httpRequest = new MockHttpServletRequest("/a/3", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+ resp = launcher.service("GET", "/a/3", "", null, null, envctx);
assertEquals(200, resp.getStatus());
assertEquals("to be to not to be", resp.getEntity());
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AcceptResourceTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import javax.ws.rs.Consumes;
@@ -32,7 +32,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class AcceptResourceTest extends AbstractResourceTest
+public class AcceptResourceTest extends BaseTest
{
@Path("/a")
@@ -204,14 +204,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 +219,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();
}
}
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/AnnotationInheritanceTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -28,11 +28,11 @@
/**
* Created by The eXo Platform SAS. <br/>
* Date: 23 Jan 2009
- *
+ *
* @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
@@ -61,7 +61,7 @@
}
}
- //
+ //
public static interface ResourceInterface1
{
@@ -102,16 +102,16 @@
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);
}
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ApplicationTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.Filter;
import org.exoplatform.services.rest.GenericContainerRequest;
import org.exoplatform.services.rest.GenericContainerResponse;
@@ -41,7 +41,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ApplicationTest extends AbstractResourceTest
+public class ApplicationTest extends BaseTest
{
public static class Application1 extends javax.ws.rs.core.Application
@@ -151,7 +151,7 @@
}
}
-
+
@Filter
public static class MethodInvokerFilter1 implements MethodInvokerFilter
{
@@ -160,9 +160,9 @@
{
invFilter = true;
}
-
+
}
-
+
@Filter
public static class RequestFilter1 implements RequestFilter
{
@@ -171,9 +171,9 @@
{
requestFilter = true;
}
-
+
}
-
+
@Filter
public static class ResponseFilter1 implements ResponseFilter
{
@@ -182,7 +182,7 @@
{
responseFilter = true;
}
-
+
}
public void testRegistry()
@@ -199,40 +199,40 @@
private static boolean requestFilter = false;
private static boolean responseFilter = false;
private static boolean invFilter = false;
-
+
public void testAsResources() throws Exception
{
binder.addApplication(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());
-
+
// check are filters were visited
assertTrue(requestFilter);
assertTrue(responseFilter);
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/ContextParametersInjectionTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.InitialProperties;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.rest.impl.header.HeaderHelper;
@@ -38,7 +38,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class ContextParametersInjectionTest extends AbstractResourceTest
+public class ContextParametersInjectionTest extends BaseTest
{
@Path("/a/b")
@@ -231,17 +231,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());
}
}
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/resource/MatchedURIsAndResourcesTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.rest.impl.resource;
-import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.BaseTest;
import org.exoplatform.services.rest.impl.header.HeaderHelper;
import java.util.ArrayList;
@@ -33,7 +33,7 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-public class MatchedURIsAndResourcesTest extends AbstractResourceTest
+public class MatchedURIsAndResourcesTest extends BaseTest
{
@Path("/a/b")
@@ -114,10 +114,10 @@
{
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 +125,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 +136,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);
}
}
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/BaseTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -22,28 +22,13 @@
import junit.framework.TestCase;
import org.exoplatform.container.StandaloneContainer;
-import org.exoplatform.services.rest.ContainerResponseWriter;
import org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher;
import org.exoplatform.services.rest.impl.ApplicationContextImpl;
-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.impl.ProviderBinder;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
import org.exoplatform.services.rest.impl.ResourceBinder;
-import org.exoplatform.services.rest.tools.DummyContainerResponseWriter;
-import org.exoplatform.services.test.mock.MockHttpServletRequest;
+import org.exoplatform.services.rest.tools.ResourceLauncher;
-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$
@@ -60,6 +45,8 @@
protected GroovyJaxrsPublisher groovyPublisher;
+ protected ResourceLauncher launcher;
+
public void setUp() throws Exception
{
StandaloneContainer.setConfigurationPath("src/test/resources/conf/standalone/test-configuration.xml");
@@ -72,40 +59,11 @@
ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers));
binder.clear();
groovyPublisher = (GroovyJaxrsPublisher)container.getComponentInstanceOfType(GroovyJaxrsPublisher.class);
+ launcher = new ResourceLauncher(requestHandler);
}
public void tearDown() throws Exception
{
}
- 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(requestURI, 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/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyContextParamTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -21,10 +21,14 @@
import org.exoplatform.services.rest.ext.BaseTest;
import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.EnvironmentContext;
import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
+import org.exoplatform.services.test.mock.MockHttpServletRequest;
import java.io.InputStream;
+import javax.servlet.http.HttpServletRequest;
+
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: GroovyContextParamTest.java 2647 2010-06-17 08:39:29Z aparfonov
@@ -60,8 +64,16 @@
assertEquals(1, groovyPublisher.resources.size());
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
+
+ EnvironmentContext envctx = new EnvironmentContext();
+
+ HttpServletRequest httpRequest =
+ new MockHttpServletRequest("http://localhost:8080/context/a/b", null, 0, "GET", null);
+ envctx.put(HttpServletRequest.class, httpRequest);
+
ContainerResponse resp =
- service("GET", "http://localhost:8080/context/a/b", "http://localhost:8080/context", null, null, writer);
+ launcher.service("GET", "http://localhost:8080/context/a/b", "http://localhost:8080/context", null, null,
+ writer, envctx);
assertEquals(200, resp.getStatus());
assertEquals("GET\n/context/a/b", new String(writer.getBody()));
}
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyDependenciesTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -50,7 +50,7 @@
{
groovyPublisher.publishPerRequest(script, new BaseResourceId("GMain1"));
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse resp = service("GET", "/a", "", null, null, writer);
+ ContainerResponse resp = launcher.service("GET", "/a", "", null, null, writer, null);
assertEquals(200, resp.getStatus());
assertEquals("dependencies.Dep1", new String(writer.getBody()));
}
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovyExoComponentTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -75,7 +75,7 @@
assertEquals(1, groovyPublisher.resources.size());
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse resp = service("GET", "/a/b", "", null, null, writer);
+ ContainerResponse resp = launcher.service("GET", "/a/b", "", null, null, writer, null);
assertEquals(200, resp.getStatus());
assertEquals("exo container's component", new String(writer.getBody()));
}
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySecureRestrictionTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -47,7 +47,7 @@
{
groovyPublisher.publishPerRequest(script, new BaseResourceId("g1"));
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse resp = service("GET", "/a/b", "", null, null, writer);
+ ContainerResponse resp = launcher.service("GET", "/a/b", "", null, null, writer, null);
assertEquals(500, resp.getStatus());
assertTrue(new String(writer.getBody()).startsWith("access denied"));
}
Modified: ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java 2010-06-24 15:00:00 UTC (rev 2697)
+++ ws/trunk/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/groovy/GroovySimpleTest.java 2010-06-24 15:06:31 UTC (rev 2698)
@@ -73,7 +73,7 @@
assertEquals("file:/groovy/script/jaxrs", cs);
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
- ContainerResponse resp = service("GET", "/a/groovy", "", null, null, writer);
+ ContainerResponse resp = launcher.service("GET", "/a/groovy", "", null, null, writer, null);
assertEquals(200, resp.getStatus());
assertEquals("hello groovy", new String(writer.getBody()));
13 years, 10 months
exo-jcr SVN: r2697 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-24 11:00:00 -0400 (Thu, 24 Jun 2010)
New Revision: 2697
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
Log:
EXOJCR-482
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-24 14:59:24 UTC (rev 2696)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-24 15:00:00 UTC (rev 2697)
@@ -303,6 +303,8 @@
dep.setProperty("jcr:lastModified", Calendar.getInstance());
dep.setProperty("jcr:data", "package dependencies; class Dep1 { String name = getClass().getName() }");
+ session.save();
+
script.setProperty("jcr:data", Thread.currentThread().getContextClassLoader().getResourceAsStream(
"TestDependency.groovy"));
13 years, 10 months