001: /*
002: * ========================================================================
003: *
004: * Copyright 2004 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.container.resin;
021:
022: import org.apache.cactus.integration.ant.AntTestCase;
023: import org.apache.tools.ant.BuildException;
024:
025: /**
026: * Unit tests for {@link Resin3xTask}.
027: *
028: * @version $Id: TestResin3xTask.java 239035 2004-08-15 15:02:27Z vmassol $
029: */
030: public final class TestResin3xTask extends AntTestCase {
031: /**
032: * True if Resin 3.x is installed.
033: */
034: private boolean isResinInstalled;
035:
036: // Constructors ------------------------------------------------------------
037:
038: /**
039: * @see AntTestCase#AntTestCase
040: */
041: public TestResin3xTask() {
042: super ("org/apache/cactus/integration/ant/container/resin/"
043: + "test-resin3x.xml");
044: }
045:
046: // TestCase Implementation -------------------------------------------------
047:
048: /**
049: * @see junit.framework.TestCase#setUp()
050: */
051: protected void setUp() throws Exception {
052: super .setUp();
053:
054: getProject().addTaskDefinition("resin3x", Resin3xTask.class);
055:
056: // If cactus.home.resin3x system property has been defined, pass
057: // it to the Ant project as a property
058: String resin3xHome = System.getProperty("cactus.home.resin3x");
059: if (resin3xHome != null) {
060: getProject()
061: .setProperty("cactus.home.resin3x", resin3xHome);
062: this .isResinInstalled = true;
063: }
064:
065: // Allow build script to use a port different than the default (8080)
066: // for testing. Useful if a server is already started on that port.
067: getProject().setProperty("cactus.port",
068: System.getProperty("cactus.port", "8080"));
069:
070: // Pass clover setting
071: String cloverEnabled = System.getProperty("clover.enable");
072: if (cloverEnabled != null) {
073: getProject().setProperty("clover.enable", cloverEnabled);
074: getProject().setProperty("clover.jar",
075: System.getProperty("clover.jar"));
076: }
077: }
078:
079: // Test Methods ------------------------------------------------------------
080:
081: /**
082: * Verifies that the task throws an exception when the action attribute
083: * has not been set.
084: */
085: public void testExecuteWhenNoDirSpecified() {
086: try {
087: executeTestTarget();
088: fail("Expected BuildException");
089: } catch (BuildException expected) {
090: assertEquals(
091: "You must specify the mandatory [dir] attribute",
092: expected.getMessage());
093: }
094: }
095:
096: /**
097: * Verifies that the task throws an exception when the action attribute
098: * has not been set.
099: */
100: public void testExecuteWhenNoActionSpecified() {
101: if (this .isResinInstalled) {
102: try {
103: executeTestTarget();
104: fail("Expected BuildException");
105: } catch (BuildException expected) {
106: assertEquals("You must specify an [action] attribute",
107: expected.getMessage());
108: }
109: }
110: }
111:
112: /**
113: * Verifies that the task throws an exception when the action attribute
114: * has an invalid value.
115: */
116: public void testExecuteWhenWrongActionSpecified() {
117: if (this .isResinInstalled) {
118: try {
119: executeTestTarget();
120: fail("Expected BuildException");
121: } catch (BuildException expected) {
122: assertEquals("Valid actions are: [start] and [stop]",
123: expected.getMessage());
124: }
125: }
126: }
127:
128: /**
129: * Verifies that the task can start and stop a Resin 3.x instance
130: * when there is nothing to deploy and when we don't use a test URL
131: * to wait for the container to be started.
132: */
133: public void testExecuteStartWithNoDeployableAndNoTestURL() {
134: if (this .isResinInstalled) {
135: executeTestTarget();
136: }
137: }
138:
139: /**
140: * Verifies that the task can start and stop a Resin 3.x instance
141: * when there is a webapp to deploy and when we don't use a test URL
142: * to wait for the container to be started.
143: */
144: public void testExecuteStartWithWarDeployableAndNoTestURL() {
145: if (this .isResinInstalled) {
146: executeTestTarget();
147: }
148: }
149:
150: /**
151: * Verifies that the task can start and stop a Resin 3.x instance
152: * when there is nothing to deploy and when we use a test URL
153: * to wait for the container to be started.
154: */
155: public void testExecuteStartWithNoDeployableAndWithTestURL() {
156: if (this.isResinInstalled) {
157: executeTestTarget();
158: }
159: }
160: }
|