cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From step...@apache.org
Subject cvs commit: cocoon-2.1/src/test/org/apache/cocoon/environment/mock MockRequest.java
Date Tue, 22 Apr 2003 07:38:18 GMT
stephan     2003/04/22 00:38:18

  Modified:    src/test/org/apache/cocoon/environment/mock MockRequest.java
  Added:       src/test/org/apache/cocoon AbstractCompositeTestCase.java
               src/test/org/apache/cocoon/components/xmlform TestBean.java
                        TestXMLFormAction.java XMLFormTestCase.java
                        XMLFormTestCase.xtest testform1.xml testform2.xml
                        testresult1.xml testresult2.xml testschema.xml
  Log:
  Add a more complex testcase for the xmlform components.
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/AbstractCompositeTestCase.java
  
  Index: AbstractCompositeTestCase.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;
  
  import java.io.IOException;
  import java.util.Map;
  import java.util.HashMap;
  
  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.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.mock.MockContext;
  import org.apache.cocoon.environment.mock.MockRedirector;
  import org.apache.cocoon.environment.mock.MockRequest;
  import org.apache.cocoon.environment.mock.MockResponse;
  import org.apache.cocoon.components.source.SourceResolverAdapter;
  import org.apache.cocoon.generation.Generator;
  import org.apache.cocoon.transformation.Transformer;
  import org.apache.cocoon.xml.WhitespaceFilter;
  import org.apache.cocoon.xml.dom.DOMBuilder;
  import org.apache.cocoon.xml.dom.DOMStreamer;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceResolver;
  import org.apache.excalibur.xml.sax.SAXParser;
  import org.custommonkey.xmlunit.Diff;
  import org.custommonkey.xmlunit.XMLUnit;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.ext.LexicalHandler;
  
  /**
   * Testcase for action, generator and transformer components. 
   *
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @version CVS $Id: AbstractCompositeTestCase.java,v 1.1 2003/04/22 07:38:18 stephan Exp $
   */
  public abstract class AbstractCompositeTestCase extends ExcaliburTestCase
  {
      private MockRequest request = new MockRequest();
      private MockResponse response = new MockResponse();
      private MockContext context = new MockContext();
      private MockRedirector redirector = new MockRedirector();
      private HashMap objectmodel = new HashMap();
  
      /**
       * Create a new composite test case.
       *
       * @param name Name of test case.
       */
      public AbstractCompositeTestCase(String name) {
          super(name);
      }
  
      public final MockRequest getRequest() {
          return request;
      }
  
      public final MockResponse getResponse() {
          return response;
      }
  
      public final MockContext getContext() {
          return context;
      }
  
      public final MockRedirector getRedirector() { 
          return redirector;
      }
  
      public final Map getObjectModel() {
          return objectmodel;
      }
  
      public void setUp() {
          objectmodel.put(ObjectModelHelper.REQUEST_OBJECT, request);
          objectmodel.put(ObjectModelHelper.RESPONSE_OBJECT, response);
          objectmodel.put(ObjectModelHelper.CONTEXT_OBJECT, context);
      }
  
      /**
       * Perform the action component.
       *
       * @param type Hint of the action. 
       * @param source Source for the action.
       * @param parameters Action parameters.
       */
      public final Map act(String type, String source, Parameters parameters) {
  
          ComponentSelector selector = null;
          Action action = null;
          SourceResolver resolver = null;
  
          Map result = null;
          try {
              selector = (ComponentSelector) this.manager.lookup(Action.ROLE +
                  "Selector");
              assertNotNull("Test lookup of action selector", selector);
  
              resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
              assertNotNull("Test lookup of source resolver", resolver);
  
              assertNotNull("Test if action name is not null", type);
              action = (Action) selector.select(type);
              assertNotNull("Test lookup of action", action);
  
              result = action.act(redirector, new SourceResolverAdapter(resolver, this.manager),
                                  objectmodel, source, parameters);
  
          } catch (ComponentException ce) {
              getLogger().error("Could not retrieve generator", ce);
              fail("Could not retrieve generator: " + ce.toString());
          } catch (Exception e) {
              getLogger().error("Could not execute test", e);
              fail("Could not execute test: " + e);
          } finally {
              if (action != null) {
                  selector.release(action);
              }
              this.manager.release(selector);
              this.manager.release(resolver);
          }
          return result;
      }
  
      /**
       * Generate the generator output.
       *
       * @param type Hint of the generator. 
       * @param source Source for the generator.
       * @param parameters Generator parameters.
       */
      public final Document generate(String type, String source, Parameters parameters) {
  
          ComponentSelector selector = null;
          Generator generator = null;
          SourceResolver resolver = null;
          SAXParser parser = null;
          Source assertionsource = null;
  
          Document document = null;
          try {
              selector = (ComponentSelector) this.manager.lookup(Generator.ROLE +
                  "Selector");
              assertNotNull("Test lookup of generator selector", selector);
  
              resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
              assertNotNull("Test lookup of source resolver", resolver);
  
              parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
              assertNotNull("Test lookup of parser", parser);
  
              assertNotNull("Test if generator name is not null", type);
  
              generator = (Generator) selector.select(type);
              assertNotNull("Test lookup of generator", generator);
  
              generator.setup(new SourceResolverAdapter(resolver, this.manager),
                              objectmodel, source, parameters);
  
              DOMBuilder builder = new DOMBuilder();
              generator.setConsumer(new WhitespaceFilter(builder));
  
              generator.generate();
  
              document = builder.getDocument();
  
              assertNotNull("Test for generator document", document);
  
          } catch (ComponentException ce) {
              getLogger().error("Could not retrieve generator", ce);
              fail("Could not retrieve generator: " + ce.toString());
          } catch (Exception e) {
              getLogger().error("Could not execute test", e);
              fail("Could not execute test: " + e);
          } finally {
              if (generator != null) {
                  selector.release(generator);
              }
              this.manager.release(selector);
              this.manager.release(resolver);
              this.manager.release((Component) parser);
          }
  
          return document;
      }
  
      /**     
       * Trannsform a document by a transformer
       *      
       * @param type Hint of the transformer. 
       * @param source Source for the transformer.
       * @param parameters Generator parameters.
       * @param input Input document.
       */ 
      public final Document transform(String type, String source, Parameters parameters, Document input) {
  
          ComponentSelector selector = null;
          Transformer transformer = null;
          SourceResolver resolver = null;
          SAXParser parser = null;
          Source inputsource = null;
  
          Document document = null;
          try {
              selector = (ComponentSelector) this.manager.lookup(Transformer.ROLE+
                  "Selector");
              assertNotNull("Test lookup of transformer selector", selector);
  
              resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
              assertNotNull("Test lookup of source resolver", resolver);
  
              parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
              assertNotNull("Test lookup of parser", parser);
  
  
              assertNotNull("Test if transformer name is not null", type);
              transformer = (Transformer) selector.select(type);
              assertNotNull("Test lookup of transformer", transformer);
  
              transformer.setup(new SourceResolverAdapter(resolver, this.manager),
                                    objectmodel, source, parameters);
  
              DOMBuilder builder = new DOMBuilder();
              transformer.setConsumer(new WhitespaceFilter(builder));
  
              assertNotNull("Test if input document is not null", input);
              DOMStreamer streamer = new DOMStreamer(transformer);
              streamer.stream(input);
  
              document = builder.getDocument();
              assertNotNull("Test for transformer document", document);
  
          } catch (ComponentException ce) {
              getLogger().error("Could not retrieve transformer", ce);
              ce.printStackTrace();
              fail("Could not retrieve transformer:"+ce.toString());
          } catch (SAXException saxe) {
              getLogger().error("Could not execute test", saxe);
              fail("Could not execute test:"+saxe.toString());
          } catch (IOException ioe) {
              getLogger().error("Could not execute test", ioe);
              fail("Could not execute test:"+ioe.toString());
          } catch (ProcessingException pe) {
              getLogger().error("Could not execute test", pe);
              pe.printStackTrace();
              fail("Could not execute test:"+pe.toString());
          } finally {
              if (transformer!=null)
                  selector.release(transformer);
  
              if (selector!=null)
                  this.manager.release(selector);
  
              if (resolver!=null)
                  this.manager.release(resolver);
  
              if (inputsource!=null)
                  resolver.release(inputsource);
  
              if (resolver!=null)
                  this.manager.release(resolver);
  
              if (parser!=null)
                  this.manager.release((Component) parser);
          }
  
          return document; 
      }
  
      public final void print(Document document) {
          TransformerFactory factory = (TransformerFactory) TransformerFactory.newInstance();
          try
          {
            javax.xml.transform.Transformer serializer = factory.newTransformer();
            serializer.transform(new DOMSource(document), new StreamResult(System.out));
            System.out.println();
          } 
          catch (TransformerException te)
          {
            te.printStackTrace();
          }
      }
  
      public final Document load(String source) {
  
          SourceResolver resolver = null;
          SAXParser parser = null;
          Source assertionsource = null;
  
          Document assertiondocument = null;
          try {
              resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
              assertNotNull("Test lookup of source resolver", resolver);
  
              parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
              assertNotNull("Test lookup of parser", parser);
  
              assertNotNull("Test if assertion document is not null",
                            source);
              assertionsource = resolver.resolveURI(source);
              assertNotNull("Test lookup of assertion source",
                            assertionsource);
              assertTrue("Test if source exist", assertionsource.exists());
  
              DOMBuilder builder = new DOMBuilder();
              assertNotNull("Test if inputstream of the assertion source is not null",
                            assertionsource.getInputStream());
  
              parser.parse(new InputSource(assertionsource.getInputStream()),
                           new WhitespaceFilter(builder),
                           builder);
  
              assertiondocument = builder.getDocument();
              assertNotNull("Test if assertion document exists", assertiondocument);
  
          } catch (ComponentException ce) {
              getLogger().error("Could not retrieve generator", ce);
              fail("Could not retrieve generator: " + ce.toString());
          } catch (Exception e) {
              getLogger().error("Could not execute test", e);
              fail("Could not execute test: " + e);
          } finally {
              if (resolver != null) {
                  resolver.release(assertionsource);
              }
              this.manager.release(resolver);
              this.manager.release((Component) parser);
          }
  
          return assertiondocument;
      }
  
      /**
       * Compare two XML documents provided as strings
       * @param control Control document
       * @param test Document to test
       * @return Diff object describing differences in documents
       */
      public final Diff compareXML(Document control, Document test) {
          return new Diff(control, test);
      }
  
      /**
       * Assert that the result of an XML comparison is similar.
       *
       * @param msg The assertion message
       * @param expected The expected XML document
       * @param actual The actual XML Document
       */
      public final void assertEqual(String msg, Document expected, Document actual) {
  
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
  
          Diff diff = compareXML(expected, actual);
  
          assertEquals(msg + ", " + diff.toString(), true, diff.similar());
      }
  
      /**
       * Assert that the result of an XML comparison is similar.
       *
       * @param msg The assertion message
       * @param expected The expected XML document
       * @param actual The actual XML Document
       */  
      public final void assertEqual(Document expected, Document actual) {
  
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
  
          Diff diff = compareXML(expected, actual);
  
          assertEquals("Test if the assertion document is equal, " + diff.toString(), true, diff.similar());
      }
  
      /**
       * Assert that the result of an XML comparison is identical.
       *
       * @param msg The assertion message
       * @param expected The expected XML document
       * @param actual The actual XML Document
       */
      public final void assertIdentical(String msg, Document expected, Document actual) {
  
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
  
          Diff diff = compareXML(expected, actual);
  
          assertEquals(msg + ", " + diff.toString(), true, diff.identical());
      }
  
      /**
       * Assert that the result of an XML comparison is identical.
       *
       * @param msg The assertion message
       * @param expected The expected XML document
       * @param actual The actual XML Document
       */
      public final void assertIdentical(Document expected, Document actual) {
  
          expected.getDocumentElement().normalize();
          actual.getDocumentElement().normalize();
  
          Diff diff = compareXML(expected, actual);
  
          assertEquals("Test if the assertion document is equal, " + diff.toString(), true, diff.identical());
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/TestBean.java
  
  Index: TestBean.java
  ===================================================================
  package org.apache.cocoon.components.xmlform;
  
  import org.apache.avalon.framework.CascadingRuntimeException;
  
  import org.w3c.dom.*;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Set;
  
  /**
   *
   * A sample domain object used as a Form model.
   * Notice that it has mixed content: 
   * JavaBean properties and 
   * DOM Nodes, which are handled correctly by the
   * framework when referenced via XPath.
   *
   * @version CVS $Id: TestBean.java,v 1.1 2003/04/22 07:38:18 stephan Exp $
   */
  public class TestBean
  {
    private int count = 1;
    private short numInstalls = 1; 
    private String liveUrl = "http://";
    private boolean publish = true;
    private List favorites = new ArrayList();
    
    private boolean hidden = false; 
    
    private Node system;
  
    public TestBean() {
        initSystem();
        initFavorites();
    }
  
    public String getLiveUrl() {
        return liveUrl;
    }
  
    public void setLiveUrl( String newUrl ) {
        liveUrl = newUrl;
    }
  
    public short getNumber() {
        return numInstalls;
    }
    
    public void setNumber( short num ) {
        numInstalls = num;
    }
    
    public boolean getPublish() {
        return publish;
    }
    
    public void setPublish(boolean newPublish) {
        publish = newPublish;
    }
    
    
    public Node getSystem() {
        return system;
    }
  
    public void setSystem( Node newSystem ) {
        system = newSystem;
    }
  
    public boolean getHidden() {
        return hidden;
    }
   
    public void setHidden(boolean newHidden) {
        hidden = newHidden;
    }
  
    public int getCount() {
      return count;
    }
  
    public void incrementCount() {
      count++;
    }
  
    public List getFavorite()
    {
      return favorites;
    }
  
    public void setFavorite( List newFavorites )
    {
      favorites = newFavorites;
    }
  
    public void initSystem()
    {
      DOMImplementation impl;
      try
      {
        // Find the implementation
        DocumentBuilderFactory factory
         = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(false);
        factory.setValidating ( false );
        DocumentBuilder builder = factory.newDocumentBuilder();
        impl = builder.getDOMImplementation();
      }
      catch (Exception ex)
      {
        throw new CascadingRuntimeException("Failed to initialize DOM factory.", ex);
      }
  
      // initialize system as dom node
      Document doc = impl.createDocument( null, "XMLForm_Wizard_System_Node", null);
      Node rootElement = doc.getDocumentElement();
  
      Node os = doc.createElement ( "os" );
      Text text = doc.createTextNode( "Linux" );
      os.appendChild(text);
      rootElement.appendChild( os );
  
      Node processor = doc.createElement ( "processor" );
      text = doc.createTextNode( "p4" );
      processor.appendChild(text);
      rootElement.appendChild( processor );
  
      Attr ram = doc.createAttribute ( "ram" );
      ram.setValue ( "512" );
      NamedNodeMap nmap = rootElement.getAttributes();
      nmap.setNamedItem ( ram );
  
      Node servletEngine = doc.createElement ( "servletEngine" );
      text = doc.createTextNode( "Tomcat" );
      servletEngine.appendChild(text);
      rootElement.appendChild( servletEngine );
  
      Node javaVersion = doc.createElement ( "javaVersion" );
      text = doc.createTextNode( "1.3" );
      javaVersion.appendChild(text);
      rootElement.appendChild( javaVersion );
  
      system = rootElement;
  
    }
  
    public void initFavorites()
    {
      favorites.add( "http://cocoon.apache.org" );
      favorites.add( "http://jakarta.apache.org" );
      favorites.add( "http://www.google.com" );
      favorites.add( "http://www.slashdot.org" );
      favorites.add( "http://www.yahoo.com" );
    }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/TestXMLFormAction.java
  
  Index: TestXMLFormAction.java
  ===================================================================
  /* 
   * $Revision: 1.1 $
   * $Date: 2003/04/22 07:38:18 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   *
   *
   * Copyright (c) 1999-2001 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 and was
   * originally based on software copyright (c) 2001, Plotnix, Inc,
   * <http://www.plotnix.com/>.
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.cocoon.components.xmlform;
  
  import org.apache.cocoon.acting.AbstractXMLFormAction;
  import org.apache.cocoon.components.xmlform.Form;
  import org.apache.cocoon.components.xmlform.FormListener;
  
  import java.util.Map;
  
  public class TestXMLFormAction extends AbstractXMLFormAction
    implements FormListener
  {
  
    // different form views
    // participating in the wizard
    final String VIEW_START = "start";
    final String VIEW_FIRST = "view1";
    final String VIEW_SECOND = "view2";
  
    // action commands used in the wizard
    final String CMD_START = "start";
    final String CMD_NEXT = "next";
    final String CMD_PREV = "prev";
  
    public Map prepare()
    { 
      if ( getCommand() == null )
          return page( VIEW_START );
      else if ( getCommand().equals( CMD_START ) )
        return page( VIEW_FIRST );
      else if ( Form.lookup ( getObjectModel(), getFormId() ) == null)
          return page( VIEW_START );
  
      return super.PREPARE_RESULT_CONTINUE;
    }
  
    public Map perform ()
    {
      TestBean model = (TestBean) getForm().getModel();
      model.incrementCount();
  
      if ((getCommand().equals(CMD_NEXT)) &&
          (getForm().getViolations () != null))
          return page( getFormView() );
      else
      {
        getForm().clearViolations();
  
        // get the user submitted command (through a submit button)
        String command = getCommand();
        // get the form view which was submitted
        String formView = getFormView();
  
        // apply state machine (flow control) rules
        if ( formView.equals ( VIEW_FIRST ) )
        {
          if (command.equals( CMD_NEXT ) )
            return page( VIEW_SECOND );
          else if( command.equals( CMD_PREV ) )
            return page( VIEW_START );
        }
        else if (formView.equals ( VIEW_SECOND ) )
        {
          if ( command.equals( CMD_NEXT ) )
            return page(VIEW_START);
          else if( command.equals( CMD_PREV ) )
            return page( VIEW_FIRST );
        }
      }
  
      return page( VIEW_START );
    }
  
    public void reset( Form form )
    {
      return;
    }
  
    public boolean filterRequestParameter (Form form, String parameterName)
    {
      return false;
    }
  }
  
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/XMLFormTestCase.java
  
  Index: XMLFormTestCase.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.components.xmlform;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.AbstractCompositeTestCase;
  
  /**
   *
   *
   * @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
   * @version CVS $Id: XMLFormTestCase.java,v 1.1 2003/04/22 07:38:18 stephan Exp $
   */
  public class XMLFormTestCase extends AbstractCompositeTestCase {
  
      public XMLFormTestCase(String name) {
          super(name);
      }
  
      public void testXMLForm() {
  
          getRequest().addParameter("cocoon-action-start", "true");
  
          Parameters parameters = new Parameters();
          parameters.setParameter("xmlform-validator-schema-ns", "http://www.ascc.net/xml/schematron");
          parameters.setParameter("xmlform-validator-schema", "resource://org/apache/cocoon/components/xmlform/testschema.xml");
          parameters.setParameter("xmlform-id", "testform");
          parameters.setParameter("xmlform-scope", "session");
          parameters.setParameter("xmlform-model", "org.apache.cocoon.components.xmlform.TestBean");
  
          Map result = act("xmlform", null, parameters);
  
          assertNotNull("Test if resource exists", result);
          assertEquals("Test for parameter", "view1", (String)result.get("page"));
  
          String testform1 = "resource://org/apache/cocoon/components/xmlform/testform1.xml";
          String testresult1 = "resource://org/apache/cocoon/components/xmlform/testresult1.xml";
  
          assertEqual(load(testresult1), transform("xmlform", testform1, new Parameters(), load(testform1)));
  
          // Second request
  
          getRequest().reset();
          getRequest().addParameter("cocoon-xmlform-view", "view1");
          getRequest().addParameter("/system/os", "Other");
          getRequest().addParameter("/system/processor", "p3");
          getRequest().addParameter("/system/@ram", "1024");
          getRequest().addParameter("/system/servletEngine", "Jetty");
          getRequest().addParameter("/system/javaVersion", "1.3");
          getRequest().addParameter("cocoon-action-next", "true");
  
          result = act("xmlform", null, parameters);
  
          assertNotNull("Test if resource exists", result);
          assertEquals("Test for parameter", "view2", (String)result.get("page"));
  
          String testform2 = "resource://org/apache/cocoon/components/xmlform/testform2.xml";
          String testresult2 = "resource://org/apache/cocoon/components/xmlform/testresult2.xml";
  
          print(transform("xmlform", testform2, new Parameters(), load(testform2)));
  
          assertEqual(load(testresult2), transform("xmlform", testform1, new Parameters(), load(testform2)));
  
          // Third request
  
          getRequest().reset();
          getRequest().addParameter("cocoon-xmlform-view", "view2");
          getRequest().addParameter("/number", "3");
          getRequest().addParameter("/liveUrl", "http://xml.apache.org");
          getRequest().addParameter("/publish", "false"); 
          getRequest().addParameter("/favorite[1]/.", "http://cocoon.apache.org");
          getRequest().addParameter("/favorite[2]/.", "http://jakarta.apache.org");
          getRequest().addParameter("/favorite[3]/.", "http://www.google.com");
          getRequest().addParameter("cocoon-action-next", "true");
  
          result = act("xmlform", null, parameters);
  
          assertNotNull("Test if resource exists", result);
          assertEquals("Test for parameter", "start", (String)result.get("page"));
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/XMLFormTestCase.xtest
  
  Index: XMLFormTestCase.xtest
  ===================================================================
  <?xml version="1.0" ?>
  <testcase>
   <annotation>
    Test Cases: XMLForm
   </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="WARN">
      <log-target id-ref="root"/>
     </category>
    </categories>
   </logkit>
  
   <context/>
  
   <roles>
    <role name="org.apache.excalibur.xml.sax.SAXParser"
          shorthand="xml-parser"
          default-class="org.apache.excalibur.xml.impl.JaxpParser"/>
  
    <role name="org.apache.excalibur.source.SourceFactorySelector"
          shorthand="source-factories"
          default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
  
    <role name="org.apache.excalibur.source.SourceResolver"
          shorthand="source-resolver"
          default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
  
    <role name="org.apache.cocoon.acting.ActionSelector"
          shorthand="actions"
          default-class="org.apache.cocoon.sitemap.DefaultSitemapComponentSelector"/>
  
    <role name="org.apache.cocoon.transformation.TransformerSelector"
          shorthand="transformers"
          default-class="org.apache.cocoon.sitemap.DefaultSitemapComponentSelector"/>
   </roles>
  
   <components>
    <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser">
     <parameter name="validate" value="false"/>
     <parameter name="namespace-prefixes" value="false"/>
     <parameter name="stop-on-warning" value="true"/>
     <parameter name="stop-on-recoverable-error" value="true"/>
     <parameter name="reuse-parsers" value="false"/>
    </xml-parser>
  
    <source-factories>
     <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/>
     <component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/>
    </source-factories>
  
    <source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
  
    <actions logger="test">
     <component-instance class="org.apache.cocoon.components.xmlform.TestXMLFormAction" 
                         name="xmlform"/>
    </actions>
  
    <transformers logger="test">
     <component-instance class="org.apache.cocoon.transformation.XMLFormTransformer" 
                         name="xmlform"/>
    </transformers>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/testform1.xml
  
  Index: testform1.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
  
  	XMLForm instance document for the Cocoon Feedback Wizard.
  
   	author: Torsten Curdt, tcurdt@dff.st, March 2002
      author: Ivelin Ivanov, ivelin@apache.org, April 2002
      author: Simon Price <price@bristol.ac.uk>, September 2002
  
  -->
  <document xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002">
    <xf:form id="testform" view="view1" action="wizard" method="GET">
      <xf:caption>System Information</xf:caption>
      <error>
        <xf:violations class="error"/>
      </error>
      <xf:group ref="/system">
        <xf:selectOne ref="os" selectUIType="radio">
          <xf:caption>OS</xf:caption>
          <xf:item id="unix">
            <xf:caption>Unix/Linux</xf:caption>
            <xf:value>Unix</xf:value>
          </xf:item>
          <xf:item id="mac">
            <xf:caption>Mac OS/X</xf:caption>
            <xf:value>Mac OS/X</xf:value>
          </xf:item>
          <xf:item id="win">
            <xf:caption>Windows 95/98/NT/2000/XP</xf:caption>
            <xf:value>Windows</xf:value>
          </xf:item>
          <xf:item id="other">
            <xf:caption>Other</xf:caption>
            <xf:value>Other</xf:value>
          </xf:item>
        </xf:selectOne>
        <xf:selectOne ref="processor">
          <xf:caption>Processor</xf:caption>
          <xf:item>
            <xf:caption>AMD/Athlon</xf:caption>
            <xf:value>Athlon</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>AMD/Duron</xf:caption>
            <xf:value>Duron</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Pentium Celeron</xf:caption>
            <xf:value>Celeron</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Pentium III</xf:caption>
            <xf:value>p3</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Pentium IV</xf:caption>
            <xf:value>p4</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Other</xf:caption>
            <xf:value>other</xf:value>
          </xf:item>
        </xf:selectOne>
        <xf:textbox ref="@ram">
          <xf:caption>RAM</xf:caption>
          <xf:violations class="error"/>
        </xf:textbox>
        <xf:selectOne ref="servletEngine">
          <xf:caption>Servlet Engine</xf:caption>
          <xf:item>
            <xf:caption>Tomcat</xf:caption>
            <xf:value>Tomcat</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Jetty</xf:caption>
            <xf:value>Jetty</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Resin</xf:caption>
            <xf:value>Resin</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Weblogic</xf:caption>
            <xf:value>weblogic</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>WebSphere</xf:caption>
            <xf:value>WebSphere</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Other</xf:caption>
            <xf:value>other</xf:value>
          </xf:item>
        </xf:selectOne>
        <xf:selectOne ref="javaVersion">
          <xf:caption>Java Version</xf:caption>
          <xf:item>
            <xf:caption>1.1</xf:caption>
            <xf:value>1.1</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>1.2</xf:caption>
            <xf:value>1.2</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>1.3</xf:caption>
            <xf:value>1.3</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>1.4</xf:caption>
            <xf:value>1.4</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Other</xf:caption>
            <xf:value>Other</xf:value>
          </xf:item>
        </xf:selectOne>
      </xf:group>
      <xf:submit id="prev" class="button">
        <xf:caption>Prev</xf:caption>
        <xf:hint>Go to previous page</xf:hint>
      </xf:submit>
      <xf:submit id="next" class="button">
        <xf:caption>Next</xf:caption>
        <xf:hint>Go to next page</xf:hint>
      </xf:submit>
    </xf:form>
    <xf:output ref="count" id="show_count" form="testform" class="info">
      <xf:caption>Visits Count</xf:caption>
    </xf:output>
  </document>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/testform2.xml
  
  Index: testform2.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
  
  	XMLForm instance document for the Cocoon Feedback Wizard.
  
   	author: Torsten Curdt, tcurdt@dff.st, March 2002
      author: Ivelin Ivanov, ivelin@apache.org, April 2002
      author: Simon Price <price@bristol.ac.uk>, September 2002
  
  -->
  <document xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002">
  	<xf:form id="testform" view="view2" action="wizard" method="GET">
  		<xf:caption>Cocoon Deployment Information</xf:caption>
  		<error>
  			<xf:violations class="error"/>
  		</error>
  		<xf:textbox ref="/number">
  			<xf:caption>Number of deployments</xf:caption>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:textbox ref="/liveUrl">
  			<xf:caption>Live URL</xf:caption>
  			<xf:help>You must enter a valid URL</xf:help>
  			<xf:violations class="error"/>
  		</xf:textbox>
  		<xf:selectBoolean ref="/publish">
  			<xf:caption>Publish</xf:caption>
  		</xf:selectBoolean>
  		<xf:group nodeset="" id="favorites_group">
  			<xf:caption>Favorite web sites</xf:caption>
  			<!-- 
                repeat is a very powerful iterator tag,
                because it iterates over a nodeset resulting from
                the 'nodeset' selector attribute.
                Very similar to xslt's for-each tag.
  
                In this case we iterate over the top three favorite
                web sites.
              -->
  			<xf:repeat nodeset="favorite[position() &lt;= 3]" id="favorites">
  				<xf:textbox ref="." class="info">
  					<xf:caption>URL:</xf:caption>
  				</xf:textbox>
  			</xf:repeat>
  		</xf:group>
  		<xf:submit id="prev" class="button">
  			<xf:caption>Prev</xf:caption>
  			<xf:hint>Go to previous page</xf:hint>
  		</xf:submit>
  		<xf:submit id="next" class="button">
  			<xf:caption>Next</xf:caption>
  			<xf:hint>Go to next page</xf:hint>
  		</xf:submit>
  	</xf:form>
  	<xf:output ref="count" id="show_count" form="testform" class="info">
  		<xf:caption>Visits Count</xf:caption>
  	</xf:output>
  </document>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/testresult1.xml
  
  Index: testresult1.xml
  ===================================================================
  <?xml version="1.0"?>
  <document xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002">
    <xf:form action="wizard" id="testform" method="GET" view="view1">
      <xf:caption>System Information</xf:caption>
      <error/>
      <xf:group ref="/system">
        <xf:selectOne ref="/system/os" selectUIType="radio">
          <xf:value>Linux</xf:value>
          <xf:caption>OS</xf:caption>
          <xf:item id="unix">
            <xf:caption>Unix/Linux</xf:caption>
            <xf:value>Unix</xf:value>
          </xf:item>
          <xf:item id="mac">
            <xf:caption>Mac OS/X</xf:caption>
            <xf:value>Mac OS/X</xf:value>
          </xf:item>
          <xf:item id="win">
            <xf:caption>Windows 95/98/NT/2000/XP</xf:caption>
            <xf:value>Windows</xf:value>
          </xf:item>
          <xf:item id="other">
            <xf:caption>Other</xf:caption>
            <xf:value>Other</xf:value>
          </xf:item>
        </xf:selectOne>
        <xf:selectOne ref="/system/processor">
          <xf:value>p4</xf:value>
          <xf:caption>Processor</xf:caption>
          <xf:item>
            <xf:caption>AMD/Athlon</xf:caption>
            <xf:value>Athlon</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>AMD/Duron</xf:caption>
            <xf:value>Duron</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Pentium Celeron</xf:caption>
            <xf:value>Celeron</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Pentium III</xf:caption>
            <xf:value>p3</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Pentium IV</xf:caption>
            <xf:value>p4</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Other</xf:caption>
            <xf:value>other</xf:value>
          </xf:item>
        </xf:selectOne>
        <xf:textbox ref="/system/@ram">
          <xf:value>512</xf:value>
          <xf:caption>RAM</xf:caption>
        </xf:textbox>
        <xf:selectOne ref="/system/servletEngine">
          <xf:value>Tomcat</xf:value>
          <xf:caption>Servlet Engine</xf:caption>
          <xf:item>
            <xf:caption>Tomcat</xf:caption>
            <xf:value>Tomcat</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Jetty</xf:caption>
            <xf:value>Jetty</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Resin</xf:caption>
            <xf:value>Resin</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Weblogic</xf:caption>
            <xf:value>weblogic</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>WebSphere</xf:caption>
            <xf:value>WebSphere</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Other</xf:caption>
            <xf:value>other</xf:value>
          </xf:item>
        </xf:selectOne>
        <xf:selectOne ref="/system/javaVersion">
          <xf:value>1.3</xf:value>
          <xf:caption>Java Version</xf:caption>
          <xf:item>
            <xf:caption>1.1</xf:caption>
            <xf:value>1.1</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>1.2</xf:caption>
            <xf:value>1.2</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>1.3</xf:caption>
            <xf:value>1.3</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>1.4</xf:caption>
            <xf:value>1.4</xf:value>
          </xf:item>
          <xf:item>
            <xf:caption>Other</xf:caption>
            <xf:value>Other</xf:value>
          </xf:item>
        </xf:selectOne>
      </xf:group>
      <xf:submit class="button" id="prev">
        <xf:caption>Prev</xf:caption>
        <xf:hint>Go to previous page</xf:hint>
      </xf:submit>
      <xf:submit class="button" id="next">
        <xf:caption>Next</xf:caption>
        <xf:hint>Go to next page</xf:hint>
      </xf:submit>
    </xf:form>
    <xf:output class="info" form="testform" id="show_count" ref="count">
      <xf:value>1</xf:value>
      <xf:caption>Visits Count</xf:caption>
    </xf:output>
  </document>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/testresult2.xml
  
  Index: testresult2.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <document xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002">
    <xf:form action="wizard" id="testform" method="GET" view="view2">
      <xf:caption>Cocoon Deployment Information</xf:caption>
      <error/>
      <xf:textbox ref="/number">
        <xf:value>1</xf:value>
        <xf:caption>Number of deployments</xf:caption>
      </xf:textbox>
      <xf:textbox ref="/liveUrl">
        <xf:value>http://</xf:value>
        <xf:caption>Live URL</xf:caption>
        <xf:help>You must enter a valid URL</xf:help>
      </xf:textbox>
      <xf:selectBoolean ref="/publish">
        <xf:value>true</xf:value>
        <xf:caption>Publish</xf:caption>
      </xf:selectBoolean>
      <xf:group id="favorites_group" nodeset="">
        <xf:caption>Favorite web sites</xf:caption>
        <xf:repeat id="favorites" nodeset="favorite[position() &lt;= 3]">
          <xf:group ref="/favorite[1]">
            <xf:textbox class="info" ref="/favorite[1]/.">
              <xf:value>http://cocoon.apache.org</xf:value>
              <xf:caption>URL:</xf:caption>
            </xf:textbox>
          </xf:group>
          <xf:group ref="/favorite[2]">
            <xf:textbox class="info" ref="/favorite[2]/.">
              <xf:value>http://jakarta.apache.org</xf:value>
              <xf:caption>URL:</xf:caption>
            </xf:textbox>
          </xf:group>
          <xf:group ref="/favorite[3]">
            <xf:textbox class="info" ref="/favorite[3]/.">
              <xf:value>http://www.google.com</xf:value>
              <xf:caption>URL:</xf:caption>
            </xf:textbox>
          </xf:group>
        </xf:repeat>
      </xf:group>
      <xf:submit class="button" id="prev">
        <xf:caption>Prev</xf:caption>
        <xf:hint>Go to previous page</xf:hint>
      </xf:submit>
      <xf:submit class="button" id="next">
        <xf:caption>Next</xf:caption>
        <xf:hint>Go to next page</xf:hint>
      </xf:submit>
    </xf:form>
    <xf:output class="info" form="testform" id="show_count" ref="count">
      <xf:value>2</xf:value>
      <xf:caption>Visits Count</xf:caption>
    </xf:output>
  </document>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/components/xmlform/testschema.xml
  
  Index: testschema.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!--
  
  	Validating Schematron schema for the xmlform example wizard
    
    Schematron Schema language home page:
    http://www.ascc.net/xml/schematron/
    
  	Author: Ivelin Ivanov, ivelin@apache.org, April 2002
  
  -->
  <schema ns="http://xml.apache.cocoon/xmlform"
  	xmlns="http://www.ascc.net/xml/schematron">
  	<title>Schema for the XML Form example</title>
  	<phase id="userIdentity">
  		<p>For user identity information.</p>
  		<active pattern="user"/>
  	</phase>
  	<phase id="deployment">
  		<p>For deployment info page.</p>
  		<active pattern="dep" />
  	</phase>
  	<phase id="system">
  		<p>For system info page.</p>
  		<active pattern="sys" />
  	</phase>
  	<phase id="confirm">
  		<p>For final total validation and tracking some tricky problems.</p>
  		<active pattern="user" />
  		<active pattern="dep" />
  		<active pattern="sys" />
  	</phase>
  	<pattern name="User Info Validation Pattern" id="user">
  		<rule context="/firstName">
  			<assert test="string-length(.) &gt; 3">First name <anametag/> 
  				<wrapper>should</wrapper> be at least 4 characters.</assert>
  			<assert test="string-length(.) &lt; 20">First name should be less
  				than 20 characters.</assert>
  		</rule>
  		<rule context="/lastName">
  			<assert test="string-length(.) &gt; 3">Last name should be at least
  				4 characters.</assert>
  			<assert test="string-length(.) &lt; 20">Last name should be less
  				than 20 characters.</assert>
  		</rule>
  		<rule context="/email">
  			<assert test="contains( string(.),'@')">Email format is invalid.</assert>
  		</rule>
  		<rule context="/age">
  			<assert test="number() &gt; 0 and number(.) &lt; 200">Age should be
  				a reasonably big positive number.</assert>
  		</rule>
  	</pattern>
  	<pattern name="Deployment Information Validation Pattern" id="dep">
  		<rule context="/number">
  			<assert test="number() &gt; 0">The number of deployments must be
  				non-negative ( hopefully positive :-> ) .</assert>
  		</rule>
  		<rule context="/">
  			<!-- 
          If the site is to be published, then verify the URL.
          Note: This assertion demonstrates the unique ability of 
          Schematron to test document node dependencies.
          This is not possible to do with XML Schema and Relax NG.
         -->
  			<assert
  				test="not(string(publish) = 'true') or (starts-with(liveUrl, 'http://') and contains( string(liveUrl),'.') ) "
  				>The URL of the published site is invalid.</assert>
  		</rule>
  	</pattern>
  	<pattern name="System Information Validation Pattern" id="sys">
  		<rule context="/system/@ram">
  			<assert test="number() &gt; 0">The RAM value should be a positive
  				number, denoting the memory in MB (e.g. 128, 512, etc.).</assert>
  		</rule>
  	</pattern>
  </schema>
  
  
  
  1.3       +31 -3     cocoon-2.1/src/test/org/apache/cocoon/environment/mock/MockRequest.java
  
  Index: MockRequest.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/test/org/apache/cocoon/environment/mock/MockRequest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MockRequest.java	19 Apr 2003 16:03:56 -0000	1.2
  +++ MockRequest.java	22 Apr 2003 07:38:18 -0000	1.3
  @@ -69,7 +69,7 @@
   
   public class MockRequest implements Request {
   
  -    private Hashtable attributes;
  +    private Hashtable attributes = new Hashtable();
       private String scheme;
       private String protocol = "HTTP/1.1";
       private String requestURI;
  @@ -78,7 +78,7 @@
       private String servletPath;
       private String pathInfo;
       private String queryString;
  -    private String method;
  +    private String method = "GET";
       private String contentType;
       private Locale locale;
       private Principal principal;
  @@ -90,7 +90,7 @@
       private String authType;
       private String charEncoding;
       private String serverName;
  -    private int port;
  +    private int port = 80;
   
       private Hashtable parameters = new Hashtable();
       private Hashtable headers = new Hashtable();
  @@ -338,5 +338,33 @@
   
       public boolean isRequestedSessionIdFromURL() {
           return false;
  +    }
  +
  +    public void reset() {
  +        attributes.clear();
  +        scheme = null;
  +        protocol = "HTTP/1.1";
  +        requestURI = null;
  +        requestURL = null;
  +        contextPath = null;
  +        servletPath = null;
  +        pathInfo = null;
  +        queryString = null;
  +        method = "GET";
  +        contentType = null;
  +        locale = null;
  +        principal = null;
  +        remoteAddr = null;
  +        remoteHost = null;
  +        remoteUser = null;
  +        userRole = null;
  +        reqSessionId = null;
  +        authType = null;
  +        charEncoding = null;
  +        serverName = null;
  +        port = 80;
  +
  +        parameters.clear();
  +        headers.clear();
       }
   }
  
  
  

Mime
View raw message