cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor EnumConvertorBuilder.java
Date Sun, 16 Nov 2003 08:55:29 GMT
ugo         2003/11/16 00:55:29

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor
                        EnumConvertorBuilder.java
  Added:       src/blocks/woody/test/org/apache/cocoon/woody/datatype
                        EnumConvertorTestCase.conf.xml
               src/blocks/woody/test/org/apache/cocoon/woody/datatype/convertor
                        Sex.java EnumConvertorBuilderTestCase.java
  Log:
  Added testcase for EnumConvertorBuilder.
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/EnumConvertorTestCase.conf.xml
  
  Index: EnumConvertorTestCase.conf.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <wd:field id="sex" xmlns:wd="http://apache.org/cocoon/woody/definition/1.0">
    <wd:label>Sex</wd:label>
    <wd:datatype base="enum">
    	<wd:convertor type="enum">
        <wd:enum>org.apache.cocoon.woody.datatype.convertor.Sex</wd:enum>
    	</wd:convertor>
    </wd:datatype>
    <wd:selection-list type="enum" class="org.apache.cocoon.woody.datatype.convertor.Sex"/>
  </wd:field>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/convertor/Sex.java
  
  Index: Sex.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  
  /**
   * Description of Sex.
   * @version CVS $Id: Sex.java,v 1.1 2003/11/16 08:55:29 ugo Exp $
   */
  public class Sex {
  
      public static final Sex MALE = new Sex("M");
      public static final Sex FEMALE = new Sex("F");
      private String code;
  
      private Sex(String code) { this.code = code; }
  
      public String toString() {
        // Will probably have some i18n support here
        switch(code.charAt(0)) {
            case 'M' : return this.getClass().getName() + ".MALE";
            case 'F' : return this.getClass().getName() + ".FEMALE";
            default : return "unknown"; // Should never happen
        }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/convertor/EnumConvertorBuilderTestCase.java
  
  Index: EnumConvertorBuilderTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import junit.framework.TestCase;
  
  import org.apache.cocoon.woody.Constants;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.impl.ResourceSource;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  /**
   * Test case for the {@link EnumConvertorBuilder} class.
   * 
   * @version CVS $Id: EnumConvertorBuilderTestCase.java,v 1.1 2003/11/16 08:55:29 ugo Exp
$
   */
  public class EnumConvertorBuilderTestCase extends TestCase {
  
      protected DocumentBuilder parser;
  
      /* (non-Javadoc)
       * @see junit.framework.TestCase#setUp()
       */
      protected void setUp() throws Exception {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          parser = factory.newDocumentBuilder();
      }
  
      /* (non-Javadoc)
       * @see junit.framework.TestCase#tearDown()
       */
      protected void tearDown() throws Exception {
      }
  
      public EnumConvertorBuilderTestCase(String name) {
          super(name);
      }
  
      /**
       * Test the {@link EnumConvertorBuilder#build(org.w3c.dom.Element)
       * build} method.
       * @throws Exception
       */
      public void testBuild() throws Exception {
          Source confSource = new ResourceSource("resource://org/apache/cocoon/woody/datatype/EnumConvertorTestCase.conf.xml");
          Document sample = parser.parse(confSource.getInputStream());
          Element convertorElement = (Element) sample.getElementsByTagNameNS(Constants.WD_NS,
"convertor").item(0);
          String enumClassName = convertorElement.getElementsByTagNameNS(Constants.WD_NS,
"enum").item(0).getFirstChild().getNodeValue();
          EnumConvertorBuilder builder = new EnumConvertorBuilder();
          Convertor convertor = builder.build(convertorElement);
          assertTrue("The returned convertor is not an EnumConvertor",
                  convertor instanceof EnumConvertor);
          assertEquals("The convertor does not convert the expected class",
                  Class.forName(enumClassName), convertor.getTypeClass());
      }
  }
  
  
  
  1.3       +3 -2      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/EnumConvertorBuilder.java
  
  Index: EnumConvertorBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/EnumConvertorBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EnumConvertorBuilder.java	6 Nov 2003 23:03:50 -0000	1.2
  +++ EnumConvertorBuilder.java	16 Nov 2003 08:55:29 -0000	1.3
  @@ -55,7 +55,8 @@
   import org.w3c.dom.Element;
   
   /**
  - * Description of EnumConvertorBuilder.
  + * Builds {@link EnumConvertor}s.
  + * 
    * @version CVS $Id$
    */
   public class EnumConvertorBuilder implements ConvertorBuilder {
  
  
  

Mime
View raw message