commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy Element.java Elements.java TestElementsIO.java TestHyphenatedNameMapper.java
Date Mon, 16 Dec 2002 21:59:21 GMT
rdonkin     2002/12/16 13:59:21

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        BeanCreateRule.java
               betwixt/src/test/org/apache/commons/betwixt/strategy
                        TestHyphenatedNameMapper.java
  Added:       betwixt/src/test/org/apache/commons/betwixt/strategy
                        Element.java Elements.java TestElementsIO.java
  Log:
  Fixed bug reported by Tim Anderson who also contributed the test cases. This manifest in
differences between different kinds of NameMapper but the real cause was that betwixt wrongly
identified subelements mapped to the same name as the bean as recursive elements.
  
  Revision  Changes    Path
  1.13      +2 -1      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanCreateRule.java
  
  Index: BeanCreateRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanCreateRule.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BeanCreateRule.java	11 Dec 2002 22:12:11 -0000	1.12
  +++ BeanCreateRule.java	16 Dec 2002 21:59:21 -0000	1.13
  @@ -423,7 +423,8 @@
                   // this code is for making sure that recursive elements
                   // can also be used..
                   
  -                if (qualifiedName.equals(currentDescriptor.getQualifiedName())) {
  +                if ( qualifiedName.equals( currentDescriptor.getQualifiedName() ) 
  +                        && currentDescriptor.getPropertyName() != null ) {
                       log.trace("Creating generic rule for recursive elements");
                       int index = -1;
                       if (childDescriptor.isWrapCollectionsInElement()) {
  
  
  
  1.4       +58 -5     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestHyphenatedNameMapper.java
  
  Index: TestHyphenatedNameMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestHyphenatedNameMapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestHyphenatedNameMapper.java	26 Sep 2002 21:20:52 -0000	1.3
  +++ TestHyphenatedNameMapper.java	16 Dec 2002 21:59:21 -0000	1.4
  @@ -1,12 +1,65 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  + * $Header$
  + * $Revision$
  + * $Date$
    *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  + * ====================================================================
  + *
  + * 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$
    */
  +
   package org.apache.commons.betwixt.strategy;
   
   import java.util.ArrayList;
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/Element.java
  
  Index: Element.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/Element.java,v
1.1 2002/12/16 21:59:21 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/16 21:59:21 $
   *
   * ====================================================================
   *
   * 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/16 21:59:21 rdonkin Exp $
   */
  
  package org.apache.commons.betwixt.strategy;
  
  /**
   * <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/Elements.java
  
  Index: Elements.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/Elements.java,v
1.1 2002/12/16 21:59:21 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/16 21:59:21 $
   *
   * ====================================================================
   *
   * 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/16 21:59:21 rdonkin Exp $
   */
  
  package org.apache.commons.betwixt.strategy;
  
  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/TestElementsIO.java
  
  Index: TestElementsIO.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestElementsIO.java,v
1.1 2002/12/16 21:59:21 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/16 21:59:21 $
   *
   * ====================================================================
   *
   * 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: TestElementsIO.java,v 1.1 2002/12/16 21:59:21 rdonkin Exp $
   */
  
  package org.apache.commons.betwixt.strategy;
  
  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 TestElementsIO extends TestCase {
  
  //    private SimpleLog testLog;
  
      public TestElementsIO(String name) {
          super(name);
  //        testLog = new SimpleLog("[TextElementsIO]");
  //        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("[TextElementsIO:BeanReader]");
  //        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
          
          BeanReader reader = new BeanReader();
  //        reader.setLog(log);
  
  //        log = new SimpleLog("[TextElementsIO: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("[TextElementsIO:BeanWriter]");
  //        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
          
          BeanWriter result = new BeanWriter(writer);
  //        result.setLog(log);
          
  //        log = new SimpleLog("[TextElementsIO: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:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message