1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.comic; |
17 | |
18 | import java.io.File; |
19 | import java.io.IOException; |
20 | |
21 | import junit.framework.TestCase; |
22 | import net.sf.jomic.tools.FileTools; |
23 | import net.sf.jomic.tools.TestTools; |
24 | |
25 | /** |
26 | * TestCase for CreateZipArchiveTask. |
27 | * |
28 | * @author Thomas Aglassinger |
29 | */ |
30 | public class CreateZipArchiveTaskTest extends TestCase |
31 | { |
32 | public void testCreateZipArchiveTask() |
33 | throws IOException { |
34 | TestTools testTools = TestTools.instance(); |
35 | FileTools fileTools = FileTools.instance(); |
36 | String targetZipName = testTools.getTestFileName( |
37 | CreateZipArchiveTaskTest.class, "testCreateZipArchiveTask", null, "zip"); |
38 | File targetZipFile = testTools.getTestOutputFile(targetZipName); |
39 | String sourceBaseDirName = testTools.getTestFileName( |
40 | CreateZipArchiveTaskTest.class, "testCreateZipArchiveTask", null, null); |
41 | File sourceBaseDir = testTools.getTestInputFile(sourceBaseDirName); |
42 | File sourceBaseSubDir = new File(sourceBaseDir, "subDir"); |
43 | File testImageFile = testTools.getTestImageFile(); |
44 | String testImageName = testImageFile.getName(); |
45 | File imageInRootDirFile = new File(sourceBaseDir, testImageName); |
46 | File imageInSubDirFile = new File(sourceBaseSubDir, testImageName); |
47 | |
48 | fileTools.mkdirs(sourceBaseSubDir); |
49 | fileTools.copyFile(testImageFile, imageInRootDirFile); |
50 | fileTools.copyFile(testImageFile, imageInSubDirFile); |
51 | |
52 | String[] sourceFileNames = new String[]{ |
53 | fileTools.getRelativePath(sourceBaseDir, imageInRootDirFile), |
54 | fileTools.getRelativePath(sourceBaseDir, imageInSubDirFile) |
55 | }; |
56 | CreateZipArchiveTask zipTask = new CreateZipArchiveTask(targetZipFile, sourceBaseDir, sourceFileNames); |
57 | |
58 | targetZipFile.delete(); |
59 | assertFalse(targetZipFile.exists()); |
60 | zipTask.start(); |
61 | assertTrue(targetZipFile.exists()); |
62 | } |
63 | } |