KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > util > test > IOUtilsTestCase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.util.test;
17
18 import java.io.File JavaDoc;
19 import junit.framework.TestCase;
20 import org.apache.cocoon.util.IOUtils;
21
22 /**
23  * Test Cases for the IOUtils Class.
24  * @see org.apache.cocoon.util.IOUtils
25  *
26  * @author <a HREF="mailto:stuart.roebuck@adolos.com">Stuart Roebuck</a>
27  * @author <a HREF="mailto:berni_huber@a1.net">Bernhard Huber</a>
28  * @version CVS $Id: IOUtilsTestCase.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public class IOUtilsTestCase extends TestCase
31 {
32
33     /**
34      *Constructor for the IOUtilsTestCase object
35      *
36      * @param name Description of Parameter
37      * @since
38      */

39     public IOUtilsTestCase(String JavaDoc name) {
40         super(name);
41     }
42
43
44     /**
45      *Description of the Method
46      *
47      * @param args Description of Parameter
48      * @since
49      */

50     public static void main(String JavaDoc args[]) {
51         junit.textui.TestRunner.run(IOUtilsTestCase.class);
52     }
53
54
55     /**
56      * A unit test for <code>normalizedFilename()</code>
57      *
58      * @exception Exception Description of Exception
59      * @since
60      */

61     public void testNormalizedFilename() throws Exception JavaDoc {
62         Object JavaDoc[] test_values = {
63                 new String JavaDoc[]{".", "__"},
64                 new String JavaDoc[]{"", ""},
65                 new String JavaDoc[]{"file://", "file_"},
66                 // was new String[]{"file://", "file_" + File.separator + "_" + File.separator + "_"},
67
new String JavaDoc[]{"/a/b/c", "a" + File.separator + "b" + File.separator + "c"},
68                 new String JavaDoc[]{"\\a\\b\\c", "a" + File.separator + "b" + File.separator + "c"},
69                 new String JavaDoc[]{"a/b/c", "a" + File.separator + "b" + File.separator + "c"},
70                 new String JavaDoc[]{"a\\b\\c", "a" + File.separator + "b" + File.separator + "c"},
71                 
72                 new String JavaDoc[]{"a/b/../c", "a" + File.separator + "c"},
73                 new String JavaDoc[]{"public/final.xml", "public_" + File.separator + "final_xml"},
74                 new String JavaDoc[]{"123", "_123"}
75                 };
76         for (int i = 0; i < test_values.length; i++) {
77             String JavaDoc tests[] = (String JavaDoc[]) test_values[i];
78             String JavaDoc test = tests[0];
79             String JavaDoc expected = tests[1];
80
81             String JavaDoc result = IOUtils.normalizedFilename(test);
82             String JavaDoc message = "Test " + "'" + test + "'";
83             assertEquals(message, expected, result);
84         }
85     }
86
87
88     /**
89      * A unit test for <code>getContextFilePath()</code>
90      *
91      * @exception Exception Description of Exception
92      * @since
93      */

94     public void testGetContextFilePath() throws Exception JavaDoc {
95         Object JavaDoc[] test_values = {
96                 new String JavaDoc[]{"a", "a" + File.separator + "b", "b"},
97                 new String JavaDoc[]{"a\\b", "a\\b" + File.separator + "c/d", "c" + File.separator + "d"},
98                 new String JavaDoc[]{"a/b", "a/b" + File.separator + "c\\d", "c" + File.separator + "d"},
99                 };
100         for (int i = 0; i < test_values.length; i++) {
101             String JavaDoc tests[] = (String JavaDoc[]) test_values[i];
102             String JavaDoc test_directory_path = tests[0];
103             String JavaDoc test_file_path = tests[1];
104             String JavaDoc expected = tests[2];
105
106             String JavaDoc result = IOUtils.getContextFilePath(test_directory_path, test_file_path);
107             String JavaDoc message = "Test " + "'" + test_directory_path + "'" + ", " +
108                     "'" + test_file_path + "'";
109             assertEquals(message, expected, result);
110         }
111     }
112
113
114     /**
115      * A unit test for <code>objectToBytes()</code>, and <code>bytesToObject()</code>
116      *
117      * @exception Exception Description of Exception
118      * @since
119      */

120     public void testObjectToBytesBytesToObject() throws Exception JavaDoc {
121         String JavaDoc test = "test";
122         String JavaDoc expected = "test";
123
124         String JavaDoc message = "Test " + "'" + test + "'";
125
126         byte[] bytes = IOUtils.objectToBytes(test);
127         String JavaDoc result = (String JavaDoc) IOUtils.bytesToObject(bytes);
128
129         assertEquals(message, expected, result);
130     }
131 }
132
133
Popular Tags