KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > TestCactusTask


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;
21
22 import org.apache.tools.ant.BuildException;
23
24 /**
25  * Unit tests for {@link CactusTask}.
26  *
27  * @version $Id: TestCactusTask.java,v 1.14 2004/02/29 10:21:34 vmassol Exp $
28  */

29 public final class TestCactusTask extends AntTestCase
30 {
31
32     // Constructors ------------------------------------------------------------
33

34     /**
35      * @see AntTestCase#AntTestCase
36      */

37     public TestCactusTask()
38     {
39         super("org/apache/cactus/integration/ant/test-cactus.xml");
40     }
41
42     // TestCase Implementation -------------------------------------------------
43

44     /**
45      * @see junit.framework.TestCase#setUp()
46      */

47     protected void setUp() throws Exception JavaDoc
48     {
49         super.setUp();
50
51         getProject().addTaskDefinition("cactus", CactusTask.class);
52     }
53
54     // Test Methods ------------------------------------------------------------
55

56     /**
57      * Verifies that the task throws an exception when the warfile attribute
58      * has not been set.
59      *
60      * @throws Exception If an unexpected error occurs
61      */

62     public void testNeitherWarFileNorEarFileSet() throws Exception JavaDoc
63     {
64         try
65         {
66             executeTestTarget();
67             fail("Expected BuildException");
68         }
69         catch (BuildException expected)
70         {
71             assertEquals("You must specify either the [warfile] or the "
72                 + "[earfile] attribute", expected.getMessage());
73         }
74     }
75
76     /**
77      * Verifies that the task throws an exception when the warfile attribute
78      * is set to a non-existing file.
79      *
80      * @throws Exception If an unexpected error occurs
81      */

82     public void testWarFileNotExisting() throws Exception JavaDoc
83     {
84         try
85         {
86             executeTestTarget();
87             fail("Expected BuildException");
88         }
89         catch (BuildException expected)
90         {
91             assertTrue(true);
92         }
93     }
94
95     /**
96      * Verifies that the task throws an exception when the warfile attribute
97      * is set to a web-app archive that has not been cactified.
98      *
99      * @throws Exception If an unexpected error occurs
100      */

101     public void testWarFileNotCactified() throws Exception JavaDoc
102     {
103         try
104         {
105             executeTestTarget();
106             fail("Expected BuildException");
107         }
108         catch (BuildException expected)
109         {
110             assertEquals("The WAR has not been cactified",
111                 expected.getMessage());
112         }
113     }
114
115     /**
116      * Verifies that the task does nothing if it is given a cactified web
117      * application, but neither tests nor containers.
118      *
119      * @throws Exception If an unexpected error occurs
120      */

121     public void testWarFileCactified() throws Exception JavaDoc
122     {
123         executeTestTarget();
124     }
125
126     /**
127      * Verifies that the task throws an exception when the earfile attribute
128      * is set to an empty enterprise application archive.
129      *
130      * @throws Exception If an unexpected error occurs
131      */

132     public void testEarFileEmpty() throws Exception JavaDoc
133     {
134         try
135         {
136             executeTestTarget();
137             fail("Expected BuildException");
138         }
139         catch (BuildException expected)
140         {
141             assertTrue(true);
142         }
143     }
144
145     /**
146      * Verifies that the task throws an exception when the earfile attribute
147      * is set to an enterprise application archive that doesn't contain a web
148      * module with the definition of the test redirectors.
149      *
150      * @throws Exception If an unexpected error occurs
151      */

152     public void testEarFileNotCactified() throws Exception JavaDoc
153     {
154         try
155         {
156             executeTestTarget();
157             fail("Expected BuildException");
158         }
159         catch (BuildException expected)
160         {
161             assertTrue(true);
162         }
163     }
164
165     /**
166      * Verifies that the task does nothing if it is given a cactified enterprise
167      * application, but neither tests nor containers.
168      *
169      * @throws Exception If an unexpected error occurs
170      */

171     public void testEarFileCactified() throws Exception JavaDoc
172     {
173         executeTestTarget();
174     }
175
176 }
177
Popular Tags