cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor EnumConvertorBuilderTestCase.java EnumConvertorTestCase.java EnumConvertorTestCase.conf.xml
Date Tue, 09 Mar 2004 13:03:13 GMT
cziegeler    2004/03/09 05:03:13

  Added:       src/blocks/forms/test/org/apache/cocoon/forms/datatype
                        FlowJXPathSelectionListTestCase.source.xml
                        EnumSelectionListTestCase.xtest
                        DynamicSelectionListTestCase.source.xml Sex.java
                        EnumSelectionListTestCase.java
                        FlowJXPathSelectionListTestCase.dest.xml
                        FlowJXPathSelectionListTestCase.xtest
                        DynamicSelectionListTestCase.java
                        FlowJXPathSelectionListTestCaseWithNull.dest.xml
                        EnumSelectionListTestCase.dest-no-null.xml
                        DynamicSelectionListTestCase.dest.xml
                        DynamicSelectionListTestCase.xtest
                        EnumSelectionListTestCase.dest.xml
                        FlowJXPathSelectionListTestCase.java
               src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor
                        EnumConvertorBuilderTestCase.java
                        EnumConvertorTestCase.java
                        EnumConvertorTestCase.conf.xml
  Removed:     src/blocks/forms/test/org/apache/cocoon/woody/datatype
                        DynamicSelectionListTestCase.dest.xml
                        EnumSelectionListTestCase.dest.xml
                        EnumSelectionListTestCase.java
                        EnumSelectionListTestCase.dest-no-null.xml
                        EnumSelectionListTestCase.xtest Sex.java
                        FlowJXPathSelectionListTestCase.source.xml
                        DynamicSelectionListTestCase.xtest
                        DynamicSelectionListTestCase.source.xml
                        FlowJXPathSelectionListTestCaseWithNull.dest.xml
                        FlowJXPathSelectionListTestCase.xtest
                        FlowJXPathSelectionListTestCase.java
                        DynamicSelectionListTestCase.java
                        FlowJXPathSelectionListTestCase.dest.xml
               src/blocks/forms/test/org/apache/cocoon/woody/datatype/convertor
                        EnumConvertorBuilderTestCase.java
                        EnumConvertorTestCase.java
                        EnumConvertorTestCase.conf.xml
  Log:
  Rename test classes
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml
  
  Index: FlowJXPathSelectionListTestCase.source.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
    Copyright 1999-2004 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.
  -->
  
  <!--+
      |   Source file for FlowModelSelectionList test case.
      |   $Id: FlowJXPathSelectionListTestCase.source.xml,v 1.1 2004/03/09 13:03:10 cziegeler Exp $
      +-->
  
  <wd:field xmlns:wd="http://apache.org/cocoon/woody/definition/1.0"
    id="sample" required="false">
    <wd:datatype base="string"/>
    <wd:selection-list model="beans"/>
  </wd:field>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.xtest
  
  Index: EnumSelectionListTestCase.xtest
  ===================================================================
  <?xml version="1.0" ?>
  <!--
    Copyright 1999-2004 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.
  -->
  <testcase>
   <annotation>
    Test Cases: Woody Enum Selection List
   </annotation>
  
   <logkit>
    <factories>
     <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
    </factories>
    <targets>
     <stream id="root">
      <stream>System.out</stream>
      <format type="extended">
       %7.7{priority} %5.5{time}   [%9.9{category}] (%{context}): %{message}\n%{throwable}
      </format>
     </stream>
    </targets>
    <categories>
     <category name="test" log-level="ERROR">
      <log-target id-ref="root"/>
     </category>
    </categories>
   </logkit>
  
   <context/>
  
   <roles>
  
    <role name="org.apache.cocoon.woody.datatype.DatatypeManager"
      shorthand="woody-datatype"
      default-class="org.apache.cocoon.woody.datatype.DefaultDatatypeManager"/>
  
    <role name="org.apache.cocoon.woody.expression.ExpressionManager"
      shorthand="woody-expression"
      default-class="org.apache.cocoon.woody.expression.DefaultExpressionManager"/>
  
    <role name="org.apache.excalibur.xmlizer.XMLizer"
          shorthand="xmlizer"
          default-class="org.apache.excalibur.xmlizer.DefaultXMLizer"/>
  
    <role name="org.apache.excalibur.xml.sax.SAXParser"
          shorthand="xml-parser"
          default-class="org.apache.excalibur.xml.impl.JaxpParser"/>
  
   </roles>
  
   <components>
    <woody-datatype logger="woody">
      <datatypes>
        <datatype name="string" src="org.apache.cocoon.woody.datatype.typeimpl.StringTypeBuilder">
          <convertors default="dummy" plain="dummy">
            <convertor name="dummy" src="org.apache.cocoon.woody.datatype.convertor.DummyStringConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="long" src="org.apache.cocoon.woody.datatype.typeimpl.LongTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainLongConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingLongConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="decimal" src="org.apache.cocoon.woody.datatype.typeimpl.DecimalTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainDecimalConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingDecimalConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="date" src="org.apache.cocoon.woody.datatype.typeimpl.DateTypeBuilder">
          <convertors default="formatting" plain="millis">
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingDateConvertorBuilder"/>
            <convertor name="millis" src="org.apache.cocoon.woody.datatype.convertor.MillisDateConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="boolean" src="org.apache.cocoon.woody.datatype.typeimpl.BooleanTypeBuilder">
          <convertors default="plain" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainBooleanConvertorBuilder"/>
          </convertors>
        </datatype>  
        <datatype name="integer" src="org.apache.cocoon.woody.datatype.typeimpl.IntegerTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainIntegerConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingIntegerConvertorBuilder"/>
          </convertors>
        </datatype>  
      </datatypes>
      <validation-rules>
        <validation-rule name="length" src="org.apache.cocoon.woody.datatype.validationruleimpl.LengthValidationRuleBuilder"/>
        <validation-rule name="email" src="org.apache.cocoon.woody.datatype.validationruleimpl.EmailValidationRuleBuilder"/>
        <validation-rule name="value-count" src="org.apache.cocoon.woody.datatype.validationruleimpl.ValueCountValidationRuleBuilder"/>
        <validation-rule name="range" src="org.apache.cocoon.woody.datatype.validationruleimpl.RangeValidationRuleBuilder"/>
        <validation-rule name="assert" src="org.apache.cocoon.woody.datatype.validationruleimpl.AssertValidationRuleBuilder"/>
        <validation-rule name="mod10" src="org.apache.cocoon.woody.datatype.validationruleimpl.Mod10ValidationRuleBuilder"/>
        <validation-rule name="regexp" src="org.apache.cocoon.woody.datatype.validationruleimpl.RegExpValidationRuleBuilder"/>
      </validation-rules>
    </woody-datatype>
  
    <woody-expression logger="woody.expression"/>
  
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml
  
  Index: DynamicSelectionListTestCase.source.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
    Copyright 1999-2004 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.
  -->
  
  <!--+
      |   Source file for DynamicSelectionList test case.
      |   $Id: DynamicSelectionListTestCase.source.xml,v 1.1 2004/03/09 13:03:10 cziegeler Exp $
      +-->
  
  <wd:selection-list xmlns:wd="http://apache.org/cocoon/woody/definition/1.0">
    <wd:convertor type="formatting" base="date">
      <wd:patterns>
        <wd:pattern>yyyy-MM-dd</wd:pattern>
      </wd:patterns>
    </wd:convertor>
    <wd:item value="2003-10-11"/>
    <wd:item value="1963-02-04"><wd:label>My birthdate</wd:label></wd:item>
  </wd:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/Sex.java
  
  Index: Sex.java
  ===================================================================
  /*
   * Copyright 1999-2004 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.cocoon.forms.datatype;
  
  
  /**
   * Description of Sex.
   * @version CVS $Id: Sex.java,v 1.1 2004/03/09 13:03:10 cziegeler 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/forms/test/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.java
  
  Index: EnumSelectionListTestCase.java
  ===================================================================
  /*
   * Copyright 1999-2004 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.cocoon.forms.datatype;
  
  import java.io.Writer;
  import java.util.Locale;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  
  import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.WrapperServiceManager;
  import org.apache.cocoon.transformation.I18nTransformer;
  import org.apache.cocoon.forms.Constants;
  import org.apache.cocoon.forms.datatype.EnumType;
  import org.apache.cocoon.xml.dom.DOMBuilder;
  import org.apache.excalibur.source.impl.ResourceSource;
  import org.custommonkey.xmlunit.Diff;
  import org.w3c.dom.Document;
  
  /**
   * Test case for Woody's DynamicSelectionList datatype.
   * @version CVS $Id: EnumSelectionListTestCase.java,v 1.1 2004/03/09 13:03:10 cziegeler Exp $
   */
  public class EnumSelectionListTestCase extends ExcaliburTestCase {
  
      protected ServiceManager serviceManager;
      protected DatatypeManager datatypeManager;
      protected DocumentBuilder parser;
  
      /**
       * Construct a new test case.
       * @param name The test case's name.
       */
      public EnumSelectionListTestCase(String name) {
          super(name);
      }
  
      /* (non-Javadoc)
       * @see junit.framework.TestCase#setUp()
       */
      protected void setUp() throws Exception {
          super.setUp();
          serviceManager = new WrapperServiceManager(manager); 
          datatypeManager = (DatatypeManager) serviceManager.lookup(DatatypeManager.ROLE);
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          parser = factory.newDocumentBuilder();
      }
      
      /* (non-Javadoc)
       * @see junit.framework.TestCase#tearDown()
       */
      protected void tearDown() throws Exception {
          if (datatypeManager != null) {
              serviceManager.release(datatypeManager);
          }
          super.tearDown();
      }
      
      /**
       * Test the generateSaxFragment method.
       * @throws MalformedURLException
       * @throws ParserConfigurationException
       */
      public void testGenerateSaxFragment() throws Exception {
          DOMBuilder dest = new DOMBuilder();
          EnumSelectionList list = 
              new EnumSelectionList(Sex.class.getName(), new EnumType(), false);
          list.generateSaxFragment(dest, Locale.ENGLISH);
          ResourceSource expectedSource =
              new ResourceSource("resource://org/apache/cocoon/woody/datatype/EnumSelectionListTestCase.dest-no-null.xml");
          Document expected = parser.parse(expectedSource.getInputStream());
          assertEqual("Test if output is what is expected",
                  expected, dest.getDocument());
      }
      
      /**
       * Test the generateSaxFragment method with a nullable selection list
       * @throws MalformedURLException
       * @throws ParserConfigurationException
       */
      public void testGenerateSaxFragmentNullable() throws Exception {
          DOMBuilder dest = new DOMBuilder();
          EnumSelectionList list = 
              new EnumSelectionList(Sex.class.getName(), new EnumType(), true);
          list.generateSaxFragment(dest, Locale.ENGLISH);
          ResourceSource expectedSource =
              new ResourceSource("resource://org/apache/cocoon/woody/datatype/EnumSelectionListTestCase.dest.xml");
          Document expected = parser.parse(expectedSource.getInputStream());
          assertEqual("Test if output is what is expected",
                  expected, dest.getDocument());
      }
      
      /**
       * Check is the source document is equal to the one produced by the method under test.
       * @param message A message to print in case of failure.
       * @param expected The expected (source) document.
       * @param actual The actual (output) document.
       */
      private void assertEqual(String message, Document expected, Document actual) {
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
          // DIRTY HACK WARNING: we add the "xmlns:*" attributes reported
          // by DOM, as expected, but not generated by the method under test,
          // otherwise the comparison would fail. 
          actual.getDocumentElement().setAttribute(Constants.FI_PREFIX,
                  Constants.FI_NS);
          actual.getDocumentElement().setAttribute("i18n",
                  I18nTransformer.I18N_NAMESPACE_URI);
          Diff diff =  new Diff(expected, actual);
          assertTrue(message + ", " + diff.toString(), diff.similar());
      }
  
      /**
       * Print a document to a writer for debugging purposes.
       * @param document The document to print.
       * @param out The writer to write to.
       */
      public final void print(Document document, Writer out) {
          TransformerFactory factory = TransformerFactory.newInstance();
          try {
              javax.xml.transform.Transformer serializer =
                  factory.newTransformer();
              serializer.transform(
                  new DOMSource(document),
                  new StreamResult(out));
              out.write('\n');
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml
  
  Index: FlowJXPathSelectionListTestCase.dest.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Copyright 1999-2004 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.
  -->
  <wi:selection-list xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"><wi:item value="1"><wi:label>One</wi:label></wi:item><wi:item value="2"><wi:label>Two</wi:label></wi:item></wi:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.xtest
  
  Index: FlowJXPathSelectionListTestCase.xtest
  ===================================================================
  <?xml version="1.0" ?>
  <!--
    Copyright 1999-2004 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.
  -->
  <testcase>
   <annotation>
    Test Cases: Woody Flow Model Selection List
   </annotation>
  
   <logkit>
    <factories>
     <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
    </factories>
    <targets>
     <stream id="root">
      <stream>System.out</stream>
      <format type="extended">
       %7.7{priority} %5.5{time}   [%9.9{category}] (%{context}): %{message}\n%{throwable}
      </format>
     </stream>
    </targets>
    <categories>
     <category name="test" log-level="ERROR">
      <log-target id-ref="root"/>
     </category>
    </categories>
   </logkit>
  
   <context/>
  
   <roles>
  
    <role name="org.apache.cocoon.woody.datatype.DatatypeManager"
      shorthand="woody-datatype"
      default-class="org.apache.cocoon.woody.datatype.DefaultDatatypeManager"/>
  
    <role name="org.apache.cocoon.woody.expression.ExpressionManager"
      shorthand="woody-expression"
      default-class="org.apache.cocoon.woody.expression.DefaultExpressionManager"/>
  
   </roles>
  
   <components>
    <woody-datatype logger="woody">
      <datatypes>
        <datatype name="string" src="org.apache.cocoon.woody.datatype.typeimpl.StringTypeBuilder">
          <convertors default="dummy" plain="dummy">
            <convertor name="dummy" src="org.apache.cocoon.woody.datatype.convertor.DummyStringConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="long" src="org.apache.cocoon.woody.datatype.typeimpl.LongTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainLongConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingLongConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="decimal" src="org.apache.cocoon.woody.datatype.typeimpl.DecimalTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainDecimalConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingDecimalConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="date" src="org.apache.cocoon.woody.datatype.typeimpl.DateTypeBuilder">
          <convertors default="formatting" plain="millis">
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingDateConvertorBuilder"/>
            <convertor name="millis" src="org.apache.cocoon.woody.datatype.convertor.MillisDateConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="boolean" src="org.apache.cocoon.woody.datatype.typeimpl.BooleanTypeBuilder">
          <convertors default="plain" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainBooleanConvertorBuilder"/>
          </convertors>
        </datatype>  
        <datatype name="integer" src="org.apache.cocoon.woody.datatype.typeimpl.IntegerTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainIntegerConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingIntegerConvertorBuilder"/>
          </convertors>
        </datatype>  
      </datatypes>
      <validation-rules>
        <validation-rule name="length" src="org.apache.cocoon.woody.datatype.validationruleimpl.LengthValidationRuleBuilder"/>
        <validation-rule name="email" src="org.apache.cocoon.woody.datatype.validationruleimpl.EmailValidationRuleBuilder"/>
        <validation-rule name="value-count" src="org.apache.cocoon.woody.datatype.validationruleimpl.ValueCountValidationRuleBuilder"/>
        <validation-rule name="range" src="org.apache.cocoon.woody.datatype.validationruleimpl.RangeValidationRuleBuilder"/>
        <validation-rule name="assert" src="org.apache.cocoon.woody.datatype.validationruleimpl.AssertValidationRuleBuilder"/>
        <validation-rule name="mod10" src="org.apache.cocoon.woody.datatype.validationruleimpl.Mod10ValidationRuleBuilder"/>
        <validation-rule name="regexp" src="org.apache.cocoon.woody.datatype.validationruleimpl.RegExpValidationRuleBuilder"/>
      </validation-rules>
    </woody-datatype>
  
    <woody-expression logger="woody.expression"/>
  
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.java
  
  Index: DynamicSelectionListTestCase.java
  ===================================================================
  /*
   * Copyright 1999-2004 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.cocoon.forms.datatype;
  
  import java.io.Writer;
  import java.util.Locale;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  
  import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.WrapperServiceManager;
  import org.apache.cocoon.forms.Constants;
  import org.apache.cocoon.xml.dom.DOMBuilder;
  import org.apache.excalibur.source.impl.ResourceSource;
  import org.custommonkey.xmlunit.Diff;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  /**
   * Test case for Woody's DynamicSelectionList datatype.
   * @version CVS $Id: DynamicSelectionListTestCase.java,v 1.1 2004/03/09 13:03:10 cziegeler Exp $
   */
  public class DynamicSelectionListTestCase extends ExcaliburTestCase {
  
      protected ServiceManager serviceManager;
      protected DatatypeManager datatypeManager;
      protected DocumentBuilder parser;
  
      /**
       * Construct a new test case.
       * @param name The test case's name.
       */
      public DynamicSelectionListTestCase(String name) {
          super(name);
      }
  
      /* (non-Javadoc)
       * @see junit.framework.TestCase#setUp()
       */
      protected void setUp() throws Exception {
          super.setUp();
          serviceManager = new WrapperServiceManager(manager); 
          datatypeManager = (DatatypeManager) serviceManager.lookup(DatatypeManager.ROLE);
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          parser = factory.newDocumentBuilder();
      }
      
      /* (non-Javadoc)
       * @see junit.framework.TestCase#tearDown()
       */
      protected void tearDown() throws Exception {
          if (datatypeManager != null) {
              serviceManager.release(datatypeManager);
          }
          super.tearDown();
      }
      
      /**
       * Test the generateSaxFragment method.
       * @throws MalformedURLException
       * @throws ParserConfigurationException
       */
      public void testGenerateSaxFragment() throws Exception {
          DOMBuilder dest = new DOMBuilder();
          ResourceSource source = 
              new ResourceSource("resource://org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.source.xml");
          Document sourceDoc = parser.parse(source.getInputStream());
          Element datatypeElement = (Element) sourceDoc.getElementsByTagNameNS(Constants.FD_NS, "convertor").item(0);
          Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
          DynamicSelectionList list = 
              new DynamicSelectionList(datatype, null, serviceManager);
          list.generateSaxFragment(dest, Locale.ENGLISH, source);
          ResourceSource expectedSource =
              new ResourceSource("resource://org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.dest.xml");
          Document expected = parser.parse(expectedSource.getInputStream());
          assertEqual("Test if output is what is expected",
                  expected, dest.getDocument());
      }
  
      /**
       * Check is the source document is equal to the one produced by the method under test.
       * @param message A message to print in case of failure.
       * @param expected The expected (source) document.
       * @param actual The actual (output) document.
       */
      private void assertEqual(String message, Document expected, Document actual) {
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
          // DIRTY HACK WARNING: we add the "xmlns:wi" attribute reported
          // by DOM, as expected, but not generated by the method under test,
          // otherwise the comparison would fail. 
          actual.getDocumentElement().setAttribute(Constants.FI_PREFIX,
                  Constants.FI_NS);
          Diff diff =  new Diff(expected, actual);
          assertTrue(message + ", " + diff.toString(), diff.similar());
      }
  
      /**
       * Print a document to a writer for debugging purposes.
       * @param document The document to print.
       * @param out The writer to write to.
       */
      public final void print(Document document, Writer out) {
          TransformerFactory factory = TransformerFactory.newInstance();
          try {
              javax.xml.transform.Transformer serializer =
                  factory.newTransformer();
              serializer.transform(
                  new DOMSource(document),
                  new StreamResult(out));
              out.write('\n');
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml
  
  Index: FlowJXPathSelectionListTestCaseWithNull.dest.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Copyright 1999-2004 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.
  -->
  <wi:selection-list xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"><wi:item value=""/><wi:item value="1"><wi:label>One</wi:label></wi:item><wi:item value="2"><wi:label>Two</wi:label></wi:item></wi:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml
  
  Index: EnumSelectionListTestCase.dest-no-null.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Copyright 1999-2004 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.
  -->
  <wi:selection-list
    xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1"><wi:item value="org.apache.cocoon.woody.datatype.Sex.MALE"><wi:label><i18n:text>org.apache.cocoon.woody.datatype.Sex.MALE</i18n:text></wi:label></wi:item><wi:item value="org.apache.cocoon.woody.datatype.Sex.FEMALE"><wi:label><i18n:text>org.apache.cocoon.woody.datatype.Sex.FEMALE</i18n:text></wi:label></wi:item></wi:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml
  
  Index: DynamicSelectionListTestCase.dest.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Copyright 1999-2004 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.
  -->
  <wi:selection-list xmlns:wi="http://apache.org/cocoon/woody/instance/1.0">
    
    <wi:item value="10/11/03"><wi:label>10/11/03</wi:label></wi:item>
    <wi:item value="2/4/63"><wi:label>My birthdate</wi:label></wi:item>
  </wi:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.xtest
  
  Index: DynamicSelectionListTestCase.xtest
  ===================================================================
  <?xml version="1.0" ?>
  <!--
    Copyright 1999-2004 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.
  -->
  <testcase>
   <annotation>
    Test Cases: Woody Dynamic Selection List
   </annotation>
  
   <logkit>
    <factories>
     <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
    </factories>
    <targets>
     <stream id="root">
      <stream>System.out</stream>
      <format type="extended">
       %7.7{priority} %5.5{time}   [%9.9{category}] (%{context}): %{message}\n%{throwable}
      </format>
     </stream>
    </targets>
    <categories>
     <category name="test" log-level="ERROR">
      <log-target id-ref="root"/>
     </category>
    </categories>
   </logkit>
  
   <context/>
  
   <roles>
  
    <role name="org.apache.cocoon.woody.datatype.DatatypeManager"
      shorthand="woody-datatype"
      default-class="org.apache.cocoon.woody.datatype.DefaultDatatypeManager"/>
  
    <role name="org.apache.cocoon.woody.expression.ExpressionManager"
      shorthand="woody-expression"
      default-class="org.apache.cocoon.woody.expression.DefaultExpressionManager"/>
  
    <role name="org.apache.excalibur.xmlizer.XMLizer"
          shorthand="xmlizer"
          default-class="org.apache.excalibur.xmlizer.DefaultXMLizer"/>
  
    <role name="org.apache.excalibur.xml.sax.SAXParser"
          shorthand="xml-parser"
          default-class="org.apache.excalibur.xml.impl.JaxpParser"/>
  
   </roles>
  
   <components>
    <woody-datatype logger="woody">
      <datatypes>
        <datatype name="string" src="org.apache.cocoon.woody.datatype.typeimpl.StringTypeBuilder">
          <convertors default="dummy" plain="dummy">
            <convertor name="dummy" src="org.apache.cocoon.woody.datatype.convertor.DummyStringConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="long" src="org.apache.cocoon.woody.datatype.typeimpl.LongTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainLongConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingLongConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="decimal" src="org.apache.cocoon.woody.datatype.typeimpl.DecimalTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainDecimalConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingDecimalConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="date" src="org.apache.cocoon.woody.datatype.typeimpl.DateTypeBuilder">
          <convertors default="formatting" plain="millis">
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingDateConvertorBuilder"/>
            <convertor name="millis" src="org.apache.cocoon.woody.datatype.convertor.MillisDateConvertorBuilder"/>
          </convertors>
        </datatype>
        <datatype name="boolean" src="org.apache.cocoon.woody.datatype.typeimpl.BooleanTypeBuilder">
          <convertors default="plain" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainBooleanConvertorBuilder"/>
          </convertors>
        </datatype>  
        <datatype name="integer" src="org.apache.cocoon.woody.datatype.typeimpl.IntegerTypeBuilder">
          <convertors default="formatting" plain="plain">
            <convertor name="plain" src="org.apache.cocoon.woody.datatype.convertor.PlainIntegerConvertorBuilder"/>
            <convertor name="formatting" src="org.apache.cocoon.woody.datatype.convertor.FormattingIntegerConvertorBuilder"/>
          </convertors>
        </datatype>  
      </datatypes>
      <validation-rules>
        <validation-rule name="length" src="org.apache.cocoon.woody.datatype.validationruleimpl.LengthValidationRuleBuilder"/>
        <validation-rule name="email" src="org.apache.cocoon.woody.datatype.validationruleimpl.EmailValidationRuleBuilder"/>
        <validation-rule name="value-count" src="org.apache.cocoon.woody.datatype.validationruleimpl.ValueCountValidationRuleBuilder"/>
        <validation-rule name="range" src="org.apache.cocoon.woody.datatype.validationruleimpl.RangeValidationRuleBuilder"/>
        <validation-rule name="assert" src="org.apache.cocoon.woody.datatype.validationruleimpl.AssertValidationRuleBuilder"/>
        <validation-rule name="mod10" src="org.apache.cocoon.woody.datatype.validationruleimpl.Mod10ValidationRuleBuilder"/>
        <validation-rule name="regexp" src="org.apache.cocoon.woody.datatype.validationruleimpl.RegExpValidationRuleBuilder"/>
      </validation-rules>
    </woody-datatype>
  
    <woody-expression logger="woody.expression"/>
  
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml
  
  Index: EnumSelectionListTestCase.dest.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Copyright 1999-2004 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.
  -->
  <wi:selection-list
    xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1"><wi:item value=""/><wi:item value="org.apache.cocoon.woody.datatype.Sex.MALE"><wi:label><i18n:text>org.apache.cocoon.woody.datatype.Sex.MALE</i18n:text></wi:label></wi:item><wi:item value="org.apache.cocoon.woody.datatype.Sex.FEMALE"><wi:label><i18n:text>org.apache.cocoon.woody.datatype.Sex.FEMALE</i18n:text></wi:label></wi:item></wi:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.java
  
  Index: FlowJXPathSelectionListTestCase.java
  ===================================================================
  /*
   * Copyright 1999-2004 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.cocoon.forms.datatype;
  
  import java.io.Writer;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  
  import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.WrapperServiceManager;
  import org.apache.cocoon.components.ContextHelper;
  import org.apache.cocoon.components.flow.FlowHelper;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.mock.MockRequest;
  import org.apache.cocoon.forms.Constants;
  import org.apache.cocoon.xml.dom.DOMBuilder;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.impl.ResourceSource;
  import org.custommonkey.xmlunit.Diff;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  /**
   * Test case for Woody's FlowModelSelectionList datatype.
   * @version CVS $Id: FlowJXPathSelectionListTestCase.java,v 1.1 2004/03/09 13:03:10 cziegeler Exp $
   */
  public class FlowJXPathSelectionListTestCase extends ExcaliburTestCase {
  
      protected ServiceManager serviceManager;
      protected DatatypeManager datatypeManager;
      protected DocumentBuilder parser;
  
      /**
       * Construct a new test case.
       * @param name The test case's name.
       */
      public FlowJXPathSelectionListTestCase(String name) {
          super(name);
      }
  
      /* (non-Javadoc)
       * @see junit.framework.TestCase#setUp()
       */
      protected void setUp() throws Exception {
          super.setUp();
          serviceManager = new WrapperServiceManager(manager); 
          datatypeManager = (DatatypeManager) serviceManager.lookup(DatatypeManager.ROLE);
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          parser = factory.newDocumentBuilder();
      }
      
      /* (non-Javadoc)
       * @see junit.framework.TestCase#tearDown()
       */
      protected void tearDown() throws Exception {
          if (datatypeManager != null) {
              serviceManager.release(datatypeManager);
          }
          super.tearDown();
      }
      
      /**
       * Test the generateSaxFragment method.
       */
      public void testGenerateSaxFragment() throws Exception {
          List beans = new ArrayList(2);
          beans.add(new TestBean("1", "One"));
          beans.add(new TestBean("2", "Two"));
          Map flowContextObject = new HashMap();
          flowContextObject.put("beans", beans);
          Request request = new MockRequest();
          request.setAttribute(FlowHelper.CONTEXT_OBJECT, flowContextObject);
          Map objectModel = new HashMap();
          objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
          Map contextObjectModel = new HashMap();
          contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel);
          Context context = new DefaultContext(contextObjectModel);
          Source sampleSource = new ResourceSource("resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCase.source.xml");
          Document sample = parser.parse(sampleSource.getInputStream());
          Element datatypeElement = (Element) sample.getElementsByTagNameNS(Constants.FD_NS, "datatype").item(0);
          Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
          FlowJXPathSelectionList list = new FlowJXPathSelectionList
              (context, "beans", "key", "value", datatype);
          DOMBuilder dest = new DOMBuilder();
          list.generateSaxFragment(dest, Locale.ENGLISH);
          Source expectedSource = new ResourceSource("resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCase.dest.xml");
          Document expected = parser.parse(expectedSource.getInputStream());
          assertEqual("Test if generated list matches expected",
              expected, dest.getDocument());
      }
      
      /**
       * Test the generateSaxFragment method with a list containing a null value.
       */
      public void testGenerateSaxFragmentWithNull() throws Exception {
          List beans = new ArrayList(2);
          beans.add(null);
          beans.add(new TestBean("1", "One"));
          beans.add(new TestBean("2", "Two"));
          Map flowContextObject = new HashMap();
          flowContextObject.put("beans", beans);
          Request request = new MockRequest();
          request.setAttribute(FlowHelper.CONTEXT_OBJECT, flowContextObject);
          Map objectModel = new HashMap();
          objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
          Map contextObjectModel = new HashMap();
          contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel);
          Context context = new DefaultContext(contextObjectModel);
          Source sampleSource = new ResourceSource("resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCase.source.xml");
          Document sample = parser.parse(sampleSource.getInputStream());
          Element datatypeElement = (Element) sample.getElementsByTagNameNS(Constants.FD_NS, "datatype").item(0);
          Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
          FlowJXPathSelectionList list = new FlowJXPathSelectionList
              (context, "beans", "key", "value", datatype);
          DOMBuilder dest = new DOMBuilder();
          list.generateSaxFragment(dest, Locale.ENGLISH);
          Source expectedSource = new ResourceSource("resource://org/apache/cocoon/woody/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml");
          Document expected = parser.parse(expectedSource.getInputStream());
          assertEqual("Test if generated list matches expected",
                  expected, dest.getDocument());
      }
      
      /**
       * Check is the source document is equal to the one produced by the method under test.
       * @param message A message to print in case of failure.
       * @param expected The expected (source) document.
       * @param actual The actual (output) document.
       */
      private void assertEqual(String message, Document expected, Document actual) {
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
          // DIRTY HACK WARNING: we add the "xmlns:wi" attribute reported
          // by DOM, as expected, but not generated by the method under test,
          // otherwise the comparison would fail. 
          actual.getDocumentElement().setAttribute(Constants.FI_PREFIX,
                  Constants.FI_NS);
          Diff diff =  new Diff(expected, actual);
          assertTrue(message + ", " + diff.toString(), diff.similar());
      }
  
      /**
       * Print a document to a writer for debugging purposes.
       * @param document The document to print.
       * @param out The writer to write to.
       */
      public final void print(Document document, Writer out) {
          TransformerFactory factory = TransformerFactory.newInstance();
          try {
              javax.xml.transform.Transformer serializer =
                  factory.newTransformer();
              serializer.transform(
                  new DOMSource(document),
                  new StreamResult(out));
              out.write('\n');
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      
      public static class TestBean {
          private String key;
          private String value;
  
          public TestBean(String key, String value) {
              this.key = key;
              this.value = value;
          }
          
          public String getKey() {
              return key;
          }
          
          public String getValue() {
              return value;
          }
          
          public String toString() {
              return "{ " + key + " : " + value + " }";
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilderTestCase.java
  
  Index: EnumConvertorBuilderTestCase.java
  ===================================================================
  /*
   * Copyright 1999-2004 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.cocoon.forms.datatype.convertor;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import junit.framework.TestCase;
  
  import org.apache.cocoon.forms.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 2004/03/09 13:03:13 cziegeler 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/convertor/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.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java
  
  Index: EnumConvertorTestCase.java
  ===================================================================
  /*
   * Copyright 1999-2004 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.cocoon.forms.datatype.convertor;
  
  import java.util.Locale;
  
  import org.apache.cocoon.forms.datatype.Sex;
  
  import junit.framework.TestCase;
  
  /**
   * Test case for the {@link EnumConvertor} class.
   * 
   * @version CVS $Id: EnumConvertorTestCase.java,v 1.1 2004/03/09 13:03:13 cziegeler Exp $
   */
  public class EnumConvertorTestCase extends TestCase {
  
      public EnumConvertorTestCase(String name) {
          super(name);
      }
  
      /**
       * Test the {@link EnumConvertor#convertFromString(java.lang.String, java.util.Locale, org.apache.cocoon.woody.datatype.convertor.Convertor.FormatCache)
       * method.
       */
      public void testConvertFromString() {
          EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.woody.datatype.Sex");
          Object sex = convertor.convertFromString
              (Sex.class.getName() + ".FEMALE", Locale.getDefault(), null);
          assertSame("Returned sex must be FEMALE", Sex.FEMALE, sex);
      }
      
      /**
       * Test the {@link EnumConvertor##convertToString(java.lang.Object, java.util.Locale, org.apache.cocoon.woody.datatype.convertor.Convertor.FormatCache)
       * method.
       */
      public void testConvertToString() {
          EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.woody.datatype.Sex");
          assertEquals("Converted value must match string",
                  Sex.class.getName() + ".MALE",
                  convertor.convertToString
                      (Sex.MALE, Locale.getDefault(), null));
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/forms/test/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml
  
  Index: EnumConvertorTestCase.conf.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Copyright 1999-2004 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.
  -->
  
  <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.Sex</wd:enum>
    	</wd:convertor>
    </wd:datatype>
    <wd:selection-list type="enum" class="org.apache.cocoon.woody.datatype.Sex"/>
  </wd:field>
  
  
  

Mime
View raw message