stephan     2003/04/26 05:09:44

  Modified:    src/blocks/xmlform/test/org/apache/cocoon/components/xmlform
                        TestBean.java TestXMLFormAction.java
                        XMLFormTestCase.java
  Added:       src/blocks/xmlform/test/org/apache/cocoon/components/validation
                        ZNestedBean.java ZTestBean.java
                        ZValidationTest.java zxmlform-sch-report-test.xml
  Log:
  Beautify code, and add lost testcases.
  
  Revision  Changes    Path
  1.1                  
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/validation/ZNestedBean.java
  
  Index: ZNestedBean.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.validation;
  
  /**
   * Just a test bean.
   *
   * @version CVS $Id: ZNestedBean.java,v 1.1 2003/04/26 12:09:43 stephan Exp $
   */
  public class ZNestedBean {
      private String kind = "mammal";
  
      public void setKind(String newKind) {
          kind = newKind;
      }
  
      public String getKind() {
          return kind;
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/validation/ZTestBean.java
  
  Index: ZTestBean.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.validation;
  
  import java.util.ArrayList;
  
  /**
   * Just a test bean.
   *
   * @version CVS $Id: ZTestBean.java,v 1.1 2003/04/26 12:09:44 stephan Exp $
   */
  public class ZTestBean {
      private String name = "dog";
      private String scope = "galaxy";
      private int count = 0;
      private ArrayList preferences = new ArrayList();
      private ZNestedBean personal = new ZNestedBean();
  
      public ZTestBean() {
          preferences.add("likeVodka");
          preferences.add("likeSkiing");
      }
  
      public ZTestBean(String newName, String newScope) {
          this();
          name = newName;
          scope = newScope;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String newName) {
          name = newName;
      }
  
      public void setScope(String newScope) {
          scope = newScope;
      }
  
      public String getScope() {
          return scope;
      }
  
      public ArrayList getPreferences() {
          return preferences;
      }
  
      public ZNestedBean getPersonalInfo() {
          return personal;
      }
  
      public void setPersonalInfo(ZNestedBean newPersonal) {
          personal = newPersonal;
      }
  
      public int getCount() {
          return count;
      }
  
      public void incrementCount() {
          count++;
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/validation/ZValidationTest.java
  
  Index: ZValidationTest.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.validation;
  
  import org.apache.cocoon.components.validation.Schema;
  import org.apache.cocoon.components.validation.SchemaFactory;
  import org.apache.cocoon.components.validation.Validator;
  import org.apache.cocoon.components.validation.Violation;
  import org.xml.sax.InputSource;
  
  import java.io.InputStream;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ArrayList;
  
  import junit.framework.TestCase;
  import junit.swingui.TestRunner;
  
  /**
   * Test class for the Validation API.
   *
   * <p>Uses file 
src/test/org/apache/cocoon/components/validation/test/zxmlform-sch-report-test.xml.
   *
   * @version CVS $Id: ZValidationTest.java,v 1.1 2003/04/26 12:09:44 stephan 
Exp $
   */
  public class ZValidationTest extends TestCase {
  
      private static final int count = 100;
  
      public ZValidationTest(String name) {
          super(name);
      }
  
      private void testSchema(String schema, String phase, List violations) {
          // use custom schema
          InputStream in = getClass().getResourceAsStream(schema);
          if (in==null) {
              fail("Error: schema file "+schema+" not found");
          }
  
          try {
              InputSource is = new InputSource(in);
              SchemaFactory schf = 
SchemaFactory.lookup(SchemaFactory.NAMESPACE_SCHEMATRON);
              Schema sch = schf.compileSchema(is);
              Validator validator = sch.newValidator();
  
              // set preprocessor parameters
              if (phase!=null) {
                  validator.setProperty(Validator.PROPERTY_PHASE, phase);
              }
  
              ZTestBean tbean = new ZTestBean();
  
              // measure validation speed
              long time = System.currentTimeMillis();
              List vs = null;
  
              for (int i = 0; i<count; i++) {
                  // perform validation
                  vs = validator.validate(tbean);
              }
              time = System.currentTimeMillis()-time;
              System.out.println("Validation performed "+count+
                                 " times for a total of "+time+" ms");
              System.out.println("Avarage validation time is "+(time/count)+
                                 " ms ");
  
              if (vs==null) {
                  vs = new ArrayList();
              }
  
              // everything ok?
              assertEquals("Violations count does not match",
                           violations.size(), vs.size());
              for (Iterator i = violations.iterator(); i.hasNext(); ) {
                  Violation v = (Violation) i.next();
                  boolean gotit = false;
  
                  for (Iterator j = vs.iterator(); j.hasNext(); ) {
                      Violation w = (Violation) j.next();
  
                      if (v.getPath().equals(w.getPath()) &&
                          v.getMessage().equals(w.getMessage())) {
                          gotit = true;
                          break;
                      }
                  }
                  assertTrue("Expected violation "+v.getPath()+" '"+
                             v.getMessage()+"' not found", gotit);
              }
              for (Iterator i = vs.iterator(); i.hasNext(); ) {
                  Violation v = (Violation) i.next();
                  boolean gotit = false;
  
                  for (Iterator j = violations.iterator(); j.hasNext(); ) {
                      Violation w = (Violation) j.next();
  
                      if (v.getPath().equals(w.getPath()) &&
                          v.getMessage().equals(w.getMessage())) {
                          gotit = true;
                          break;
                      }
                  }
                  assertTrue("Unexpected violation "+v.getPath()+" '"+
                             v.getMessage()+"' found", gotit);
              }
          } catch (Exception e) {
              fail("Got an exception "+e);
          }
      }
  
      public void testSchema() {
          Violation violation;
          List violations = new ArrayList();
  
          violation = new Violation();
          violation.setPath("/scope");
          violation.setMessage("Scope should be request or session.");
          violations.add(violation);
  
          violation = new Violation();
          violation.setPath("/name");
          violation.setMessage("Animal name should be at least 4 characters.");
          violations.add(violation);
  
          violation = new Violation();
          violation.setPath("/count");
          violation.setMessage("The counter should be > 0.");
          violations.add(violation);
  
          testSchema("zxmlform-sch-report-test.xml", null, violations);
      }
  
      public void testSchema_PhaseNew() {
          Violation violation;
          List violations = new ArrayList();
  
          violation = new Violation();
          violation.setPath("/scope");
          violation.setMessage("Scope should be request or session.");
          violations.add(violation);
  
          violation = new Violation();
          violation.setPath("/name");
          violation.setMessage("Animal name should be at least 4 characters.");
          violations.add(violation);
  
          testSchema("zxmlform-sch-report-test.xml", "New", violations);
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/validation/zxmlform-sch-report-test.xml
  
  Index: zxmlform-sch-report-test.xml
  ===================================================================
  <?xml version="1.0" ?>
  
  <!--+
      | Sample Schematron schema for the ZValidationTest
      |
      | Pass this file as a first argument on the command line to 
ZValidationTest
      |
      | Ivelin Ivanov, [EMAIL PROTECTED]
      | CVS $Id: zxmlform-sch-report-test.xml,v 1.1 2003/04/26 12:09:44 stephan 
Exp $
      +-->
  
  <schema ns="http://xml.apache.cocoon/xmlform";  
xmlns="http://www.ascc.net/xml/schematron";>
      <title>Schema for the XML Form example</title>
  
      <phase id="New">
          <p>For creating new documents.</p>
          <active pattern="mini"/>
      </phase>
      <phase id="Draft">
          <p>For fast validation of draft documents.</p>
          <active pattern="required" />
      </phase>
      <phase id="Full">
          <p>For final validation and tracking some tricky problems.</p>
          <active pattern="mini" />
          <active pattern="required" />
          <active pattern="extra" />
      </phase>
  
      <pattern name="A Simple Validation Pattern" id="mini">
          <rule context="name">
              <assert  test="string-length(.) > 3" diagnostics="dname 
dcount">Animal name should be at least 4 characters.</assert>
              <assert  test="string-length(.) &lt; 10">Animal name should be 
less than 10 characters.</assert>
          </rule>
          <rule context="scope">
              <assert test="normalize-space(.) = 'session' or 
normalize-space(.) = 'request'">Scope should be request or session.</assert>
          </rule>
      </pattern>
  
      <pattern name="Required Validation Pattern" id="required">
          <rule context="count">
              <assert  test="number(.) > 0" diagnostics="dcount">The counter 
should be > 0.</assert>
          </rule>
      </pattern>
  
      <pattern name="Extra Simple Validation Pattern" id="extra">
            a pattern
          <rule context="/personalInfo/type"> a rule 
              <assert  test="text(.) = 'mammal'">Animal type should be 
mammal.</assert>
              <report  test="text(.) != 'mammal'">Animal is not mammal.</report>
          </rule>
      </pattern>
  
      <diagnostics>
          <diagnostic id="dname">
              Animals rarely have names shorter than 5 characters.
              Dog and Cat are among the rare exceptions.
              All right, all right, don't hold me to these words, this is just 
a sloppy test after all.
          </diagnostic>
          <diagnostic id="dcount">
              The animal counter simply keeps track of the number of times this 
animal was visited .
          </diagnostic>
      </diagnostics>
  </schema>
  
  
  
  
  
  
  
  
  
  
  
  
  1.2       +190 -139  
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/xmlform/TestBean.java
  
  Index: TestBean.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/xmlform/TestBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestBean.java     25 Apr 2003 08:34:59 -0000      1.1
  +++ TestBean.java     26 Apr 2003 12:09:44 -0000      1.2
  @@ -1,3 +1,53 @@
  +/*
  +
  + ============================================================================
  +                   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
  +    [EMAIL PROTECTED]
  +
  + 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  <[EMAIL PROTECTED]>. For more  information on the Apache
  + Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
   package org.apache.cocoon.components.xmlform;
   
   import org.apache.avalon.framework.CascadingRuntimeException;
  @@ -13,149 +63,150 @@
   import java.util.Set;
   
   /**
  - *
    * A sample domain object used as a Form model.
  - * Notice that it has mixed content: 
  - * JavaBean properties and 
  + * 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$
    */
  -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"; );
  -  }
  +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.2       +125 -129  
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/xmlform/TestXMLFormAction.java
  
  Index: TestXMLFormAction.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/xmlform/TestXMLFormAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXMLFormAction.java    25 Apr 2003 08:34:59 -0000      1.1
  +++ TestXMLFormAction.java    26 Apr 2003 12:09:44 -0000      1.2
  @@ -1,64 +1,53 @@
  -/* 
  - * $Revision$
  - * $Date$
  - *
  - * ====================================================================
  - * 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 [EMAIL PROTECTED]
  - *
  - * 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/>.
  - */
  +/*
  +
  + ============================================================================
  +                   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
  +    [EMAIL PROTECTED]
  +
  + 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  <[EMAIL PROTECTED]>. For more  information on the Apache
  + Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
   
   package org.apache.cocoon.components.xmlform;
   
  @@ -68,78 +57,85 @@
   
   import java.util.Map;
   
  +/**
  + *
  + *
  + * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels </a>
  + * @version CVS $Id$
  + */
   public class TestXMLFormAction extends AbstractXMLFormAction
  -  implements FormListener
  -{
  +  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";
   
  -  // 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 );
  -      }
  +    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);
       }
   
  -    return page( VIEW_START );
  -  }
  +    public void reset(Form form) {
  +        return;
  +    }
   
  -  public void reset( Form form )
  -  {
  -    return;
  -  }
  -
  -  public boolean filterRequestParameter (Form form, String parameterName)
  -  {
  -    return false;
  -  }
  +    public boolean filterRequestParameter(Form form, String parameterName) {
  +        return false;
  +    }
   }
   
  
  
  
  1.2       +26 -13    
cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/xmlform/XMLFormTestCase.java
  
  Index: XMLFormTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/xmlform/test/org/apache/cocoon/components/xmlform/XMLFormTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLFormTestCase.java      25 Apr 2003 08:34:59 -0000      1.1
  +++ XMLFormTestCase.java      26 Apr 2003 12:09:44 -0000      1.2
  @@ -74,21 +74,28 @@
           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-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");
  +        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"));
  +        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)));
  +        assertEqual(load(testresult1),
  +                    transform("xmlform", testform1, new Parameters(),
  +                              load(testform1)));
   
           // Second request
   
  @@ -104,14 +111,17 @@
           result = act("xmlform", null, parameters);
   
           assertNotNull("Test if resource exists", result);
  -        assertEquals("Test for parameter", "view2", 
(String)result.get("page"));
  +        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)));
  +        // print(transform("xmlform", testform2, new Parameters(), 
load(testform2)));
   
  -        assertEqual(load(testresult2), transform("xmlform", testform1, new 
Parameters(), load(testform2)));
  +        assertEqual(load(testresult2),
  +                    transform("xmlform", testform1, new Parameters(),
  +                              load(testform2)));
   
           // Third request
   
  @@ -119,15 +129,18 @@
           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("/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"));
  +        assertEquals("Test for parameter", "start",
  +                     (String) result.get("page"));
       }
   }
  
  
  

Reply via email to