You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ug...@apache.org on 2003/10/19 19:20:56 UTC

cvs commit: cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype DynamicSelectionListTestCase.dest.xml DynamicSelectionListTestCase.xtest DynamicSelectionListTestCase.java DynamicSelectionListTestCase.source.xml

ugo         2003/10/19 10:20:56

  Modified:    src/blocks/woody/test/org/apache/cocoon/woody/datatype
                        DynamicSelectionListTestCase.java
                        DynamicSelectionListTestCase.source.xml
  Added:       src/blocks/woody/test/org/apache/cocoon/woody/datatype
                        DynamicSelectionListTestCase.dest.xml
                        DynamicSelectionListTestCase.xtest
  Log:
  Fixed test case for Woody's DynamicSelectionList class.
  There's a NPE when the test is finished that I wasn't able to remove, but it shouldn't influence the outcome of the test.
  
  Revision  Changes    Path
  1.2       +71 -18    cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.java
  
  Index: DynamicSelectionListTestCase.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DynamicSelectionListTestCase.java	11 Oct 2003 15:57:00 -0000	1.1
  +++ DynamicSelectionListTestCase.java	19 Oct 2003 17:20:56 -0000	1.2
  @@ -53,16 +53,22 @@
   
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.Writer;
   import java.util.Locale;
   
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.FactoryConfigurationError;
   import javax.xml.parsers.ParserConfigurationException;
  -
  -import junit.framework.TestCase;
  -
  -import org.apache.cocoon.woody.datatype.typeimpl.IntegerType;
  +import javax.xml.transform.TransformerException;
  +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.woody.Constants;
   import org.apache.cocoon.xml.dom.DOMBuilder;
   import org.apache.cocoon.xml.dom.DocumentWrapper;
   import org.apache.excalibur.source.Source;
  @@ -72,6 +78,7 @@
   import org.apache.excalibur.xml.sax.XMLizable;
   import org.custommonkey.xmlunit.Diff;
   import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  @@ -79,7 +86,11 @@
    * Test case for Woody's DynamicSelectionList datatype.
    * @version CVS $Id$
    */
  -public class DynamicSelectionListTestCase extends TestCase {
  +public class DynamicSelectionListTestCase extends ExcaliburTestCase {
  +
  +    protected ServiceManager serviceManager;
  +    protected DatatypeManager datatypeManager;
  +    protected DocumentBuilder parser;
   
       /**
        * Construct a new test case.
  @@ -88,6 +99,28 @@
       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.
  @@ -95,14 +128,19 @@
        * @throws ParserConfigurationException
        */
       public void testGenerateSaxFragment() throws Exception {
  -        DynamicSelectionList list = 
  -            new DynamicSelectionList(new IntegerType(), null, null);
           DOMBuilder dest = new DOMBuilder();
           XMLizableSource source =
               new XMLizableSource("resource://org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.source.xml");
  +        Element datatypeElement = (Element) source.getDocument().getElementsByTagNameNS(Constants.WD_NS, "convertor").item(0);
  +        Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
  +        DynamicSelectionList list = 
  +            new DynamicSelectionList(datatype, null, serviceManager);
           list.generateSaxFragment(dest, Locale.ENGLISH, source);
  -        assertEqual("Test if input is equal to output",
  -            source.getDocument(), dest.getDocument());
  +        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());
       }
   
       /**
  @@ -113,13 +151,33 @@
        */
       private void assertEqual(String message, Document expected, Document actual) {
           expected.getDocumentElement().normalize();
  -        // DIRTY HACK WARNING: we remove the "xmlns:wd" attribute reported
  +        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. 
  -        expected.getDocumentElement().removeAttribute("xmlns:wd");
  +        actual.getDocumentElement().setAttribute(Constants.WI_PREFIX,
  +                Constants.WI_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));
  +        } 
  +        catch (TransformerException te)
  +        {
  +          te.printStackTrace();
  +        }
  +    }
       
       /**
        * A class that implements both the 
  @@ -128,8 +186,6 @@
        * {@link org.apache.cocoon.xml.domDocumentWrapper} and to a 
        * {@link org.apache.excalibur.source.impl.ResourceSource},
        * respectively.
  -     * 
  -     * @version CVS $Id$
        */
       class XMLizableSource implements XMLizable, Source {
   
  @@ -147,10 +203,7 @@
            */
           public XMLizableSource(String uri) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError {
               source = new ResourceSource(uri);
  -            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  -            factory.setNamespaceAware(true);
  -            DocumentBuilder builder = factory.newDocumentBuilder();
  -            document = builder.parse(source.getInputStream());
  +            document = parser.parse(source.getInputStream());
               wrapper = new DocumentWrapper(document);
           }
           
  
  
  
  1.2       +4 -4      cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.source.xml
  
  Index: DynamicSelectionListTestCase.source.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.source.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DynamicSelectionListTestCase.source.xml	11 Oct 2003 15:57:00 -0000	1.1
  +++ DynamicSelectionListTestCase.source.xml	19 Oct 2003 17:20:56 -0000	1.2
  @@ -5,12 +5,12 @@
       |   $Id$
       +-->
   
  -<wd:selection-list xmlns:wd="http://cocoon.apache.org/woody/definition/1.0">
  -  <wd:convertor type="formatting">
  +<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>
  \ No newline at end of file
  +</wd:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.dest.xml
  
  Index: DynamicSelectionListTestCase.dest.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <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/woody/test/org/apache/cocoon/woody/datatype/DynamicSelectionListTestCase.xtest
  
  Index: DynamicSelectionListTestCase.xtest
  ===================================================================
  <?xml version="1.0" ?>
  <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"/>
  
   </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>
  
  
  

Re: cvs commit: cocoon-2.1/src/blocks/woody/test/org/apache/cocoon/woody/datatype DynamicSelectionListTestCase.dest.xml DynamicSelectionListTestCase.xtest DynamicSelectionListTestCase.java DynamicSelectionListTestCase.source.xml

Posted by Ugo Cei <ug...@apache.org>.
ugo@apache.org wrote:
>   Fixed test case for Woody's DynamicSelectionList class.
>   There's a NPE when the test is finished that I wasn't able to remove, but it shouldn't influence the outcome of the test.

Here's the stack trace. It would be great if someone with more Avalon 
knowledge than me would try to get rid of this warning.

	Ugo

WARN    2003-10-19 19:21:23.391 [cm      ] (): Error decommissioning 
component:
org.apache.cocoon.woody.datatype.DefaultDatatypeManager
java.lang.NullPointerException
         at 
org.apache.avalon.excalibur.component.DefaultComponentFactory$ServiceManagerProxy.access$100(DefaultComponentFactory.java:500)
         at 
org.apache.avalon.excalibur.component.DefaultComponentFactory.decommission(DefaultComponentFactory.java:396)
         at 
org.apache.avalon.excalibur.component.ThreadSafeComponentHandler.dispose(ThreadSafeComponentHandler.java:198)
         at 
org.apache.avalon.excalibur.component.ExcaliburComponentManager.dispose(ExcaliburComponentManager.java:653)
         at 
org.apache.avalon.excalibur.testcase.ExcaliburTestCase.done(ExcaliburTestCase.java:343)
         at 
org.apache.avalon.excalibur.testcase.ExcaliburTestCase.run(ExcaliburTestCase.java:423)
         at junit.framework.TestSuite.runTest(TestSuite.java:173)
         at junit.framework.TestSuite.run(TestSuite.java:168)
         at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:325)
         at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:536)