001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.deployment.webapp;
021:
022: import java.io.File;
023:
024: import junit.framework.TestCase;
025:
026: /**
027: * Unit tests for {@link WarArchive}.
028: *
029: * @version $Id: TestWarArchive.java 239003 2004-05-31 20:05:27Z vmassol $
030: */
031: public final class TestWarArchive extends TestCase {
032:
033: // Test Methods ------------------------------------------------------------
034:
035: /**
036: * Verifies that the method <code>containsClass()</code> returns
037: * <code>true</code> if the WAR contains the requested class in
038: * <code>WEB-INF/classes</code>.
039: *
040: * @throws Exception If an unexpected error occurs
041: */
042: public void testContainsClassInWebinfClasses() throws Exception {
043: WarArchive war = new DefaultWarArchive(
044: getTestInput("org/apache/cactus/integration/ant/deployment/containsclass.war"));
045: assertTrue(war.containsClass("test.Test"));
046: }
047:
048: /**
049: * Verifies that the method <code>containsClass()</code> returns
050: * <code>true</code> if the WAR contains the requested class in a JAR in
051: * <code>WEB-INF/lib</code>.
052: *
053: * @throws Exception If an unexpected error occurs
054: */
055: public void testContainsClassInWebinfLib() throws Exception {
056: WarArchive war = new DefaultWarArchive(
057: getTestInput("org/apache/cactus/integration/ant/deployment/"
058: + "containsclasslib.war"));
059: assertTrue(war.containsClass("test.Test"));
060: }
061:
062: /**
063: * Verifies that the method <code>containsClass()</code> returns
064: * <code>false</code> if the WAR does not contain such a class.
065: *
066: * @throws Exception If an unexpected error occurs
067: */
068: public void testContainsClassEmpty() throws Exception {
069: WarArchive war = new DefaultWarArchive(
070: getTestInput("org/apache/cactus/integration/ant/deployment/empty.war"));
071: assertTrue(!war.containsClass("test.Test"));
072: }
073:
074: // Private Methods ---------------------------------------------------------
075:
076: /**
077: * Returns a file from the test inputs directory, which is determined by the
078: * system property <code>testinput.dir</code>.
079: *
080: * @param theFileName The name of the file relative to the test input
081: * directory
082: * @return The file from the test input directory
083: */
084: private File getTestInput(String theFileName) {
085: String testInputDirProperty = System
086: .getProperty("testinput.dir");
087: assertTrue("The system property 'testinput.dir' must be set",
088: testInputDirProperty != null);
089: File testInputDir = new File(testInputDirProperty);
090: assertTrue(
091: "The system property 'testinput.dir' must point to an "
092: + "existing directory", testInputDir
093: .isDirectory());
094: File testInputFile = new File(testInputDir, theFileName);
095: assertTrue("The test input " + theFileName + " does not exist",
096: testInputFile.exists());
097: return testInputFile;
098: }
099:
100: }
|