KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > webapp > TestWarArchive


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.deployment.webapp;
21
22 import java.io.File JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  * Unit tests for {@link WarArchive}.
28  *
29  * @version $Id: TestWarArchive.java,v 1.1 2004/05/31 20:05:21 vmassol Exp $
30  */

31 public final class TestWarArchive extends TestCase
32 {
33
34     // Test Methods ------------------------------------------------------------
35

36     /**
37      * Verifies that the method <code>containsClass()</code> returns
38      * <code>true</code> if the WAR contains the requested class in
39      * <code>WEB-INF/classes</code>.
40      *
41      * @throws Exception If an unexpected error occurs
42      */

43     public void testContainsClassInWebinfClasses() throws Exception JavaDoc
44     {
45         WarArchive war = new DefaultWarArchive(getTestInput(
46             "org/apache/cactus/integration/ant/deployment/containsclass.war"));
47         assertTrue(war.containsClass("test.Test"));
48     }
49
50     /**
51      * Verifies that the method <code>containsClass()</code> returns
52      * <code>true</code> if the WAR contains the requested class in a JAR in
53      * <code>WEB-INF/lib</code>.
54      *
55      * @throws Exception If an unexpected error occurs
56      */

57     public void testContainsClassInWebinfLib() throws Exception JavaDoc
58     {
59         WarArchive war = new DefaultWarArchive(getTestInput(
60             "org/apache/cactus/integration/ant/deployment/"
61             + "containsclasslib.war"));
62         assertTrue(war.containsClass("test.Test"));
63     }
64
65     /**
66      * Verifies that the method <code>containsClass()</code> returns
67      * <code>false</code> if the WAR does not contain such a class.
68      *
69      * @throws Exception If an unexpected error occurs
70      */

71     public void testContainsClassEmpty() throws Exception JavaDoc
72     {
73         WarArchive war = new DefaultWarArchive(getTestInput(
74             "org/apache/cactus/integration/ant/deployment/empty.war"));
75         assertTrue(!war.containsClass("test.Test"));
76     }
77
78     // Private Methods ---------------------------------------------------------
79

80     /**
81      * Returns a file from the test inputs directory, which is determined by the
82      * system property <code>testinput.dir</code>.
83      *
84      * @param theFileName The name of the file relative to the test input
85      * directory
86      * @return The file from the test input directory
87      */

88     private File JavaDoc getTestInput(String JavaDoc theFileName)
89     {
90         String JavaDoc testInputDirProperty = System.getProperty("testinput.dir");
91         assertTrue("The system property 'testinput.dir' must be set",
92             testInputDirProperty != null);
93         File JavaDoc testInputDir = new File JavaDoc(testInputDirProperty);
94         assertTrue("The system property 'testinput.dir' must point to an "
95             + "existing directory", testInputDir.isDirectory());
96         File JavaDoc testInputFile = new File JavaDoc(testInputDir, theFileName);
97         assertTrue("The test input " + theFileName + " does not exist",
98             testInputFile.exists());
99         return testInputFile;
100     }
101
102 }
103
Popular Tags