001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.util.test;
018:
019: import java.io.File;
020: import junit.framework.TestCase;
021: import org.apache.cocoon.util.IOUtils;
022:
023: /**
024: * Test Cases for the IOUtils Class.
025: * @see org.apache.cocoon.util.IOUtils
026: *
027: * @author <a href="mailto:stuart.roebuck@adolos.com">Stuart Roebuck</a>
028: * @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
029: * @version CVS $Id: IOUtilsTestCase.java 433543 2006-08-22 06:22:54Z crossley $
030: */
031: public class IOUtilsTestCase extends TestCase {
032:
033: /**
034: *Constructor for the IOUtilsTestCase object
035: *
036: * @param name Description of Parameter
037: * @since
038: */
039: public IOUtilsTestCase(String name) {
040: super (name);
041: }
042:
043: /**
044: *Description of the Method
045: *
046: * @param args Description of Parameter
047: * @since
048: */
049: public static void main(String args[]) {
050: junit.textui.TestRunner.run(IOUtilsTestCase.class);
051: }
052:
053: /**
054: * A unit test for <code>normalizedFilename()</code>
055: *
056: * @exception Exception Description of Exception
057: * @since
058: */
059: public void testNormalizedFilename() throws Exception {
060: Object[] test_values = {
061: new String[] { ".", "__" },
062: new String[] { "", "" },
063: new String[] { "file://", "file_" },
064: // was new String[]{"file://", "file_" + File.separator + "_" + File.separator + "_"},
065: new String[] {
066: "/a/b/c",
067: "a" + File.separator + "b" + File.separator
068: + "c" },
069: new String[] {
070: "\\a\\b\\c",
071: "a" + File.separator + "b" + File.separator
072: + "c" },
073: new String[] {
074: "a/b/c",
075: "a" + File.separator + "b" + File.separator
076: + "c" },
077: new String[] {
078: "a\\b\\c",
079: "a" + File.separator + "b" + File.separator
080: + "c" },
081:
082: new String[] { "a/b/../c", "a" + File.separator + "c" },
083: new String[] { "public/final.xml",
084: "public_" + File.separator + "final_xml" },
085: new String[] { "123", "_123" } };
086: for (int i = 0; i < test_values.length; i++) {
087: String tests[] = (String[]) test_values[i];
088: String test = tests[0];
089: String expected = tests[1];
090:
091: String result = IOUtils.normalizedFilename(test);
092: String message = "Test " + "'" + test + "'";
093: assertEquals(message, expected, result);
094: }
095: }
096:
097: /**
098: * A unit test for <code>getContextFilePath()</code>
099: *
100: * @exception Exception Description of Exception
101: * @since
102: */
103: public void testGetContextFilePath() throws Exception {
104: Object[] test_values = {
105: new String[] { "a", "a" + File.separator + "b", "b" },
106: new String[] { "a\\b", "a\\b" + File.separator + "c/d",
107: "c" + File.separator + "d" },
108: new String[] { "a/b", "a/b" + File.separator + "c\\d",
109: "c" + File.separator + "d" }, };
110: for (int i = 0; i < test_values.length; i++) {
111: String tests[] = (String[]) test_values[i];
112: String test_directory_path = tests[0];
113: String test_file_path = tests[1];
114: String expected = tests[2];
115:
116: String result = IOUtils.getContextFilePath(
117: test_directory_path, test_file_path);
118: String message = "Test " + "'" + test_directory_path + "'"
119: + ", " + "'" + test_file_path + "'";
120: assertEquals(message, expected, result);
121: }
122: }
123:
124: /**
125: * A unit test for <code>objectToBytes()</code>, and <code>bytesToObject()</code>
126: *
127: * @exception Exception Description of Exception
128: * @since
129: */
130: public void testObjectToBytesBytesToObject() throws Exception {
131: String test = "test";
132: String expected = "test";
133:
134: String message = "Test " + "'" + test + "'";
135:
136: byte[] bytes = IOUtils.objectToBytes(test);
137: String result = (String) IOUtils.bytesToObject(bytes);
138:
139: assertEquals(message, expected, result);
140: }
141: }
|