Source Code Cross Referenced for TestEngine.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » engine » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: TestEngine.java 3669 2007-02-26 13:51:23Z gbevin $
007:         */
008:        package com.uwyn.rife.engine;
009:
010:        import java.io.InputStream;
011:        import java.net.InetAddress;
012:
013:        import com.meterware.httpunit.*;
014:        import com.uwyn.rife.TestCaseServerside;
015:        import com.uwyn.rife.template.TemplateFactory;
016:        import com.uwyn.rife.tools.ExceptionUtils;
017:        import com.uwyn.rife.tools.HttpUtils;
018:        import com.uwyn.rife.tools.IntegerUtils;
019:        import com.uwyn.rife.tools.StringUtils;
020:
021:        public class TestEngine extends TestCaseServerside {
022:            public TestEngine(int siteType, String name) {
023:                super (siteType, name);
024:            }
025:
026:            public void testNoInitParam() throws Exception {
027:                setupSite(null);
028:
029:                WebConversation conversation = new WebConversation();
030:                WebRequest request = new GetMethodWebRequest(
031:                        "http://localhost:8181/participant/element");
032:                WebResponse response = null;
033:
034:                response = conversation.getResponse(request);
035:
036:                // Get the host name
037:                String hostname = InetAddress.getByName("127.0.0.1")
038:                        .getHostName();
039:
040:                assertEquals("text/html", response.getContentType());
041:                assertEquals("Just some text 127.0.0.1:" + hostname
042:                        + ":.ELEMENT:", response.getText());
043:            }
044:
045:            public void testSimplePlain() throws Exception {
046:                setupSite("site/engine.xml");
047:
048:                WebConversation conversation = new WebConversation();
049:                WebRequest request = new GetMethodWebRequest(
050:                        "http://localhost:8181/simple/plain");
051:                WebResponse response = null;
052:
053:                response = conversation.getResponse(request);
054:
055:                // Get the host name
056:                String hostname = InetAddress.getByName("127.0.0.1")
057:                        .getHostName();
058:
059:                assertEquals("text/plain", response.getContentType());
060:                assertEquals("Just some text 127.0.0.1:" + hostname
061:                        + ":.simple_plain:", response.getText());
062:            }
063:
064:            public void testSimpleHtml() throws Exception {
065:                setupSite("site/engine.xml");
066:
067:                WebConversation conversation = new WebConversation();
068:                WebRequest request = new GetMethodWebRequest(
069:                        "http://localhost:8181/simple/html");
070:                WebResponse response = conversation.getResponse(request);
071:
072:                // Get the host name
073:                String hostname = InetAddress.getByName("127.0.0.1")
074:                        .getHostName();
075:
076:                assertEquals("text/html", response.getContentType());
077:                assertEquals("Just some text 127.0.0.1:" + hostname
078:                        + ":.simple_html:", response.getText());
079:            }
080:
081:            public void testSimpleInterface() throws Exception {
082:                setupSite("site/engine.xml");
083:
084:                WebConversation conversation = new WebConversation();
085:                WebRequest request = new GetMethodWebRequest(
086:                        "http://localhost:8181/simple/interface");
087:                WebResponse response = conversation.getResponse(request);
088:
089:                // Get the host name
090:                String hostname = InetAddress.getByName("127.0.0.1")
091:                        .getHostName();
092:
093:                assertEquals("text/html", response.getContentType());
094:                assertEquals("Just some text 127.0.0.1:" + hostname + ":",
095:                        response.getText());
096:            }
097:
098:            public void testProperties() throws Exception {
099:                setupSite("site/engine.xml");
100:
101:                WebConversation conversation = new WebConversation();
102:                WebRequest request = null;
103:                WebResponse response = null;
104:
105:                request = new GetMethodWebRequest(
106:                        "http://localhost:8181/properties1");
107:                response = conversation.getResponse(request);
108:                assertEquals("Property 1 = property1a"
109:                        + "Property 2 = property2a" + "Property 3 = null"
110:                        + "Property 4 = the value", response.getText());
111:
112:                request = new GetMethodWebRequest(
113:                        "http://localhost:8181/properties2");
114:                response = conversation.getResponse(request);
115:                assertEquals("Property 1 = property1b" + "Property 2 = null"
116:                        + "Property 3 = property3b"
117:                        + "Property 4 = out: <html>\n" + "	<head>\n"
118:                        + "		<title>Template without blocks</title>\n"
119:                        + "	</head>\n" + "\n" + "	<body>\n"
120:                        + "		<h1>This is a template without blocks.</h1>\n"
121:                        + "	</body>\n" + "</html>", response.getText());
122:            }
123:
124:            public void testArrivalRoot() throws Exception {
125:                setupSite("site/engine.xml");
126:
127:                WebConversation conversation = new WebConversation();
128:                WebRequest request = null;
129:                WebResponse response = null;
130:
131:                request = new GetMethodWebRequest("http://localhost:8181");
132:                response = conversation.getResponse(request);
133:                assertEquals("/", response.getText());
134:
135:                request = new GetMethodWebRequest("http://localhost:8181/");
136:                response = conversation.getResponse(request);
137:                assertEquals("/", response.getText());
138:            }
139:
140:            public void testArrivalNoUrl() throws Exception {
141:                setupSite("site/engine_arrivalnourl.xml");
142:
143:                WebConversation conversation = new WebConversation();
144:                WebRequest request = null;
145:                WebResponse response = null;
146:
147:                request = new GetMethodWebRequest("http://localhost:8181");
148:                response = conversation.getResponse(request);
149:                assertEquals("/", response.getText());
150:
151:                request = new GetMethodWebRequest("http://localhost:8181/");
152:                response = conversation.getResponse(request);
153:                assertEquals("/", response.getText());
154:            }
155:
156:            public void testAutoid() throws Exception {
157:                setupSite("site/engine.xml");
158:
159:                WebConversation conversation = new WebConversation();
160:                WebRequest request = null;
161:                WebResponse response = null;
162:
163:                request = new GetMethodWebRequest(
164:                        "http://localhost:8181/autoid");
165:                response = conversation.getResponse(request);
166:                assertEquals(".autoid", response.getText());
167:            }
168:
169:            public void testExplicitid() throws Exception {
170:                setupSite("site/engine.xml");
171:
172:                WebConversation conversation = new WebConversation();
173:                WebRequest request = null;
174:                WebResponse response = null;
175:
176:                request = new GetMethodWebRequest(
177:                        "http://localhost:8181/explicitid");
178:                response = conversation.getResponse(request);
179:                assertEquals(".THIS_ID_IS_EXPLICIT", response.getText());
180:            }
181:
182:            public void testPathInfoEnabled() throws Exception {
183:                setupSite("site/engine.xml");
184:
185:                WebConversation conversation = new WebConversation();
186:                WebRequest request = null;
187:                WebResponse response = null;
188:
189:                // Get the host name
190:                String hostname = InetAddress.getByName("127.0.0.1")
191:                        .getHostName();
192:
193:                request = new GetMethodWebRequest(
194:                        "http://localhost:8181/simple/pathinfo/some/path");
195:                response = conversation.getResponse(request);
196:                assertEquals("Just some text 127.0.0.1:" + hostname
197:                        + ":.PATHINFO:/some/path", response.getText());
198:
199:                request = new GetMethodWebRequest(
200:                        "http://localhost:8181/simple/pathinfo/");
201:                response = conversation.getResponse(request);
202:                assertEquals("Just some text 127.0.0.1:" + hostname
203:                        + ":.PATHINFO:/", response.getText());
204:
205:                request = new GetMethodWebRequest(
206:                        "http://localhost:8181/simple/pathinfo/another_path_info");
207:                response = conversation.getResponse(request);
208:                assertEquals("Just some text 127.0.0.1:" + hostname
209:                        + ":.PATHINFO:/another_path_info", response.getText());
210:
211:                request = new GetMethodWebRequest(
212:                        "http://localhost:8181/simple/pathinfoddd");
213:                response = conversation.getResponse(request);
214:                assertEquals("This is the fallback content.", response
215:                        .getText());
216:            }
217:
218:            public void testArrivalPathInfoEnabled() throws Exception {
219:                setupSite("site/engine_arrivalpathinfo.xml");
220:
221:                WebConversation conversation = new WebConversation();
222:                WebRequest request = null;
223:                WebResponse response = null;
224:
225:                // Get the host name
226:                String hostname = InetAddress.getByName("127.0.0.1")
227:                        .getHostName();
228:
229:                request = new GetMethodWebRequest(
230:                        "http://localhost:8181/some/path");
231:                response = conversation.getResponse(request);
232:                assertEquals("Just some text 127.0.0.1:" + hostname
233:                        + ":.:/some/path", response.getText());
234:
235:                request = new GetMethodWebRequest("http://localhost:8181/");
236:                response = conversation.getResponse(request);
237:                assertEquals("Just some text 127.0.0.1:" + hostname + ":.:/",
238:                        response.getText());
239:
240:                request = new GetMethodWebRequest(
241:                        "http://localhost:8181/another_path_info");
242:                response = conversation.getResponse(request);
243:                assertEquals("Just some text 127.0.0.1:" + hostname
244:                        + ":.:/another_path_info", response.getText());
245:            }
246:
247:            public void testPathInfoCoexist() throws Exception {
248:                setupSite("site/engine.xml");
249:
250:                WebConversation conversation = new WebConversation();
251:                WebRequest request = null;
252:                WebResponse response = null;
253:
254:                // Get the host name
255:                String hostname = InetAddress.getByName("127.0.0.1")
256:                        .getHostName();
257:
258:                request = new GetMethodWebRequest(
259:                        "http://localhost:8181/simple_coexist");
260:                response = conversation.getResponse(request);
261:                assertEquals("Just some text 127.0.0.1:" + hostname
262:                        + ":.COEXIST_REGULAR:", response.getText());
263:
264:                request = new GetMethodWebRequest(
265:                        "http://localhost:8181/simple_coexist/");
266:                response = conversation.getResponse(request);
267:                assertEquals("Just some text 127.0.0.1:" + hostname
268:                        + ":.COEXIST_REGULAR:", response.getText());
269:
270:                request = new GetMethodWebRequest(
271:                        "http://localhost:8181/simple_coexist/pathinfo");
272:                response = conversation.getResponse(request);
273:                assertEquals("Just some text 127.0.0.1:" + hostname
274:                        + ":.COEXIST_PATHINFO:/pathinfo", response.getText());
275:            }
276:
277:            public void testPathInfoDisabledFallback() throws Exception {
278:                setupSite("site/engine.xml");
279:
280:                WebConversation conversation = new WebConversation();
281:                WebRequest request = null;
282:                WebResponse response = null;
283:
284:                // this should go to the element since a trailing slash resolves to the
285:                // nearest match (slash itself or the element registered without the
286:                // trailing slash
287:                request = new GetMethodWebRequest(
288:                        "http://localhost:8181/simple/html/");
289:                response = conversation.getResponse(request);
290:                assertEquals(
291:                        "Just some text 127.0.0.1:localhost:.simple_html:",
292:                        response.getText());
293:
294:                request = new GetMethodWebRequest(
295:                        "http://localhost:8181/simple/html/some/path");
296:                response = conversation.getResponse(request);
297:                assertEquals("This is the fallback content.", response
298:                        .getText());
299:
300:                request = new GetMethodWebRequest(
301:                        "http://localhost:8181/simple/html/another_path_info");
302:                response = conversation.getResponse(request);
303:                assertEquals("This is the fallback content.", response
304:                        .getText());
305:
306:                request = new GetMethodWebRequest(
307:                        "http://localhost:8181/simple/htmlddd");
308:                response = conversation.getResponse(request);
309:                assertEquals("This is the fallback content.", response
310:                        .getText());
311:            }
312:
313:            public void testPathInfoDisabledNoFallback() throws Exception {
314:                setupSite("site/engine_nofallback.xml");
315:
316:                WebConversation conversation = new WebConversation();
317:                WebRequest request = null;
318:                WebResponse response = null;
319:
320:                // Get the host name
321:                String hostname = InetAddress.getByName("127.0.0.1")
322:                        .getHostName();
323:
324:                request = new GetMethodWebRequest(
325:                        "http://localhost:8181/simple/html");
326:                response = conversation.getResponse(request);
327:                assertEquals("Just some text 127.0.0.1:" + hostname
328:                        + ":.SIMPLEHTML:", response.getText());
329:
330:                // this should go to the element since a trailing slash resolves to the
331:                // nearest match (slash itself or the element registered without the
332:                // trailing slash
333:                request = new GetMethodWebRequest(
334:                        "http://localhost:8181/simple/html/");
335:                try {
336:                    response = conversation.getResponse(request);
337:                    assertTrue(true);
338:                } catch (HttpNotFoundException e) {
339:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
340:                }
341:
342:                request = new GetMethodWebRequest(
343:                        "http://localhost:8181/simple/html/some/path");
344:                try {
345:                    response = conversation.getResponse(request);
346:                    fail();
347:                } catch (HttpNotFoundException e) {
348:                    assertTrue(true);
349:                }
350:
351:                request = new GetMethodWebRequest(
352:                        "http://localhost:8181/simple/html/another_path_info");
353:                try {
354:                    response = conversation.getResponse(request);
355:                    fail();
356:                } catch (HttpNotFoundException e) {
357:                    assertTrue(true);
358:                }
359:
360:                request = new GetMethodWebRequest(
361:                        "http://localhost:8181/simple/htmlddd");
362:                try {
363:                    response = conversation.getResponse(request);
364:                    fail();
365:                } catch (HttpNotFoundException e) {
366:                    assertTrue(true);
367:                }
368:            }
369:
370:            public void testHeaders() throws Exception {
371:                setupSite("site/engine.xml");
372:
373:                WebConversation conversation = new WebConversation();
374:                WebRequest request = new GetMethodWebRequest(
375:                        "http://localhost:8181/headers");
376:                WebResponse response = conversation.getResponse(request);
377:
378:                assertTrue(response.getHeaderFieldNames().length > 4);
379:                assertEquals("attachment; filename=thefile.zip", response
380:                        .getHeaderField("CONTENT-DISPOSITION"));
381:                assertEquals("Fri, 25 Oct 2002 19:20:58 GMT", response
382:                        .getHeaderField("DATEHEADER"));
383:                assertEquals("1212", response.getHeaderField("INTHEADER"));
384:            }
385:
386:            public void testContentlength() throws Exception {
387:                setupSite("site/engine.xml");
388:
389:                WebConversation conversation = new WebConversation();
390:                WebRequest request = new GetMethodWebRequest(
391:                        "http://localhost:8181/contentlength");
392:                try {
393:                    WebResponse response = conversation.getResponse(request);
394:
395:                    assertEquals(13, response.getContentLength());
396:                    assertEquals("this goes out", response.getText());
397:                } catch (RuntimeException e) {
398:                    assertEquals("setContentLength not implemented", e
399:                            .getMessage());
400:                }
401:            }
402:
403:            public void testDynamicContenttype() throws Exception {
404:                setupSite("site/engine.xml");
405:
406:                WebConversation conversation = new WebConversation();
407:                WebRequest request = new GetMethodWebRequest(
408:                        "http://localhost:8181/dynamiccontenttype");
409:                WebResponse response = null;
410:
411:                request.setParameter("switch", "text");
412:                response = conversation.getResponse(request);
413:                assertEquals("text/plain", response.getContentType());
414:
415:                request.setParameter("switch", "html");
416:                response = conversation.getResponse(request);
417:                assertEquals("text/html", response.getContentType());
418:            }
419:
420:            public void testStaticProperties() throws Exception {
421:                setupSite("site/engine.xml");
422:
423:                WebConversation conversation = new WebConversation();
424:                WebRequest request = new GetMethodWebRequest(
425:                        "http://localhost:8181/staticproperties");
426:                WebResponse response = conversation.getResponse(request);
427:
428:                assertEquals(
429:                        "property1:value1"
430:                                + "property2:value2"
431:                                + "property3:value3b"
432:                                + "property4:emptyproperty4"
433:                                + "propertystring1:astring"
434:                                + "propertystring2:null"
435:                                + "propertystring2default:stringdefault"
436:                                + "propertyboolean1:true"
437:                                + "propertyboolean2:false"
438:                                + "propertyboolean2default:false"
439:                                + "propertyint1:38746873"
440:                                + "propertyint2:0"
441:                                + "propertyint2default:123"
442:                                + "propertylong1:3468364786"
443:                                + "propertylong2:0"
444:                                + "propertylong2default:983749876"
445:                                + "propertydouble1:9873434.4334"
446:                                + "propertydouble2:0.0"
447:                                + "propertydouble2default:34778.34"
448:                                + "propertyfloat1:23.12"
449:                                + "propertyfloat2:0.0"
450:                                + "propertyfloat2default:324.34"
451:                                + "propertyconfig:before-the element config value-after",
452:                        response.getText());
453:            }
454:
455:            public void testFallback() throws Exception {
456:                setupSite("site/engine.xml");
457:
458:                WebConversation conversation = new WebConversation();
459:                WebRequest request = null;
460:                WebResponse response = null;
461:
462:                request = new GetMethodWebRequest(
463:                        "http://localhost:8181/fallback");
464:                response = conversation.getResponse(request);
465:                assertEquals("This is the fallback content.", response
466:                        .getText());
467:
468:                request = new GetMethodWebRequest(
469:                        "http://localhost:8181/zefzegtze");
470:                response = conversation.getResponse(request);
471:                assertEquals("This is the fallback content.", response
472:                        .getText());
473:
474:                request = new GetMethodWebRequest(
475:                        "http://localhost:8181/dfdfgergfer");
476:                response = conversation.getResponse(request);
477:                assertEquals("This is the fallback content.", response
478:                        .getText());
479:
480:                request = new GetMethodWebRequest(
481:                        "http://localhost:8181/zegzegzegz");
482:                response = conversation.getResponse(request);
483:                assertEquals("This is the fallback content.", response
484:                        .getText());
485:            }
486:
487:            public void testBinary() throws Exception {
488:                setupSite("site/engine.xml");
489:
490:                WebConversation conversation = new WebConversation();
491:                WebRequest request = null;
492:                WebResponse response = null;
493:
494:                request = new GetMethodWebRequest(
495:                        "http://localhost:8181/binary");
496:                response = conversation.getResponse(request);
497:                InputStream inputstream = response.getInputStream();
498:                byte[] integer_bytes = new byte[4];
499:                assertEquals(4, inputstream.read(integer_bytes));
500:                assertEquals(87634675, IntegerUtils.bytesToInt(integer_bytes));
501:            }
502:
503:            public void testPrintAndWriteBuffer() throws Exception {
504:                setupSite("site/engine.xml");
505:
506:                WebConversation conversation = new WebConversation();
507:                WebRequest request = null;
508:                WebResponse response = null;
509:
510:                request = new GetMethodWebRequest(
511:                        "http://localhost:8181/printandwrite_buffer");
512:                response = conversation.getResponse(request);
513:                assertEquals("write2write4print1print3", response.getText());
514:            }
515:
516:            public void testPrintAndWriteNobuffer() throws Exception {
517:                setupSite("site/engine.xml");
518:
519:                WebConversation conversation = new WebConversation();
520:                WebRequest request = null;
521:                WebResponse response = null;
522:
523:                request = new GetMethodWebRequest(
524:                        "http://localhost:8181/printandwrite_nobuffer");
525:                response = conversation.getResponse(request);
526:                assertEquals("print1write2print3write4", response.getText());
527:            }
528:
529:            public void testInnerClass() throws Exception {
530:                setupSite("site/engine.xml");
531:
532:                WebConversation conversation = new WebConversation();
533:                WebRequest request = null;
534:                WebResponse response = null;
535:
536:                request = new GetMethodWebRequest(
537:                        "http://localhost:8181/innerclass");
538:                response = conversation.getResponse(request);
539:                assertEquals("InnerClass's output", response.getText());
540:            }
541:
542:            public void testPackagePrivateClass() throws Exception {
543:                setupSite("site/engine.xml");
544:
545:                WebConversation conversation = new WebConversation();
546:                WebRequest request = null;
547:                WebResponse response = null;
548:
549:                request = new GetMethodWebRequest(
550:                        "http://localhost:8181/packageprivateclass");
551:                response = conversation.getResponse(request);
552:                assertEquals("PackagePrivateClassOutput's output", response
553:                        .getText());
554:            }
555:
556:            public void testPackagePrivateMethod() throws Exception {
557:                setupSite("site/engine.xml");
558:
559:                WebConversation conversation = new WebConversation();
560:                WebRequest request = null;
561:                WebResponse response = null;
562:
563:                request = new GetMethodWebRequest(
564:                        "http://localhost:8181/packageprivatemethod");
565:                response = conversation.getResponse(request);
566:                assertEquals("PackagePrivateMethodOutput's output", response
567:                        .getText());
568:            }
569:
570:            public void testInitConfig() throws Exception {
571:                setupSite("site/engine.xml");
572:
573:                WebConversation conversation = new WebConversation();
574:                WebRequest request = new GetMethodWebRequest(
575:                        "http://localhost:8181/initconfig");
576:                WebResponse response = conversation.getResponse(request);
577:
578:                assertEquals("Jetty/4.2", response.getText());
579:            }
580:
581:            public void testInitialize() throws Exception {
582:                setupSite("site/engine.xml");
583:
584:                WebConversation conversation = null;
585:                WebRequest request = null;
586:                WebResponse response = null;
587:
588:                conversation = new WebConversation();
589:                request = new GetMethodWebRequest(
590:                        "http://localhost:8181/initialize");
591:                response = conversation.getResponse(request);
592:
593:                assertEquals("/initialize", response.getText());
594:            }
595:
596:            public void testInitializeInterface() throws Exception {
597:                setupSite("site/engine.xml");
598:
599:                WebConversation conversation = null;
600:                WebRequest request = null;
601:                WebResponse response = null;
602:
603:                conversation = new WebConversation();
604:                request = new GetMethodWebRequest(
605:                        "http://localhost:8181/initialize_interface");
606:                response = conversation.getResponse(request);
607:
608:                assertEquals("/initialize_interface", response.getText());
609:            }
610:
611:            public void testDeployment() throws Exception {
612:                setupSite("site/engine.xml");
613:
614:                WebConversation conversation = null;
615:                WebRequest request = null;
616:                WebResponse response = null;
617:
618:                conversation = new WebConversation();
619:                request = new GetMethodWebRequest(
620:                        "http://localhost:8181/deployment");
621:                response = conversation.getResponse(request);
622:
623:                String response_text = response.getText();
624:                String[] response_parts = StringUtils.splitToArray(
625:                        response_text, ":");
626:
627:                assertEquals("initvalue", response_parts[0]);
628:
629:                int count = Integer.parseInt(response_parts[1]);
630:
631:                assertEquals(response_text, response.getText());
632:                assertEquals(response_text, response.getText());
633:                assertEquals(response_text, response.getText());
634:
635:                setupSite("site/engine.xml");
636:
637:                conversation = new WebConversation();
638:                request = new GetMethodWebRequest(
639:                        "http://localhost:8181/deployment");
640:                response = conversation.getResponse(request);
641:
642:                assertEquals(response_parts[0] + ":" + (count + 1), response
643:                        .getText());
644:                assertEquals(response_parts[0] + ":" + (count + 1), response
645:                        .getText());
646:                assertEquals(response_parts[0] + ":" + (count + 1), response
647:                        .getText());
648:            }
649:
650:            public void testDeploymentInterface() throws Exception {
651:                setupSite("site/engine.xml");
652:
653:                WebConversation conversation = null;
654:                WebRequest request = null;
655:                WebResponse response = null;
656:
657:                conversation = new WebConversation();
658:                request = new GetMethodWebRequest(
659:                        "http://localhost:8181/deployment_interface");
660:                response = conversation.getResponse(request);
661:
662:                String response_text = response.getText();
663:                String[] response_parts = StringUtils.splitToArray(
664:                        response_text, ":");
665:
666:                assertEquals("initvalue", response_parts[0]);
667:
668:                int count = Integer.parseInt(response_parts[1]);
669:
670:                assertEquals(response_text, response.getText());
671:                assertEquals(response_text, response.getText());
672:                assertEquals(response_text, response.getText());
673:
674:                setupSite("site/engine.xml");
675:
676:                conversation = new WebConversation();
677:                request = new GetMethodWebRequest(
678:                        "http://localhost:8181/deployment_interface");
679:                response = conversation.getResponse(request);
680:
681:                assertEquals(response_parts[0] + ":" + (count + 1), response
682:                        .getText());
683:                assertEquals(response_parts[0] + ":" + (count + 1), response
684:                        .getText());
685:                assertEquals(response_parts[0] + ":" + (count + 1), response
686:                        .getText());
687:            }
688:
689:            public void testGenerateForm() throws Exception {
690:                setupSite("site/engine.xml");
691:
692:                WebConversation conversation = new WebConversation();
693:                WebRequest request = null;
694:                WebResponse response = null;
695:
696:                new HttpUtils.Request("http://localhost:8181/form").headers(
697:                        new String[][] { { "accept-encoding", "gzip" } })
698:                        .retrieve();
699:
700:                request = new GetMethodWebRequest("http://localhost:8181/form");
701:                response = conversation.getResponse(request);
702:                assertEquals(TemplateFactory.ENGINEHTML.get(
703:                        "formbuilder_fields_out_constrained_values")
704:                        .getContent(), response.getText());
705:
706:                request = new GetMethodWebRequest(
707:                        "http://localhost:8181/form?remove=1");
708:                response = conversation.getResponse(request);
709:                assertEquals(TemplateFactory.ENGINEHTML.get(
710:                        "formbuilder_fields").getContent(), response.getText());
711:            }
712:
713:            public void testGenerateEmptyForm() throws Exception {
714:                setupSite("site/engine.xml");
715:
716:                WebConversation conversation = new WebConversation();
717:                WebRequest request = null;
718:                WebResponse response = null;
719:
720:                request = new GetMethodWebRequest(
721:                        "http://localhost:8181/form_empty");
722:                response = conversation.getResponse(request);
723:                assertEquals(TemplateFactory.ENGINEHTML.get(
724:                        "formbuilder_fields_out_constrained_empty")
725:                        .getContent(), response.getText());
726:
727:                request = new GetMethodWebRequest(
728:                        "http://localhost:8181/form_empty?remove=1");
729:                response = conversation.getResponse(request);
730:                assertEquals(TemplateFactory.ENGINEHTML.get(
731:                        "formbuilder_fields").getContent(), response.getText());
732:            }
733:
734:            public void testGenerateFormPrefix() throws Exception {
735:                setupSite("site/engine.xml");
736:
737:                WebConversation conversation = new WebConversation();
738:                WebRequest request = null;
739:                WebResponse response = null;
740:
741:                request = new GetMethodWebRequest(
742:                        "http://localhost:8181/form?prefix=1");
743:                response = conversation.getResponse(request);
744:                assertEquals(TemplateFactory.ENGINEHTML.get(
745:                        "formbuilder_form_prefix_out_constrained_values")
746:                        .getContent(), response.getText());
747:
748:                request = new GetMethodWebRequest(
749:                        "http://localhost:8181/form?prefix=1&remove=1");
750:                response = conversation.getResponse(request);
751:                assertEquals(TemplateFactory.ENGINEHTML.get(
752:                        "formbuilder_form_prefix").getContent(), response
753:                        .getText());
754:            }
755:
756:            public void testGenerateEmptyFormPrefix() throws Exception {
757:                setupSite("site/engine.xml");
758:
759:                WebConversation conversation = new WebConversation();
760:                WebRequest request = null;
761:                WebResponse response = null;
762:
763:                request = new GetMethodWebRequest(
764:                        "http://localhost:8181/form_empty?prefix=1");
765:                response = conversation.getResponse(request);
766:                assertEquals(TemplateFactory.ENGINEHTML.get(
767:                        "formbuilder_form_prefix_out_constrained_empty")
768:                        .getContent(), response.getText());
769:
770:                request = new GetMethodWebRequest(
771:                        "http://localhost:8181/form_empty?prefix=1&remove=1");
772:                response = conversation.getResponse(request);
773:                assertEquals(TemplateFactory.ENGINEHTML.get(
774:                        "formbuilder_form_prefix").getContent(), response
775:                        .getText());
776:            }
777:
778:            public void testGzipEncoding() throws Exception {
779:                setupSite("site/engine.xml");
780:
781:                HttpUtils.Page compressed_page = new HttpUtils.Request(
782:                        "http://localhost:8181/simple/html").headers(
783:                        new String[][] { { "Accept-Encoding", "gzip" } })
784:                        .retrieve();
785:                String compressed_content = compressed_page.getContent();
786:                int compressed_length = Integer.parseInt(compressed_page
787:                        .getHeaderField("Content-Length"));
788:
789:                assertTrue(compressed_length != compressed_content.length());
790:
791:                HttpUtils.Page uncompressed_page = HttpUtils
792:                        .retrievePage("http://localhost:8181/simple/html");
793:                String uncompressed_content = uncompressed_page.getContent();
794:
795:                assertNull(uncompressed_page.getHeaderField("Content-Length"));
796:                assertEquals(compressed_content, uncompressed_content);
797:            }
798:
799:            public void testForward() throws Exception {
800:                setupSite("site/engine_nofallback.xml");
801:
802:                // Get the host name
803:                String hostname = InetAddress.getByName("127.0.0.1")
804:                        .getHostName();
805:
806:                HttpUtils.Page page1 = HttpUtils
807:                        .retrievePage("http://localhost:8181/forward?go=0");
808:                assertEquals("not forwarded", page1.getContent());
809:
810:                HttpUtils.Page page2 = HttpUtils
811:                        .retrievePage("http://localhost:8181/forward?go=1");
812:                assertEquals("Just some text 127.0.0.1:" + hostname
813:                        + ":.SIMPLEHTML:", page2.getContent());
814:
815:                HttpUtils.Page page3 = HttpUtils
816:                        .retrievePage("http://localhost:8181/forward?go=2");
817:                assertEquals(404, page3.getResponseCode());
818:                assertTrue(page3.getResponseMessage().indexOf("Not%2BFound") != -1);
819:                assertNull(page3.getContent());
820:            }
821:
822:            public void testTemplateContentType() throws Exception {
823:                setupSite("site/engine.xml");
824:
825:                WebConversation conversation = new WebConversation();
826:                WebRequest request = new GetMethodWebRequest(
827:                        "http://localhost:8181/template_content_type");
828:                WebResponse response = null;
829:
830:                response = conversation.getResponse(request);
831:
832:                assertEquals("application/xml", response.getContentType());
833:                assertEquals(
834:                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
835:                                + "<!DOCTYPE config SYSTEM \"/dtd/config.dtd\">\n"
836:                                + "\n" + "<config>\n"
837:                                + "<!--V 'params'/--></config>\n", response
838:                                .getText());
839:            }
840:
841:            public void testGeneratedProperties() throws Exception {
842:                setupSite("site/engine.xml");
843:
844:                WebConversation conversation = new WebConversation();
845:                WebRequest request = new GetMethodWebRequest(
846:                        "http://localhost:8181/generated_properties");
847:                WebResponse response = null;
848:
849:                response = conversation.getResponse(request);
850:
851:                assertEquals(System.getProperty("java.vm.specification.vendor")
852:                        + " "
853:                        + System.getProperty("java.vm.specification.version")
854:                        + "\n" + "<!--V 'PROPERTY:unknownProperty'/-->\n"
855:                        + "custom property value\n" + "default\n", response
856:                        .getText());
857:            }
858:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.