Source Code Cross Referenced for TestContainerRunner.java in  » Testing » jakarta-cactus » org » apache » cactus » integration » ant » container » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta cactus » org.apache.cactus.integration.ant.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003-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;
021:
022:        import java.net.URL;
023:
024:        import org.apache.tools.ant.BuildException;
025:
026:        import junit.framework.TestCase;
027:
028:        /**
029:         * Unit tests for {@link ContainerRunner}.
030:         *
031:         * @version $Id: TestContainerRunner.java 239003 2004-05-31 20:05:27Z vmassol $
032:         */
033:        public final class TestContainerRunner extends TestCase {
034:
035:            // Instance Variables ------------------------------------------------------
036:
037:            /**
038:             * The dummy HTTP server used to test the container runner.
039:             */
040:            private MockHttpServer server;
041:
042:            // TestCase Implementation -------------------------------------------------
043:
044:            /**
045:             * @see junit.framework.TestCase#setUp()
046:             */
047:            protected void setUp() throws Exception {
048:                int unusedPort = MockHttpServer.findUnusedLocalPort(
049:                        "localhost", 8000, 8099);
050:                if (unusedPort > 0) {
051:                    this .server = new MockHttpServer(unusedPort);
052:                    this .server.expectMethod("GET");
053:                    this .server.expectUri("/test");
054:                }
055:            }
056:
057:            // Test Methods ------------------------------------------------------------
058:
059:            /**
060:             * Verifies that an exception is thrown when setting the URL property to a 
061:             * non-HTTP URL.
062:             * 
063:             * @throws Exception If an unexpected error occurs
064:             */
065:            public void testSetInvalidUrl() throws Exception {
066:                ContainerRunner runner = new ContainerRunner(new MockContainer(
067:                        this .server));
068:                try {
069:                    runner.setURL(new URL("ftp://ftp.example.com/test/"));
070:                    fail("Expected IllegalArgumentException");
071:                } catch (IllegalArgumentException expected) {
072:                    // expected
073:                }
074:            }
075:
076:            /**
077:             * Verifies that an exception is thrown if startUpContainer() is invoked
078:             * before a URL has been set. 
079:             * 
080:             * @throws Exception If an unexpected error occurs
081:             */
082:            public void testStartUpWithoutUrl() throws Exception {
083:                ContainerRunner runner = new ContainerRunner(new MockContainer(
084:                        this .server));
085:                try {
086:                    runner.startUpContainer();
087:                    fail("Expected IllegalStateException");
088:                } catch (IllegalStateException expected) {
089:                    // expected
090:                }
091:            }
092:
093:            /**
094:             * Verifies that an exception is thrown if shutDownContainer() is invoked
095:             * before a URL has been set. 
096:             * 
097:             * @throws Exception If an unexpected error occurs
098:             */
099:            public void testShutDownWithoutUrl() throws Exception {
100:                ContainerRunner runner = new ContainerRunner(new MockContainer(
101:                        this .server));
102:                try {
103:                    runner.shutDownContainer();
104:                    fail("Expected IllegalStateException");
105:                } catch (IllegalStateException expected) {
106:                    // expected
107:                }
108:            }
109:
110:            /**
111:             * Verifies that the runner correctly starts and stops a well-behaved
112:             * container.
113:             * 
114:             * @throws Exception If an unexpected error occurs
115:             */
116:            public void testStartUpShutDown() throws Exception {
117:                this .server.setResponse("HTTP/1.1 200 Ok\n\n");
118:                this .server.expectRequestCount(3);
119:
120:                ContainerRunner runner = new ContainerRunner(new MockContainer(
121:                        this .server));
122:                runner.setURL(new URL("http", "localhost", this .server
123:                        .getPort(), "/test"));
124:                runner.setTimeout(0);
125:                runner.setCheckInterval(250);
126:                runner.setShutDownWait(0);
127:                runner.startUpContainer();
128:                runner.shutDownContainer();
129:
130:                server.verify();
131:            }
132:
133:            /**
134:             * Verifies that the runner throws an exception when a container doesn't
135:             * return a success status.
136:             * 
137:             * @throws Exception If an unexpected error occurs
138:             */
139:            public void testStartUpFailure() throws Exception {
140:                this .server
141:                        .setResponse("HTTP/1.1 500 Internal Server Error\n\n");
142:                this .server.expectRequestCount(1);
143:
144:                ContainerRunner runner = new ContainerRunner(new MockContainer(
145:                        this .server));
146:                runner.setURL(new URL("http", "localhost", this .server
147:                        .getPort(), "/test"));
148:                runner.setTimeout(0);
149:                runner.setCheckInterval(250);
150:                runner.setShutDownWait(0);
151:                try {
152:                    runner.startUpContainer();
153:                    fail("Expected BuildException");
154:                } catch (BuildException expected) {
155:                    // expected
156:                }
157:
158:                server.stop();
159:                server.verify();
160:            }
161:
162:            /**
163:             * Verifies that the runner tries for a time approximately close to the
164:             * timeout period to start up the container, and then fails if the container
165:             * isn't responding.
166:             * 
167:             * @throws Exception If an unexpected error occurs
168:             */
169:            public void testStartUpTimeout() throws Exception {
170:                this .server
171:                        .setResponse("HTTP/1.1 500 Internal Server Error\n\n");
172:                this .server.expectRequestCount(-1); // can't tell exactly
173:
174:                ContainerRunner runner = new ContainerRunner(new MockContainer(
175:                        this .server));
176:                runner.setURL(new URL("http", "localhost", this .server
177:                        .getPort(), "/test"));
178:                runner.setTimeout(5000);
179:                runner.setCheckInterval(250);
180:                runner.setShutDownWait(0);
181:                long startTime = System.currentTimeMillis();
182:                try {
183:                    runner.startUpContainer();
184:                    fail("Expected BuildException");
185:                } catch (BuildException expected) {
186:                    // expected
187:                }
188:
189:                long time = System.currentTimeMillis() - startTime;
190:                assertTrue("Process finished before the timeout was reached",
191:                        time > 5000);
192:                assertTrue("Process took " + (time - 5000)
193:                        + "ms longer than the " + "timeout period",
194:                        time < 10000);
195:
196:                server.stop();
197:                server.verify();
198:            }
199:
200:            /**
201:             * Verifies that the runner correctly recognizes an already running
202:             * container, and does not attempt to shut it down.
203:             * 
204:             * @throws Exception If an unexpected error occurs
205:             */
206:            public void testIgnoreAlreadyRunning() throws Exception {
207:                this .server.setResponse("HTTP/1.1 200 Ok\n\n");
208:                this .server.expectRequestCount(1);
209:                Thread thread = new Thread(this .server);
210:                thread.start();
211:
212:                MockContainer container = new MockContainer(this .server);
213:                container.expectStartUpCalled(false);
214:                container.expectShutDownCalled(false);
215:
216:                ContainerRunner runner = new ContainerRunner(container);
217:                runner.setURL(new URL("http", "localhost", this .server
218:                        .getPort(), "/test"));
219:                runner.setTimeout(0);
220:                runner.setCheckInterval(250);
221:                runner.setShutDownWait(0);
222:                runner.startUpContainer();
223:                runner.shutDownContainer();
224:
225:                container.verify();
226:
227:                server.stop();
228:                server.verify();
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.