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/07/31 13:38:40 UTC
svn commit: r226631 -
/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMapUpdater.java
Author: rdonkin
Date: Sun Jul 31 04:38:37 2005
New Revision: 226631
URL: http://svn.apache.org/viewcvs?rev=226631&view=rev
Log:
Test case for map updater problem. Contributed by Glenn Goldenberg.
Added:
jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMapUpdater.java
Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMapUpdater.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMapUpdater.java?rev=226631&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMapUpdater.java (added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMapUpdater.java Sun Jul 31 04:38:37 2005
@@ -0,0 +1,98 @@
+/*
+ * 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.io;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.betwixt.AbstractTestCase;
+import org.xml.sax.InputSource;
+
+public class TestMapUpdater extends AbstractTestCase {
+
+ public TestMapUpdater(String testName) {
+ super(testName);
+ }
+
+ public void testMapUpdater() throws Exception {
+ String config = "<?xml version='1.0'?>"
+ + "<betwixt-config primitiveTypes='attribute'>"
+ + " <class name='org.apache.commons.betwixt.io.TestMapUpdater$ParentBean'>"
+ + " <element name='parentBean'>"
+ + " <element name='pairs'>"
+ + " <element property='pairs' updater='addPair'/>"
+ + " </element>"
+ + " <addDefaults add-properties='true' add-adders='false'/>"
+ + " </element>" + " </class>" + "</betwixt-config>";
+
+ String result = "<?xml version=\"1.0\"?>\n"
+ + " <parentBean id=\"1\">\n" + " <pairs>\n"
+ + " <entry id=\"2\">\n" + " <key>key</key>\n"
+ + " <value>value</value>\n" + " </entry>\n"
+ + " </pairs>\n" + " </parentBean>\n";
+
+ ParentBean pb = new ParentBean();
+ pb.getPairs().put("key", "value");
+
+ StringWriter writer = new StringWriter();
+ BeanWriter beanWriter = new BeanWriter(writer);
+ beanWriter.enablePrettyPrint();
+ beanWriter.getXMLIntrospector().register(
+ new InputSource(new StringReader(config)));
+ beanWriter.writeXmlDeclaration("<?xml version=\"1.0\"?>");
+ beanWriter.write(pb);
+
+ xmlAssertIsomorphic(parseString(result), parseString(writer));
+
+ BeanReader beanReader = new BeanReader();
+ beanReader.registerMultiMapping(new InputSource(
+ new StringReader(config)));
+
+ ParentBean pbRead = (ParentBean) beanReader.parse(new StringReader(
+ writer.toString()));
+
+ StringWriter writer2 = new StringWriter();
+ BeanWriter beanWriter2 = new BeanWriter(writer2);
+ beanWriter2.enablePrettyPrint();
+ beanWriter2.getXMLIntrospector().register(
+ new InputSource(new StringReader(config)));
+ beanWriter2.writeXmlDeclaration("<?xml version=\"1.0\"?>");
+ beanWriter2.write(pbRead);
+
+ xmlAssertIsomorphic(parseString(result), parseString(writer2));
+
+ }
+
+ public static class ParentBean {
+ private Map pairs = new HashMap();
+
+ public Map getPairs() {
+ return pairs;
+ }
+
+ public void setPairs(Map pairs) {
+ this.pairs = pairs;
+ }
+
+ public void addPair(String key, String value) {
+ pairs.put(key, value);
+ }
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org