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 2003/04/24 20:29:59 UTC
cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt NoAdderBean.java TestBeanWriter.java
rdonkin 2003/04/24 11:29:59
Modified: betwixt/src/test/org/apache/commons/betwixt
TestBeanWriter.java
Added: betwixt/src/test/org/apache/commons/betwixt NoAdderBean.java
Log:
Added some new test cases.
Revision Changes Path
1.12 +105 -0 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanWriter.java
Index: TestBeanWriter.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanWriter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TestBeanWriter.java 24 Apr 2003 08:52:20 -0000 1.11
+++ TestBeanWriter.java 24 Apr 2003 18:29:59 -0000 1.12
@@ -65,6 +65,8 @@
import java.io.PrintStream;
import java.io.StringWriter;
+import java.util.ArrayList;
+
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
@@ -73,6 +75,7 @@
import org.apache.commons.betwixt.io.CyclicReferenceException;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
+import org.apache.commons.betwixt.strategy.CapitalizeNameMapper;
/** Test harness for the BeanWriter
@@ -460,6 +463,108 @@
+ "<name><name>Harry</name></name>"
+ "</names>"
+"</Names>";
+
+ xmlAssertIsomorphicContent(
+ parseString(out.getBuffer().toString()),
+ parseString(xml),
+ true);
+ }
+
+ public void testWriteNameMapperStrategy() throws Exception {
+ ListOfNames names = new ListOfNames();
+ names.addName(new NameBean("Sid James"));
+ names.addName(new NameBean("Kenneth Williams"));
+ names.addName(new NameBean("Joan Simms"));
+ names.addName(new NameBean("Charles Hawtrey"));
+
+ StringWriter out = new StringWriter();
+ out.write("<?xml version='1.0'?>");
+
+ BeanWriter writer = new BeanWriter(out);
+ writer.setWriteEmptyElements(true);
+ writer.getXMLIntrospector().setWrapCollectionsInElement(true);
+ writer.setWriteIDs(false);
+ writer.write("CarryOn", names);
+
+ String xml = "<?xml version='1.0'?><CarryOn><names>"
+ + "<name><name>Sid James</name></name>"
+ + "<name><name>Kenneth Williams</name></name>"
+ + "<name><name>Joan Simms</name></name>"
+ + "<name><name>Charles Hawtrey</name></name>"
+ + "</names>"
+ +"</CarryOn>";
+
+ xmlAssertIsomorphicContent(
+ parseString(out.getBuffer().toString()),
+ parseString(xml),
+ true);
+
+ out = new StringWriter();
+ out.write("<?xml version='1.0'?>");
+
+ writer = new BeanWriter(out);
+ writer.setWriteEmptyElements(true);
+ writer.getXMLIntrospector().setWrapCollectionsInElement(true);
+ writer.setWriteIDs(false);
+ writer.getXMLIntrospector().setElementNameMapper(new CapitalizeNameMapper());
+ writer.write("CarryOn", names);
+
+ xml = "<?xml version='1.0'?><CarryOn><Names>"
+ + "<Name><Name>Sid James</Name></Name>"
+ + "<Name><Name>Kenneth Williams</Name></Name>"
+ + "<Name><Name>Joan Simms</Name></Name>"
+ + "<Name><Name>Charles Hawtrey</Name></Name>"
+ + "</Names>"
+ +"</CarryOn>";
+
+ xmlAssertIsomorphicContent(
+ parseString(out.getBuffer().toString()),
+ parseString(xml),
+ true);
+
+ ArrayList things = new ArrayList();
+ things.add(new NameBean("Sugar"));
+ things.add(new NameBean("Spice"));
+ things.add(new NameBean("All Things Nice"));
+
+ NoAdderBean bean = new NoAdderBean();
+ bean.setThings(things);
+
+ out = new StringWriter();
+ out.write("<?xml version='1.0'?>");
+ writer = new BeanWriter(out);
+ writer.setWriteEmptyElements(true);
+ writer.getXMLIntrospector().setWrapCollectionsInElement(true);
+ writer.setWriteIDs(false);
+ writer.write(bean);
+
+ xml = "<?xml version='1.0'?><NoAdderBean><things>"
+ + "<NameBean><name>Sugar</name></NameBean>"
+ + "<NameBean><name>Spice</name></NameBean>"
+ + "<NameBean><name>All Things Nice</name></NameBean>"
+ + "</things>"
+ +"</NoAdderBean>";
+
+ xmlAssertIsomorphicContent(
+ parseString(out.getBuffer().toString()),
+ parseString(xml),
+ true);
+
+ out = new StringWriter();
+ out.write("<?xml version='1.0'?>");
+ writer = new BeanWriter(out);
+ writer.setWriteEmptyElements(true);
+ writer.getXMLIntrospector().setWrapCollectionsInElement(true);
+ writer.setWriteIDs(false);
+ writer.getXMLIntrospector().setElementNameMapper(new CapitalizeNameMapper());
+ writer.write(bean);
+
+ xml = "<?xml version='1.0'?><NoAdderBean><Things>"
+ + "<NameBean><Name>Sugar</Name></NameBean>"
+ + "<NameBean><Name>Spice</Name></NameBean>"
+ + "<NameBean><Name>All Things Nice</Name></NameBean>"
+ + "</Things>"
+ +"</NoAdderBean>";
xmlAssertIsomorphicContent(
parseString(out.getBuffer().toString()),
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/NoAdderBean.java
Index: NoAdderBean.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/NoAdderBean.java,v 1.1 2003/04/24 18:29:58 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2003/04/24 18:29:58 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: NoAdderBean.java,v 1.1 2003/04/24 18:29:58 rdonkin Exp $
*/
package org.apache.commons.betwixt;
import java.util.List;
import java.util.ArrayList;
/** <p>A bean with a list property with a setter but no adder.</p>
*
* @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
*/
public class NoAdderBean {
private List things = new ArrayList();
public List getThings() {
return things;
}
public void setThings(List things) {
this.things = things;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org