KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > util > MhfFileUtilsTest


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.util;
22
23 import java.util.*;
24 import java.io.*;
25 import java.sql.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import org.apache.commons.io.*;
31
32 public class MhfFileUtilsTest extends TestCase {
33
34   File testdir_ = null;
35   File f = null;
36   File src = null;
37
38   static {
39     TestUtils.initLogger();
40     TestUtils.initDb();
41   }
42
43   public MhfFileUtilsTest( String JavaDoc name ) {
44     super( name );
45   }
46
47   protected void setUp() {
48     try {
49       testdir_ = new File( "testdir" );
50
51       if ( testdir_.exists() )
52         FileUtils.deleteDirectory( testdir_ );
53
54       testdir_.mkdir();
55     }
56     catch ( Exception JavaDoc e ) {
57       fail( e.getMessage() );
58     }
59   }
60
61   protected void tearDown() {
62   }
63
64   public void testUnzip() {
65     try {
66       src = new File( "support/test.zip" );
67
68       MhfFileUtils.unzip( src, testdir_ );
69
70       f = new File( testdir_, "test.txt" );
71       assertTrue( f.exists() );
72       assertTrue( f.isFile() );
73
74       f = new File( testdir_, "subdir" );
75       assertTrue( f.exists() );
76       assertTrue( f.isDirectory() );
77
78       f = new File( testdir_, "subdir/test2.txt" );
79       assertTrue( f.exists() );
80       assertTrue( f.isFile() );
81     }
82     catch ( Exception JavaDoc e ) {
83       e.printStackTrace();
84       fail();
85     }
86   }
87
88   public void testUnzipWin() {
89     try {
90       src = new File( "support/wintest.zip" );
91
92       MhfFileUtils.unzip( src, testdir_ );
93
94       f = new File( testdir_, "test.txt" );
95       assertTrue( f.exists() );
96       assertTrue( f.isFile() );
97
98       f = new File( testdir_, "subdir" );
99       assertTrue( f.exists() );
100       assertTrue( f.isDirectory() );
101
102       f = new File( testdir_, "subdir/test2.txt" );
103       assertTrue( f.exists() );
104       assertTrue( f.isFile() );
105     }
106     catch ( Exception JavaDoc e ) {
107       e.printStackTrace();
108       fail();
109     }
110   }
111 }
112
Popular Tags