[seam-commits] Seam SVN: r10233 - in trunk/examples/restbay: src/org/jboss/seam/example/restbay and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Mar 30 11:37:09 EDT 2009


Author: jharting
Date: 2009-03-30 11:37:09 -0400 (Mon, 30 Mar 2009)
New Revision: 10233

Added:
   trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceHome.java
   trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceQuery.java
   trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceHomeTest.java
   trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceQueryTest.java
Modified:
   trunk/examples/restbay/resources/WEB-INF/components.xml
   trunk/examples/restbay/src/org/jboss/seam/example/restbay/Category.java
   trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
Log:
JBSEAM-3987 added tests

Modified: trunk/examples/restbay/resources/WEB-INF/components.xml
===================================================================
--- trunk/examples/restbay/resources/WEB-INF/components.xml	2009-03-30 15:16:52 UTC (rev 10232)
+++ trunk/examples/restbay/resources/WEB-INF/components.xml	2009-03-30 15:37:09 UTC (rev 10233)
@@ -7,6 +7,7 @@
             xmlns:async="http://jboss.com/products/seam/async"
             xmlns:web="http://jboss.com/products/seam/web"
             xmlns:resteasy="http://jboss.com/products/seam/resteasy"
+            xmlns:framework="http://jboss.com/products/seam/framework"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation=
                 "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
@@ -15,8 +16,10 @@
                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                  http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.1.xsd
                  http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
-                 http://jboss.com/products/seam/resteasy http://jboss.com/products/seam/resteasy-2.1.xsd
+                 http://jboss.com/products/seam/resteasy /home/jharting/jboss/workspace/Seam_trunk_working_copy/src/resteasy/org/jboss/seam/resteasy/resteasy-2.1.xsd
+                 http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.1.xsd
                  http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd">
+                 <!-- TODO change back the reference -->
 
     <core:init jndi-pattern="@jndiPattern@" debug="true"/>
  
@@ -29,7 +32,19 @@
 
     <async:quartz-dispatcher/>
 
+    <framework:entity-home name="categoryHome"
+    entity-class="org.jboss.seam.example.restbay.Category"
+    auto-create="true" />
+    
     <resteasy:application resource-path-prefix="/restv1">
     </resteasy:application>
+    
+	<resteasy:resource-home path="/configuredCategory" name="configuredCategoryResourceHome"
+	entity-home="#{categoryHome}" entity-id-class="java.lang.Integer"
+	media-types="application/xml application/json" />
+	
+	<resteasy:resource-query path="/configuredCategory" name="configuredCategoryResourceQuery"
+	entity-class="org.jboss.seam.example.restbay.Category"
+	media-types="application/xml application/json"/>
 
 </components>

Modified: trunk/examples/restbay/src/org/jboss/seam/example/restbay/Category.java
===================================================================
--- trunk/examples/restbay/src/org/jboss/seam/example/restbay/Category.java	2009-03-30 15:16:52 UTC (rev 10232)
+++ trunk/examples/restbay/src/org/jboss/seam/example/restbay/Category.java	2009-03-30 15:37:09 UTC (rev 10233)
@@ -3,11 +3,14 @@
 import java.io.Serializable;
 
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
+import javax.xml.bind.annotation.XmlRootElement;
 
 @Entity
+ at XmlRootElement
 public class Category implements Serializable
 {
    private static final long serialVersionUID = 411989568594034566L;
@@ -17,6 +20,7 @@
    private Category parent;
    
    @Id
+   @GeneratedValue
    public Integer getCategoryId()
    {
       return categoryId;

Added: trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceHome.java
===================================================================
--- trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceHome.java	                        (rev 0)
+++ trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceHome.java	2009-03-30 15:37:09 UTC (rev 10233)
@@ -0,0 +1,37 @@
+package org.jboss.seam.example.restbay;
+
+import javax.ws.rs.Path;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.framework.EntityHome;
+import org.jboss.seam.framework.Home;
+import org.jboss.seam.resteasy.ResourceHome;
+
+/**
+ * This resource demonstrates using ResourceHome component. This resource is
+ * used for testing purposes.
+ * 
+ * @author Jozef Hartinger
+ * 
+ */
+
+ at Name("categoryResourceHome")
+ at Path("extendedCategory")
+public class CategoryResourceHome extends ResourceHome<Category, Integer>
+{
+
+   @In
+   private EntityHome<Category> categoryHome;
+
+   @Override
+   public Home<?, Category> getEntityHome()
+   {
+      return categoryHome;
+   }
+
+   public CategoryResourceHome()
+   {
+      setMediaTypes(new String[] { "application/xml", "application/json" });
+   }
+}


Property changes on: trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceHome.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceQuery.java
===================================================================
--- trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceQuery.java	                        (rev 0)
+++ trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceQuery.java	2009-03-30 15:37:09 UTC (rev 10233)
@@ -0,0 +1,19 @@
+package org.jboss.seam.example.restbay;
+
+import javax.ws.rs.Path;
+
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.resteasy.ResourceQuery;
+
+/**
+ * Example of ResourceQuery usage. Used for testing purposes.
+ * 
+ * @author Jozef Hartinger
+ * 
+ */
+ at Name("categoryResourceQuery")
+ at Path("extendedCategory")
+public class CategoryResourceQuery extends ResourceQuery<Category>
+{
+
+}


Property changes on: trunk/examples/restbay/src/org/jboss/seam/example/restbay/CategoryResourceQuery.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceHomeTest.java
===================================================================
--- trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceHomeTest.java	                        (rev 0)
+++ trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceHomeTest.java	2009-03-30 15:37:09 UTC (rev 10233)
@@ -0,0 +1,164 @@
+package org.jboss.seam.example.restbay.test;
+
+import org.jboss.seam.example.restbay.test.fwk.MockHttpServletRequest;
+import org.jboss.seam.example.restbay.test.fwk.MockHttpServletResponse;
+import org.jboss.seam.example.restbay.test.fwk.ResourceSeamTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * 
+ * @author Jozef Hartinger
+ * 
+ */
+public class ResourceHomeTest extends ResourceSeamTest
+{
+
+   @DataProvider(name = "queryPaths")
+   public Object[][] getData()
+   {
+      String[][] data = { { "/configuredCategory" }, { "/extendedCategory" } };
+      return data;
+   }
+
+   @Test(dataProvider = "queryPaths")
+   public void testResourceHomeRead(final String resourcePath) throws Exception
+   {
+      final String expectedResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><category><categoryId>1</categoryId><name>Antiques</name></category>";
+      final String path = "/restv1" + resourcePath + "/1";
+
+      new ResourceRequest(Method.GET, path)
+      {
+
+         @Override
+         protected void prepareRequest(MockHttpServletRequest request)
+         {
+            super.prepareRequest(request);
+            request.addHeader("Accept", "application/xml");
+         }
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            assertEquals(response.getContentAsString(), expectedResponse, "Unexpected response.");
+         }
+
+      }.run();
+   }
+
+   @Test(dataProvider = "queryPaths")
+   public void testResourceHomeCreate(final String resourcePath) throws Exception
+   {
+      final String name = "Airplanes";
+      final String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><category><name>" + name + "</name></category>";
+      final String mediaType = "application/xml";
+      final String path = "/restv1" + resourcePath;
+
+      new ResourceRequest(Method.POST, path)
+      {
+         @Override
+         protected void prepareRequest(MockHttpServletRequest request)
+         {
+            super.prepareRequest(request);
+            // TODO for some reason content type must be set using both these
+            // methods
+            request.addHeader("Content-Type", mediaType);
+            request.setContentType(mediaType);
+            request.setContent(body.getBytes());
+         }
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            assertEquals(response.getStatus(), 201, "Unexpected response code.");
+         }
+
+      }.run();
+   }
+
+   @Test(dataProvider = "queryPaths")
+   public void testResourceHomeUpdate(String resourcePath) throws Exception
+   {
+      final String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><category><categoryId>5</categoryId><name>" + resourcePath.hashCode() + "</name></category>";
+      final String mediaType = "application/xml";
+      final String path = "/restv1" + resourcePath + "/5";
+
+      new ResourceRequest(Method.PUT, path)
+      {
+
+         @Override
+         protected void prepareRequest(MockHttpServletRequest request)
+         {
+            super.prepareRequest(request);
+            request.setContentType(mediaType);
+            request.addHeader("Content-Type", mediaType);
+            request.setContent(body.getBytes());
+         }
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            assertEquals(response.getStatus(), 204, "Unexpected response code.");
+         }
+
+      }.run();
+
+      new ResourceRequest(Method.GET, path)
+      {
+
+         @Override
+         protected void prepareRequest(MockHttpServletRequest request)
+         {
+            super.prepareRequest(request);
+            request.addHeader("Accept", mediaType);
+         }
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            assertEquals(response.getStatus(), 200, "Unexpected response code.");
+            assertEquals(response.getContentAsString(), body, "Unexpected response.");
+         }
+
+      }.run();
+
+   }
+
+   @Test
+   public void testResourceHomeDelete() throws Exception
+   {
+
+      final String path = "/restv1/configuredCategory/15004";
+
+      new ResourceRequest(Method.DELETE, path)
+      {
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            assertEquals(response.getStatus(), 204, "Unexpected response code.");
+         }
+
+      }.run();
+
+      new ResourceRequest(Method.GET, path)
+      {
+
+         @Override
+         protected void prepareRequest(MockHttpServletRequest request)
+         {
+            super.prepareRequest(request);
+            request.addHeader("Accept", "application/xml");
+         }
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            assertEquals(response.getStatus(), 404, "Unexpected response code.");
+         }
+
+      }.run();
+   }
+}


Property changes on: trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceHomeTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceQueryTest.java
===================================================================
--- trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceQueryTest.java	                        (rev 0)
+++ trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceQueryTest.java	2009-03-30 15:37:09 UTC (rev 10233)
@@ -0,0 +1,52 @@
+package org.jboss.seam.example.restbay.test;
+
+import static org.testng.Assert.assertEquals;
+
+import org.jboss.seam.example.restbay.test.fwk.MockHttpServletRequest;
+import org.jboss.seam.example.restbay.test.fwk.MockHttpServletResponse;
+import org.jboss.seam.example.restbay.test.fwk.ResourceSeamTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * 
+ * @author Jozef Hartinger
+ * 
+ */
+public class ResourceQueryTest extends ResourceSeamTest
+{
+
+   @DataProvider(name = "queryPaths")
+   public Object[][] getData()
+   {
+      String[][] data = new String[2][1];
+      data[0][0] = "/configuredCategory";
+      data[1][0] = "/extendedCategory";
+      return data;
+   }
+
+   @Test(dataProvider = "queryPaths")
+   public void testResourceQuery(String path) throws Exception
+   {
+      new ResourceRequest(Method.GET, "/restv1" + path)
+      {
+
+         @Override
+         protected void prepareRequest(MockHttpServletRequest request)
+         {
+            super.prepareRequest(request);
+            request.addHeader("Accept", "application/xml");
+            request.setQueryString("start=2&show=2");
+         }
+
+         @Override
+         protected void onResponse(MockHttpServletResponse response)
+         {
+            String expectedResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><resteasy:collection xmlns:resteasy=\"http://jboss.org/resteasy\"><category><categoryId>3</categoryId><name>Books</name></category><category><categoryId>4</categoryId><name>Cameras and Photography</name></category></resteasy:collection>";
+            assertEquals(response.getContentAsString(), expectedResponse, "Unexpected response.");
+         }
+
+      }.run();
+   }
+
+}


Property changes on: trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/ResourceQueryTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
===================================================================
--- trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml	2009-03-30 15:16:52 UTC (rev 10232)
+++ trunk/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml	2009-03-30 15:37:09 UTC (rev 10233)
@@ -13,5 +13,16 @@
         <class name="org.jboss.seam.example.restbay.test.AuctionServiceTest"/>
       </classes>
     </test>
-
+    
+    <test name="RestBay: ResourceHome">
+      <classes>
+        <class name="org.jboss.seam.example.restbay.test.ResourceHomeTest"/>
+      </classes>
+    </test>
+    
+    <test name="RestBay: ResourceQuery">
+      <classes>
+        <class name="org.jboss.seam.example.restbay.test.ResourceQueryTest"/>
+      </classes>
+    </test>
 </suite>
\ No newline at end of file




More information about the seam-commits mailing list