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;
021:
022: import org.apache.tools.ant.BuildException;
023:
024: /**
025: * Unit tests for {@link CactusTask}.
026: *
027: * @version $Id: TestCactusTask.java 238812 2004-02-29 10:21:34Z vmassol $
028: */
029: public final class TestCactusTask extends AntTestCase {
030:
031: // Constructors ------------------------------------------------------------
032:
033: /**
034: * @see AntTestCase#AntTestCase
035: */
036: public TestCactusTask() {
037: super ("org/apache/cactus/integration/ant/test-cactus.xml");
038: }
039:
040: // TestCase Implementation -------------------------------------------------
041:
042: /**
043: * @see junit.framework.TestCase#setUp()
044: */
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: getProject().addTaskDefinition("cactus", CactusTask.class);
049: }
050:
051: // Test Methods ------------------------------------------------------------
052:
053: /**
054: * Verifies that the task throws an exception when the warfile attribute
055: * has not been set.
056: *
057: * @throws Exception If an unexpected error occurs
058: */
059: public void testNeitherWarFileNorEarFileSet() throws Exception {
060: try {
061: executeTestTarget();
062: fail("Expected BuildException");
063: } catch (BuildException expected) {
064: assertEquals(
065: "You must specify either the [warfile] or the "
066: + "[earfile] attribute", expected
067: .getMessage());
068: }
069: }
070:
071: /**
072: * Verifies that the task throws an exception when the warfile attribute
073: * is set to a non-existing file.
074: *
075: * @throws Exception If an unexpected error occurs
076: */
077: public void testWarFileNotExisting() throws Exception {
078: try {
079: executeTestTarget();
080: fail("Expected BuildException");
081: } catch (BuildException expected) {
082: assertTrue(true);
083: }
084: }
085:
086: /**
087: * Verifies that the task throws an exception when the warfile attribute
088: * is set to a web-app archive that has not been cactified.
089: *
090: * @throws Exception If an unexpected error occurs
091: */
092: public void testWarFileNotCactified() throws Exception {
093: try {
094: executeTestTarget();
095: fail("Expected BuildException");
096: } catch (BuildException expected) {
097: assertEquals("The WAR has not been cactified", expected
098: .getMessage());
099: }
100: }
101:
102: /**
103: * Verifies that the task does nothing if it is given a cactified web
104: * application, but neither tests nor containers.
105: *
106: * @throws Exception If an unexpected error occurs
107: */
108: public void testWarFileCactified() throws Exception {
109: executeTestTarget();
110: }
111:
112: /**
113: * Verifies that the task throws an exception when the earfile attribute
114: * is set to an empty enterprise application archive.
115: *
116: * @throws Exception If an unexpected error occurs
117: */
118: public void testEarFileEmpty() throws Exception {
119: try {
120: executeTestTarget();
121: fail("Expected BuildException");
122: } catch (BuildException expected) {
123: assertTrue(true);
124: }
125: }
126:
127: /**
128: * Verifies that the task throws an exception when the earfile attribute
129: * is set to an enterprise application archive that doesn't contain a web
130: * module with the definition of the test redirectors.
131: *
132: * @throws Exception If an unexpected error occurs
133: */
134: public void testEarFileNotCactified() throws Exception {
135: try {
136: executeTestTarget();
137: fail("Expected BuildException");
138: } catch (BuildException expected) {
139: assertTrue(true);
140: }
141: }
142:
143: /**
144: * Verifies that the task does nothing if it is given a cactified enterprise
145: * application, but neither tests nor containers.
146: *
147: * @throws Exception If an unexpected error occurs
148: */
149: public void testEarFileCactified() throws Exception {
150: executeTestTarget();
151: }
152:
153: }
|