01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.geronimo.farm.deployment;
21:
22: import java.io.BufferedReader;
23: import java.io.File;
24: import java.io.FileInputStream;
25: import java.io.FileNotFoundException;
26: import java.io.IOException;
27: import java.io.InputStream;
28: import java.io.InputStreamReader;
29:
30: import org.apache.geronimo.testsupport.TestSupport;
31:
32: /**
33: *
34: * @version $Rev:$ $Date:$
35: */
36: public class ZipDirectoryPackagerTest extends TestSupport {
37:
38: public void testPackAndUnpack() throws Exception {
39: ZipDirectoryPackager packager = new ZipDirectoryPackager();
40: File packedDir = packager.pack(new File(BASEDIR,
41: "src/test/resources/folderToZip"));
42:
43: File unpackedDir = packager.unpack(packedDir);
44:
45: assertFile(unpackedDir, "folder1/file1");
46: assertFile(unpackedDir, "folder1/file2");
47: assertFile(unpackedDir, "folder2/file1");
48: }
49:
50: private void assertFile(File unpackedDir, String fileName)
51: throws FileNotFoundException, IOException {
52: File file = new File(unpackedDir, fileName);
53: assertTrue(file.exists());
54:
55: InputStream in = new FileInputStream(file);
56: BufferedReader reader2 = new BufferedReader(
57: new InputStreamReader(in));
58: String line = reader2.readLine();
59: assertEquals(fileName, line);
60: in.close();
61: }
62:
63: }
|