1 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 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 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 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 e ) { 107 e.printStackTrace(); 108 fail(); 109 } 110 } 111 } 112 | Popular Tags |