KickJava   Java API By Example, From Geeks To Geeks.

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


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 RunServerTestsTask}.
26  *
27  * @version $Id: TestRunServerTestsTask.java,v 1.6 2004/02/29 10:21:34 vmassol Exp $
28  */

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

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

37     public TestRunServerTestsTask()
38     {
39         super("org/apache/cactus/integration/ant/test-runservertests.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("runservertests",
52             RunServerTestsTask.class);
53     }
54
55     // Test Methods ------------------------------------------------------------
56

57     /**
58      * Verifies that a build exception is thrown if neither the
59      * <code>starttarget</code> nor a nested <code>start</code> element has been
60      * specified.
61      *
62      * @throws Exception If an unexpected error occurs
63      */

64     public void testStartNotSet() throws Exception JavaDoc
65     {
66         try
67         {
68             executeTestTarget();
69             fail("Expected BuildException");
70         }
71         catch (BuildException expected)
72         {
73             assertEquals("You must specify either a nested [start] element or "
74                 + "the [starttarget] attribute", expected.getMessage());
75         }
76     }
77
78     /**
79      * Verifies that the <code>starttarget</code> is run before the timeout is
80      * exceeded.
81      *
82      * @throws Exception If an unexpected error occurs
83      */

84     public void testStartTimeout() throws Exception JavaDoc
85     {
86         try
87         {
88             executeTestTarget();
89             fail("Expected BuildException");
90         }
91         catch (BuildException expected)
92         {
93             assertEquals("Failed to start the container after more than [0] "
94                 + "ms.", expected.getMessage());
95         }
96         assertTargetExecuted("startDummy");
97     }
98
99     /**
100      * Verifies that a build exception is thrown if neither the
101      * <code>stoptarget</code> nor a nested <code>stop</code> element has been
102      * specified.
103      *
104      * @throws Exception If an unexpected error occurs
105      */

106     public void testStopNotSet() throws Exception JavaDoc
107     {
108         try
109         {
110             executeTestTarget();
111             fail("Expected BuildException");
112         }
113         catch (BuildException expected)
114         {
115             assertEquals("You must specify either a nested [stop] element or "
116                 + "the [stoptarget] attribute", expected.getMessage());
117         }
118     }
119
120     /**
121      * Verifies that a build exception is thrown if neither the
122      * <code>testtarget</code> nor a nested <code>test</code> element has been
123      * specified.
124      *
125      * @throws Exception If an unexpected error occurs
126      */

127     public void testTestNotSet() throws Exception JavaDoc
128     {
129         try
130         {
131             executeTestTarget();
132             fail("Expected BuildException");
133         }
134         catch (BuildException expected)
135         {
136             assertEquals("You must specify either a nested [test] element or "
137                 + "the [testtarget] attribute", expected.getMessage());
138         }
139     }
140
141     /**
142      * Verifies that a build exception is thrown if the <code>testurl</code>
143      * attribute is not set.
144      *
145      * @throws Exception If an unexpected error occurs
146      */

147     public void testTestUrlNotSet() throws Exception JavaDoc
148     {
149         try
150         {
151             executeTestTarget();
152             fail("Expected BuildException");
153         }
154         catch (BuildException expected)
155         {
156             assertEquals("The [testurl] attribute must be specified",
157                 expected.getMessage());
158         }
159     }
160
161     /**
162      * Verifies that a build exception is thrown if the <code>testurl</code>
163      * attribute is set to a non-HTTP URL.
164      *
165      * @throws Exception If an unexpected error occurs
166      */

167     public void testNonHttpTestUrl() throws Exception JavaDoc
168     {
169         try
170         {
171             executeTestTarget();
172             fail("Expected BuildException");
173         }
174         catch (IllegalArgumentException JavaDoc expected)
175         {
176             assertEquals("Not a HTTP URL", expected.getMessage());
177         }
178     }
179
180 }
181
Popular Tags