You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2005/10/09 22:11:09 UTC

svn commit: r312496 - in /jakarta/commons/proper/betwixt/trunk: project.xml src/test/org/apache/commons/betwixt/TestTextMapping.java

Author: rdonkin
Date: Sun Oct  9 13:11:04 2005
New Revision: 312496

URL: http://svn.apache.org/viewcvs?rev=312496&view=rev
Log:
Unit tests for bug fixed earlier today. Submitted by Thomas Dudziak. Issue #36978.

Added:
    jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestTextMapping.java
Modified:
    jakarta/commons/proper/betwixt/trunk/project.xml

Modified: jakarta/commons/proper/betwixt/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/project.xml?rev=312496&r1=312495&r2=312496&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/project.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/project.xml Sun Oct  9 13:11:04 2005
@@ -137,7 +137,11 @@
   </developers>
     <contributors>
     <contributor>
-      <name>Brian Pugh</name>
+      <name>Dave Brosius</name>
+      <email></email>
+    </contributor>
+    <contributor>
+      <name>Thomas Dudziak</name>
       <email></email>
     </contributor>
     <contributor>
@@ -145,7 +149,7 @@
       <email></email>
     </contributor>
     <contributor>
-      <name>Dave Brosius</name>
+      <name>Brian Pugh</name>
       <email></email>
     </contributor>
   </contributors>

Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestTextMapping.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestTextMapping.java?rev=312496&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestTextMapping.java (added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/TestTextMapping.java Sun Oct  9 13:11:04 2005
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.apache.commons.betwixt;
+
+
+import java.beans.IntrospectionException;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.apache.commons.betwixt.io.BeanReader;
+import org.apache.commons.betwixt.io.BeanWriter;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Tests the mapping of a property to the inner text of an element.
+ * 
+ * @author Thomas Dudziak (tomdz@apache.org)
+ */
+public class TestTextMapping extends AbstractTestCase
+{
+    public static class Element
+    {
+        private String value;
+
+        public String getValue()
+        {
+            return value;
+        }
+        public void setValue(String value)
+        {
+            this.value = value;
+        }
+    }
+
+    private static final String MAPPING =
+        "<?xml version=\"1.0\"?>\n"+
+        "<betwixt-config>\n"+
+        "  <class name=\"org.apache.commons.betwixt.TestTextMapping$Element\">\n"+
+        "    <element name=\"element\">\n"+
+        "      <text property=\"value\"/>\n"+
+        "    </element>\n"+
+        "  </class>\n"+
+        "</betwixt-config>";
+    private static final String EXPECTED =
+        "<?xml version=\"1.0\" ?>\n"+
+        "  <element>Some text</element>\n";
+    
+    public TestTextMapping(String testName)
+    {
+        super(testName);
+    }
+
+    public void testRoundTripWithSingleMappingFile() throws IOException, SAXException, IntrospectionException
+    {
+        Element element = new Element();
+
+        element.setValue("Some text");
+
+        StringWriter outputWriter = new StringWriter();
+
+        outputWriter.write("<?xml version=\"1.0\" ?>\n");
+
+        BeanWriter beanWriter = new BeanWriter(outputWriter);
+        beanWriter.setEndOfLine("\n");
+        beanWriter.enablePrettyPrint();
+        beanWriter.setWriteEmptyElements(true);
+        beanWriter.getBindingConfiguration().setMapIDs(false);
+        beanWriter.getXMLIntrospector().register(new InputSource(new StringReader(MAPPING)));
+        beanWriter.setEndOfLine("\n"); //force to \n so expected values match for sure
+        beanWriter.write(element);
+
+        String output = outputWriter.toString();
+
+        assertEquals(EXPECTED, output);
+            
+        BeanReader beanReader = new BeanReader();
+
+        beanReader.registerMultiMapping(new InputSource(new StringReader(MAPPING)));
+
+        StringReader xmlReader = new StringReader(output);
+
+        element = (Element)beanReader.parse(xmlReader);
+
+        assertEquals("Some text",
+                     element.getValue());
+    }
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org