[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: svn commit: r226680 -
From: rdonkin () apache ! org
Date: 2005-07-31 19:05:26
Message-ID: 20050731190526.10273.qmail () minotaur ! apache ! org
[Download RAW message or body]
Author: rdonkin
Date: Sun Jul 31 12:05:22 2005
New Revision: 226680
URL: http://svn.apache.org/viewcvs?rev=226680&view=rev
Log:
Unit test demonstrating problems with mixed collections when add-adder is used. \
Contributed by Glenn Goldenberg.
Added:
jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMixedCollection.java
Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMixedCollection.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMixedCollection.java?rev=226680&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMixedCollection.java \
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/io/TestMixedCollection.java \
Sun Jul 31 12:05:22 2005 @@ -0,0 +1,126 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import org.apache.commons.betwixt.AbstractTestCase;
+import org.xml.sax.InputSource;
+
+import junit.framework.TestCase;
+
+
+public class TestMixedCollection extends AbstractTestCase {
+ public TestMixedCollection(String name) {
+ super(name);
+ }
+
+ public void testWithDefaults() throws Exception {
+ toXml(true);
+ }
+
+ public void testWithoutDefaults() throws Exception {
+ toXml(false);
+ }
+
+ protected void toXml(boolean addAdders) throws Exception {
+ StringReader configReader = new StringReader(
+ "<?xml version='1.0' ?>"
+ + "<betwixt-config primitiveTypes='attribute'>"
+ + " <class \
name='org.apache.commons.betwixt.io.TestMixedCollection$ParentBean'>" + \
+ " <element name='parentBean'>" + + " \
<element name='childBeans'>" + + " <element \
property='childBeans'/>" + + " </element>"
+ + " <addDefaults add-properties='true' \
guess-names='false' add-adders='" + + addAdders
+ + "'/>"
+ + " </element>"
+ + " </class>"
+ + " <class \
name='org.apache.commons.betwixt.io.TestMixedCollection$ChildBean1'>" + \
+ " <element name='childBean1'>" + + " \
<addDefaults/>" + + " </element>"
+ + " </class>"
+ + " <class \
name='org.apache.commons.betwixt.io.TestMixedCollection$ChildBean2'>" + \
+ " <element name='childBean2'>" + + " \
<addDefaults/>" + " </element>" + + " </class>" + \
"</betwixt-config>"); +
+ ParentBean pb = new ParentBean();
+ pb.setStuff("stuff");
+ ChildBean1 cb1 = new ChildBean1();
+ pb.getChildBeans().add(cb1);
+ ChildBean2 cb2 = new ChildBean2();
+ pb.getChildBeans().add(cb2);
+
+ StringWriter writer = new StringWriter();
+ BeanWriter beanWriter = new BeanWriter(writer);
+ beanWriter.enablePrettyPrint();
+ beanWriter.getXMLIntrospector().register(
+ new InputSource(configReader));
+ beanWriter.writeXmlDeclaration("<?xml version=\"1.0\"?>");
+ beanWriter.write(pb);
+
+ String expected = "<?xml version='1.0'?>" +
+ "<parentBean stuff='stuff' id='1'>" +
+ " <childBeans>" +
+ " <childBean1/>" +
+ " <childBean2/>" +
+ " </childBeans>" +
+ "</parentBean>";
+
+ xmlAssertIsomorphic(parseString(expected), parseString(writer));
+ }
+
+ public static class ParentBean {
+ private List childBeans = new ArrayList();
+
+ private String stuff = null;
+
+ public List getChildBeans() {
+ return childBeans;
+ }
+
+ public void setChildBeans(List childBeans) {
+ this.childBeans = childBeans;
+ }
+
+ public void addChildBean(ChildBean childBean) {
+ getChildBeans().add(childBean);
+ }
+
+ public String getStuff() {
+ return stuff;
+ }
+
+ public void setStuff(String stuff) {
+ this.stuff = stuff;
+ }
+ }
+
+ public static abstract class ChildBean {
+ }
+
+ public static class ChildBean1 extends ChildBean {
+ }
+
+ public static class ChildBean2 extends ChildBean {
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic