001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.util;
022:
023: import java.util.*;
024: import java.io.*;
025: import java.sql.*;
026: import junit.framework.*;
027: import org.apache.log4j.*;
028: import com.methodhead.persistable.*;
029: import com.methodhead.test.*;
030: import org.apache.commons.io.*;
031:
032: public class MhfFileUtilsTest extends TestCase {
033:
034: File testdir_ = null;
035: File f = null;
036: File src = null;
037:
038: static {
039: TestUtils.initLogger();
040: TestUtils.initDb();
041: }
042:
043: public MhfFileUtilsTest(String name) {
044: super (name);
045: }
046:
047: protected void setUp() {
048: try {
049: testdir_ = new File("testdir");
050:
051: if (testdir_.exists())
052: FileUtils.deleteDirectory(testdir_);
053:
054: testdir_.mkdir();
055: } catch (Exception e) {
056: fail(e.getMessage());
057: }
058: }
059:
060: protected void tearDown() {
061: }
062:
063: public void testUnzip() {
064: try {
065: src = new File("support/test.zip");
066:
067: MhfFileUtils.unzip(src, testdir_);
068:
069: f = new File(testdir_, "test.txt");
070: assertTrue(f.exists());
071: assertTrue(f.isFile());
072:
073: f = new File(testdir_, "subdir");
074: assertTrue(f.exists());
075: assertTrue(f.isDirectory());
076:
077: f = new File(testdir_, "subdir/test2.txt");
078: assertTrue(f.exists());
079: assertTrue(f.isFile());
080: } catch (Exception e) {
081: e.printStackTrace();
082: fail();
083: }
084: }
085:
086: public void testUnzipWin() {
087: try {
088: src = new File("support/wintest.zip");
089:
090: MhfFileUtils.unzip(src, testdir_);
091:
092: f = new File(testdir_, "test.txt");
093: assertTrue(f.exists());
094: assertTrue(f.isFile());
095:
096: f = new File(testdir_, "subdir");
097: assertTrue(f.exists());
098: assertTrue(f.isDirectory());
099:
100: f = new File(testdir_, "subdir/test2.txt");
101: assertTrue(f.exists());
102: assertTrue(f.isFile());
103: } catch (Exception e) {
104: e.printStackTrace();
105: fail();
106: }
107: }
108: }
|