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 RunServerTestsTask}.
026: *
027: * @version $Id: TestRunServerTestsTask.java 238812 2004-02-29 10:21:34Z vmassol $
028: */
029: public final class TestRunServerTestsTask extends AntTestCase {
030:
031: // Constructors ------------------------------------------------------------
032:
033: /**
034: * @see AntTestCase#AntTestCase
035: */
036: public TestRunServerTestsTask() {
037: super (
038: "org/apache/cactus/integration/ant/test-runservertests.xml");
039: }
040:
041: // TestCase Implementation -------------------------------------------------
042:
043: /**
044: * @see junit.framework.TestCase#setUp()
045: */
046: protected void setUp() throws Exception {
047: super .setUp();
048:
049: getProject().addTaskDefinition("runservertests",
050: RunServerTestsTask.class);
051: }
052:
053: // Test Methods ------------------------------------------------------------
054:
055: /**
056: * Verifies that a build exception is thrown if neither the
057: * <code>starttarget</code> nor a nested <code>start</code> element has been
058: * specified.
059: *
060: * @throws Exception If an unexpected error occurs
061: */
062: public void testStartNotSet() throws Exception {
063: try {
064: executeTestTarget();
065: fail("Expected BuildException");
066: } catch (BuildException expected) {
067: assertEquals(
068: "You must specify either a nested [start] element or "
069: + "the [starttarget] attribute", expected
070: .getMessage());
071: }
072: }
073:
074: /**
075: * Verifies that the <code>starttarget</code> is run before the timeout is
076: * exceeded.
077: *
078: * @throws Exception If an unexpected error occurs
079: */
080: public void testStartTimeout() throws Exception {
081: try {
082: executeTestTarget();
083: fail("Expected BuildException");
084: } catch (BuildException expected) {
085: assertEquals(
086: "Failed to start the container after more than [0] "
087: + "ms.", expected.getMessage());
088: }
089: assertTargetExecuted("startDummy");
090: }
091:
092: /**
093: * Verifies that a build exception is thrown if neither the
094: * <code>stoptarget</code> nor a nested <code>stop</code> element has been
095: * specified.
096: *
097: * @throws Exception If an unexpected error occurs
098: */
099: public void testStopNotSet() throws Exception {
100: try {
101: executeTestTarget();
102: fail("Expected BuildException");
103: } catch (BuildException expected) {
104: assertEquals(
105: "You must specify either a nested [stop] element or "
106: + "the [stoptarget] attribute", expected
107: .getMessage());
108: }
109: }
110:
111: /**
112: * Verifies that a build exception is thrown if neither the
113: * <code>testtarget</code> nor a nested <code>test</code> element has been
114: * specified.
115: *
116: * @throws Exception If an unexpected error occurs
117: */
118: public void testTestNotSet() throws Exception {
119: try {
120: executeTestTarget();
121: fail("Expected BuildException");
122: } catch (BuildException expected) {
123: assertEquals(
124: "You must specify either a nested [test] element or "
125: + "the [testtarget] attribute", expected
126: .getMessage());
127: }
128: }
129:
130: /**
131: * Verifies that a build exception is thrown if the <code>testurl</code>
132: * attribute is not set.
133: *
134: * @throws Exception If an unexpected error occurs
135: */
136: public void testTestUrlNotSet() throws Exception {
137: try {
138: executeTestTarget();
139: fail("Expected BuildException");
140: } catch (BuildException expected) {
141: assertEquals("The [testurl] attribute must be specified",
142: expected.getMessage());
143: }
144: }
145:
146: /**
147: * Verifies that a build exception is thrown if the <code>testurl</code>
148: * attribute is set to a non-HTTP URL.
149: *
150: * @throws Exception If an unexpected error occurs
151: */
152: public void testNonHttpTestUrl() throws Exception {
153: try {
154: executeTestTarget();
155: fail("Expected BuildException");
156: } catch (IllegalArgumentException expected) {
157: assertEquals("Not a HTTP URL", expected.getMessage());
158: }
159: }
160:
161: }
|