You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by va...@apache.org on 2008/06/11 12:57:37 UTC

svn commit: r666618 - in /incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src: main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/ test/java/org/apache/tuscany/sca/itest/databindings/jaxb/

Author: vamsic007
Date: Wed Jun 11 03:57:36 2008
New Revision: 666618

URL: http://svn.apache.org/viewvc?rev=666618&view=rev
Log:
TUSCANY-2371 Databinding tests for StandardTypes, array of StandardTypes
 o Fix javax.xml.transform.Source related tests. The Source returned may use a different type of Source. Compare the content instead of using equals().

Modified:
    incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesServiceImpl.java
    incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesTransformer.java
    incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/test/java/org/apache/tuscany/sca/itest/databindings/jaxb/StandardTypesDatabindingTestCase.java

Modified: incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesServiceImpl.java?rev=666618&r1=666617&r2=666618&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesServiceImpl.java (original)
+++ incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesServiceImpl.java Wed Jun 11 03:57:36 2008
@@ -184,8 +184,7 @@
     }
     
     public Source getNewSource(Source src) {
-        src.setSystemId(src.getSystemId()+"AAA");
-        return src;
+        return StandardTypesTransformer.getNewSource(src);
     }
 
     public Source[] getNewSourceArray(Source[] srcs) {

Modified: incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesTransformer.java?rev=666618&r1=666617&r2=666618&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesTransformer.java (original)
+++ incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/main/java/org/apache/tuscany/sca/itest/databindings/jaxb/impl/StandardTypesTransformer.java Wed Jun 11 03:57:36 2008
@@ -19,6 +19,21 @@
 
 package org.apache.tuscany.sca.itest.databindings.jaxb.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+
+import org.xml.sax.InputSource;
+
 
 
 /**
@@ -40,4 +55,84 @@
         return obj;
     }
     
+    /**
+     * Returns a copy of the source object if the input is DOMSource, SAXSource or StreamSource.
+     * Returns the input object as is for other types.
+     */
+    public static Source getNewSource(Source src) {
+        Source ret = null;
+        if(src instanceof DOMSource) {
+            DOMSource dsrc = (DOMSource)src;
+            ret = new DOMSource(dsrc.getNode() != null ? dsrc.getNode().cloneNode(true) : null);
+        } else if(src instanceof SAXSource) {
+            SAXSource ssrc = (SAXSource)src;
+            if(ssrc.getInputSource().getByteStream() != null) {
+                InputStream inp = ssrc.getInputSource().getByteStream();
+                ByteArrayOutputStream bout = new ByteArrayOutputStream();
+                int b;
+                try {
+                    while((b = inp.read()) != -1) {
+                        bout.write(b);
+                    }
+                } catch (IOException ignored) {
+                }
+                try { bout.close();} catch (IOException ignored) {}
+                try { inp.reset();} catch (IOException ignored) {}
+                ret = new SAXSource(new InputSource(new ByteArrayInputStream(bout.toByteArray())));
+            } else if(ssrc.getInputSource().getCharacterStream() != null) {
+                Reader rdr = ssrc.getInputSource().getCharacterStream();
+                CharArrayWriter caw = new CharArrayWriter();
+                try {
+                    int c;
+                    while((c = rdr.read()) != -1) {
+                        caw.append((char)c);
+                    }
+                } catch (IOException ignored) {
+                }
+                caw.close();
+                try{ rdr.reset();} catch(IOException ignored) {}
+                ret = new SAXSource(new InputSource(new CharArrayReader(caw.toCharArray())));
+            } else {
+                ret = new SAXSource();
+            }
+        } else if(src instanceof StreamSource) {
+            StreamSource ssrc = (StreamSource)src;
+            if(ssrc.getInputStream() != null) {
+                InputStream inp = ssrc.getInputStream();
+                ByteArrayOutputStream bout = new ByteArrayOutputStream();
+                int b;
+                try {
+                    while((b = inp.read()) != -1) {
+                        bout.write(b);
+                    }
+                } catch (IOException ignored) {
+                }
+                try { bout.close();} catch (IOException ignored) {}
+                try { inp.reset();} catch (IOException ignored) {}
+                ret = new StreamSource(new ByteArrayInputStream(bout.toByteArray()));
+            } else if(ssrc.getReader() != null) {
+                Reader rdr = ssrc.getReader();
+                CharArrayWriter caw = new CharArrayWriter();
+                try {
+                    int c;
+                    while((c = rdr.read()) != -1) {
+                        caw.append((char)c);
+                    }
+                } catch (IOException ignored) {
+                }
+                caw.close();
+                try{ rdr.reset();} catch(IOException ignored) {}
+                ret = new StreamSource(new CharArrayReader(caw.toCharArray()));
+            } else {
+                ret = new StreamSource();
+            }
+        }
+        
+        if(ret != null) {
+            ret.setSystemId(src.getSystemId());
+        } else {
+            ret = src;
+        }
+        return ret;
+    }
 }

Modified: incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/test/java/org/apache/tuscany/sca/itest/databindings/jaxb/StandardTypesDatabindingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/test/java/org/apache/tuscany/sca/itest/databindings/jaxb/StandardTypesDatabindingTestCase.java?rev=666618&r1=666617&r2=666618&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/test/java/org/apache/tuscany/sca/itest/databindings/jaxb/StandardTypesDatabindingTestCase.java (original)
+++ incubator/tuscany/java/sca/itest/databindings/jaxb-bottom-up/src/test/java/org/apache/tuscany/sca/itest/databindings/jaxb/StandardTypesDatabindingTestCase.java Wed Jun 11 03:57:36 2008
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.URI;
@@ -39,9 +40,12 @@
 import javax.xml.datatype.Duration;
 import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
 import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import junit.framework.Assert;
@@ -332,7 +336,6 @@
      * Service method invoked is getNewSource.
      */
     @Test
-    // @Ignore("java.lang.RuntimeException: no data binding for javax.xml.transform.Source")
     public void testSCANewSource() throws Exception {
         StandardTypesServiceClient serviceClient =
             domain.getService(StandardTypesServiceClient.class, "StandardTypesServiceClientSCAComponent");
@@ -627,7 +630,7 @@
      * Service method invoked is getNewSource.
      */
     @Test
-    // @Ignore("java.lang.RuntimeException: no data binding for javax.xml.transform.Source")
+    @Ignore("junit.framework.ComparisonFailure: null expected:<... encoding=\"UTF-8\"?><[a>A</a]>> but was:<... encoding=\"UTF-8\"?><[return xmlns=\"http://jaxb.databindings.itest.sca.tuscany.apache.org/\">A</return]>>")
     public void testWSNewSource() throws Exception {
         StandardTypesServiceClient serviceClient =
             domain.getService(StandardTypesServiceClient.class, "StandardTypesServiceClientWSComponent");
@@ -639,7 +642,7 @@
      * Service method invoked is getNewSourceArray.
      */
     @Test
-    @Ignore("java.lang.IllegalArgumentException: javax.xml.bind.MarshalException")
+    @Ignore("org.apache.tuscany.sca.databinding.TransformationException: No path found for the transformation: java:array->org.apache.axiom.om.OMElement")
     public void testWSNewSourceArray() throws Exception {
         StandardTypesServiceClient serviceClient =
             domain.getService(StandardTypesServiceClient.class, "StandardTypesServiceClientWSComponent");
@@ -915,7 +918,6 @@
      * Service method invoked is getNewSource.
      */
     @Test
-    // @Ignore("java.lang.RuntimeException: no data binding for javax.xml.transform.Source")
     public void testSCALocalNewSource() throws Exception {
         StandardTypesServiceClient serviceClient =
             domain.getService(StandardTypesServiceClient.class, "StandardTypesLocalServiceClientSCAComponent");
@@ -927,7 +929,6 @@
      * Service method invoked is getNewSourceArray.
      */
     @Test
-    // @Ignore("java.lang.RuntimeException: no data binding for javax.xml.transform.Source")
     public void testSCALocalNewSourceArray() throws Exception {
         StandardTypesServiceClient serviceClient =
             domain.getService(StandardTypesServiceClient.class, "StandardTypesLocalServiceClientSCAComponent");
@@ -1269,7 +1270,7 @@
         }
     }
 
-    private void performTestNewSource(StandardTypesServiceClient serviceClient) {
+    private void performTestNewSource(StandardTypesServiceClient serviceClient) throws Exception {
         String xml = new String("<a>A</a>");
         Source[] srcs = new Source[3];
         srcs[0] = new DOMSource(new String2Node().transform(xml, null));
@@ -1278,13 +1279,13 @@
 
         for (int i = 0; i < srcs.length; ++i) {
             Source actual = serviceClient.getNewSourceForward(srcs[i]);
-            srcs[i].setSystemId(srcs[i].getSystemId() + "AAA");
+            Source expected = StandardTypesTransformer.getNewSource(srcs[i]);
             // [rfeng] The data may come back as a different source
-            // Assert.assertEquals(srcs[i], actual);
+            Assert.assertEquals(sourceToString(expected), sourceToString(actual));
         }
     }
 
-    private void performTestNewSourceArray(StandardTypesServiceClient serviceClient) {
+    private void performTestNewSourceArray(StandardTypesServiceClient serviceClient) throws Exception {
         String xml = new String("<a>A</a>");
         Source[] srcs = new Source[3];
         srcs[0] = new DOMSource(new String2Node().transform(xml, null));
@@ -1294,8 +1295,9 @@
         Source[] actual = serviceClient.getNewSourceArrayForward(srcs);
         Assert.assertEquals(srcs.length, actual.length);
         for (int i = 0; i < srcs.length; ++i) {
-            srcs[i].setSystemId(srcs[i].getSystemId() + "AAA");
-            // Assert.assertEquals(srcs[i], actual[i]);
+            Source expected = StandardTypesTransformer.getNewSource(srcs[i]);
+            // [rfeng] The data may come back as a different source
+            Assert.assertEquals(sourceToString(expected), sourceToString(actual[i]));
         }
 
     }
@@ -1347,4 +1349,15 @@
             }
         }
     }
+    
+    /**
+     * This method returns the content of a source object as String.
+     */
+    private String sourceToString(Source s) throws Exception {
+        StringWriter sw = new StringWriter();
+        Result r  = new StreamResult(sw);
+        TransformerFactory.newInstance().newTransformer().transform(s, r);
+        sw.close();
+        return sw.toString();
+    }
 }