jericho     2002/08/17 08:12:08

  Added:       src/tests/uri URITestBase.java BasicURITest.java
  Log:
  - Add the basic URI test cases...
  
  Revision  Changes    Path
  1.1                  jakarta-slide/src/tests/uri/URITestBase.java
  
  Index: URITestBase.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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", "Slide", 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 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 (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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package uri;
  
  import junit.framework.TestCase;
  
  /**
   * The abstract class for URI {@link org.apache.util.URI}.
   *
   * @author <a href="mailto:jericho at apache.org">Sung-Gu</a>
   * @version $Id: URITestBase.java,v 1.1 2002/08/17 15:12:07 jericho Exp $
   */
  public class URITestBase extends TestCase {
  
      // ----------------------------------------------------------- constructors
  
      /**
       * The constructor.
       *
       * @param name the name
       */
      public URITestBase(String name) {
          super(name);
      }
  
      // ----------------------------------------------------------- test methods
  
  
      /**
       * Test two arguments.
       *
       * @param arg1 the character array
       * @param arg2 the character array
       * @return the compared boolean value
       */
      protected boolean assertEquals(char[] arg1, char[] arg2) {
          if (arg1 == null || arg2 == null) {
              return (arg1 == arg2);
          }
          if (arg1.length != arg2.length) return false;
  
          int length = arg1.length;
          for (int i = 0; i < length; i++) {
              if (arg1[i] != arg2[i]) {
                  return false;
              }
          }
          return true;
      }
  
  }
  
  
  
  
  1.1                  jakarta-slide/src/tests/uri/BasicURITest.java
  
  Index: BasicURITest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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", "Slide", 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 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 (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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package uri;
  
  import org.apache.util.URI;
  import org.apache.util.URIException;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * The basic testcases for URI {@link org.apache.util.URI}.
   *
   * @author <a href="mailto:jericho at apache.org">Sung-Gu</a>
   * @version $Id: BasicURITest.java,v 1.1 2002/08/17 15:12:07 jericho Exp $
   */
  public class BasicURITest extends URITestBase {
  
      // ----------------------------------------------------------- constructors
  
      /**
       * The constructor.
       *
       * @param name the name
       */
      public BasicURITest(String name) {
          super(name);
      }
  
      // ------------------------------------------------------------- properties
  
      /**
       * The URI example 1.
       */
      protected String uri01;
  
  
      /**
       * The URI example 2.
       */
      protected String uri02;
  
  
      /**
       * The URI example 3.
       */
      protected String uri03;
  
  
      /**
       * The URI example 4.
       */
      protected String uri04;
  
  
      /**
       * The URI example 5.
       */
      protected String uri05;
  
  
      /**
       * The URI example 6.
       */
      protected String uri06;
  
      // ------------------------------------------------------------------- main
  
      /**
       * The command line interface with java compiler.
       *
       * @param args arguments
       */
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      // ---------------------------------------------------------- suite methods
  
      /**
       * Return the suite.
       * 
       * @return Test
       */
      public static Test suite() {
          TestSuite suite = new TestSuite(BasicURITest.class);
          suite.setName("Basic URI tests");
          return suite;
      }
  
      /**
       * Set up.
       */
      protected void setUp() throws Exception {
          uri01 = "http://host/path?query#fragment";;
          uri02 = "http://host/path?query";;
          uri03 = "http://host/path";;
          uri04 = "http://host:8080/";;
          uri05 = "http://host/";;
          uri06 = "ftp://host";;
      }
  
  
      /**
       * Tear down.
       */
      protected void tearDown() throws Exception {
          super.tearDown();
      }
  
      // ----------------------------------------------------------- test methods
  
      /**
       * Test the example 01.
       */
      public void testExample01() throws URIException {
          URI uri = new URI(this.uri01);
  
          String scheme = "http";
          char[] rawScheme = { 'h', 't', 't', 'p' };
          assertEquals(scheme, uri.getScheme());
          assertEquals(rawScheme, uri.getRawScheme());
  
          String host = "host";
          char[] rawHost = { 'h', 'o', 's', 't' };
          assertEquals(host, uri.getHost());
          assertEquals(rawHost, uri.getRawHost());
  
          int port = -1;
          assertEquals(port, uri.getPort());
  
          String pathQuery = "/path?query";
          String escapedPathQuery = "/path?query";
          char[] rawPathQuery = { '/', 'p', 'a', 't', 'h', '?', 'q', 'u', 'e',
              'r', 'y' };
          assertEquals(pathQuery, uri.getPathQuery());
          assertEquals(escapedPathQuery, uri.getEscapedPathQuery());
          assertEquals(rawPathQuery, uri.getRawPathQuery());
  
          String path = "/path";
          String escapedPath = "/path";
          char[] rawPath = { '/', 'p', 'a', 't', 'h' };
          assertEquals(path, uri.getPath());
          assertEquals(escapedPath, uri.getEscapedPath());
          assertEquals(rawPath, uri.getRawPath());
  
          String query = "query";
          String escapedQuery = "query";
          char[] rawQuery = { 'q', 'u', 'e', 'r', 'y' };
          assertEquals(query, uri.getQuery());
          assertEquals(escapedQuery, uri.getEscapedQuery());
          assertEquals(rawQuery, uri.getRawQuery());
  
          String fragment = "fragment";
          String escapedFragment = "fragment";
          char[] rawFragment = { 'f', 'r', 'a', 'g', 'm', 'e', 'n', 't' };
          assertEquals(fragment, uri.getFragment());
          assertEquals(escapedFragment, uri.getEscapedFragment());
          assertEquals(rawFragment, uri.getRawFragment());
  
          String uriReference = "http://host/path?query#fragment";;
          String escapedUriReference = "http://host/path?query#fragment";;
          char[] rawUriReference = { 'h', 't', 't', 'p', ':', '/', '/', 'h', 'o',
              's', 't', '/', 'p', 'a', 't', 'h', '?', 'q', 'u',
              'e', 'r', 'y', '#', 'f', 'r', 'a', 'g', 'm', 'e', 'n', 't' };
          assertEquals(uriReference, uri.getURI());
          assertEquals(escapedUriReference, uri.getEscapedURI());
          assertEquals(rawUriReference, uri.getRawURI());
      }
  
  
      /**
       * Test the example 02.
       */
      public void testExample02() throws URIException {
          URI uri = new URI(this.uri02);
  
          String scheme = "http";
          char[] rawScheme = { 'h', 't', 't', 'p' };
          assertEquals(scheme, uri.getScheme());
          assertEquals(rawScheme, uri.getRawScheme());
  
          String host = "host";
          char[] rawHost = { 'h', 'o', 's', 't' };
          assertEquals(host, uri.getHost());
          assertEquals(rawHost, uri.getRawHost());
  
          int port = -1;
          assertEquals(port, uri.getPort());
  
          String pathQuery = "/path?query";
          String escapedPathQuery = "/path?query";
          char[] rawPathQuery = { '/', 'p', 'a', 't', 'h', '?', 'q', 'u', 'e',
              'r', 'y' };
          assertEquals(pathQuery, uri.getPathQuery());
          assertEquals(escapedPathQuery, uri.getEscapedPathQuery());
          assertEquals(rawPathQuery, uri.getRawPathQuery());
  
          String path = "/path";
          String escapedPath = "/path";
          char[] rawPath = { '/', 'p', 'a', 't', 'h' };
          assertEquals(path, uri.getPath());
          assertEquals(escapedPath, uri.getEscapedPath());
          assertEquals(rawPath, uri.getRawPath());
  
          String query = "query";
          String escapedQuery = "query";
          char[] rawQuery = { 'q', 'u', 'e', 'r', 'y' };
          assertEquals(query, uri.getQuery());
          assertEquals(escapedQuery, uri.getEscapedQuery());
          assertEquals(rawQuery, uri.getRawQuery());
  
          String fragment = null;
          String escapedFragment = null;
          char[] rawFragment = null;
          assertEquals(fragment, uri.getFragment());
          assertEquals(escapedFragment, uri.getEscapedFragment());
          assertEquals(rawFragment, uri.getRawFragment());
  
          String uriReference = "http://host/path?query";;
          String escapedUriReference = "http://host/path?query";;
          char[] rawUriReference = { 'h', 't', 't', 'p', ':', '/', '/', 'h', 'o',
              's', 't', '/', 'p', 'a', 't', 'h', '?', 'q', 'u', 'e', 'r', 'y'};
          assertEquals(uriReference, uri.getURI());
          assertEquals(escapedUriReference, uri.getEscapedURI());
          assertEquals(rawUriReference, uri.getRawURI());
      }
  
  
      /**
       * Test the example 03.
       */
      public void testExample03() throws URIException {
          URI uri = new URI(this.uri03);
  
          String scheme = "http";
          char[] rawScheme = { 'h', 't', 't', 'p' };
          assertEquals(scheme, uri.getScheme());
          assertEquals(rawScheme, uri.getRawScheme());
  
          String host = "host";
          char[] rawHost = { 'h', 'o', 's', 't' };
          assertEquals(host, uri.getHost());
          assertEquals(rawHost, uri.getRawHost());
  
          int port = -1;
          assertEquals(port, uri.getPort());
  
          String pathQuery = "/path";
          String escapedPathQuery = "/path";
          char[] rawPathQuery = { '/', 'p', 'a', 't', 'h' };
          assertEquals(pathQuery, uri.getPathQuery());
          assertEquals(escapedPathQuery, uri.getEscapedPathQuery());
          assertEquals(rawPathQuery, uri.getRawPathQuery());
  
          String path = "/path";
          String escapedPath = "/path";
          char[] rawPath = { '/', 'p', 'a', 't', 'h' };
          assertEquals(path, uri.getPath());
          assertEquals(escapedPath, uri.getEscapedPath());
          assertEquals(rawPath, uri.getRawPath());
  
          String query = null;
          String escapedQuery = null;
          char[] rawQuery = null;
          assertEquals(query, uri.getQuery());
          assertEquals(escapedQuery, uri.getEscapedQuery());
          assertEquals(rawQuery, uri.getRawQuery());
  
          String fragment = null;
          String escapedFragment = null;
          char[] rawFragment = null;
          assertEquals(fragment, uri.getFragment());
          assertEquals(escapedFragment, uri.getEscapedFragment());
          assertEquals(rawFragment, uri.getRawFragment());
  
          String uriReference = "http://host/path";;
          String escapedUriReference = "http://host/path";;
          char[] rawUriReference = { 'h', 't', 't', 'p', ':', '/', '/', 'h', 'o',
              's', 't', '/', 'p', 'a', 't', 'h' };
          assertEquals(uriReference, uri.getURI());
          assertEquals(escapedUriReference, uri.getEscapedURI());
          assertEquals(rawUriReference, uri.getRawURI());
      }
  
  
      /**
       * Test the example 04.
       */
      public void testExample04() throws URIException {
          URI uri = new URI(this.uri04);
  
          String scheme = "http";
          char[] rawScheme = { 'h', 't', 't', 'p' };
          assertEquals(scheme, uri.getScheme());
          assertEquals(rawScheme, uri.getRawScheme());
  
          String host = "host";
          char[] rawHost = { 'h', 'o', 's', 't' };
          assertEquals(host, uri.getHost());
          assertEquals(rawHost, uri.getRawHost());
  
          int port = 8080;
          assertEquals(port, uri.getPort());
  
          String pathQuery = "/";
          String escapedPathQuery = "/";
          char[] rawPathQuery = { '/' };
          assertEquals(pathQuery, uri.getPathQuery());
          assertEquals(escapedPathQuery, uri.getEscapedPathQuery());
          assertEquals(rawPathQuery, uri.getRawPathQuery());
  
          String path = "/";
          String escapedPath = "/";
          char[] rawPath = { '/' };
          assertEquals(path, uri.getPath());
          assertEquals(escapedPath, uri.getEscapedPath());
          assertEquals(rawPath, uri.getRawPath());
  
          String query = null;
          String escapedQuery = null;
          char[] rawQuery = null;
          assertEquals(query, uri.getQuery());
          assertEquals(escapedQuery, uri.getEscapedQuery());
          assertEquals(rawQuery, uri.getRawQuery());
  
          String fragment = null;
          String escapedFragment = null;
          char[] rawFragment = null;
          assertEquals(fragment, uri.getFragment());
          assertEquals(escapedFragment, uri.getEscapedFragment());
          assertEquals(rawFragment, uri.getRawFragment());
  
          String uriReference = "http://host:8080/";;
          String escapedUriReference = "http://host:8080/";;
          char[] rawUriReference = { 'h', 't', 't', 'p', ':', '/', '/', 'h', 'o',
              's', 't', ':', '8', '0', '8', '0', '/' };
          assertEquals(uriReference, uri.getURI());
          assertEquals(escapedUriReference, uri.getEscapedURI());
          assertEquals(rawUriReference, uri.getRawURI());
      }
  
  
      /**
       * Test the example 05.
       */
      public void testExample05() throws URIException {
          URI uri = new URI(this.uri05);
  
          String scheme = "http";
          char[] rawScheme = { 'h', 't', 't', 'p' };
          assertEquals(scheme, uri.getScheme());
          assertEquals(rawScheme, uri.getRawScheme());
  
          String host = "host";
          char[] rawHost = { 'h', 'o', 's', 't' };
          assertEquals(host, uri.getHost());
          assertEquals(rawHost, uri.getRawHost());
  
          int port = -1;
          assertEquals(port, uri.getPort());
  
          String pathQuery = "/";
          String escapedPathQuery = "/";
          char[] rawPathQuery = { '/' };
          assertEquals(pathQuery, uri.getPathQuery());
          assertEquals(escapedPathQuery, uri.getEscapedPathQuery());
          assertEquals(rawPathQuery, uri.getRawPathQuery());
  
          String path = "/";
          String escapedPath = "/";
          char[] rawPath = { '/' };
          assertEquals(path, uri.getPath());
          assertEquals(escapedPath, uri.getEscapedPath());
          assertEquals(rawPath, uri.getRawPath());
  
          String query = null;
          String escapedQuery = null;
          char[] rawQuery = null;
          assertEquals(query, uri.getQuery());
          assertEquals(escapedQuery, uri.getEscapedQuery());
          assertEquals(rawQuery, uri.getRawQuery());
  
          String fragment = null;
          String escapedFragment = null;
          char[] rawFragment = null;
          assertEquals(fragment, uri.getFragment());
          assertEquals(escapedFragment, uri.getEscapedFragment());
          assertEquals(rawFragment, uri.getRawFragment());
  
          String uriReference = "http://host/";;
          String escapedUriReference = "http://host/";;
          char[] rawUriReference = { 'h', 't', 't', 'p', ':', '/', '/', 'h', 'o',
              's', 't', '/' };
          assertEquals(uriReference, uri.getURI());
          assertEquals(escapedUriReference, uri.getEscapedURI());
          assertEquals(rawUriReference, uri.getRawURI());
      }
  
  
      /**
       * Test the example 06.
       */
      public void testExample06() throws URIException {
          URI uri = new URI(this.uri06);
  
          String scheme = "ftp";
          char[] rawScheme = { 'f', 't', 'p' };
          assertEquals(scheme, uri.getScheme());
          assertEquals(rawScheme, uri.getRawScheme());
  
          String host = "host";
          char[] rawHost = { 'h', 'o', 's', 't' };
          assertEquals(host, uri.getHost());
          assertEquals(rawHost, uri.getRawHost());
  
          int port = -1;
          assertEquals(port, uri.getPort());
  
          String pathQuery = null;
          String escapedPathQuery = null;
          char[] rawPathQuery = null;
          assertEquals(pathQuery, uri.getPathQuery());
          assertEquals(escapedPathQuery, uri.getEscapedPathQuery());
          assertEquals(rawPathQuery, uri.getRawPathQuery());
  
          String path = null;
          String escapedPath = null;
          char[] rawPath = null;
          assertEquals(path, uri.getPath());
          assertEquals(escapedPath, uri.getEscapedPath());
          assertEquals(rawPath, uri.getRawPath());
  
          String query = null;
          String escapedQuery = null;
          char[] rawQuery = null;
          assertEquals(query, uri.getQuery());
          assertEquals(escapedQuery, uri.getEscapedQuery());
          assertEquals(rawQuery, uri.getRawQuery());
  
          String fragment = null;
          String escapedFragment = null;
          char[] rawFragment = null;
          assertEquals(fragment, uri.getFragment());
          assertEquals(escapedFragment, uri.getEscapedFragment());
          assertEquals(rawFragment, uri.getRawFragment());
  
          String uriReference = "ftp://host";;
          String escapedUriReference = "ftp://host";;
          char[] rawUriReference = { 'f', 't', 'p', ':', '/', '/', 'h', 'o', 's',
              't' };
          assertEquals(uriReference, uri.getURI());
          assertEquals(escapedUriReference, uri.getEscapedURI());
          assertEquals(rawUriReference, uri.getRawURI());
      }
  
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to