1 22 package org.objectweb.petals.util; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.URISyntaxException ; 27 import java.util.zip.ZipFile ; 28 29 import junit.framework.TestCase; 30 31 import org.objectweb.petals.PetalsException; 32 33 38 public class ZipUtilTest extends TestCase { 39 40 43 private String baseDir; 44 45 48 public void setUp() { 49 baseDir = this.getClass().getResource(".").toString(); 50 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 51 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 52 } 53 54 60 public void testExplodeZip() throws PetalsException, IOException { 61 File extractedDir = new File (baseDir + "src" + File.separator 62 + "test-data" + File.separator + "extracted"); 63 extractedDir.delete(); 64 extractedDir.mkdir(); 65 ZipUtil.explodeIntoDirectory(new ZipFile (baseDir + "src" 66 + File.separator + "test-data" + File.separator 67 + "test-ziputil.zip"), extractedDir); 68 if (extractedDir.listFiles().length != 3) { 69 fail(); 70 } 71 } 72 73 79 public void testExplodeZip1() { 80 File extractedDir = new File (baseDir + "src" + File.separator 81 + "test-data" + File.separator + "extracted"); 82 try { 83 ZipUtil.explodeIntoDirectory(null, extractedDir); 84 fail(); 85 } catch (Exception e) { 86 87 } 88 } 89 90 96 public void testExplodeZip2() { 97 try { 98 ZipUtil.explodeIntoDirectory(new ZipFile (baseDir + "src" 99 + File.separator + "test-data" + File.separator 100 + "test-ziputil.zip"), null); 101 fail(); 102 } catch (Exception e) { 103 104 } 105 } 106 107 112 public void testGetEntryAsTemp() throws IOException { 113 assertNotNull(ZipUtil.getEntryAsTemp(new ZipFile (baseDir + "src" 114 + File.separator + "test-data" + File.separator 115 + "test-ziputil.zip"), "META-INF/jbi.xml")); 116 } 117 118 123 public void testGetEntryAsTemp1() throws IOException { 124 File entryFile = ZipUtil.getEntryAsTemp(new ZipFile (baseDir + "src" 125 + File.separator + "test-data" + File.separator 126 + "test-ziputil.zip"), "META-INF" + File.separator + "manifest.mf"); 127 if (entryFile != null) { 128 fail(); 129 } 130 } 131 132 136 public void testGetEntryAsTemp2() { 137 try { 138 ZipUtil.getEntryAsTemp(null, "META-INF" + File.separator 139 + "manifest.mf"); 140 fail(); 141 } catch (Exception e) { 142 143 } 144 } 145 146 150 public void testGetEntryAsTemp3() { 151 try { 152 ZipUtil.getEntryAsTemp(new ZipFile (baseDir + "src" + File.separator 153 + "test-data" + File.separator + "test-ziputil.zip"), null); 154 fail(); 155 } catch (Exception e) { 156 } 157 } 158 159 163 public void testGetEntryAsTemp4() { 164 try { 165 ZipUtil.getEntryAsTemp(new ZipFile (baseDir + "src" + File.separator 166 + "test-data" + File.separator + "test-ziputil.zip"), ""); 167 fail(); 168 } catch (Exception e) { 169 } 170 } 171 172 177 public void testHasEntry() throws IOException { 178 assertTrue(ZipUtil.hasEntry(new ZipFile (baseDir + "src" 179 + File.separator + "test-data" + File.separator 180 + "test-ziputil.zip"), "META-INF/jbi.xml")); 181 } 182 183 188 public void testHasEntry1() throws IOException { 189 assertFalse(ZipUtil.hasEntry(new ZipFile (baseDir + "src" 190 + File.separator + "test-data" + File.separator 191 + "test-ziputil.zip"), "test.xml")); 192 } 193 194 200 public void testOpenZipFile() throws PetalsException, URISyntaxException { 201 assertNotNull(ZipUtil.openZipFile(new File (baseDir + "src" 202 + File.separator + "test-data" + File.separator 203 + "test-ziputil.zip").toURI())); 204 } 205 206 } 207 | Popular Tags |