[exo-jcr-commits] exo-jcr SVN: r2984 - in ws: branches/2.1.x/exo.ws.frameworks.json and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Aug 25 03:06:00 EDT 2010


Author: aparfonov
Date: 2010-08-25 03:05:59 -0400 (Wed, 25 Aug 2010)
New Revision: 2984

Added:
   ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookBean.groovy
   ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy
   ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy
   ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/
   ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/GroovyBeanTest.java
Removed:
   ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/
Modified:
   ws/branches/2.1.x/exo.ws.frameworks.json/pom.xml
   ws/branches/2.1.x/pom.xml
Log:
EXOJCR-890 : add TestCase

Modified: ws/branches/2.1.x/exo.ws.frameworks.json/pom.xml
===================================================================
--- ws/branches/2.1.x/exo.ws.frameworks.json/pom.xml	2010-08-25 05:24:18 UTC (rev 2983)
+++ ws/branches/2.1.x/exo.ws.frameworks.json/pom.xml	2010-08-25 07:05:59 UTC (rev 2984)
@@ -39,6 +39,11 @@
          <artifactId>junit</artifactId>
          <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>org.codehaus.groovy</groupId>
+         <artifactId>groovy-all</artifactId>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
 
    <build>
@@ -48,6 +53,7 @@
             <includes>
                <include>**/*.json</include>
                <include>**/*.txt</include>
+               <include>**/*.groovy</include>
             </includes>
          </testResource>
       </testResources>

Added: ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookBean.groovy
===================================================================
--- ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookBean.groovy	                        (rev 0)
+++ ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookBean.groovy	2010-08-25 07:05:59 UTC (rev 2984)
@@ -0,0 +1,32 @@
+public class BookBean
+{
+   
+   String author
+   
+   String title
+   
+   double price
+   
+   long isdn
+   
+   int pages
+   
+   boolean availability
+   
+   boolean delivery
+   
+   String toString()
+   {
+      StringBuffer sb = new StringBuffer()
+      sb.append("Book:{").append("Author: ").append(author).append(" ").append("Title: ").append(title).append(" ")
+      .append("Pages: ").append(pages).append(" ").append("Price: ").append(price).append(" ").append("ISDN: ")
+      .append(isdn).append("Availability: ").append(availability).append(" ").append("Delivery: ").append(delivery)
+      .append(" ").append("} ")
+      sb.toString()
+   }
+   
+   boolean equals(Object other)
+   {
+      return other != null && other instanceof BookBean && other.author == author && other.title == title && other.isdn == isdn && other.pages == pages && other.price == price && other.availability == availability && other.delivery == delivery
+   }
+}
\ No newline at end of file

Added: ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy
===================================================================
--- ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy	                        (rev 0)
+++ ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy	2010-08-25 07:05:59 UTC (rev 2984)
@@ -0,0 +1,51 @@
+
+public class BookStorage
+{
+   
+   List<BookBean> books = new ArrayList<BookBean>()
+   
+   public BookStorage()
+   {
+   }
+   
+   void initStorage()
+   {
+      
+      BookBean b1 = new BookBean(
+      author:'Vincent Masson',
+      title:'JUnit in Action',
+      pages:386,
+      price:19.37,
+      isdn:93011099534534L,
+      availability:true,
+      delivery:true)
+      
+      BookBean b2 = new BookBean(
+                        author:'Christian Gross',
+                        title:'Beginning C# 2008 from novice to professional',
+                        pages:511,
+                        price:23.56,
+                        isdn:9781590598696L,
+                        availability:true,
+                        delivery:true)
+      
+      BookBean b3 = new BookBean(
+                        author:'Chuck Easttom',
+                        title:'Advanced JavaScript, Third Edition',
+                        pages:617,
+                        price:25.99,
+                        isdn:9781598220339L,
+                        availability:false,
+                        delivery:false)
+      
+      books.add(b1)
+      books.add(b2)
+      books.add(b3)
+   }
+   
+   String toString()
+   {
+      books.toString()
+   }
+   
+}
\ No newline at end of file

Added: ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy
===================================================================
--- ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy	                        (rev 0)
+++ ws/branches/2.1.x/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy	2010-08-25 07:05:59 UTC (rev 2984)
@@ -0,0 +1,9 @@
+public class SimpleBean
+{
+   String value
+   
+   String toString()
+   {
+      value
+   }
+}
\ No newline at end of file

Modified: ws/branches/2.1.x/pom.xml
===================================================================
--- ws/branches/2.1.x/pom.xml	2010-08-25 05:24:18 UTC (rev 2983)
+++ ws/branches/2.1.x/pom.xml	2010-08-25 07:05:59 UTC (rev 2984)
@@ -167,6 +167,12 @@
             <version>1.5.8</version>
             <scope>test</scope>
          </dependency>               
+         <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-all</artifactId>
+            <version>1.6.5</version>
+            <scope>test</scope>
+         </dependency>               
       </dependencies>
    </dependencyManagement>
    <dependencies>

Added: ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/GroovyBeanTest.java
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/GroovyBeanTest.java	                        (rev 0)
+++ ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/GroovyBeanTest.java	2010-08-25 07:05:59 UTC (rev 2984)
@@ -0,0 +1,101 @@
+/*
+ * 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.ws.frameworks.json.impl.groovy;
+
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyObject;
+import junit.framework.TestCase;
+
+import org.exoplatform.ws.frameworks.json.JsonHandler;
+import org.exoplatform.ws.frameworks.json.impl.BeanBuilder;
+import org.exoplatform.ws.frameworks.json.impl.JsonDefaultHandler;
+import org.exoplatform.ws.frameworks.json.impl.JsonGeneratorImpl;
+import org.exoplatform.ws.frameworks.json.impl.JsonParserImpl;
+import org.exoplatform.ws.frameworks.json.value.JsonValue;
+import org.exoplatform.ws.frameworks.json.value.impl.ObjectValue;
+import org.exoplatform.ws.frameworks.json.value.impl.StringValue;
+
+import java.io.InputStreamReader;
+import java.util.Iterator;
+import java.util.List;
+
+public class GroovyBeanTest extends TestCase
+{
+
+   @SuppressWarnings("unchecked")
+   public void testRestoreGroovyBean() throws Exception
+   {
+      GroovyClassLoader cl = new GroovyClassLoader();
+      Class c = cl.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("SimpleBean.groovy"));
+      JsonValue ov = new ObjectValue();
+      StringValue sv = new StringValue("test restore groovy bean");
+      ov.addElement("value", sv);
+      assertEquals("test restore groovy bean", new BeanBuilder().createObject(c, ov).toString());
+   }
+
+   @SuppressWarnings("unchecked")
+   public void testSerializeGroovyBean() throws Exception
+   {
+      GroovyClassLoader cl = new GroovyClassLoader();
+      Class c = cl.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("SimpleBean.groovy"));
+      GroovyObject groovyObject = (GroovyObject)c.newInstance();
+      groovyObject.invokeMethod("setValue", new Object[]{"test serialize groovy bean"});
+      assertEquals("{\"value\":\"test serialize groovy bean\"}", new JsonGeneratorImpl().createJsonObject(groovyObject)
+         .toString());
+   }
+
+   @SuppressWarnings("unchecked")
+   public void testSerializeGroovyBean1() throws Exception
+   {
+      GroovyClassLoader cl = new GroovyClassLoader();
+      Class c = cl.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("BookStorage.groovy"));
+      GroovyObject groovyObject = (GroovyObject)c.newInstance();
+      groovyObject.invokeMethod("initStorage", new Object[]{});
+
+      JsonValue jsonValue = new JsonGeneratorImpl().createJsonObject(groovyObject);
+      //System.out.println(jsonValue);
+      assertTrue(jsonValue.isObject());
+      Iterator<JsonValue> iterator = jsonValue.getElement("books").getElements();
+      assertEquals("JUnit in Action", iterator.next().getElement("title").getStringValue());
+      assertEquals("Beginning C# 2008 from novice to professional", iterator.next().getElement("title")
+         .getStringValue());
+      assertEquals("Advanced JavaScript, Third Edition", iterator.next().getElement("title").getStringValue());
+      assertFalse(iterator.hasNext());
+   }
+
+   @SuppressWarnings("unchecked")
+   public void testRestoreGroovyBean1() throws Exception
+   {
+      GroovyClassLoader cl = new GroovyClassLoader();
+      Class c = cl.parseClass(Thread.currentThread().getContextClassLoader().getResourceAsStream("BookStorage.groovy"));
+      JsonParserImpl jsonParser = new JsonParserImpl();
+      JsonHandler jsonHandler = new JsonDefaultHandler();
+      jsonParser.parse(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(
+         "BookStorage.txt")), jsonHandler);
+      JsonValue jv = jsonHandler.getJsonObject();
+      GroovyObject o = (GroovyObject)new BeanBuilder().createObject(c, jv);
+      //System.out.println(o);
+      List<GroovyObject> books = (List<GroovyObject>)o.getProperty("books");
+      assertEquals(3, books.size());
+      assertEquals(books.get(0).getProperty("title"), "JUnit in Action");
+      assertEquals(books.get(1).getProperty("title"), "Beginning C# 2008 from novice to professional");
+      assertEquals(books.get(2).getProperty("title"), "Advanced JavaScript. Third Edition");
+   }
+
+}


Property changes on: ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/groovy/GroovyBeanTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list