Source Code Cross Referenced for SanityCheck.java in  » Testing » htmlunit » com » gargoylesoftware » htmlunit » 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 » htmlunit » com.gargoylesoftware.htmlunit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2008 Gargoyle Software Inc. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         * 1. Redistributions of source code must retain the above copyright notice,
008:         *    this list of conditions and the following disclaimer.
009:         * 2. Redistributions in binary form must reproduce the above copyright notice,
010:         *    this list of conditions and the following disclaimer in the documentation
011:         *    and/or other materials provided with the distribution.
012:         * 3. The end-user documentation included with the redistribution, if any, must
013:         *    include the following acknowledgment:
014:         *
015:         *       "This product includes software developed by Gargoyle Software Inc.
016:         *        (http://www.GargoyleSoftware.com/)."
017:         *
018:         *    Alternately, this acknowledgment may appear in the software itself, if
019:         *    and wherever such third-party acknowledgments normally appear.
020:         * 4. The name "Gargoyle Software" must not be used to endorse or promote
021:         *    products derived from this software without prior written permission.
022:         *    For written permission, please contact info@GargoyleSoftware.com.
023:         * 5. Products derived from this software may not be called "HtmlUnit", nor may
024:         *    "HtmlUnit" appear in their name, without prior written permission of
025:         *    Gargoyle Software Inc.
026:         *
027:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
028:         * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
029:         * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
030:         * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
031:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
032:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
033:         * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
036:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037:         */
038:        package com.gargoylesoftware.htmlunit;
039:
040:        import java.net.MalformedURLException;
041:
042:        import junit.textui.TestRunner;
043:
044:        import com.gargoylesoftware.htmlunit.html.HtmlForm;
045:        import com.gargoylesoftware.htmlunit.html.HtmlPage;
046:        import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
047:
048:        /**
049:         * This class runs live tests against popular webservers just to make sure
050:         * nothing obvious has broken. Don't run this very often lest we piss off the
051:         * web masters.
052:         *
053:         * @version $Revision: 2132 $
054:         * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
055:         * @author <a href="mailto:cse@dynabean.de">Christian Sell</a>
056:         * @author Marc Guillemot
057:         * @author Ahmed Ashour
058:         */
059:        public class SanityCheck extends WebTestCase {
060:
061:            private static final BrowserVersion BROWSER_VERSION = BrowserVersion.FIREFOX_2;
062:
063:            /**
064:             * Create an instance.
065:             * @param name The name of the test.
066:             */
067:            public SanityCheck(final String name) {
068:                super (name);
069:            }
070:
071:            /**
072:             * Main entry point for testing.
073:             * @param args the arguments.
074:             * @throws Exception If a problem occurs.
075:             */
076:            public static void main(final String args[]) throws Exception {
077:                new MainTestSuite("foo").enableAllLogging();
078:                TestRunner.run(SanityCheck.class);
079:                System.exit(0);
080:            }
081:
082:            /**
083:             * Test against a live server: Yahoo mail
084:             * @throws Exception If something goes wrong.
085:             */
086:            public void testYahooMail() throws Exception {
087:                final WebClient webClient = new WebClient(BROWSER_VERSION);
088:                assertInstanceOf(webClient.getPage("http://mail.yahoo.com/"),
089:                        HtmlPage.class);
090:            }
091:
092:            /**
093:             * Test against a live server: Yahoo
094:             * @throws Exception If something goes wrong.
095:             */
096:            public void testYahoo() throws Exception {
097:                final WebClient webClient = new WebClient(BROWSER_VERSION);
098:                assertInstanceOf(webClient.getPage("http://yahoo.com/"),
099:                        HtmlPage.class);
100:            }
101:
102:            /**
103:             * Test against a live server: Yahoo
104:             * @throws Exception If something goes wrong.
105:             */
106:            public void testYahoo_Spanish() throws Exception {
107:                final WebClient webClient = new WebClient(BROWSER_VERSION);
108:                assertInstanceOf(
109:                        webClient
110:                                .getPage("http://edit.europe.yahoo.com/config/mail?.intl=es"),
111:                        HtmlPage.class);
112:            }
113:
114:            /**
115:             * Test against a live server: IBM
116:             * @throws Exception If something goes wrong.
117:             */
118:            public void testIBM() throws Exception {
119:                final WebClient webClient = new WebClient(BROWSER_VERSION);
120:                webClient.setRedirectEnabled(true);
121:                final HtmlPage page = (HtmlPage) webClient
122:                        .getPage("http://www.ibm.com/");
123:                assertEquals("http://www.ibm.com/us/", page.getWebResponse()
124:                        .getUrl());
125:            }
126:
127:            /**
128:             * Test against a live server: IBM Alphaworks
129:             * @throws Exception If something goes wrong.
130:             */
131:            public void testAlphaWorks() throws Exception {
132:                final WebClient webClient = new WebClient(BROWSER_VERSION);
133:                assertInstanceOf(webClient
134:                        .getPage("http://www.alphaworks.ibm.com"),
135:                        HtmlPage.class);
136:            }
137:
138:            /**
139:             * Test against a live server: CNN
140:             * @throws Exception If something goes wrong.
141:             */
142:            public void testCNN() throws Exception {
143:                final WebClient webClient = new WebClient(BROWSER_VERSION);
144:                assertInstanceOf(webClient.getPage("http://www.cnn.com"),
145:                        HtmlPage.class);
146:            }
147:
148:            /**
149:             * Test against a live server: Toyota Canada
150:             * @throws Exception If something goes wrong.
151:             */
152:            public void testToyotaCanada() throws Exception {
153:                final WebClient webClient = new WebClient(BROWSER_VERSION);
154:                assertInstanceOf(webClient.getPage("http://www.toyota.ca"),
155:                        HtmlPage.class);
156:            }
157:
158:            /**
159:             * Test against a live server: HtmlUnit page on sourceforge using https
160:             * @throws Exception If something goes wrong.
161:             */
162:            public void testSourceForge_secure() throws Exception {
163:                try {
164:                    final WebClient webClient = new WebClient(BROWSER_VERSION);
165:                    webClient.setPrintContentOnFailingStatusCode(true);
166:                    assertInstanceOf(
167:                            webClient
168:                                    .getPage("https://sourceforge.net/projects/htmlunit/"),
169:                            HtmlPage.class);
170:                } catch (final MalformedURLException e) {
171:                    System.out.println("Skipping https test: " + getName());
172:                }
173:            }
174:
175:            /**
176:             * Test against a live server: Yahoo secure login
177:             * @throws Exception If something goes wrong.
178:             */
179:            public void testYahooLogin_secure() throws Exception {
180:                try {
181:                    final WebClient webClient = new WebClient(BROWSER_VERSION);
182:                    final HtmlPage page = (HtmlPage) webClient
183:                            .getPage("https://login.yahoo.com/");
184:                    final HtmlForm form = page.getFormByName("login_form");
185:                    assertNotNull(form);
186:                } catch (final MalformedURLException e) {
187:                    System.out.println("Skipping https test: " + getName());
188:                }
189:            }
190:
191:            /**
192:             * Test against a live server: Amazon Canada
193:             * @throws Exception If something goes wrong.
194:             */
195:            public void testAmazonCanada() throws Exception {
196:                final WebClient webClient = new WebClient(BROWSER_VERSION);
197:                assertInstanceOf(webClient.getPage("http://www.amazon.ca/"),
198:                        HtmlPage.class);
199:            }
200:
201:            /**
202:             * Test against a live server: CNN After hours
203:             * @throws Exception If something goes wrong.
204:             */
205:            public void testCnnAfterHours() throws Exception {
206:                final WebClient webClient = new WebClient(BROWSER_VERSION);
207:                assertInstanceOf(webClient
208:                        .getPage("http://money.cnn.com/markets/afterhours/"),
209:                        HtmlPage.class);
210:            }
211:
212:            /**
213:             * Test against a live server: htmlunit.sourceforge.net
214:             * @throws Exception If something goes wrong.
215:             */
216:            public void testHtmlUnitHomepage() throws Exception {
217:                final WebClient webClient = new WebClient(BROWSER_VERSION);
218:                assertInstanceOf(webClient
219:                        .getPage("http://htmlunit.sourceforge.net"),
220:                        HtmlPage.class);
221:            }
222:
223:            /**
224:             * Test against a live server: Adobe Acrobat Reader download step 2
225:             * @throws Exception If something goes wrong.
226:             */
227:            public void testAdobeAcrobatReaderDownloadStep2() throws Exception {
228:                final WebClient webClient = new WebClient();
229:                assertInstanceOf(
230:                        webClient
231:                                .getPage("http://www.adobe.com/products/acrobat/readstep2.html"),
232:                        HtmlPage.class);
233:            }
234:
235:            /**
236:             * Print out the name of the test that is running.
237:             */
238:            public void setUp() {
239:                System.out.println();
240:                System.out.println("=====================================");
241:                System.out.println("==  Starting test: " + getName());
242:                System.out.println("=====================================");
243:            }
244:
245:            private String getPrintEnvUrl() throws MalformedURLException {
246:                return "http://htmlunit.sourceforge.net/cgi-bin/printenv";
247:            }
248:
249:            /**
250:             * Test against htmlunit.sourceforge.net to make sure parameters are being passed
251:             * correctly for GET methods
252:             * @throws Exception If something goes wrong.
253:             */
254:            public void testGetMethodWithParameters() throws Exception {
255:                final WebClient webClient = new WebClient();
256:                final HtmlPage firstPage = (HtmlPage) webClient
257:                        .getPage(getPrintEnvUrl());
258:
259:                assertEquals("GET", firstPage.getHtmlElementById(
260:                        "REQUEST_METHOD").asText());
261:
262:                final HtmlForm form = firstPage.getFormByName("form1");
263:                assertEquals("get", form.getMethodAttribute());
264:
265:                final HtmlSubmitInput button = (HtmlSubmitInput) form
266:                        .getInputByName("button1");
267:                final HtmlPage secondPage = (HtmlPage) button.click();
268:                assertEquals("GET", secondPage.getHtmlElementById(
269:                        "REQUEST_METHOD").asText());
270:                assertEquals("textfield1=*&button1=PushMe", secondPage
271:                        .getHtmlElementById("QUERY_STRING").asText());
272:                assertEquals("", secondPage.getHtmlElementById("CONTENT")
273:                        .asText());
274:            }
275:
276:            /**
277:             * Test against htmlunit.sourceforge.net to make sure parameters are being passed
278:             * correctly for POST methods.
279:             * @throws Exception If something goes wrong.
280:             */
281:            public void testPostMethodWithDuplicateParameters()
282:                    throws Exception {
283:                final WebClient webClient = new WebClient();
284:                final HtmlPage firstPage = (HtmlPage) webClient
285:                        .getPage(getPrintEnvUrl());
286:
287:                assertEquals("GET", firstPage.getHtmlElementById(
288:                        "REQUEST_METHOD").asText());
289:
290:                final HtmlForm form = firstPage.getFormByName("form1");
291:                form.setMethodAttribute("post");
292:
293:                final HtmlSubmitInput button = (HtmlSubmitInput) form
294:                        .getInputByName("button1");
295:                button.setAttributeValue("name", "textfield1");
296:
297:                final HtmlPage secondPage = (HtmlPage) button.click();
298:                assertEquals("POST", secondPage.getHtmlElementById(
299:                        "REQUEST_METHOD").asText());
300:                assertEquals("", secondPage.getHtmlElementById("QUERY_STRING")
301:                        .asText());
302:                assertEquals("textfield1=*&textfield1=PushMe", secondPage
303:                        .getHtmlElementById("CONTENT").asText());
304:            }
305:
306:            /**
307:             * Test against htmlunit.sourceforge.net to make sure parameters are being passed
308:             * correctly for POST methods.
309:             * @throws Exception If something goes wrong.
310:             */
311:            public void testPostMethodWithParameters() throws Exception {
312:                final WebClient webClient = new WebClient();
313:                final HtmlPage firstPage = (HtmlPage) webClient
314:                        .getPage(getPrintEnvUrl());
315:
316:                assertEquals("GET", firstPage.getHtmlElementById(
317:                        "REQUEST_METHOD").asText());
318:
319:                final HtmlForm form = firstPage.getFormByName("form1");
320:                form.setMethodAttribute("post");
321:
322:                final HtmlSubmitInput button = (HtmlSubmitInput) form
323:                        .getInputByName("button1");
324:                final HtmlPage secondPage = (HtmlPage) button.click();
325:                assertEquals("POST", secondPage.getHtmlElementById(
326:                        "REQUEST_METHOD").asText());
327:                assertEquals("", secondPage.getHtmlElementById("QUERY_STRING")
328:                        .asText());
329:                assertEquals("textfield1=*&button1=PushMe", secondPage
330:                        .getHtmlElementById("CONTENT").asText());
331:            }
332:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.