[exo-jcr-commits] exo-jcr SVN: r1334 - in ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl: method and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 11 04:47:11 EST 2010


Author: max_shaposhnik
Date: 2010-01-11 04:47:10 -0500 (Mon, 11 Jan 2010)
New Revision: 1334

Added:
   ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java
   ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
Log:
https://jira.jboss.org/jira/browse/EXOJCR-353;

Added: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java	                        (rev 0)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java	2010-01-11 09:47:10 UTC (rev 1334)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.impl;
+
+import org.exoplatform.services.rest.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 org.exoplatform.services.rest.ContainerResponseWriter;
+
+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 at 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());
+
+   }
+
+}


Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/AbstractResourceTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
===================================================================
--- ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java	                        (rev 0)
+++ ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java	2010-01-11 09:47:10 UTC (rev 1334)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.impl.method;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.exoplatform.services.rest.impl.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.method.MethodExceptionTest.UncheckedException;
+
+/**
+ * Created by The eXo Platform SAS. <br/>
+ * Date: 24 Dec 2009
+ * 
+ * @author <a href="mailto:max.shaposhnik at exoplatform.com">Max Shaposhnik</a>
+ * @version $Id: WebApplicationExceptionTest.java
+ */
+public class WebApplicationExceptionTest extends AbstractResourceTest
+{
+
+   @Path("/a")
+   public static class Resource1
+   {
+
+      @GET
+      @Path("/0")
+      public void m0() throws WebApplicationException
+      {
+         Exception e = new Exception("testmsg");
+         throw new WebApplicationException(e, 500);
+      }
+
+      @GET
+      @Path("/1")
+      public Response m1() throws WebApplicationException
+      {
+         throw new WebApplicationException(500);
+      }
+
+      @GET
+      @Path("/2")
+      public void m2() throws Exception
+      {
+         throw new UncheckedException("Unchecked exception");
+      }
+
+   }
+
+   public void testExceptionMessage() throws Exception
+   {
+      Resource1 resource = new Resource1();
+      registry(resource);
+
+      assertEquals(500, service("GET", "/a/0", "", null, null).getStatus());
+      String entity = (String)service("GET", "/a/0", "", null, null).getEntity();
+      assertTrue(entity.indexOf("testmsg") > 0);
+
+      assertEquals(500, service("GET", "/a/1", "", null, null).getStatus());
+      assertEquals(null, service("GET", "/a/1", "", null, null).getEntity());
+      unregistry(resource);
+   }
+
+}


Property changes on: ws/branches/2.2.x/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list