tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r820844 - in /tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json: JSONTransformerTestCase.java POJOTestCase.java
Date Thu, 01 Oct 2009 23:25:52 GMT
Author: lresende
Date: Thu Oct  1 23:25:51 2009
New Revision: 820844

URL: http://svn.apache.org/viewvc?rev=820844&view=rev
Log:
Finalizing test bringup

Modified:
    tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java
    tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java

Modified: tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java?rev=820844&r1=820843&r2=820844&view=diff
==============================================================================
--- tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java
(original)
+++ tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java
Thu Oct  1 23:25:51 2009
@@ -29,10 +29,11 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import junit.framework.Assert;
-import junit.framework.TestCase;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.tuscany.sca.common.xml.stax.impl.XMLStreamSerializer;
+import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.databinding.TransformationContext;
 import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl;
 import org.apache.tuscany.sca.databinding.json.axiom.JSON2OMElement;
@@ -40,8 +41,9 @@
 import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
 import org.apache.tuscany.sca.interfacedef.util.XMLType;
 import org.json.JSONObject;
+import org.junit.Test;
 
-public class JSONTransformerTestCase extends TestCase {
+public class JSONTransformerTestCase  {
     private static final String IPO_XML = "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
                                           + "  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
                                           + "  xmlns:ipo=\"http://www.example.com/IPO\""
@@ -73,9 +75,12 @@
 
     private static final String JSON_STR = "{\"xsl:root\":{\"@xmlns\":{\"xsl\":\"http://foo.com\"},\"data\":{\"$\":\"my
json string\"}}}";
 
+    @Test
     public void testXML2JSON() throws Exception {
+    	ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
+    	
         XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new
StringReader(IPO_XML));
-        XMLStreamReader2JSON t1 = new XMLStreamReader2JSON();
+        XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(extensionPointRegistry);
         JSONObject json = (JSONObject) t1.transform(reader, null);
         Assert.assertNotNull(json);
 
@@ -89,20 +94,23 @@
          streamWriter.flush();
          System.out.println(sw.toString());
          */
-
     }
 
+    @Test
     public void testJSON2XML() throws Exception {
+    	ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
+    	StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);
+    	
         JSON2XMLStreamReader t2 = new JSON2XMLStreamReader();
         XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null);
         StringWriter sw = new StringWriter();
         XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
-        new XMLStreamSerializer().serialize(reader2, streamWriter);
-        streamWriter.flush();
+        helper.save(reader2, streamWriter);
         Assert.assertTrue(sw.toString()
             .contains("<xsl:root xmlns:xsl=\"http://foo.com\"><data>my json string</data></xsl:root>"));
     }
 
+    @Test
     public void testJSON2OMElement() throws Exception {
         JSON2OMElement t1 = new JSON2OMElement();
         TransformationContext context = new TransformationContextImpl();
@@ -114,15 +122,16 @@
         // System.out.println(writer.toString());
     }
 
+    @Test
     public void testString2JSON() throws Exception {
         String json = "{\"name\":\"John\",\"age\":25}";
         String2JSON t1 = new String2JSON();
         JSONObject jsonObject = (JSONObject) t1.transform(json, null);
-        assertEquals(jsonObject.getString("name"), "John");
-        assertEquals(jsonObject.getInt("age"), 25);
+        Assert.assertEquals(jsonObject.getString("name"), "John");
+        Assert.assertEquals(jsonObject.getInt("age"), 25);
         JSON2String t2 = new JSON2String();
         String str = t2.transform(jsonObject, null);
-        assertTrue(str.contains("\"name\":\"John\""));
-        assertTrue(str.contains("\"age\":25"));
+        Assert.assertTrue(str.contains("\"name\":\"John\""));
+        Assert.assertTrue(str.contains("\"age\":25"));
     }
 }

Modified: tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java?rev=820844&r1=820843&r2=820844&view=diff
==============================================================================
--- tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java
(original)
+++ tuscany/java/sca/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/POJOTestCase.java
Thu Oct  1 23:25:51 2009
@@ -20,13 +20,14 @@
 
 import java.lang.reflect.Array;
 
-import junit.framework.TestCase;
+import junit.framework.Assert;
 
 import org.apache.tuscany.sca.databinding.TransformationContext;
 import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl;
 import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.junit.Test;
 
-public class POJOTestCase extends TestCase {
+public class POJOTestCase  {
     public void testPOJO() throws Exception {
         MyBean bean = new MyBean();
         bean.setName("Test");
@@ -55,33 +56,37 @@
 
         if (newBean != null && newBean.getClass().isArray()) {
             int len = Array.getLength(newBean);
-            assertEquals(Array.getLength(bean), len);
+            Assert.assertEquals(Array.getLength(bean), len);
             for (int i = 0; i < len; i++) {
-                assertEquals(Array.get(bean, i), Array.get(newBean, i));
+            	Assert.assertEquals(Array.get(bean, i), Array.get(newBean, i));
             }
             return;
         }
-        assertEquals(bean, newBean);
+        Assert.assertEquals(bean, newBean);
     }
 
+    @Test
     public void testString() throws Exception {
         roundTrip("ABC");
     }
 
+    @Test
     public void testNull() throws Exception {
         roundTrip(null);
     }
 
+    @Test
     public void testArray() throws Exception {
         roundTrip(new String[] {"123", "ABC"});
     }
 
+    @Test
     public void testByteArray() throws Exception {
         roundTrip("ABC".getBytes());
     }
 
+    @Test
     public void testPrimitive() throws Exception {
         roundTrip(123);
     }
-
 }



Mime
View raw message