[exo-jcr-commits] exo-jcr SVN: r2982 - in ws/trunk/exo.ws.frameworks.json: src/test/java/org/exoplatform/ws/frameworks/json/impl and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Aug 25 01:21:04 EDT 2010


Author: aparfonov
Date: 2010-08-25 01:21:03 -0400 (Wed, 25 Aug 2010)
New Revision: 2982

Added:
   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
   ws/trunk/exo.ws.frameworks.json/src/test/resources/BookBean.groovy
   ws/trunk/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy
   ws/trunk/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy
Modified:
   ws/trunk/exo.ws.frameworks.json/pom.xml
   ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonGeneratorTest.java
   ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonParserTest.java
Log:
EXOJCR-890 : add TestCase

Modified: ws/trunk/exo.ws.frameworks.json/pom.xml
===================================================================
--- ws/trunk/exo.ws.frameworks.json/pom.xml	2010-08-24 07:18:30 UTC (rev 2981)
+++ ws/trunk/exo.ws.frameworks.json/pom.xml	2010-08-25 05:21:03 UTC (rev 2982)
@@ -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>

Modified: ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonGeneratorTest.java
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonGeneratorTest.java	2010-08-24 07:18:30 UTC (rev 2981)
+++ ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonGeneratorTest.java	2010-08-25 05:21:03 UTC (rev 2982)
@@ -30,7 +30,6 @@
 import org.exoplatform.ws.frameworks.json.JavaMapBean;
 import org.exoplatform.ws.frameworks.json.StringEnum;
 import org.exoplatform.ws.frameworks.json.value.JsonValue;
-import org.exoplatform.ws.frameworks.json.value.impl.ArrayValue;
 
 import java.util.ArrayList;
 import java.util.Arrays;

Modified: ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonParserTest.java
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonParserTest.java	2010-08-24 07:18:30 UTC (rev 2981)
+++ ws/trunk/exo.ws.frameworks.json/src/test/java/org/exoplatform/ws/frameworks/json/impl/JsonParserTest.java	2010-08-25 05:21:03 UTC (rev 2982)
@@ -31,7 +31,6 @@
 import org.exoplatform.ws.frameworks.json.JsonParser;
 import org.exoplatform.ws.frameworks.json.StringEnum;
 import org.exoplatform.ws.frameworks.json.value.JsonValue;
-import org.exoplatform.ws.frameworks.json.value.impl.ArrayValue;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStreamReader;

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 05:21:03 UTC (rev 2982)
@@ -0,0 +1,83 @@
+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:mime-type
   + text/plain

Added: ws/trunk/exo.ws.frameworks.json/src/test/resources/BookBean.groovy
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/test/resources/BookBean.groovy	                        (rev 0)
+++ ws/trunk/exo.ws.frameworks.json/src/test/resources/BookBean.groovy	2010-08-25 05:21:03 UTC (rev 2982)
@@ -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/trunk/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy	                        (rev 0)
+++ ws/trunk/exo.ws.frameworks.json/src/test/resources/BookStorage.groovy	2010-08-25 05:21:03 UTC (rev 2982)
@@ -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/trunk/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy	                        (rev 0)
+++ ws/trunk/exo.ws.frameworks.json/src/test/resources/SimpleBean.groovy	2010-08-25 05:21:03 UTC (rev 2982)
@@ -0,0 +1,9 @@
+public class SimpleBean
+{
+   String value
+   
+   String toString()
+   {
+      value
+   }
+}
\ No newline at end of file



More information about the exo-jcr-commits mailing list