KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > util > FileUtilsTest


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: FileUtilsTest.java,v 1.5 2007/01/07 06:14:55 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.util;
23
24 import java.io.File JavaDoc;
25
26 import junit.framework.TestCase;
27
28 /**
29  * Test for functions from FileUtils class
30  *
31  * @version $Id: FileUtilsTest.java,v 1.5 2007/01/07 06:14:55 bastafidli Exp $
32  * @author Martin Cerba
33  * @code.reviewer Miro Halas
34  * @code.reviewed Initial revision
35  */

36 public class FileUtilsTest extends TestCase
37 {
38    /**
39     * @param arg0 -
40     * test argument
41     */

42    public FileUtilsTest(String JavaDoc arg0)
43    {
44       super(arg0);
45    }
46    /**
47     * Results array for testGetFileStoragePath
48     */

49    protected static final String JavaDoc[] GET_FILE_STRORAGE_PATH_RESULTS
50       = {
51          "root1/00" + File.separatorChar + "00" + File.separatorChar + "00" + File.separatorChar
52                + "0000000001.pdf",
53          "root2/00" + File.separatorChar + "00" + File.separatorChar + "00" + File.separatorChar
54                + "0000000001_extension1.pdf",
55          "root3/12" + File.separatorChar + "34" + File.separatorChar + "56"
56                + File.separatorChar + "12345678.pdf",
57          "root4/12" + File.separatorChar + "34" + File.separatorChar + "56"
58                + File.separatorChar + "12345678_extension2.pdf",
59          "root5/9999999999.jpg",
60          "root6/9999999999_extension3.jpg",
61          "root7/0000000001.tif",
62          "root8/0000000001_extension4.tif",
63          "root9/0000" + File.separatorChar + "1234" + File.separatorChar + "0000123456.tif",
64          "root10/0000" + File.separatorChar + "1234" + File.separatorChar
65                + "0000123456_extension5.tif",
66          "root11/1" + File.separatorChar + "2" + File.separatorChar + "3" + File.separatorChar
67                + "4" + File.separatorChar + "5" + File.separatorChar + "6" + File.separatorChar
68                + "7" + File.separatorChar + "8" + File.separatorChar + "9"
69                + File.separatorChar + "1234567890.tif",
70          "root12/1" + File.separatorChar + "2" + File.separatorChar + "3" + File.separatorChar
71                + "4" + File.separatorChar + "5" + File.separatorChar + "6" + File.separatorChar
72                + "7" + File.separatorChar + "8" + File.separatorChar + "9"
73                + File.separatorChar + "1234567890_extension6.tif",
74          "root13/000001" + File.separatorChar + "2" + File.separatorChar + "3" + File.separatorChar
75                + "4" + File.separatorChar + "5" + File.separatorChar + "6" + File.separatorChar
76                + "7" + File.separatorChar + "8" + File.separatorChar + "9"
77                + File.separatorChar + "000001234567890.tif",
78          "root14/000001" + File.separatorChar + "2" + File.separatorChar + "3" + File.separatorChar
79                + "4" + File.separatorChar + "5" + File.separatorChar + "6" + File.separatorChar
80                + "7" + File.separatorChar + "8" + File.separatorChar + "9"
81                + File.separatorChar + "000001234567890_extension7.tif",
82          "root15/1" + File.separatorChar + "2" + File.separatorChar + "3" + File.separatorChar
83                + "4" + File.separatorChar + "00005" + File.separatorChar + "6" + File.separatorChar
84                + "7" + File.separatorChar + "8" + File.separatorChar + "9" + File.separatorChar
85                + "12340000567890.tif",
86          "root16/1" + File.separatorChar + "2" + File.separatorChar + "3" + File.separatorChar
87                + "4" + File.separatorChar + "00005" + File.separatorChar + "6" + File.separatorChar
88                + "7" + File.separatorChar + "8" + File.separatorChar + "9" + File.separatorChar
89                + "12340000567890_extension8.tif",
90    };
91
92    /**
93     * test for getFileStroragePath function
94     *
95     * @throws Exception - error in test
96     */

97    public void testGetFileStoragePath() throws Exception JavaDoc
98    {
99       int iIndex = 0;
100       String JavaDoc retval = null;
101       retval = FileUtils.getFileStoragePath(1, "root1/", null, ".pdf",
102                             new int[] {2, 2, 2, 4});
103       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
104       retval = FileUtils.getFileStoragePath(1, "root2/", "_extension1", ".pdf",
105                             new int[] {2, 2, 2, 4});
106       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
107       retval = FileUtils.getFileStoragePath(12345678, "root3/", null, ".pdf",
108                             new int[] {2, 2, 2, 2});
109       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
110       retval = FileUtils.getFileStoragePath(12345678, "root4/", "_extension2", ".pdf",
111                             new int[] {2, 2, 2, 2});
112       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
113       retval = FileUtils.getFileStoragePath(9999999999L, "root5/", null, ".jpg",
114                             new int[] {10});
115       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
116       retval = FileUtils.getFileStoragePath(9999999999L, "root6/", "_extension3", ".jpg",
117                             new int[] {10});
118       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
119       retval = FileUtils.getFileStoragePath(1, "root7/", null, ".tif",
120                             new int[] {10});
121       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
122       retval = FileUtils.getFileStoragePath(1, "root8/", "_extension4", ".tif",
123                             new int[] {10});
124       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
125       retval = FileUtils.getFileStoragePath(123456, "root9/", null, ".tif",
126                             new int[] {4, 4, 2});
127       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
128       retval = FileUtils.getFileStoragePath(123456, "root10/", "_extension5", ".tif",
129                             new int[] {4, 4, 2});
130       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
131       retval = FileUtils.getFileStoragePath(1234567890L, "root11/", null, ".tif",
132                             new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
133       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
134       retval = FileUtils.getFileStoragePath(1234567890L, "root12/", "_extension6", ".tif",
135                             new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
136       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
137       retval = FileUtils.getFileStoragePath(1234567890L, "root13/", null, ".tif",
138                             new int[] {6, 1, 1, 1, 1, 1, 1, 1, 1, 1});
139       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
140       retval = FileUtils.getFileStoragePath(1234567890L, "root14/", "_extension7", ".tif",
141                             new int[] {6, 1, 1, 1, 1, 1, 1, 1, 1, 1});
142       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
143       retval = FileUtils.getFileStoragePath(12340000567890L, "root15/", null, ".tif",
144                             new int[] {1, 1, 1, 1, 5, 1, 1, 1, 1, 1});
145       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
146       retval = FileUtils.getFileStoragePath(12340000567890L, "root16/", "_extension8", ".tif",
147                             new int[] {1, 1, 1, 1, 5, 1, 1, 1, 1, 1});
148       assertEquals(GET_FILE_STRORAGE_PATH_RESULTS[iIndex++], retval);
149    }
150 }
151
Popular Tags