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 2002/12/23 20:26:53 UTC
cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt Element.java Elements.betwixt Elements.java TestElementsAlt.java
rdonkin 2002/12/23 11:26:53
Modified: betwixt/src/test/org/apache/commons/betwixt/dotbetwixt
TestBeanToXml.java
Added: betwixt/src/test/org/apache/commons/betwixt/strategy/alt
Element.java Elements.betwixt Elements.java
TestElementsAlt.java
Log:
Added some units tests for problem with adding updater defaults
Revision Changes Path
1.5 +9 -5 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java
Index: TestBeanToXml.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestBeanToXml.java 15 Dec 2002 19:03:34 -0000 1.4
+++ TestBeanToXml.java 23 Dec 2002 19:26:53 -0000 1.5
@@ -68,6 +68,7 @@
import org.apache.commons.betwixt.xmlunit.XmlTestCase;
import org.apache.commons.betwixt.io.BeanWriter;
+import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.logging.LogFactory;
@@ -107,10 +108,13 @@
public void testSimpleBean() throws Exception {
StringWriter out = new StringWriter();
out.write("<?xml version='1.0' encoding='UTF-8'?>");
-// SimpleLog log = new SimpleLog("LOG");
+// SimpleLog log = new SimpleLog("[testSimpleBean:XMLIntrospector]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
BeanWriter writer = new BeanWriter(out);
// writer.getXMLIntrospector().setLog(log);
+
+// log = new SimpleLog("[testSimpleBean:XMLIntrospectorHelper]");
+// XMLIntrospectorHelper.setLog(log);
writer.setWriteIDs(false);
SimpleTestBean bean = new SimpleTestBean("alpha-value","beta-value","gamma-value");
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/Element.java
Index: Element.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/Element.java,v 1.1 2002/12/23 19:26:53 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2002/12/23 19:26:53 $
*
* ====================================================================
*
* 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: Element.java,v 1.1 2002/12/23 19:26:53 rdonkin Exp $
*/
package org.apache.commons.betwixt.strategy.alt;
/**
* <code>Element</code> is a sample bean for use with test cases
*
* @author <a href="mailto:tima@intalio.com">Tim Anderson</a>
* @version $Revision: 1.1 $
*/
public class Element {
private String value;
public Element() {
}
public Element(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/Elements.betwixt
Index: Elements.betwixt
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<info>
<element name="elements">
<element name="element" property="elements"/>
<addDefaults/>
</element>
</info>
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/Elements.java
Index: Elements.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/Elements.java,v 1.1 2002/12/23 19:26:53 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2002/12/23 19:26:53 $
*
* ====================================================================
*
* 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: Elements.java,v 1.1 2002/12/23 19:26:53 rdonkin Exp $
*/
package org.apache.commons.betwixt.strategy.alt;
import java.util.HashMap;
import java.util.Iterator;
/**
* <code>Elements</code> is a sample bean for use with test cases
*
* @author <a href="mailto:tima@intalio.com">Tim Anderson</a>
* @version $Revision: 1.1 $
*/
public class Elements {
private HashMap elements = new HashMap();
public Elements() {
}
public void addElement(Element element) {
elements.put(element.getValue(), element);
}
public Iterator getElements() {
return elements.values().iterator();
}
public Element getElement(String name) {
return (Element) elements.get(name);
}
}
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/TestElementsAlt.java
Index: TestElementsAlt.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/alt/TestElementsAlt.java,v 1.1 2002/12/23 19:26:53 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2002/12/23 19:26:53 $
*
* ====================================================================
*
* 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: TestElementsAlt.java,v 1.1 2002/12/23 19:26:53 rdonkin Exp $
*/
package org.apache.commons.betwixt.strategy.alt;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import junit.framework.TestCase;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.betwixt.XMLIntrospector;
import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.betwixt.io.BeanCreateRule;
import org.apache.commons.betwixt.strategy.CapitalizeNameMapper;
import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
import org.apache.commons.betwixt.strategy.DefaultNameMapper;
import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
import org.apache.commons.betwixt.strategy.NameMapper;
/**
* Tests streaming/destreaming of an <code>Elements</code> bean,
* a container for <code>Element</code> instances, using various name mappers
* The objective of this is to verify that containers whose names
* are plurals of their contents can be written and read back successfully.
*
* @author <a href="mailto:tima@intalio.com">Tim Anderson</a>
*/
public class TestElementsAlt extends TestCase {
// private SimpleLog testLog;
public TestElementsAlt(String name) {
super(name);
// testLog = new SimpleLog("[TestElementsAlt]");
// testLog.setLevel(SimpleLog.LOG_LEVEL_TRACE);
}
public void testCapitalizeNameMapper() throws Exception {
// testLog.debug("Testing capitalize name mapper");
doTest(new CapitalizeNameMapper(), "capitalize name mapper");
}
public void testDecapitalizeNameMapper() throws Exception {
// testLog.debug("Testing decapitalize name mapper");
doTest(new DecapitalizeNameMapper(), "decapitalize name mapper");
}
public void testDefaultElementMapper() throws Exception {
// testLog.debug("Testing default name mapper");
doTest(new DefaultNameMapper(), "default name mapper");
}
public void testHyphenatedNameMapper() throws Exception {
// testLog.debug("Testing hyphenated name mapper");
doTest(new HyphenatedNameMapper(), "hyphenated name mapper");
}
private void doTest(NameMapper mapper, String testName) throws Exception {
Elements elements = new Elements();
elements.addElement(new Element("a"));
elements.addElement(new Element("b"));
elements.addElement(new Element("c"));
StringWriter out = new StringWriter();
BeanWriter writer = newBeanWriter(out, mapper);
writer.write(elements);
writer.flush();
String xmlOut = out.toString();
// testLog.debug(xmlOut);
StringReader in = new StringReader(xmlOut);
// SimpleLog log = new SimpleLog("[TestElementsAlt:BeanReader]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
BeanReader reader = new BeanReader();
// reader.setLog(log);
// log = new SimpleLog("[TestElementsAlt:BeanReader]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
// BeanCreateRule.setLog(log);
reader.setXMLIntrospector(newXMLIntrospector(mapper));
reader.registerBeanClass(Elements.class);
Elements result = (Elements) reader.parse(in);
assertNotNull("Element 'a' is null (" + testName + ")", result.getElement("a"));
assertNotNull("Element 'b' is null (" + testName + ")", result.getElement("b"));
assertNotNull("Element 'c' is null (" + testName + ")", result.getElement("c"));
}
private BeanWriter newBeanWriter(Writer writer, NameMapper mapper) {
// SimpleLog log = new SimpleLog("[TestElementsAlt:BeanWriter]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
BeanWriter result = new BeanWriter(writer);
// result.setLog(log);
// log = new SimpleLog("[TestElementsAlt:AbstractBeanWriter]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
// result.setAbstractBeanWriterLog(log);
result.setXMLIntrospector(newXMLIntrospector(mapper));
result.enablePrettyPrint();
result.setWriteIDs(false);
return result;
}
private XMLIntrospector newXMLIntrospector(NameMapper mapper) {
XMLIntrospector introspector = new XMLIntrospector();
introspector.setAttributesForPrimitives(true);
introspector.setWrapCollectionsInElement(false);
introspector.setElementNameMapper(mapper);
return introspector;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>