KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > container > resin > TestResin3xTask


1 /*
2  * ========================================================================
3  *
4  * Copyright 2004 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.container.resin;
21
22 import org.apache.cactus.integration.ant.AntTestCase;
23 import org.apache.tools.ant.BuildException;
24
25 /**
26  * Unit tests for {@link Resin3xTask}.
27  *
28  * @version $Id: TestResin3xTask.java,v 1.2 2004/08/15 15:02:27 vmassol Exp $
29  */

30 public final class TestResin3xTask extends AntTestCase
31 {
32     /**
33      * True if Resin 3.x is installed.
34      */

35     private boolean isResinInstalled;
36     
37     // Constructors ------------------------------------------------------------
38

39     /**
40      * @see AntTestCase#AntTestCase
41      */

42     public TestResin3xTask()
43     {
44         super("org/apache/cactus/integration/ant/container/resin/"
45             + "test-resin3x.xml");
46     }
47     
48     // TestCase Implementation -------------------------------------------------
49

50     /**
51      * @see junit.framework.TestCase#setUp()
52      */

53     protected void setUp() throws Exception JavaDoc
54     {
55         super.setUp();
56
57         getProject().addTaskDefinition("resin3x", Resin3xTask.class);
58         
59         // If cactus.home.resin3x system property has been defined, pass
60
// it to the Ant project as a property
61
String JavaDoc resin3xHome = System.getProperty("cactus.home.resin3x");
62         if (resin3xHome != null)
63         {
64             getProject().setProperty("cactus.home.resin3x", resin3xHome);
65             this.isResinInstalled = true;
66         }
67
68         // Allow build script to use a port different than the default (8080)
69
// for testing. Useful if a server is already started on that port.
70
getProject().setProperty("cactus.port",
71             System.getProperty("cactus.port", "8080"));
72
73         // Pass clover setting
74
String JavaDoc cloverEnabled = System.getProperty("clover.enable");
75         if (cloverEnabled != null)
76         {
77             getProject().setProperty("clover.enable", cloverEnabled);
78             getProject().setProperty("clover.jar",
79                 System.getProperty("clover.jar"));
80         }
81     }
82
83     // Test Methods ------------------------------------------------------------
84

85     /**
86      * Verifies that the task throws an exception when the action attribute
87      * has not been set.
88      */

89     public void testExecuteWhenNoDirSpecified()
90     {
91         try
92         {
93             executeTestTarget();
94             fail("Expected BuildException");
95         }
96         catch (BuildException expected)
97         {
98             assertEquals("You must specify the mandatory [dir] attribute",
99                 expected.getMessage());
100         }
101     }
102     
103     /**
104      * Verifies that the task throws an exception when the action attribute
105      * has not been set.
106      */

107     public void testExecuteWhenNoActionSpecified()
108     {
109         if (this.isResinInstalled)
110         {
111             try
112             {
113                 executeTestTarget();
114                 fail("Expected BuildException");
115             }
116             catch (BuildException expected)
117             {
118                 assertEquals("You must specify an [action] attribute",
119                     expected.getMessage());
120             }
121         }
122     }
123
124     /**
125      * Verifies that the task throws an exception when the action attribute
126      * has an invalid value.
127      */

128     public void testExecuteWhenWrongActionSpecified()
129     {
130         if (this.isResinInstalled)
131         {
132             try
133             {
134                 executeTestTarget();
135                 fail("Expected BuildException");
136             }
137             catch (BuildException expected)
138             {
139                 assertEquals("Valid actions are: [start] and [stop]",
140                     expected.getMessage());
141             }
142         }
143     }
144
145     /**
146      * Verifies that the task can start and stop a Resin 3.x instance
147      * when there is nothing to deploy and when we don't use a test URL
148      * to wait for the container to be started.
149      */

150     public void testExecuteStartWithNoDeployableAndNoTestURL()
151     {
152         if (this.isResinInstalled)
153         {
154             executeTestTarget();
155         }
156     }
157
158     /**
159      * Verifies that the task can start and stop a Resin 3.x instance
160      * when there is a webapp to deploy and when we don't use a test URL
161      * to wait for the container to be started.
162      */

163     public void testExecuteStartWithWarDeployableAndNoTestURL()
164     {
165         if (this.isResinInstalled)
166         {
167             executeTestTarget();
168         }
169     }
170     
171     /**
172      * Verifies that the task can start and stop a Resin 3.x instance
173      * when there is nothing to deploy and when we use a test URL
174      * to wait for the container to be started.
175      */

176     public void testExecuteStartWithNoDeployableAndWithTestURL()
177     {
178         if (this.isResinInstalled)
179         {
180             executeTestTarget();
181         }
182     }
183 }
184
Popular Tags