01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.taskdefs;
20:
21: import java.io.File;
22: import java.io.IOException;
23: import java.util.ArrayList;
24: import org.apache.tools.ant.BuildFileTest;
25:
26: /**
27: */
28: public class ProtectedJarMethodsTest extends BuildFileTest {
29:
30: private static String tempJar = "tmp.jar";
31:
32: public ProtectedJarMethodsTest(String name) {
33: super (name);
34: }
35:
36: public void setUp() {
37: configureProject("src/etc/testcases/taskdefs/jar.xml");
38: }
39:
40: public void tearDown() {
41: executeTarget("cleanup");
42: }
43:
44: public void testGrabFilesAndDirs() throws IOException {
45: executeTarget("testIndexTests");
46: String archive = getProject().resolveFile(tempJar)
47: .getAbsolutePath();
48: ArrayList dirs = new ArrayList();
49: ArrayList files = new ArrayList();
50: String[] expectedDirs = new String[] { "sub/", };
51: String[] expectedFiles = new String[] { "foo", };
52: Jar.grabFilesAndDirs(archive, dirs, files);
53: assertEquals(expectedDirs.length, dirs.size());
54: for (int i = 0; i < expectedDirs.length; i++) {
55: assertTrue("Found " + expectedDirs[i], dirs
56: .contains(expectedDirs[i]));
57: }
58: assertEquals(expectedFiles.length, files.size());
59: for (int i = 0; i < expectedFiles.length; i++) {
60: assertTrue("Found " + expectedFiles[i], files
61: .contains(expectedFiles[i]));
62: }
63: }
64:
65: public void testFindJarNameNoClasspath() {
66: assertEquals("foo", Jar.findJarName("foo", null));
67: assertEquals("foo", Jar.findJarName("lib" + File.separatorChar
68: + "foo", null));
69: }
70:
71: public void testFindJarNameNoMatch() {
72: assertNull(Jar.findJarName("foo", new String[] { "bar" }));
73: }
74:
75: public void testFindJarNameSimpleMatches() {
76: assertEquals("foo", Jar.findJarName("foo",
77: new String[] { "foo" }));
78: assertEquals("lib/foo", Jar.findJarName("foo",
79: new String[] { "lib/foo" }));
80: assertEquals("foo", Jar.findJarName("bar" + File.separatorChar
81: + "foo", new String[] { "foo" }));
82: assertEquals("lib/foo", Jar.findJarName("bar"
83: + File.separatorChar + "foo",
84: new String[] { "lib/foo" }));
85: }
86:
87: public void testFindJarNameLongestMatchWins() {
88: assertEquals("lib/foo", Jar.findJarName("lib/foo",
89: new String[] { "foo", "lib/foo", "lib/bar/foo" }));
90: }
91: }
|