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.cactus.integration.ant.container.Container;
023:
024: /**
025: * Unit tests for {@link ContainerSet}.
026: *
027: * @version $Id: TestContainerSet.java 238812 2004-02-29 10:21:34Z vmassol $
028: */
029: public final class TestContainerSet extends AntTestCase {
030:
031: // Constructors ------------------------------------------------------------
032:
033: /**
034: * @see AntTestCase#AntTestCase
035: */
036: public TestContainerSet() {
037: super ("org/apache/cactus/integration/ant/test-containerset.xml");
038: }
039:
040: // TestCase Implementation -------------------------------------------------
041:
042: /**
043: * @see junit.framework.TestCase#setUp()
044: */
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: getProject().addDataTypeDefinition("containerset",
049: ContainerSet.class);
050: }
051:
052: // Test Methods ------------------------------------------------------------
053:
054: /**
055: * Verifies that a completely empty container set definition is constructed
056: * as expected.
057: *
058: * @throws Exception If an unexpected error occurs
059: */
060: public void testEmpty() throws Exception {
061: executeTestTarget();
062: ContainerSet set = (ContainerSet) getProject().getReference(
063: "test");
064: assertEquals(-1, set.getProxyPort());
065: assertEquals(-1, set.getTimeout());
066: Container[] containers = set.getContainers();
067: assertEquals(0, containers.length);
068: }
069:
070: /**
071: * Verifies that the <code>proxyport</code> attribute of a container set
072: * results in the proxy port being set as expected.
073: *
074: * @throws Exception If an unexpected error occurs
075: */
076: public void testEmptyWithProxyPort() throws Exception {
077: executeTestTarget();
078: ContainerSet set = (ContainerSet) getProject().getReference(
079: "test");
080: assertEquals(8088, set.getProxyPort());
081: assertEquals(-1, set.getTimeout());
082: Container[] containers = set.getContainers();
083: assertEquals(0, containers.length);
084: }
085:
086: /**
087: * Verifies that the <code>timeout</code> attribute of a container set
088: * results in the timeout being set as expected.
089: *
090: * @throws Exception If an unexpected error occurs
091: */
092: public void testEmptyWithTimeout() throws Exception {
093: executeTestTarget();
094: ContainerSet set = (ContainerSet) getProject().getReference(
095: "test");
096: assertEquals(-1, set.getProxyPort());
097: assertEquals(60000, set.getTimeout());
098: Container[] containers = set.getContainers();
099: assertEquals(0, containers.length);
100: }
101:
102: /**
103: * Verifies that a <em>generic</em> container can be added to an otherwise
104: * empty container, and be retrieved as expected.
105: *
106: * @throws Exception If an unexpected error occurs
107: */
108: public void testGenericContainer() throws Exception {
109: executeTestTarget();
110: ContainerSet set = (ContainerSet) getProject().getReference(
111: "test");
112: Container[] containers = set.getContainers();
113: assertEquals(1, containers.length);
114: Container container = (Container) containers[0];
115: assertEquals(8080, container.getPort());
116: }
117:
118: /**
119: * Verifies that setting the proxy port on the container set results in the
120: * port of the nested containers being set to the proxy port.
121: *
122: * @throws Exception If an unexpected error occurs
123: */
124: public void testGenericContainerWithProxyPort() throws Exception {
125: executeTestTarget();
126: ContainerSet set = (ContainerSet) getProject().getReference(
127: "test");
128: Container[] containers = set.getContainers();
129: assertEquals(1, containers.length);
130: Container container = containers[0];
131: assertEquals(8088, container.getPort());
132: }
133:
134: /**
135: * Verifies that the startup and shutdown hooks of a generic container
136: * nested in a container set definition are not invoked when defined, but
137: * when explicitly calling the container lifecycle methods.
138: *
139: * @throws Exception If an unexpected error occurs
140: */
141: public void testGenericContainerWithTasks() throws Exception {
142: executeTestTarget();
143: ContainerSet set = (ContainerSet) getProject().getReference(
144: "test");
145: Container[] containers = set.getContainers();
146:
147: // Make sure that neither the startup nor the shutdown hook have been
148: // called yet
149: assertNull("The startup hook should not have been executed",
150: getProject().getProperty("startup.executed"));
151: assertNull("The shutdown hook should not have been executed",
152: getProject().getProperty("shutdown.executed"));
153:
154: // Call the startup and shutdown hooks and assert that they have been
155: // executed
156: Container container = containers[0];
157: container.startUp();
158: assertEquals("The startup hook should have been executed, ",
159: "true", getProject().getProperty("startup.executed"));
160: container.shutDown();
161: assertEquals("The shutdown hook should have been executed, ",
162: "true", getProject().getProperty("shutdown.executed"));
163: }
164:
165: }
|