huber       01/12/28 13:32:36

  Added:       test/org/apache/cocoon/util/test IOUtilsTestCase.java
                        NetUtilsTestCase.java
  Log:
  initial version, JUnit tests
  
  Revision  Changes    Path
  1.1                  
xml-cocoon2/test/org/apache/cocoon/util/test/IOUtilsTestCase.java
  
  Index: IOUtilsTestCase.java
  ===================================================================
  /**
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   */
  
  package org.apache.cocoon.util.test;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.cocoon.util.IOUtils;
  
  /**
   * Test Cases for the IOUtils Class.
   * @see org.apache.Cocoon.util.IOUtils
   *
   * @author     <a href="mailto:[EMAIL PROTECTED]";>Stuart Roebuck</a>
   * @author     <a href="mailto:[EMAIL PROTECTED]";>Bernhard Huber</a>
   * @version    CVS $Revision: 1.1 $ $Date: 2001/12/28 21:32:36 $
   */
  public class IOUtilsTestCase extends TestCase
  {
  
      /**
       *Constructor for the IOUtilsTestCase object
       *
       * @param  name  Description of Parameter
       * @since
       */
      public IOUtilsTestCase(String name) {
          super(name);
      }
  
  
      /**
       *Description of the Method
       *
       * @param  args  Description of Parameter
       * @since
       */
      public static void main(String args[]) {
          junit.textui.TestRunner.run(IOUtilsTestCase.class);
      }
  
  
      /**
       * A unit test for <code>normalizedFilename()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testNormalizedFilename() throws Exception {
          Object[] test_values = {
                  new String[]{".", "__"},
                  new String[]{"", ""},
                  new String[]{"file://", "file_" + File.separator + "_" + 
File.separator + "_"},
                  new String[]{"/a/b/c", "a" + File.separator + "b" + File.separator + 
"c"},
                  new String[]{"\\a\\b\\c", "a" + File.separator + "b" + 
File.separator + "c"},
                  new String[]{"a/b/c", "a" + File.separator + "b" + File.separator + 
"c"},
                  new String[]{"a\\b\\c", "a" + File.separator + "b" + File.separator 
+ "c"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test = tests[0];
              String expected = tests[1];
  
              String result = IOUtils.normalizedFilename(test);
              String message = "Test " + "'" + test + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>getContextFilePath()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testGetContextFilePath() throws Exception {
          Object[] test_values = {
                  new String[]{"a", "a" + File.separator + "b", "b"},
                  new String[]{"a\\b", "a\\b" + File.separator + "c/d", "c" + 
File.separator + "d"},
                  new String[]{"a/b", "a/b" + File.separator + "c\\d", "c" + 
File.separator + "d"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test_directory_path = tests[0];
              String test_file_path = tests[1];
              String expected = tests[2];
  
              String result = IOUtils.getContextFilePath(test_directory_path, 
test_file_path);
              String message = "Test " + "'" + test_directory_path + "'" + ", " +
                      "'" + test_file_path + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>objectToBytes()</code>, and <code>bytesToObject()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testObjectToBytesBytesToObject() throws Exception {
          String test = "test";
          String expected = "test";
  
          String message = "Test " + "'" + test + "'";
  
          byte[] bytes = IOUtils.objectToBytes(test);
          String result = (String) IOUtils.bytesToObject(bytes);
  
          assertEquals(message, expected, result);
      }
  }
  
  
  
  
  1.1                  
xml-cocoon2/test/org/apache/cocoon/util/test/NetUtilsTestCase.java
  
  Index: NetUtilsTestCase.java
  ===================================================================
  /**
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   */
  //
  package org.apache.cocoon.util.test;
  
  import java.io.File;
  import java.util.HashMap;
  import java.util.Map;
  import junit.framework.TestCase;
  
  import org.apache.cocoon.util.NetUtils;
  
  /**
   * Test Cases for the NetUtils class.
   * @see org.apache.cocoon.util.NetUtils
   *
   * @author     <a href="mailto:[EMAIL PROTECTED]";>Bernhard Huber</a>
   * @version    CVS $Id: NetUtilsTestCase.java,v 1.1 2001/12/28 21:32:36 huber Exp $
   */
  public class NetUtilsTestCase extends TestCase
  {
  
      /**
       *Constructor for the IOUtilsTestCase object
       *
       * @param  name  Description of Parameter
       * @since
       */
      public NetUtilsTestCase(String name) {
          super(name);
      }
  
  
      /**
       *Description of the Method
       *
       * @param  args  Description of Parameter
       * @since
       */
      public static void main(String args[]) {
          junit.textui.TestRunner.run(NetUtilsTestCase.class);
      }
  
  
      /**
       * A unit test for <code>NetUtils.getPath()</code>.
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testGetPath() throws Exception {
          Object[] test_values = {
                  new String[]{"/", ""},
                  new String[]{"/foo.bar", ""},
                  new String[]{"foo/bar", "foo"},
                  new String[]{"/foo/bar", "/foo"}
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test = tests[0];
              String expected = tests[1];
  
              String result = NetUtils.getPath(test);
              String message = "Test " + "'" + test + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.getExtension()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testGetExtension() throws Exception {
          Object[] test_values = {
                  new String[]{"/foo.bar", ".bar"},
                  new String[]{"foo.bar#a", ".bar"},
                  new String[]{"foo.bar?b=c", ".bar"},
                  new String[]{"foo.bar#a?b=c", ".bar"},
                  new String[]{"foo.bar", ".bar"},
                  new String[]{"foo/bar", null},
                  new String[]{"/x.html", ".html"},
                  new String[]{"/foo.bar.org/x.y.z.html", ".html"}
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test = tests[0];
              String expected = tests[1];
  
              String result = NetUtils.getExtension(test);
              String message = "Test " + "'" + test + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.absolutize()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testAbsolutize() throws Exception {
  
          Object[] test_values = {
                  new String[]{"http://xml.apache.org";, "foo.bar", 
"http://xml.apache.org/foo.bar"},
                  new String[]{"http://xml.apache.org/";, "foo.bar", 
"http://xml.apache.org/foo.bar"},
                  new String[]{"http://xml.apache.org";, "/foo.bar", "/foo.bar"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test_path = tests[0];
              String test_rel_resource = tests[1];
              String expected = tests[2];
  
              String result = NetUtils.absolutize(test_path, test_rel_resource);
              String message = "Test " +
                      " path " + "'" + test_path + "'" +
                      " relativeResource " + "'" + test_rel_resource;
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.testEncodePath()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testEncodePath() throws Exception {
  
          Object[] test_values = {
                  new String[]{"abc def", "abc%20def"},
                  new String[]{"foo/bar?n=v&N=V", "foo/bar%3Fn=v&N=V"}
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String original = tests[0];
              String expected = tests[1];
  
              String result = NetUtils.encodePath(original);
              String message = "Test " +
                      " original " + "'" + original + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.relativize()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testRelativize() throws Exception {
  
          Object[] test_values = {
                  new String[]{"/xml.apache.org", "/xml.apache.org/foo.bar", 
"foo.bar"},
                  new String[]{"/xml.apache.org", "/xml.apache.org/foo.bar", 
"foo.bar"},
                  new String[]{"/xml.apache.org", "/xml.apache.org/foo.bar", 
"foo.bar"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test_path = tests[0];
              String test_abs_resource = tests[1];
              String expected = tests[2];
  
              String result = NetUtils.relativize(test_path, test_abs_resource);
              String message = "Test " +
                      " path " + "'" + test_path + "'" +
                      " absoluteResource " + "'" + test_abs_resource;
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.normalize()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testNormalize() throws Exception {
          Object[] test_values = {
                  new String[]{"/foo/bar", "/foo/bar"},
                  new String[]{"bar", "bar"},
                  new String[]{"foo/../bar", "bar"},
                  new String[]{"foo/./bar", "foo/bar"},
                  new String[]{"foo/bar1/bar2/bar3/../../..", "foo"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test = tests[0];
              String expected = tests[1];
  
              String result = NetUtils.normalize(test);
              String message = "Test " + "'" + test + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.deparameterize()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testDeparameterize() throws Exception {
          Map parameters = new HashMap();
          Object[] test_values = {
                  new String[]{"/foo/bar", "/foo/bar"},
                  new String[]{"bar?a=b&c=d", "bar"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              String tests[] = (String[]) test_values[i];
              String test = tests[0];
              String expected = tests[1];
  
              parameters.clear();
              String result = NetUtils.deparameterize(test, parameters);
              if (test.indexOf('?') > -1) {
                  assertTrue(parameters.size() > 0);
              }
              String message = "Test " + "'" + test + "'";
              assertEquals(message, expected, result);
          }
      }
  
  
      /**
       * A unit test for <code>NetUtils.parameterize()</code>
       *
       * @exception  Exception  Description of Exception
       * @since
       */
      public void testParameterize() throws Exception {
          Map parameters1 = new HashMap();
          Map parameters2 = new HashMap();
          parameters2.put("a", "b");
          parameters2.put("c", "d");
  
          Object[] test_values = {
                  new Object[]{"/foo/bar", parameters1, "/foo/bar"},
                  new Object[]{"bar", parameters2, "bar?a=b&c=d"},
                  };
          for (int i = 0; i < test_values.length; i++) {
              Object tests[] = (Object[]) test_values[i];
              String test = (String) tests[0];
              Map parameters = (Map) tests[1];
              String expected = (String) tests[2];
  
              String result = NetUtils.parameterize(test, parameters);
              String message = "Test " + "'" + test + "'";
              assertEquals(message, expected, result);
          }
      }
  }
  
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to