[HippoCMS-svn] [20620] ecm/site-toolkit/trunk: HSTTWO-882: Adding initial unit test cases for jax-rs services

View: New views
1 Messages — Rating Filter:   Alert me  

[HippoCMS-svn] [20620] ecm/site-toolkit/trunk: HSTTWO-882: Adding initial unit test cases for jax-rs services

by bvdschans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Revision: 20620
Author:   wko
Date:     2009-11-10 16:27:54 +0100 (Tue, 10 Nov 2009)
Log Message:
-----------
HSTTWO-882: Adding initial unit test cases for jax-rs services

Modified Paths:
--------------
    ecm/site-toolkit/trunk/pom.xml
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/pom.xml
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ContentService.java
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/HippoFolderBeanContent.java
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ItemContent.java
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/NodeContent.java
    ecm/site-toolkit/trunk/testsuite/site/pom.xml

Added Paths:
-----------
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/content/
    ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/content/TestContentService.java

Modified: ecm/site-toolkit/trunk/pom.xml
===================================================================
--- ecm/site-toolkit/trunk/pom.xml 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/pom.xml 2009-11-10 15:27:54 UTC (rev 20620)
@@ -94,6 +94,8 @@
     
     <yui.sources.version>1.01.06</yui.sources.version>
     <spring.js.version>2.0.5.RELEASE</spring.js.version>
+    
+    <cxf.version>2.2.4</cxf.version>
 
     <!-- use UTF-8 encoding for filtered file copy -->
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -561,6 +563,12 @@
         <artifactId>spring-test</artifactId>
         <version>${spring.version}</version>
         <scope>test</scope>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+          </exclusion>
+        </exclusions>
       </dependency>
       
       <!-- Hippo ECM Depedencies -->
@@ -645,6 +653,34 @@
         <version>${yui.sources.version}</version>
       </dependency>
       
+      <dependency>
+        <groupId>org.apache.cxf</groupId>
+        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        <version>${cxf.version}</version>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      
       <!-- Test dependencies -->
     
       <dependency>

Modified: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/pom.xml
===================================================================
--- ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/pom.xml 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/pom.xml 2009-11-10 15:27:54 UTC (rev 20620)
@@ -144,7 +144,42 @@
       <artifactId>geronimo-jta_1.1_spec</artifactId>
       <scope>test</scope>
     </dependency>
-
+    
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- Apache CXF Runtime for JAX-RS Services Testing -->
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>spring-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>spring-beans</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>spring-context</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>spring-web</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
   </dependencies>
   
   <build>

Modified: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ContentService.java
===================================================================
--- ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ContentService.java 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ContentService.java 2009-11-10 15:27:54 UTC (rev 20620)
@@ -28,8 +28,10 @@
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
@@ -49,13 +51,19 @@
     
     private static Logger log = LoggerFactory.getLogger(ContentService.class);
     
+    @Context
+    private HttpServletRequest servletRequest;
+    
+    @Context
+    private UriInfo uriInfo;
+    
     public ContentService() {
         super();
     }
     
     @GET
     @Path("/uuid/{uuid}/")
-    public HippoBeanContent getContentNodeByUUID(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("uuid") String uuid) {
+    public HippoBeanContent getContentNodeByUUID(@PathParam("uuid") String uuid) {
         HippoBeanContent beanContent = new HippoBeanContent();
         
         try {
@@ -65,8 +73,8 @@
             if (bean != null) {
                 beanContent = createHippoBeanContent(bean);
                 String encoding = servletRequest.getCharacterEncoding();
-                beanContent.buildUrl(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
-                beanContent.buildChildUrls(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
+                beanContent.buildUri(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
+                beanContent.buildChildUris(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
             }
         } catch (Exception e) {
             if (log.isDebugEnabled()) {
@@ -74,6 +82,8 @@
             } else {
                 log.warn("Failed to retrieve content bean. {}", e.toString());
             }
+            
+            throw new WebApplicationException(e);
         }
         
         return beanContent;
@@ -81,7 +91,7 @@
     
     @GET
     @Path("/{path:.*}")
-    public ItemContent getContentItem(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("path") List<PathSegment> pathSegments) {
+    public ItemContent getContentItem(@PathParam("path") List<PathSegment> pathSegments) {
         String itemPath = getContentItemPath(servletRequest, pathSegments);
         ItemContent itemContent = new ItemContent();
         
@@ -95,14 +105,14 @@
                 if (bean != null) {
                     HippoBeanContent beanContent = createHippoBeanContent(bean);
                     String encoding = servletRequest.getCharacterEncoding();
-                    beanContent.buildUrl(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
-                    beanContent.buildChildUrls(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
+                    beanContent.buildUri(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
+                    beanContent.buildChildUris(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
                     itemContent = beanContent;
                 }
             } else {
                 PropertyContent propContent = new PropertyContent((Property) item);
                 String encoding = servletRequest.getCharacterEncoding();
-                propContent.buildUrl(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
+                propContent.buildUri(getRequestURIBase(uriInfo) + SERVICE_PATH, getSiteContentPath(servletRequest), encoding);
                 itemContent = propContent;
             }
         } catch (Exception e) {
@@ -111,6 +121,8 @@
             } else {
                 log.warn("Failed to retrieve content bean. {}", e.toString());
             }
+            
+            throw new WebApplicationException(e);
         }
         
         return itemContent;
@@ -118,7 +130,7 @@
     
     @DELETE
     @Path("/{path:.*}")
-    public Response deleteContentNode(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("path") List<PathSegment> pathSegments) {
+    public Response deleteContentNode(@PathParam("path") List<PathSegment> pathSegments) {
         String itemPath = getContentItemPath(servletRequest, pathSegments);
         
         try {
@@ -140,7 +152,7 @@
                 log.warn("The path is not found: {}. {}", itemPath, e.toString());
             }
             
-            return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new WebApplicationException(e);
         } catch (Exception e) {
             if (log.isDebugEnabled()) {
                 log.warn("Failed to retrieve content bean.", e);
@@ -148,13 +160,13 @@
                 log.warn("Failed to retrieve content bean. {}", e.toString());
             }
             
-            return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new WebApplicationException(e);
         }
     }
     
     @POST
     @Path("/{path:.*}")
-    public Response createContentDocument(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("path") List<PathSegment> pathSegments, HippoDocumentBeanContent documentBeanContent) {
+    public Response createContentDocument(@PathParam("path") List<PathSegment> pathSegments, HippoDocumentBeanContent documentBeanContent) {
         String itemPath = getContentItemPath(servletRequest, pathSegments);
         
         try {
@@ -187,7 +199,7 @@
                 return Response.serverError().status(Response.Status.NOT_FOUND).build();
             } else {
                 documentBeanContent = (HippoDocumentBeanContent) createHippoBeanContent(bean);
-                return Response.ok(documentBeanContent).build();
+                return Response.status(Response.Status.CREATED).entity(documentBeanContent).build();
             }
         } catch (Exception e) {
             if (log.isDebugEnabled()) {
@@ -196,13 +208,13 @@
                 log.warn("Failed to save document. {}", e.toString());
             }
             
-            return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new WebApplicationException(e);
         }
     }
     
     @POST
-    @Path("/node/{path:.*}")
-    public Response createContentNode(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("path") List<PathSegment> pathSegments, NodeContent nodeContent) {
+    @Path("/{path:.*}")
+    public Response createContentNode(@PathParam("path") List<PathSegment> pathSegments, NodeContent nodeContent) {
         String itemPath = getContentItemPath(servletRequest, pathSegments);
         
         try {
@@ -232,7 +244,8 @@
                 
                 bean = (HippoBean) cpm.getObject(parentPath);
                 beanContent = createHippoBeanContent(bean);
-                return Response.ok(beanContent).build();
+                
+                return Response.status(Response.Status.CREATED).entity(beanContent).build();
             }
         } catch (Exception e) {
             if (log.isDebugEnabled()) {
@@ -241,34 +254,64 @@
                 log.warn("Failed to save document. {}", e.toString());
             }
             
-            return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new WebApplicationException(e);
         }
     }
     
-    @POST
-    @Path("/property/{path:.*}")
-    public Response setContentProperty(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("path") List<PathSegment> pathSegments, PropertyContent propertyContent) {
+    @PUT
+    @Path("/{path:.*}")
+    public Response updateContentItem(@PathParam("path") List<PathSegment> pathSegments, ItemContent itemContent) {
         String itemPath = getContentItemPath(servletRequest, pathSegments);
         
         try {
             ContentPersistenceManager cpm = getContentPersistenceManager(servletRequest);
-            int offset = itemPath.lastIndexOf('/');
-            String nodePath = itemPath.substring(0, offset);
             
-            HippoBean bean = (HippoBean) cpm.getObject(nodePath);
-            
-            if (bean == null) {
-                return Response.serverError().status(Response.Status.NOT_FOUND).build();
-            } else {
-                HippoBeanContent beanContent = createHippoBeanContent(bean);
-                setPropertyValue(beanContent.getCanonicalNode(), propertyContent);
-                cpm.update(bean);
-                cpm.save();
+            if (itemContent instanceof PropertyContent) {
+                PropertyContent propertyContent = (PropertyContent) itemContent;
+                int offset = itemPath.lastIndexOf('/');
+                String nodePath = itemPath.substring(0, offset);
                 
-                bean = (HippoBean) cpm.getObject(nodePath);
-                beanContent = (HippoBeanContent) createHippoBeanContent(bean);
-                return Response.ok(beanContent).build();
+                HippoBean bean = (HippoBean) cpm.getObject(nodePath);
+                
+                if (bean == null) {
+                    return Response.serverError().status(Response.Status.NOT_FOUND).build();
+                } else {
+                    HippoBeanContent beanContent = createHippoBeanContent(bean);
+                    setPropertyValue(beanContent.getCanonicalNode(), propertyContent);
+                    cpm.update(bean);
+                    cpm.save();
+                    
+                    bean = (HippoBean) cpm.getObject(nodePath);
+                    beanContent = (HippoBeanContent) createHippoBeanContent(bean);
+                    
+                    return Response.status(Response.Status.ACCEPTED).entity(beanContent).build();
+                }
+            } else if (itemContent instanceof HippoBeanContent) {
+                HippoBean bean = (HippoBean) cpm.getObject(itemPath);
+                
+                if (bean == null) {
+                    return Response.serverError().status(Response.Status.NOT_FOUND).build();
+                } else {
+                    HippoBeanContent beanContent = createHippoBeanContent(bean);
+                    Collection<PropertyContent> propertyContents = ((HippoBeanContent) itemContent).getPropertyContents();
+                    
+                    if (propertyContents != null) {
+                        for (PropertyContent propertyContent : propertyContents) {
+                            setPropertyValue(beanContent.getCanonicalNode(), propertyContent);
+                        }
+                    }
+                    
+                    cpm.update(bean);
+                    cpm.save();
+                    
+                    bean = (HippoBean) cpm.getObject(itemPath);
+                    beanContent = (HippoBeanContent) createHippoBeanContent(bean);
+                    
+                    return Response.status(Response.Status.ACCEPTED).entity(beanContent).build();
+                }
             }
+            
+            return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
         } catch (Exception e) {
             if (log.isDebugEnabled()) {
                 log.warn("Failed to retrieve save bean.", e);
@@ -276,7 +319,7 @@
                 log.warn("Failed to retrieve save bean. {}", e.toString());
             }
             
-            return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new WebApplicationException(e);
         }
     }
     

Modified: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/HippoFolderBeanContent.java
===================================================================
--- ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/HippoFolderBeanContent.java 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/HippoFolderBeanContent.java 2009-11-10 15:27:54 UTC (rev 20620)
@@ -104,24 +104,24 @@
     }
     
     @Override
-    public void buildChildUrls(String urlBase, String siteContentPath, String encoding) throws UnsupportedEncodingException {
+    public void buildChildUris(String urlBase, String siteContentPath, String encoding) throws UnsupportedEncodingException {
         Collection<PropertyContent> propertyContents = getPropertyContents();
         
         if (propertyContents != null) {
             for (PropertyContent propertyContent : propertyContents) {
-                propertyContent.buildUrl(urlBase, siteContentPath, encoding);
+                propertyContent.buildUri(urlBase, siteContentPath, encoding);
             }
         }
         
         if (childFolderBeanContents != null) {
             for (HippoFolderBeanContent folderContent : childFolderBeanContents) {
-                folderContent.buildUrl(urlBase, siteContentPath, encoding);
+                folderContent.buildUri(urlBase, siteContentPath, encoding);
             }
         }
         
         if (childDocumentBeanContents != null) {
             for (HippoDocumentBeanContent documentContent : childDocumentBeanContents) {
-                documentContent.buildUrl(urlBase, siteContentPath, encoding);
+                documentContent.buildUri(urlBase, siteContentPath, encoding);
             }
         }
     }

Modified: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ItemContent.java
===================================================================
--- ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ItemContent.java 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/ItemContent.java 2009-11-10 15:27:54 UTC (rev 20620)
@@ -31,7 +31,8 @@
     
     private String name;
     private String path;
-    private URI url;
+    private URI uri;
+    private transient Item item;
     
     public ItemContent() {
     }
@@ -49,6 +50,10 @@
         this(item.getName(), item.getPath());
     }
     
+    public Item getItem() {
+        return item;
+    }
+    
     @XmlAttribute
     public String getName() {
         return name;
@@ -68,15 +73,15 @@
     }
     
     @XmlAttribute
-    public URI getUrl() {
-        return url;
+    public URI getUri() {
+        return uri;
     }
     
-    public void setUrl(URI url) {
-        this.url = url;
+    public void setUri(URI uri) {
+        this.uri = uri;
     }
     
-    public void buildUrl(String urlBase, String siteContentPath, String encoding) throws UnsupportedEncodingException {
+    public void buildUri(String urlBase, String siteContentPath, String encoding) throws UnsupportedEncodingException {
         if (encoding == null) {
             encoding = "ISO-8859-1";
         }
@@ -109,7 +114,7 @@
             relativeContentPath = relativeContentPathBuilder.toString();
         }
         
-        setUrl(URI.create(urlBase + relativeContentPath));
+        setUri(URI.create(urlBase + relativeContentPath));
     }
     
 }

Modified: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/NodeContent.java
===================================================================
--- ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/NodeContent.java 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/main/java/org/hippoecm/hst/services/support/jaxrs/content/NodeContent.java 2009-11-10 15:27:54 UTC (rev 20620)
@@ -101,16 +101,16 @@
         this.childNodeContents = childNodeContents;
     }
     
-    public void buildChildUrls(String urlBase, String siteContentPath, String encoding) throws UnsupportedEncodingException {
+    public void buildChildUris(String urlBase, String siteContentPath, String encoding) throws UnsupportedEncodingException {
         if (propertyContents != null) {
             for (PropertyContent propertyContent : propertyContents) {
-                propertyContent.buildUrl(urlBase, siteContentPath, encoding);
+                propertyContent.buildUri(urlBase, siteContentPath, encoding);
             }
         }
         
         if (childNodeContents != null) {
             for (NodeContent nodeContent : childNodeContents) {
-                nodeContent.buildUrl(urlBase, siteContentPath, encoding);
+                nodeContent.buildUri(urlBase, siteContentPath, encoding);
             }
         }
     }

Added: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/content/TestContentService.java
===================================================================
--- ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/content/TestContentService.java                        (rev 0)
+++ ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/content/TestContentService.java 2009-11-10 15:27:54 UTC (rev 20620)
@@ -0,0 +1,173 @@
+/*
+ *  Copyright 2008 Hippo.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.hippoecm.hst.services.support.jaxrs.content;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.mock.web.MockServletConfig;
+import org.springframework.mock.web.MockServletContext;
+
+public class TestContentService {
+
+    private MockServletContext servletContext;
+    private MockServletConfig servletConfig;
+    private HttpServlet jaxrsServlet;
+    
+    @Before
+    public void setUp() throws ServletException {
+        jaxrsServlet = new CXFNonSpringJaxrsServlet();
+        
+        servletContext = new MockServletContext();
+        servletContext.setServletContextName("testapp");
+        servletContext.setContextPath("/testapp");
+        
+        servletConfig = new MockServletConfig(servletContext);
+        servletConfig.addInitParameter("jaxrs.serviceClasses", "org.hippoecm.hst.services.support.jaxrs.demo.CustomerService org.hippoecm.hst.services.support.jaxrs.content.ContentService");
+        
+        jaxrsServlet.init(servletConfig);
+    }
+    
+    @After
+    public void tearDown() {
+        jaxrsServlet.destroy();
+    }
+    
+    @Test
+    public void testDemo() throws ServletException, IOException {
+        // retrieves customer json data...
+        MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
+        MockHttpServletResponse response = new MockHttpServletResponse();
+        request.setProtocol("http");
+        request.setServerName("localhost");
+        request.setServerPort(8085);
+        request.setMethod("GET");
+        request.setRequestURI("/testapp/preview/services/customerservice/customers/123/");
+        request.setContextPath("/testapp");
+        request.setServletPath("/preview/services");
+        request.setPathInfo("/customerservice/customers/123/");
+
+        jaxrsServlet.service(request, response);
+        
+        assertEquals(200, response.getStatus());
+        assertNotNull(response.getContentAsString());
+        assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}", response.getContentAsString());
+        
+        // updating the existing customer...
+        request = new MockHttpServletRequest(servletContext);
+        response = new MockHttpServletResponse();
+        request.setProtocol("http");
+        request.setServerName("localhost");
+        request.setServerPort(8085);
+        request.setMethod("PUT");
+        request.setRequestURI("/testapp/preview/services/customerservice/customers/");
+        request.setContextPath("/testapp");
+        request.setServletPath("/preview/services");
+        request.setPathInfo("/customerservice/customers/");
+        request.setContentType("application/json");
+        request.setContent("{\"Customer\":{\"id\":123,\"name\":\"John Doe\"}}".getBytes());
+
+        response = new MockHttpServletResponse();
+        
+        jaxrsServlet.service(request, response);
+        
+        assertEquals(200, response.getStatus());
+        
+        // adding a new customer...
+        request = new MockHttpServletRequest(servletContext);
+        response = new MockHttpServletResponse();
+        request.setProtocol("http");
+        request.setServerName("localhost");
+        request.setServerPort(8085);
+        request.setMethod("POST");
+        request.setRequestURI("/testapp/preview/services/customerservice/customers/");
+        request.setContextPath("/testapp");
+        request.setServletPath("/preview/services");
+        request.setPathInfo("/customerservice/customers/");
+        request.setContentType("application/json");
+        request.setContent("{\"Customer\":{\"name\":\"Jisung Park\"}}".getBytes());
+
+        response = new MockHttpServletResponse();
+        
+        jaxrsServlet.service(request, response);
+        
+        assertEquals(200, response.getStatus());
+        assertNotNull(response.getContentAsString());
+        assertTrue(response.getContentAsString().startsWith("{\"Customer\":"));
+        assertTrue(response.getContentAsString().contains("\"name\":\"Jisung Park\""));
+        
+        // deleting a new customer...
+        request = new MockHttpServletRequest(servletContext);
+        response = new MockHttpServletResponse();
+        request.setProtocol("http");
+        request.setServerName("localhost");
+        request.setServerPort(8085);
+        request.setMethod("DELETE");
+        request.setRequestURI("/testapp/preview/services/customerservice/customers/123/");
+        request.setContextPath("/testapp");
+        request.setServletPath("/preview/services");
+        request.setPathInfo("/customerservice/customers/123/");
+
+        response = new MockHttpServletResponse();
+        
+        jaxrsServlet.service(request, response);
+        
+        assertEquals(200, response.getStatus());
+    }
+    
+    @Test
+    public void testGetContentNodeByUUID() throws ServletException, IOException {
+        // TODO:
+    }
+    
+    @Test
+    public void testGetContentItem() throws ServletException, IOException {
+        // TODO:
+    }
+    
+    @Test
+    public void testDeleteContentNode() throws ServletException, IOException {
+        // TODO:
+    }
+    
+    @Test
+    public void testCreateContentDocument() throws ServletException, IOException {
+        // TODO:
+    }
+    
+    @Test
+    public void testCreateContentNode() throws ServletException, IOException {
+        // TODO:
+    }
+    
+    @Test
+    public void testSetContentProperty() throws ServletException, IOException {
+        // TODO:
+    }
+    
+}


Property changes on: ecm/site-toolkit/trunk/testsuite/sandbox/jaxrs/src/test/java/org/hippoecm/hst/services/support/jaxrs/content/TestContentService.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: ecm/site-toolkit/trunk/testsuite/site/pom.xml
===================================================================
--- ecm/site-toolkit/trunk/testsuite/site/pom.xml 2009-11-10 15:16:21 UTC (rev 20619)
+++ ecm/site-toolkit/trunk/testsuite/site/pom.xml 2009-11-10 15:27:54 UTC (rev 20620)
@@ -166,7 +166,6 @@
     <dependency>
       <groupId>org.apache.cxf</groupId>
       <artifactId>cxf-rt-frontend-jaxrs</artifactId>
-      <version>2.2.3</version>
       <exclusions>
         <exclusion>
           <groupId>commons-logging</groupId>

_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@...
http://lists.hippo.nl/mailman/listinfo/hippocms-svn