You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by bc...@locus.apache.org on 2000/12/01 05:38:22 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests TestDOMUtils.java

bcholmes    00/11/30 20:38:22

  Modified:    .        build.xml
               src/webdav/client/src/org/apache/webdav/lib/util
                        DOMUtils.java
  Added:       src/webdav/client/src/org/apache/webdav/lib/util/tests
                        TestDOMUtils.java
  Log:
  Slightly different fix to DAV prefix problem in DOMUtils (classic off-by-one error).  Also:
  
  - provide JUnit testcase for DOMUtils
  - update build.xml (I'm not sure if the build machine has JUnit on it, and I don't want to crash it)
  
  Revision  Changes    Path
  1.56      +1 -1      jakarta-slide/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/build.xml,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- build.xml	2000/11/25 01:43:30	1.55
  +++ build.xml	2000/12/01 04:38:21	1.56
  @@ -236,7 +236,7 @@
       <javac srcdir="src/webdav/client/src" 
        destdir="${webdavclient.build}/classes"
        debug="off" deprecation="off" 
  -     excludes="**/CVS/**,**/package.html" />
  +     excludes="**/CVS/**,**/package.html,**/tests/**" />
       <copy todir="${webdavclient.build}/bin">
         <fileset dir="src/webdav/client/bin">
           <include name="**/*.bat" />
  
  
  
  1.4       +11 -7     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/DOMUtils.java
  
  Index: DOMUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/DOMUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMUtils.java	2000/11/30 06:53:25	1.3
  +++ DOMUtils.java	2000/12/01 04:38:21	1.4
  @@ -1,4 +1,7 @@
   /*
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/DOMUtils.java,v 1.4 2000/12/01 04:38:21 bcholmes Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/12/01 04:38:21 $
    *
    * ====================================================================
    *
  @@ -77,8 +80,12 @@
   import org.w3c.dom.Text;
   
   
  -/** This class provides some basic utility methods for working with
  - *  XML Document objects.
  +/** 
  + * This class provides some basic utility methods for working with
  + * XML Document objects.
  + *
  + * @author B.C. Holmes
  + * @version $Revision: 1.4 $
    */
   public class DOMUtils {
   
  @@ -124,11 +131,8 @@
                       attr.getName().startsWith("xmlns") &&
                       attr.getValue().equals("DAV:")) {
                       int indx = attr.getName().indexOf(":");
  -                    if ((indx >= 0) && (indx < attr.getName().length())) {
  -                        prefix = attr.getName().substring(indx + 1);
  -                        if (!prefix.equals("")) {
  -                            prefix = prefix + ":";
  -                        }
  +                    if ((indx >= 0) && (indx < attr.getName().length()-1)) {
  +                        prefix = attr.getName().substring(indx + 1) + ":";
                       } else {
                           prefix = "";
                       }
  
  
  
  1.1                  jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests/TestDOMUtils.java
  
  Index: TestDOMUtils.java
  ===================================================================
  package org.apache.webdav.lib.util.tests;
  
  import java.io.StringReader;
  
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.FactoryConfigurationError;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.apache.webdav.lib.util.DOMUtils;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  import junit.framework.*;
  
  /**
   * Testcases for DOMUtils 
   *
   * @author B.C. Holmes
   */
  public class TestDOMUtils extends TestCase {
  
      protected String xml1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
          "<D:multistatus xmlns:D=\"DAV:\"><D:response>"+
              "<D:href>/foo/index.html</D:href>" +
                  "<D:propstat>" + 
                  "<D:prop><D:resourcetype/></D:prop>" +
                  "<D:status>HTTP/1.1 200 OK</D:status>" +
                  "</D:propstat>" + 
              "</D:response></D:multistatus>";
  
      protected String xml2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
          "<multistatus xmlns=\"DAV:\"><response>"+
              "<href>/foo/index.html</href>" +
                  "<propstat>" + 
                  "<prop><resourcetype/></prop>" +
                  "<status>HTTP/1.1 200 OK</status>" +
                  "</propstat>" + 
              "</response></multistatus>";
  
      public TestDOMUtils(String name) {
          super(name);
      }
  
      public static Test suite() {
          return new TestSuite(TestDOMUtils.class);
      }
  
  /*
      public void testIsDOM2Compliant() throws Exception {
          DocumentBuilderFactory factory = 
              DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          DocumentBuilder builder = factory.newDocumentBuilder();
          Document document = builder.newDocument();
  
          System.out.println("Result: " + DocumentWrapper.isDOM2Compliant(document));
      }
  */
  
      public void testGetTextValue() throws Exception {
          String xml = "<root><customer>Joe Schmoe</customer>" + 
                             "<customer>Jane Doe</customer></root>";
  
          Document document = parse(xml);
          Element root = document.getDocumentElement();
          Element child = (Element) root.getFirstChild();
          assert("Text value should be \"Joe Schmoe\", and is \"" + 
                 DOMUtils.getTextValue(child) + "\" instead", 
                 "Joe Schmoe".equals(DOMUtils.getTextValue(child)));
      }
  
      public void testFindDavPrefix1() throws Exception {
          Document document = parse(xml1);
          assert("DAV Prefix should be \"D:\", and is \"" + 
                 DOMUtils.findDavPrefix(document) + "\" instead", 
                 "D:".equals(DOMUtils.findDavPrefix(document)));
      }
  
      public void testFindDavPrefix2() throws Exception {
          Document document = parse(xml2);
          assert("DAV Prefix should be \"\", and is \"" + 
                 DOMUtils.findDavPrefix(document) + "\" instead", 
                 "".equals(DOMUtils.findDavPrefix(document)));
      }
  
      public void testParseStatus() throws Exception {
          Document document = parse(xml1);
          String prefix = DOMUtils.findDavPrefix(document);
          NodeList list = document.getElementsByTagName(prefix + "status");
          String statusText = DOMUtils.getTextValue(list.item(0));
          int status = DOMUtils.parseStatus(statusText);
          assert("Status should be \"200\" and is \"" + 
                 status + "\" instead", status == 200);
      }
  
      protected Document parse(String xml) throws Exception {
          DocumentBuilderFactory factory = 
              DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
          return builder.parse(new InputSource(new StringReader(xml)));
      }
  }
  
  
  

Re: cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests TestDOMUtils.java

Posted by "B.C. Holmes" <bc...@roxton.com>.
Remy Maucherat wrote:
> 
> I don't think it does right now.
> I'll convert the excludes to a conditional switch. Craig will eventually put
> the junit.jar on the nightly build machine.

Thanks, Remy.

BCing you
-- 
B.C. Holmes         \u2625           http://www.roxton.com/~bcholmes/
"Well, whatever you do, however terrible, however hurtful, it all 
 makes sense, doesn't it, in your head?  You never meet anybody that
 thinks they're a bad person."
         - _The Talented Mr. Ripley_

Re: cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests TestDOMUtils.java

Posted by "B.C. Holmes" <bc...@roxton.com>.
"Craig R. McClanahan" wrote:
> 
> Where do I get [JUnit]?  www.junit.org?

     Yup.

BCing you
-- 
B.C. Holmes         \u2625           http://www.roxton.com/~bcholmes/
"How often has somebody sensed they were needed without being told?
 When you have a hurt in your heart you're too proud to disclose
 Look over there... look over there...  Somebody always knows."
                  - _La Cage aux Folles_

Re: cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests TestDOMUtils.java

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Remy Maucherat wrote:

> > bcholmes    00/11/30 20:38:22
> >
> >   Modified:    .        build.xml
> >                src/webdav/client/src/org/apache/webdav/lib/util
> >                         DOMUtils.java
> >   Added:       src/webdav/client/src/org/apache/webdav/lib/util/tests
> >                         TestDOMUtils.java
> >   Log:
> >   Slightly different fix to DAV prefix problem in DOMUtils (classic
> off-by-one error).  Also:
> >
> >   - provide JUnit testcase for DOMUtils
> >   - update build.xml (I'm not sure if the build machine has JUnit on it,
> and I don't want to crash it)
>
> I don't think it does right now.
> I'll convert the excludes to a conditional switch. Craig will eventually put
> the junit.jar on the nightly build machine.
>

Where do I get it?  www.junit.org?

>
> Remy

Craig



Re: cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests TestDOMUtils.java

Posted by Remy Maucherat <re...@apache.org>.
> bcholmes    00/11/30 20:38:22
>
>   Modified:    .        build.xml
>                src/webdav/client/src/org/apache/webdav/lib/util
>                         DOMUtils.java
>   Added:       src/webdav/client/src/org/apache/webdav/lib/util/tests
>                         TestDOMUtils.java
>   Log:
>   Slightly different fix to DAV prefix problem in DOMUtils (classic
off-by-one error).  Also:
>
>   - provide JUnit testcase for DOMUtils
>   - update build.xml (I'm not sure if the build machine has JUnit on it,
and I don't want to crash it)

I don't think it does right now.
I'll convert the excludes to a conditional switch. Craig will eventually put
the junit.jar on the nightly build machine.

Remy