KickJava   Java API By Example, From Geeks To Geeks.

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


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.cactus.integration.ant.container.Container;
23
24 /**
25  * Unit tests for {@link ContainerSet}.
26  *
27  * @version $Id: TestContainerSet.java,v 1.5 2004/02/29 10:21:34 vmassol Exp $
28  */

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

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

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

56     /**
57      * Verifies that a completely empty container set definition is constructed
58      * as expected.
59      *
60      * @throws Exception If an unexpected error occurs
61      */

62     public void testEmpty() throws Exception JavaDoc
63     {
64         executeTestTarget();
65         ContainerSet set = (ContainerSet) getProject().getReference("test");
66         assertEquals(-1, set.getProxyPort());
67         assertEquals(-1, set.getTimeout());
68         Container[] containers = set.getContainers();
69         assertEquals(0, containers.length);
70     }
71
72     /**
73      * Verifies that the <code>proxyport</code> attribute of a container set
74      * results in the proxy port being set as expected.
75      *
76      * @throws Exception If an unexpected error occurs
77      */

78     public void testEmptyWithProxyPort() throws Exception JavaDoc
79     {
80         executeTestTarget();
81         ContainerSet set = (ContainerSet) getProject().getReference("test");
82         assertEquals(8088, set.getProxyPort());
83         assertEquals(-1, set.getTimeout());
84         Container[] containers = set.getContainers();
85         assertEquals(0, containers.length);
86     }
87
88     /**
89      * Verifies that the <code>timeout</code> attribute of a container set
90      * results in the timeout being set as expected.
91      *
92      * @throws Exception If an unexpected error occurs
93      */

94     public void testEmptyWithTimeout() throws Exception JavaDoc
95     {
96         executeTestTarget();
97         ContainerSet set = (ContainerSet) getProject().getReference("test");
98         assertEquals(-1, set.getProxyPort());
99         assertEquals(60000, set.getTimeout());
100         Container[] containers = set.getContainers();
101         assertEquals(0, containers.length);
102     }
103
104     /**
105      * Verifies that a <em>generic</em> container can be added to an otherwise
106      * empty container, and be retrieved as expected.
107      *
108      * @throws Exception If an unexpected error occurs
109      */

110     public void testGenericContainer() throws Exception JavaDoc
111     {
112         executeTestTarget();
113         ContainerSet set = (ContainerSet) getProject().getReference("test");
114         Container[] containers = set.getContainers();
115         assertEquals(1, containers.length);
116         Container container = (Container) containers[0];
117         assertEquals(8080, container.getPort());
118     }
119
120     /**
121      * Verifies that setting the proxy port on the container set results in the
122      * port of the nested containers being set to the proxy port.
123      *
124      * @throws Exception If an unexpected error occurs
125      */

126     public void testGenericContainerWithProxyPort() throws Exception JavaDoc
127     {
128         executeTestTarget();
129         ContainerSet set = (ContainerSet) getProject().getReference("test");
130         Container[] containers = set.getContainers();
131         assertEquals(1, containers.length);
132         Container container = containers[0];
133         assertEquals(8088, container.getPort());
134     }
135
136     /**
137      * Verifies that the startup and shutdown hooks of a generic container
138      * nested in a container set definition are not invoked when defined, but
139      * when explicitly calling the container lifecycle methods.
140      *
141      * @throws Exception If an unexpected error occurs
142      */

143     public void testGenericContainerWithTasks() throws Exception JavaDoc
144     {
145         executeTestTarget();
146         ContainerSet set = (ContainerSet) getProject().getReference("test");
147         Container[] containers = set.getContainers();
148
149         // Make sure that neither the startup nor the shutdown hook have been
150
// called yet
151
assertNull("The startup hook should not have been executed",
152             getProject().getProperty("startup.executed"));
153         assertNull("The shutdown hook should not have been executed",
154             getProject().getProperty("shutdown.executed"));
155
156         // Call the startup and shutdown hooks and assert that they have been
157
// executed
158
Container container = containers[0];
159         container.startUp();
160         assertEquals("The startup hook should have been executed, ",
161             "true", getProject().getProperty("startup.executed"));
162         container.shutDown();
163         assertEquals("The shutdown hook should have been executed, ",
164             "true", getProject().getProperty("shutdown.executed"));
165     }
166
167 }
168
Popular Tags