Source Code Cross Referenced for TestEngineContinuations.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) 


0001:        /*
0002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003:         * Distributed under the terms of either:
0004:         * - the common development and distribution license (CDDL), v1.0; or
0005:         * - the GNU Lesser General Public License, v2.1 or later
0006:         * $Id: TestEngineContinuations.java 3794 2007-06-19 17:50:38Z gbevin $
0007:         */
0008:        package com.uwyn.rife.engine;
0009:
0010:        import com.meterware.httpunit.*;
0011:
0012:        import com.uwyn.rife.TestCaseServerside;
0013:        import com.uwyn.rife.engine.testelements.continuations.AllTypes;
0014:        import com.uwyn.rife.tools.StringUtils;
0015:        import java.net.InetAddress;
0016:        import junit.framework.ComparisonFailure;
0017:
0018:        public class TestEngineContinuations extends TestCaseServerside {
0019:            public TestEngineContinuations(int siteType, String name) {
0020:                super (siteType, name);
0021:            }
0022:
0023:            public void testNoPause() throws Exception {
0024:                setupSite("site/continuations.xml");
0025:
0026:                WebConversation conversation = new WebConversation();
0027:                WebRequest request = null;
0028:                WebResponse response = null;
0029:
0030:                request = new GetMethodWebRequest(
0031:                        "http://localhost:8181/nopause");
0032:                response = conversation.getResponse(request);
0033:
0034:                assertEquals("", response.getText());
0035:            }
0036:
0037:            public void testSimple() throws Exception {
0038:                setupSite("site/continuations.xml");
0039:
0040:                WebConversation conversation = new WebConversation();
0041:                WebRequest request = null;
0042:                WebResponse response = null;
0043:
0044:                request = new GetMethodWebRequest(
0045:                        "http://localhost:8181/simple");
0046:                response = conversation.getResponse(request);
0047:
0048:                String text = response.getText();
0049:                String[] lines = StringUtils.splitToArray(text, "\n");
0050:                assertEquals(2, lines.length);
0051:                assertEquals("before simple pause", lines[0]);
0052:
0053:                request = new GetMethodWebRequest(
0054:                        "http://localhost:8181/simple?"
0055:                                + ReservedParameters.CONTID + "=" + lines[1]);
0056:                response = conversation.getResponse(request);
0057:
0058:                assertEquals("after simple pause", response.getText());
0059:            }
0060:
0061:            public void testSimpleInterface() throws Exception {
0062:                setupSite("site/continuations.xml");
0063:
0064:                WebConversation conversation = new WebConversation();
0065:                WebRequest request = null;
0066:                WebResponse response = null;
0067:
0068:                request = new GetMethodWebRequest(
0069:                        "http://localhost:8181/simple_interface");
0070:                response = conversation.getResponse(request);
0071:
0072:                String text = response.getText();
0073:                String[] lines = StringUtils.splitToArray(text, "\n");
0074:                assertEquals(2, lines.length);
0075:                assertEquals("before simple pause", lines[0]);
0076:
0077:                request = new GetMethodWebRequest(
0078:                        "http://localhost:8181/simple_interface?"
0079:                                + ReservedParameters.CONTID + "=" + lines[1]);
0080:                response = conversation.getResponse(request);
0081:
0082:                assertEquals("after simple pause", response.getText());
0083:            }
0084:
0085:            public void testNull() throws Exception {
0086:                setupSite("site/continuations.xml");
0087:
0088:                WebConversation conversation = new WebConversation();
0089:                WebRequest request = null;
0090:                WebResponse response = null;
0091:
0092:                request = new GetMethodWebRequest("http://localhost:8181/null");
0093:                response = conversation.getResponse(request);
0094:
0095:                String text = response.getText();
0096:                String[] lines = StringUtils.splitToArray(text, "\n");
0097:                assertEquals(2, lines.length);
0098:                assertEquals("before null pause", lines[0]);
0099:
0100:                request = new GetMethodWebRequest(
0101:                        "http://localhost:8181/null?response=after%20null%20pause&"
0102:                                + ReservedParameters.CONTID + "=" + lines[1]);
0103:                response = conversation.getResponse(request);
0104:
0105:                assertEquals("after null pause", response.getText());
0106:            }
0107:
0108:            public void testNullReference() throws Exception {
0109:                setupSite("site/continuations.xml");
0110:
0111:                WebConversation conversation = new WebConversation();
0112:                WebRequest request = null;
0113:                WebResponse response = null;
0114:
0115:                request = new GetMethodWebRequest(
0116:                        "http://localhost:8181/null_reference");
0117:                response = conversation.getResponse(request);
0118:
0119:                request = new GetMethodWebRequest(
0120:                        "http://localhost:8181/null_reference?"
0121:                                + ReservedParameters.CONTID + "="
0122:                                + response.getText());
0123:                try {
0124:                    response = conversation.getResponse(request);
0125:                } catch (Throwable e) {
0126:                    assertTrue(getLogSink().getInternalException() instanceof  NullPointerException);
0127:                }
0128:            }
0129:
0130:            public void testNullConditional() throws Exception {
0131:                setupSite("site/continuations.xml");
0132:
0133:                WebConversation conversation = new WebConversation();
0134:                WebRequest request = null;
0135:                WebResponse response = null;
0136:
0137:                request = new GetMethodWebRequest(
0138:                        "http://localhost:8181/null_conditional?value=thevalue");
0139:                response = conversation.getResponse(request);
0140:
0141:                String text = response.getText();
0142:                assertTrue(text.startsWith("thevalue"));
0143:
0144:                request = new GetMethodWebRequest(
0145:                        "http://localhost:8181/null_conditional?"
0146:                                + ReservedParameters.CONTID + "="
0147:                                + text.substring(8));
0148:                response = conversation.getResponse(request);
0149:
0150:                assertEquals("thevalue", response.getText());
0151:            }
0152:
0153:            public void testConditional() throws Exception {
0154:                setupSite("site/continuations.xml");
0155:
0156:                WebConversation conversation = new WebConversation();
0157:                WebRequest request = null;
0158:                WebResponse response = null;
0159:                WebForm form = null;
0160:
0161:                request = new GetMethodWebRequest(
0162:                        "http://localhost:8181/conditional");
0163:                response = conversation.getResponse(request);
0164:
0165:                assertEquals("printing", response.getTitle());
0166:                form = response.getFormWithName("pause");
0167:                assertNotNull(form);
0168:                form.setParameter("answer", "1");
0169:                response = form.submit();
0170:
0171:                assertEquals("pauzing", response.getTitle());
0172:                form = response.getFormWithName("pause");
0173:                assertNotNull(form);
0174:                form.setParameter("answer", "1"); // will not be checked
0175:                response = form.submit();
0176:
0177:                assertEquals("pauzingprinting", response.getTitle());
0178:                form = response.getFormWithName("pause");
0179:                assertNotNull(form);
0180:                form.setParameter("answer", "0");
0181:                response = form.submit();
0182:
0183:                assertEquals("printing", response.getTitle());
0184:                form = response.getFormWithName("pause");
0185:                assertNotNull(form);
0186:
0187:                request = new GetMethodWebRequest(
0188:                        "http://localhost:8181/conditional");
0189:                response = conversation.getResponse(request);
0190:
0191:                assertEquals("printing", response.getTitle());
0192:                form = response.getFormWithName("pause");
0193:                assertNotNull(form);
0194:                form.setParameter("stop", "1");
0195:                response = form.submit();
0196:
0197:                assertEquals("stopping", response.getTitle());
0198:            }
0199:
0200:            public void testMemberMethod() throws Exception {
0201:                setupSite("site/continuations.xml");
0202:
0203:                WebConversation conversation = new WebConversation();
0204:                WebRequest request = null;
0205:                WebResponse response = null;
0206:
0207:                request = new GetMethodWebRequest(
0208:                        "http://localhost:8181/membermethod");
0209:                response = conversation.getResponse(request);
0210:
0211:                String text = response.getText();
0212:                String[] lines = StringUtils.splitToArray(text, "\n");
0213:                assertEquals(2, lines.length);
0214:                assertEquals("before pause", lines[0]);
0215:
0216:                request = new GetMethodWebRequest(
0217:                        "http://localhost:8181/membermethod?"
0218:                                + ReservedParameters.CONTID + "=" + lines[1]);
0219:                response = conversation.getResponse(request);
0220:
0221:                assertEquals("me value 6899", response.getText());
0222:            }
0223:
0224:            public void testPrivateMethod() throws Exception {
0225:                setupSite("site/continuations.xml");
0226:
0227:                WebConversation conversation = new WebConversation();
0228:                WebRequest request = null;
0229:                WebResponse response = null;
0230:
0231:                request = new GetMethodWebRequest(
0232:                        "http://localhost:8181/private_method");
0233:                response = conversation.getResponse(request);
0234:
0235:                request = new GetMethodWebRequest(
0236:                        "http://localhost:8181/private_method?"
0237:                                + ReservedParameters.CONTID + "="
0238:                                + response.getText());
0239:                response = conversation.getResponse(request);
0240:
0241:                assertEquals("1234", response.getText());
0242:            }
0243:
0244:            public void testSynchronization() throws Exception {
0245:                setupSite("site/continuations.xml");
0246:
0247:                WebConversation conversation = new WebConversation();
0248:                WebRequest request = null;
0249:                WebResponse response = null;
0250:                String text = null;
0251:                String[] lines = null;
0252:
0253:                request = new GetMethodWebRequest(
0254:                        "http://localhost:8181/synchronization");
0255:                response = conversation.getResponse(request);
0256:
0257:                text = response.getText();
0258:                lines = StringUtils.splitToArray(text, "\n");
0259:                assertEquals(2, lines.length);
0260:                assertEquals("monitor this", lines[0]);
0261:
0262:                request = new GetMethodWebRequest(
0263:                        "http://localhost:8181/synchronization?"
0264:                                + ReservedParameters.CONTID + "=" + lines[1]);
0265:                response = conversation.getResponse(request);
0266:
0267:                text = response.getText();
0268:                lines = StringUtils.splitToArray(text, "\n");
0269:                assertEquals(2, lines.length);
0270:                assertEquals("monitor member", lines[0]);
0271:
0272:                request = new GetMethodWebRequest(
0273:                        "http://localhost:8181/synchronization?"
0274:                                + ReservedParameters.CONTID + "=" + lines[1]);
0275:                response = conversation.getResponse(request);
0276:
0277:                text = response.getText();
0278:                lines = StringUtils.splitToArray(text, "\n");
0279:                assertEquals(2, lines.length);
0280:                assertEquals("monitor static", lines[0]);
0281:
0282:                request = new GetMethodWebRequest(
0283:                        "http://localhost:8181/synchronization?"
0284:                                + ReservedParameters.CONTID + "=" + lines[1]);
0285:                response = conversation.getResponse(request);
0286:
0287:                assertEquals("done", response.getText());
0288:            }
0289:
0290:            public void testThrow() throws Exception {
0291:                setupSite("site/continuations.xml");
0292:
0293:                WebConversation conversation = new WebConversation();
0294:                WebRequest request = null;
0295:                WebResponse response = null;
0296:                WebForm form = null;
0297:
0298:                request = new GetMethodWebRequest("http://localhost:8181/throw");
0299:                response = conversation.getResponse(request);
0300:
0301:                form = response.getFormWithName("action");
0302:                assertNotNull(form);
0303:                form.setParameter("throw", "1");
0304:                response = form.submit();
0305:
0306:                assertEquals(
0307:                        "do throw = true : throw message : finally message",
0308:                        response.getTitle());
0309:                form = response.getFormWithName("action");
0310:                assertNotNull(form);
0311:                form.setParameter("throw", "1"); // will not be checked
0312:                response = form.submit();
0313:
0314:                assertEquals(
0315:                        "do throw = true : throw message : finally message : all done",
0316:                        response.getTitle());
0317:                form = response.getFormWithName("action");
0318:                assertNotNull(form);
0319:
0320:                request = new GetMethodWebRequest("http://localhost:8181/throw");
0321:                response = conversation.getResponse(request);
0322:
0323:                form = response.getFormWithName("action");
0324:                assertNotNull(form);
0325:                form.setParameter("throw", "0");
0326:                response = form.submit();
0327:
0328:                assertEquals("do throw = false : finally message", response
0329:                        .getTitle());
0330:                form = response.getFormWithName("action");
0331:                assertNotNull(form);
0332:                form.setParameter("throw", "1"); // will not be checked
0333:                response = form.submit();
0334:
0335:                assertEquals("do throw = false : finally message : all done",
0336:                        response.getTitle());
0337:                form = response.getFormWithName("action");
0338:                assertNotNull(form);
0339:            }
0340:
0341:            public void testTryCatch() throws Exception {
0342:                setupSite("site/continuations.xml");
0343:
0344:                WebConversation conversation = new WebConversation();
0345:                WebRequest request = null;
0346:                WebResponse response = null;
0347:                WebForm form = null;
0348:
0349:                request = new GetMethodWebRequest(
0350:                        "http://localhost:8181/trycatch");
0351:                response = conversation.getResponse(request);
0352:
0353:                assertEquals("start", response.getTitle());
0354:                form = response.getFormWithName("action");
0355:                assertNotNull(form);
0356:                form.setParameter("throw", "1");
0357:                response = form.submit();
0358:
0359:                assertEquals("start : throw done catch", response.getTitle());
0360:                form = response.getFormWithName("action");
0361:                assertNotNull(form);
0362:                form.setParameter("throw", "1"); // will not be checked since the value of the first param is stored in a local variable in the element
0363:                response = form.submit();
0364:
0365:                assertEquals("start : throw done catch : finally done",
0366:                        response.getTitle());
0367:                form = response.getFormWithName("action");
0368:                assertNotNull(form);
0369:                form.setParameter("throw", "0"); // will not be checked since the value of the first param is stored in a local variable in the element
0370:                response = form.submit();
0371:
0372:                assertEquals(
0373:                        "start : throw done catch : finally done : all done",
0374:                        response.getTitle());
0375:                form = response.getFormWithName("action");
0376:                assertNotNull(form);
0377:                form.setParameter("throw", "1"); // will not be checked since the value of the first param is stored in a local variable in the element
0378:                response = form.submit();
0379:
0380:                assertEquals("start", response.getTitle());
0381:                form = response.getFormWithName("action");
0382:                assertNotNull(form);
0383:                form.setParameter("throw", "0");
0384:                response = form.submit();
0385:
0386:                assertEquals("start : throw not done", response.getTitle());
0387:                form = response.getFormWithName("action");
0388:                assertNotNull(form);
0389:                form.setParameter("throw", "1"); // will not be checked since the value of the first param is stored in a local variable in the element
0390:                response = form.submit();
0391:
0392:                assertEquals("start : throw not done : finally done", response
0393:                        .getTitle());
0394:                form = response.getFormWithName("action");
0395:                assertNotNull(form);
0396:                form.setParameter("throw", "0"); // will not be checked since the value of the first param is stored in a local variable in the element
0397:                response = form.submit();
0398:
0399:                assertEquals(
0400:                        "start : throw not done : finally done : all done",
0401:                        response.getTitle());
0402:                form = response.getFormWithName("action");
0403:                assertNotNull(form);
0404:                form.setParameter("throw", "1"); // will not be checked since the value of the first param is stored in a local variable in the element
0405:                response = form.submit();
0406:            }
0407:
0408:            public void testFinally() throws Exception {
0409:                setupSite("site/continuations.xml");
0410:
0411:                WebConversation conversation = new WebConversation();
0412:                WebRequest request = null;
0413:                WebResponse response = null;
0414:                String text;
0415:                String[] lines;
0416:
0417:                try {
0418:                    request = new GetMethodWebRequest(
0419:                            "http://localhost:8181/finally");
0420:                    response = conversation.getResponse(request);
0421:                    text = response.getText();
0422:                    lines = StringUtils.splitToArray(text, "\n");
0423:                    assertEquals(2, lines.length);
0424:                    assertEquals("start", lines[0]);
0425:
0426:                    request = new GetMethodWebRequest(
0427:                            "http://localhost:8181/finally?"
0428:                                    + ReservedParameters.CONTID + "="
0429:                                    + lines[1]);
0430:                    response = conversation.getResponse(request);
0431:                    text = response.getText();
0432:                    lines = StringUtils.splitToArray(text, "\n");
0433:                    assertEquals(2, lines.length);
0434:                    assertEquals("try", lines[0]);
0435:
0436:                    request = new GetMethodWebRequest(
0437:                            "http://localhost:8181/finally?"
0438:                                    + ReservedParameters.CONTID + "="
0439:                                    + lines[1]);
0440:                    response = conversation.getResponse(request);
0441:                    text = response.getText();
0442:                    lines = StringUtils.splitToArray(text, "\n");
0443:                    assertEquals(2, lines.length);
0444:                    assertEquals("catch", lines[0]);
0445:
0446:                    request = new GetMethodWebRequest(
0447:                            "http://localhost:8181/finally?"
0448:                                    + ReservedParameters.CONTID + "="
0449:                                    + lines[1]);
0450:                    response = conversation.getResponse(request);
0451:                    text = response.getText();
0452:                    lines = StringUtils.splitToArray(text, "\n");
0453:                    assertEquals(2, lines.length);
0454:                    assertEquals("finally", lines[0]);
0455:
0456:                    request = new GetMethodWebRequest(
0457:                            "http://localhost:8181/finally?"
0458:                                    + ReservedParameters.CONTID + "="
0459:                                    + lines[1]);
0460:                    response = conversation.getResponse(request);
0461:                    assertEquals("after finally", response.getText());
0462:                } catch (ComparisonFailure e) {
0463:                    throw e;
0464:                } catch (Throwable e) {
0465:                    /* leave this in, since JDK 1.4 compiles finally differently (with JSR/RET opcodes)
0466:                       in that case continuations doesn't work
0467:                       see http://uwyn.com/issues/browse/RIFE-114 */
0468:                    getLogSink().getInternalException().printStackTrace();
0469:                }
0470:            }
0471:
0472:            public void testInstanceOf() throws Exception {
0473:                setupSite("site/continuations.xml");
0474:
0475:                WebConversation conversation = new WebConversation();
0476:                WebRequest request = null;
0477:                WebResponse response = null;
0478:
0479:                request = new GetMethodWebRequest(
0480:                        "http://localhost:8181/instanceof");
0481:                response = conversation.getResponse(request);
0482:
0483:                String text = response.getText();
0484:                String[] lines = StringUtils.splitToArray(text, "\n");
0485:                assertEquals(2, lines.length);
0486:                assertEquals("before instanceof pause", lines[0]);
0487:
0488:                request = new GetMethodWebRequest(
0489:                        "http://localhost:8181/instanceof?"
0490:                                + ReservedParameters.CONTID + "=" + lines[1]);
0491:                response = conversation.getResponse(request);
0492:
0493:                assertEquals("after instanceof pause", response.getText());
0494:            }
0495:
0496:            public void testInnerClass() throws Exception {
0497:                setupSite("site/continuations.xml");
0498:
0499:                WebConversation conversation = new WebConversation();
0500:                WebRequest request = null;
0501:                WebResponse response = null;
0502:
0503:                request = new GetMethodWebRequest(
0504:                        "http://localhost:8181/innerclass");
0505:                response = conversation.getResponse(request);
0506:
0507:                String text = response.getText();
0508:                String[] lines = StringUtils.splitToArray(text, "\n");
0509:                assertEquals(2, lines.length);
0510:                assertEquals("before pause", lines[0]);
0511:
0512:                request = new GetMethodWebRequest(
0513:                        "http://localhost:8181/innerclass?"
0514:                                + ReservedParameters.CONTID + "=" + lines[1]);
0515:                response = conversation.getResponse(request);
0516:
0517:                assertEquals("InnerClass's output", response.getText());
0518:            }
0519:
0520:            public void testAllTypes() throws Exception {
0521:                setupSite("site/continuations.xml");
0522:
0523:                WebConversation conversation = new WebConversation();
0524:                WebRequest request = null;
0525:                WebResponse response = null;
0526:                String text = null;
0527:                String[] lines = null;
0528:
0529:                request = new GetMethodWebRequest(
0530:                        "http://localhost:8181/alltypes");
0531:                response = conversation.getResponse(request);
0532:
0533:                for (int i = 8; i < 40; i++) {
0534:                    text = response.getText();
0535:                    lines = StringUtils.splitToArray(text, "\n");
0536:                    assertEquals(2, lines.length);
0537:                    assertEquals(AllTypes.BEFORE + " while " + i, lines[0]);
0538:
0539:                    request = new GetMethodWebRequest(
0540:                            "http://localhost:8181/alltypes?"
0541:                                    + ReservedParameters.CONTID + "="
0542:                                    + lines[1]);
0543:                    response = conversation.getResponse(request);
0544:                }
0545:
0546:                text = response.getText();
0547:                lines = StringUtils.splitToArray(text, "\n");
0548:                assertEquals(2, lines.length);
0549:                assertEquals(AllTypes.BEFORE + " a", lines[0]);
0550:
0551:                request = new GetMethodWebRequest(
0552:                        "http://localhost:8181/alltypes?"
0553:                                + ReservedParameters.CONTID + "=" + lines[1]);
0554:                response = conversation.getResponse(request);
0555:
0556:                text = response.getText();
0557:                lines = StringUtils.splitToArray(text, "\n");
0558:                assertEquals(2, lines.length);
0559:                assertEquals(AllTypes.BEFORE + " b", lines[0]);
0560:
0561:                request = new GetMethodWebRequest(
0562:                        "http://localhost:8181/alltypes?"
0563:                                + ReservedParameters.CONTID + "=" + lines[1]);
0564:                response = conversation.getResponse(request);
0565:
0566:                text = response.getText();
0567:                lines = StringUtils.splitToArray(text, "\n");
0568:                assertEquals(2, lines.length);
0569:                assertEquals(AllTypes.BEFORE + " c", lines[0]);
0570:
0571:                request = new GetMethodWebRequest(
0572:                        "http://localhost:8181/alltypes?"
0573:                                + ReservedParameters.CONTID + "=" + lines[1]);
0574:                response = conversation.getResponse(request);
0575:
0576:                assertEquals(
0577:                        "40,1209000,11,16,7,8,\n"
0578:                                + "9223372036854775807,0,9223372036854775709,922337203685477570,8,-1,99,\n"
0579:                                + "0.4,8.4,-80.4,-80.0,0.0,-1.0,\n"
0580:                                + "2389.98,2407.3799996185303,-10.0,-1.0,-0.0,2397.3799996185303,\n"
0581:                                + "local ok,some value 6899,\n"
0582:                                + "true|false|false,K|O,54.7|9.8,82324.45|997823.23|87.8998,98|12,8|11,\n"
0583:                                + "111111|444444|666666|999999,111111|444444|666666|999999,333|8888|99,333|66|99,\n"
0584:                                + "zero|one|two|null,zero|one|two|null,ini|mini|moo,\n"
0585:                                + "3:str 0 0|replaced|str 0 2|str 0 3||str 1 0|str 1 1|str 1 2|str 1 3||str 2 0|str 2 1|str 2 2|str 2 3,\n"
0586:                                + "3:str 0 0|replaced|str 0 2|str 0 3||str 1 0|str 1 1|str 1 2|str 1 3||str 2 0|str 2 1|str 2 2|str 2 3,\n"
0587:                                + "2:str 0 0|str 0 1||str 1 0|str 1 1,\n"
0588:                                + "-98|97,-98|97,98|23|11,\n"
0589:                                + "2:0|1|2|3|4||100|101|102|-89|104,\n"
0590:                                + "2:0|1|2|3|4||100|101|102|-89|104,\n"
0591:                                + "3:0|1|2||100|101|102||200|201|202,\n"
0592:                                + "2,4,member ok,8111|8333,2:31|32|33|34||35|36|37|38,\n"
0593:                                + "1,3,static ok,9111|9333,3:1|2|3|4||5|6|7|8||9|10|11|12,\n"
0594:                                + "2,4,member ok,8111|8333,2:31|32|33|34||35|36|37|38,\n"
0595:                                + "1,3,static ok,9111|9333,3:1|2|3|4||5|6|7|8||9|10|11|12,\n"
0596:                                + "100,400,member ok two,8333|8111|23687,1:35|36|37|38,\n"
0597:                                + "60,600,static ok two,23476|9333|9111|8334,2:9|10|11|12||1|2|3|4,\n"
0598:                                + "2:3:3:0|1|2|3|4|5|6|7||10|11|12|13|14|15|16|17||20|21|22|23|24|25|26|27|||100|101|102|103|104|105|106|107||110|111|112|113|114|115|116|117||120|121|122|123|-99|null|126|127,\n"
0599:                                + "2:3:3:0|1|2|3|4|5|6|7||10|11|12|13|14|15|16|17||20|21|22|23|24|25|26|27|||100|101|102|103|104|105|106|107||110|111|112|113|114|115|116|117||120|121|122|123|-99|null|126|127,\n"
0600:                                + "4:1|3||5|7||11|-199||17|19,\n"
0601:                                + "4:1|3||5|7||11|-199||17|19,\n"
0602:                                + "me value 6899,\n"
0603:                                + "2147483647,25,4,109912,118,-2147483648",
0604:                        response.getText());
0605:            }
0606:
0607:            public void testStepBack() throws Exception {
0608:                setupSite("site/continuations.xml");
0609:
0610:                WebConversation conversation = new WebConversation();
0611:                WebRequest request = null;
0612:                WebForm form = null;
0613:
0614:                request = new GetMethodWebRequest(
0615:                        "http://localhost:8181/stepback");
0616:                WebResponse response1 = conversation.getResponse(request);
0617:
0618:                form = response1.getFormWithName("getanswer");
0619:                assertEquals(" : true", response1.getTitle());
0620:                assertNotNull(form);
0621:                form.setCheckbox("start", true);
0622:                WebResponse response2 = form.submit();
0623:                assertEquals("0 : false", response2.getTitle());
0624:
0625:                form = response2.getFormWithName("getanswer");
0626:                assertNotNull(form);
0627:                form.setParameter("answer", "12");
0628:                WebResponse response3 = form.submit();
0629:                assertEquals("12 : true", response3.getTitle());
0630:
0631:                form = response3.getFormWithName("getanswer");
0632:                assertNotNull(form);
0633:                form.setParameter("answer", "32");
0634:                WebResponse response4 = form.submit();
0635:                assertEquals("44 : true", response4.getTitle());
0636:
0637:                form = response4.getFormWithName("getanswer");
0638:                assertNotNull(form);
0639:                form.setParameter("answer", "41");
0640:                WebResponse response5 = form.submit();
0641:                assertEquals("got a total of 85 : false", response5.getTitle());
0642:            }
0643:
0644:            public void testSubmissionForm() throws Exception {
0645:                setupSite("site/continuations.xml");
0646:
0647:                WebConversation conversation = new WebConversation();
0648:                WebRequest request = null;
0649:                WebForm form = null;
0650:
0651:                request = new GetMethodWebRequest(
0652:                        "http://localhost:8181/submission/form");
0653:                WebResponse response1 = conversation.getResponse(request);
0654:
0655:                form = response1.getFormWithName("getanswer");
0656:                assertEquals("0", response1.getTitle());
0657:                assertNotNull(form);
0658:                form.setParameter("answer", "12");
0659:                WebResponse response2 = form.submit();
0660:                assertEquals("12", response2.getTitle());
0661:
0662:                form = response2.getFormWithName("nocontinuations");
0663:                assertNotNull(form);
0664:                form.setParameter("answer", "32");
0665:                WebResponse response3a = form.submit();
0666:                assertEquals("0", response3a.getTitle());
0667:
0668:                form = response2.getFormWithName("getanswer");
0669:                assertNotNull(form);
0670:                form.setParameter("answer", "32");
0671:                WebResponse response3b = form.submit();
0672:                assertEquals("44", response3b.getTitle());
0673:
0674:                form = response3b.getFormWithName("getanswer");
0675:                assertNotNull(form);
0676:                form.setParameter("answer", "41");
0677:                WebResponse response4 = form.submit();
0678:                assertEquals("", response4.getTitle());
0679:
0680:                form = response4.getFormWithName("getanswer");
0681:                assertNull(form);
0682:
0683:                assertEquals("got a total of 85", response4.getText());
0684:            }
0685:
0686:            public void testExitForm() throws Exception {
0687:                setupSite("site/continuations.xml");
0688:
0689:                WebConversation conversation = new WebConversation();
0690:                WebRequest request = null;
0691:                WebForm form = null;
0692:
0693:                request = new GetMethodWebRequest(
0694:                        "http://localhost:8181/exit/form");
0695:                WebResponse response1 = conversation.getResponse(request);
0696:                assertEquals("0", response1.getTitle());
0697:
0698:                form = response1.getFormWithName("getanswer");
0699:                assertNotNull(form);
0700:                form.setParameter("answer", "12");
0701:                WebResponse response2 = form.submit();
0702:                assertEquals("12", response2.getTitle());
0703:
0704:                form = response2.getFormWithName("getanswer");
0705:                assertNotNull(form);
0706:                form.setParameter("answer", "32");
0707:                WebResponse response3a = form.submit();
0708:                assertEquals("44", response3a.getTitle());
0709:
0710:                form = response2.getFormWithName("nocontinuations");
0711:                assertNotNull(form);
0712:                form.setParameter("answer", "32");
0713:                WebResponse response3b = form.submit();
0714:                assertEquals("0", response3b.getTitle());
0715:
0716:                form = response3a.getFormWithName("getanswer");
0717:                assertNotNull(form);
0718:                form.setParameter("answer", "41");
0719:                WebResponse response4 = form.submit();
0720:                assertEquals("", response4.getTitle());
0721:
0722:                form = response4.getFormWithName("getanswer");
0723:                assertNull(form);
0724:
0725:                assertEquals("got a total of 85", response4.getText());
0726:            }
0727:
0728:            public void testSubmissionQuery() throws Exception {
0729:                setupSite("site/continuations.xml");
0730:
0731:                WebConversation conversation = new WebConversation();
0732:                WebRequest request = null;
0733:                WebLink link = null;
0734:                String link_text = null;
0735:
0736:                request = new GetMethodWebRequest(
0737:                        "http://localhost:8181/submission/query");
0738:                WebResponse response1 = conversation.getResponse(request);
0739:
0740:                link = response1.getLinkWith("getanswer");
0741:                assertNotNull(link);
0742:                link_text = link.getURLString() + "&answer=9";
0743:                request = new GetMethodWebRequest("http://localhost:8181"
0744:                        + link_text);
0745:                WebResponse response2 = conversation.getResponse(request);
0746:                assertEquals("9", response2.getTitle());
0747:
0748:                link = response2.getLinkWith("nocontinuations");
0749:                assertNotNull(link);
0750:                link_text = link.getURLString() + "&answer=14";
0751:                request = new GetMethodWebRequest("http://localhost:8181"
0752:                        + link_text);
0753:                WebResponse response3a = conversation.getResponse(request);
0754:                assertEquals("0", response3a.getTitle());
0755:
0756:                link = response2.getLinkWith("getanswer");
0757:                assertNotNull(link);
0758:                link_text = link.getURLString() + "&answer=14";
0759:                request = new GetMethodWebRequest("http://localhost:8181"
0760:                        + link_text);
0761:                WebResponse response3b = conversation.getResponse(request);
0762:                assertEquals("23", response3b.getTitle());
0763:
0764:                link = response3b.getLinkWith("getanswer");
0765:                assertNotNull(link);
0766:                link_text = link.getURLString() + "&answer=89";
0767:                request = new GetMethodWebRequest("http://localhost:8181"
0768:                        + link_text);
0769:                WebResponse response4 = conversation.getResponse(request);
0770:                assertEquals("", response4.getTitle());
0771:
0772:                link = response4.getLinkWith("getanswer");
0773:                assertNull(link);
0774:
0775:                assertEquals("got a total of 112", response4.getText());
0776:            }
0777:
0778:            public void testExitQuery() throws Exception {
0779:                setupSite("site/continuations.xml");
0780:
0781:                WebConversation conversation = new WebConversation();
0782:                WebRequest request = null;
0783:                WebLink link = null;
0784:                String link_text = null;
0785:
0786:                request = new GetMethodWebRequest(
0787:                        "http://localhost:8181/exit/query");
0788:                WebResponse response1 = conversation.getResponse(request);
0789:                assertEquals("0", response1.getTitle());
0790:
0791:                link = response1.getLinkWith("getanswer");
0792:                assertNotNull(link);
0793:                link_text = link.getURLString() + "&answer=9";
0794:                request = new GetMethodWebRequest("http://localhost:8181"
0795:                        + link_text);
0796:                WebResponse response2 = conversation.getResponse(request);
0797:                assertEquals("9", response2.getTitle());
0798:
0799:                link = response2.getLinkWith("getanswer");
0800:                assertNotNull(link);
0801:                link_text = link.getURLString() + "&answer=14";
0802:                request = new GetMethodWebRequest("http://localhost:8181"
0803:                        + link_text);
0804:                WebResponse response3a = conversation.getResponse(request);
0805:                assertEquals("23", response3a.getTitle());
0806:
0807:                link = response2.getLinkWith("nocontinuations");
0808:                assertNotNull(link);
0809:                link_text = link.getURLString() + "?answer=14";
0810:                request = new GetMethodWebRequest("http://localhost:8181"
0811:                        + link_text);
0812:                WebResponse response3b = conversation.getResponse(request);
0813:                assertEquals("0", response3b.getTitle());
0814:
0815:                link = response3a.getLinkWith("getanswer");
0816:                assertNotNull(link);
0817:                link_text = link.getURLString() + "&answer=89";
0818:                request = new GetMethodWebRequest("http://localhost:8181"
0819:                        + link_text);
0820:                WebResponse response4 = conversation.getResponse(request);
0821:                assertEquals("", response4.getTitle());
0822:
0823:                link = response4.getLinkWith("getanswer");
0824:                assertNull(link);
0825:
0826:                assertEquals("got a total of 112", response4.getText());
0827:            }
0828:
0829:            public void testInheritance() throws Exception {
0830:                setupSite("site/continuations.xml");
0831:
0832:                WebConversation conversation = new WebConversation();
0833:                WebRequest request = null;
0834:                WebForm form = null;
0835:                WebLink link = null;
0836:
0837:                request = new GetMethodWebRequest(
0838:                        "http://localhost:8181/inheritance");
0839:                WebResponse response1 = null;
0840:                response1 = conversation.getResponse(request);
0841:
0842:                link = response1.getLinkWith("activate child");
0843:                response1 = link.click();
0844:
0845:                form = response1.getFormWithName("getanswer");
0846:                assertEquals("0", response1.getTitle());
0847:                assertNotNull(form);
0848:                form.setParameter("answer", "12");
0849:                WebResponse response2 = form.submit();
0850:
0851:                link = response2.getLinkWith("activate child");
0852:                response2 = link.click();
0853:
0854:                assertEquals("12", response2.getTitle());
0855:
0856:                form = response2.getFormWithName("getanswer");
0857:                assertNotNull(form);
0858:                form.setParameter("answer", "32");
0859:                WebResponse response3 = form.submit();
0860:
0861:                link = response3.getLinkWith("activate child");
0862:                response3 = link.click();
0863:
0864:                assertEquals("44", response3.getTitle());
0865:
0866:                form = response3.getFormWithName("getanswer");
0867:                assertNotNull(form);
0868:                form.setParameter("answer", "41");
0869:                WebResponse response4 = form.submit();
0870:
0871:                link = response4.getLinkWith("activate child");
0872:                response4 = link.click();
0873:
0874:                form = response4.getFormWithName("getanswer");
0875:                assertNull(form);
0876:
0877:                assertEquals("got a total of 85", response4.getText());
0878:            }
0879:
0880:            public void testUniqueIDPerRequestNoClone() throws Exception {
0881:                setupSite("site/continuations.xml");
0882:
0883:                WebConversation conversation = new WebConversation();
0884:                WebRequest request = null;
0885:
0886:                request = new GetMethodWebRequest(
0887:                        "http://localhost:8181/noclone");
0888:                WebResponse response1 = conversation.getResponse(request);
0889:
0890:                WebForm form1 = response1.getFormWithName("getanswer");
0891:                assertEquals("0", response1.getTitle());
0892:                assertNotNull(form1);
0893:                String cont1 = form1.getParameterValue("contid");
0894:                assertNotNull(cont1);
0895:                form1.setParameter("answer", "12");
0896:
0897:                WebResponse response2 = form1.submit();
0898:                assertEquals("12", response2.getTitle());
0899:                WebForm form2 = response2.getFormWithName("getanswer");
0900:                assertNotNull(form2);
0901:                String cont2 = form2.getParameterValue("contid");
0902:                assertNotNull(cont2);
0903:                assertFalse(cont2.equals(cont1));
0904:                form2.setParameter("answer", "32");
0905:
0906:                WebResponse response3 = form2.submit();
0907:                assertEquals("44", response3.getTitle());
0908:                WebForm form3 = response3.getFormWithName("getanswer");
0909:                assertNotNull(form3);
0910:                String cont3 = form3.getParameterValue("contid");
0911:                assertNotNull(cont3);
0912:                assertFalse(cont3.equals(cont1));
0913:                assertFalse(cont3.equals(cont2));
0914:                form3.setParameter("answer", "41");
0915:
0916:                // check if previous continuation contexts makes the logic
0917:                // start from scratch again
0918:                WebResponse response4 = form1.submit();
0919:                assertEquals("0", response4.getTitle());
0920:                WebForm form4 = response4.getFormWithName("getanswer");
0921:                assertNotNull(form4);
0922:                String cont4 = form4.getParameterValue("contid");
0923:                assertNotNull(cont4);
0924:
0925:                WebResponse response5 = form2.submit();
0926:                assertEquals("0", response5.getTitle());
0927:                WebForm form5 = response5.getFormWithName("getanswer");
0928:                assertNotNull(form5);
0929:                String cont5 = form5.getParameterValue("contid");
0930:                assertNotNull(cont5);
0931:
0932:                // each should have a unique id
0933:                assertFalse(cont4.equals(cont1));
0934:                assertFalse(cont4.equals(cont2));
0935:                assertFalse(cont4.equals(cont3));
0936:                assertFalse(cont4.equals(cont5));
0937:                assertFalse(cont5.equals(cont1));
0938:                assertFalse(cont5.equals(cont2));
0939:                assertFalse(cont5.equals(cont3));
0940:                assertFalse(cont5.equals(cont4));
0941:
0942:                // perform the last step in the calculation
0943:                WebResponse response6 = form3.submit();
0944:                WebForm form6 = response6.getFormWithName("getanswer");
0945:                assertNull(form6);
0946:
0947:                assertEquals("got a total of 85", response6.getText());
0948:            }
0949:
0950:            public void testUniqueIDPerRequestClone() throws Exception {
0951:                setupSite("site/continuations.xml");
0952:
0953:                WebConversation conversation = new WebConversation();
0954:                WebRequest request = null;
0955:
0956:                request = new GetMethodWebRequest("http://localhost:8181/clone");
0957:                WebResponse response1 = conversation.getResponse(request);
0958:
0959:                WebForm form1 = response1.getFormWithName("getanswer");
0960:                assertEquals("0", response1.getTitle());
0961:                assertNotNull(form1);
0962:                String cont1 = form1.getParameterValue("contid");
0963:                assertNotNull(cont1);
0964:                form1.setParameter("answer", "12");
0965:
0966:                WebResponse response2 = form1.submit();
0967:                assertEquals("12", response2.getTitle());
0968:                WebForm form2 = response2.getFormWithName("getanswer");
0969:                assertNotNull(form2);
0970:                String cont2 = form2.getParameterValue("contid");
0971:                assertNotNull(cont2);
0972:                assertFalse(cont2.equals(cont1));
0973:                form2.setParameter("answer", "32");
0974:
0975:                WebResponse response3 = form2.submit();
0976:                assertEquals("44", response3.getTitle());
0977:                WebForm form3 = response3.getFormWithName("getanswer");
0978:                assertNotNull(form3);
0979:                String cont3 = form3.getParameterValue("contid");
0980:                assertNotNull(cont3);
0981:                assertFalse(cont3.equals(cont1));
0982:                assertFalse(cont3.equals(cont2));
0983:                form3.setParameter("answer", "41");
0984:
0985:                // check if previous continuation contexts have been preserved
0986:                // and new ones cloned
0987:                WebResponse response4 = form1.submit();
0988:                assertEquals("12", response4.getTitle());
0989:                WebForm form4 = response4.getFormWithName("getanswer");
0990:                assertNotNull(form4);
0991:                String cont4 = form4.getParameterValue("contid");
0992:                assertNotNull(cont4);
0993:
0994:                WebResponse response5 = form2.submit();
0995:                assertEquals("44", response5.getTitle());
0996:                WebForm form5 = response5.getFormWithName("getanswer");
0997:                assertNotNull(form5);
0998:                String cont5 = form5.getParameterValue("contid");
0999:                assertNotNull(cont5);
1000:
1001:                // each should have a unique id
1002:                assertFalse(cont4.equals(cont1));
1003:                assertFalse(cont4.equals(cont2));
1004:                assertFalse(cont4.equals(cont3));
1005:                assertFalse(cont4.equals(cont5));
1006:                assertFalse(cont5.equals(cont1));
1007:                assertFalse(cont5.equals(cont2));
1008:                assertFalse(cont5.equals(cont3));
1009:                assertFalse(cont5.equals(cont4));
1010:
1011:                // perform the last step in the calculation
1012:                WebResponse response6 = form3.submit();
1013:                WebForm form6 = response6.getFormWithName("getanswer");
1014:                assertNull(form6);
1015:
1016:                assertEquals("got a total of 85", response6.getText());
1017:            }
1018:
1019:            public void testEmbedding() throws Exception {
1020:                setupSite("site/continuations.xml");
1021:
1022:                WebConversation conversation = new WebConversation();
1023:                WebRequest request = null;
1024:                WebResponse response = null;
1025:                WebForm form = null;
1026:
1027:                String hostname = InetAddress.getByName("127.0.0.1")
1028:                        .getHostName();
1029:                String embedded = "Just some text 127.0.0.1:" + hostname
1030:                        + ":.EMBEDDING_EMBEDDED:";
1031:
1032:                request = new GetMethodWebRequest(
1033:                        "http://localhost:8181/embedding");
1034:                response = conversation.getResponse(request);
1035:
1036:                assertEquals(response.getTitle(), embedded);
1037:                form = response.getFormWithName("getanswer");
1038:                assertNotNull(form);
1039:                form.setParameter("answer", "12");
1040:                response = form.submit();
1041:
1042:                assertEquals(response.getTitle(), embedded);
1043:                form = response.getFormWithName("getanswer");
1044:                assertNotNull(form);
1045:                form.setParameter("answer", "32");
1046:                response = form.submit();
1047:
1048:                assertEquals(response.getTitle(), embedded);
1049:                form = response.getFormWithName("getanswer");
1050:                assertNotNull(form);
1051:                form.setParameter("answer", "41");
1052:                response = form.submit();
1053:
1054:                assertEquals(response.getTitle(), "");
1055:                form = response.getFormWithName("getanswer");
1056:                assertNull(form);
1057:
1058:                assertEquals("got a total of 85", response.getText());
1059:            }
1060:
1061:            public void testNumberguess() throws Exception {
1062:                setupSite("site/continuations.xml");
1063:
1064:                WebConversation conversation = new WebConversation();
1065:                WebRequest request = null;
1066:                WebResponse response = null;
1067:                WebForm form = null;
1068:
1069:                int low_bound = 0;
1070:                int high_bound = 100;
1071:                int last_guess = 50;
1072:
1073:                int tries = 0;
1074:
1075:                request = new GetMethodWebRequest(
1076:                        "http://localhost:8181/numberguess");
1077:                response = conversation.getResponse(request);
1078:
1079:                do {
1080:                    form = response.getFormWithName("perform_guess");
1081:                    assertNotNull(form);
1082:                    form.setParameter("guess", String.valueOf(last_guess));
1083:                    response = form.submit();
1084:                    tries++;
1085:
1086:                    String text = response.getText();
1087:                    if (text.indexOf("lower") != -1) {
1088:                        high_bound = last_guess;
1089:                        last_guess = low_bound + (last_guess - low_bound) / 2;
1090:                    } else if (text.indexOf("higher") != -1) {
1091:                        low_bound = last_guess;
1092:                        last_guess = last_guess + (high_bound - last_guess) / 2;
1093:                    }
1094:                } while (response.getTitle().equals("Perform a guess"));
1095:
1096:                String text = response.getText();
1097:                assertTrue(text.indexOf("the answer was " + last_guess) != -1);
1098:                assertTrue(text.indexOf("guessed it in " + tries + " tries") != -1);
1099:            }
1100:
1101:            public void testCallNoAnswer() throws Exception {
1102:                setupSite("site/continuations.xml");
1103:
1104:                WebConversation conversation = new WebConversation();
1105:                WebRequest request = null;
1106:                WebResponse response = null;
1107:
1108:                request = new GetMethodWebRequest(
1109:                        "http://localhost:8181/no_answer");
1110:                response = conversation.getResponse(request);
1111:
1112:                String text = response.getText();
1113:                String[] lines = StringUtils.splitToArray(text, "\n");
1114:                assertEquals(4, lines.length);
1115:                assertEquals("before simple call", lines[0]);
1116:                assertEquals("in exit", lines[2]);
1117:                assertEquals("", lines[3]);
1118:
1119:                request = new GetMethodWebRequest(
1120:                        "http://localhost:8181/no_answer?"
1121:                                + ReservedParameters.CONTID + "=" + lines[1]);
1122:                response = conversation.getResponse(request);
1123:
1124:                assertEquals("after simple call", response.getText());
1125:            }
1126:
1127:            public void testSimpleCall() throws Exception {
1128:                setupSite("site/continuations.xml");
1129:
1130:                WebConversation conversation = new WebConversation();
1131:                WebRequest request = null;
1132:                WebResponse response = null;
1133:
1134:                request = new GetMethodWebRequest(
1135:                        "http://localhost:8181/simple_call");
1136:                response = conversation.getResponse(request);
1137:
1138:                String text = response.getText();
1139:                String[] lines = StringUtils.splitToArray(text, "\n");
1140:                assertEquals(4, lines.length);
1141:                assertEquals("before simple call", lines[0]);
1142:                assertEquals("in exit", lines[2]);
1143:                assertEquals("after simple call", lines[3]);
1144:
1145:                request = new GetMethodWebRequest(
1146:                        "http://localhost:8181/simple_call?"
1147:                                + ReservedParameters.CONTID + "=" + lines[1]);
1148:                response = conversation.getResponse(request);
1149:
1150:                assertEquals("after simple call", response.getText());
1151:            }
1152:
1153:            public void testChainedCall() throws Exception {
1154:                setupSite("site/continuations.xml");
1155:
1156:                WebConversation conversation = new WebConversation();
1157:                WebRequest request = null;
1158:                WebResponse response = null;
1159:
1160:                request = new GetMethodWebRequest(
1161:                        "http://localhost:8181/chained_call1");
1162:                response = conversation.getResponse(request);
1163:
1164:                String text = response.getText();
1165:                String[] lines = StringUtils.splitToArray(text, "\n");
1166:                assertEquals(7, lines.length);
1167:                assertEquals("before chained call 1", lines[0]);
1168:                assertEquals("before chained call 2", lines[2]);
1169:                assertEquals("before chained call 3", lines[4]);
1170:                assertEquals("", lines[6]);
1171:
1172:                request = new GetMethodWebRequest(
1173:                        "http://localhost:8181/chained_call3?"
1174:                                + ReservedParameters.CONTID + "=" + lines[5]);
1175:                response = conversation.getResponse(request);
1176:
1177:                assertEquals("after chained call 3\n"
1178:                        + "after chained call 2\n" + "after chained call 1\n",
1179:                        response.getText());
1180:
1181:                request = new GetMethodWebRequest(
1182:                        "http://localhost:8181/chained_call2?"
1183:                                + ReservedParameters.CONTID + "=" + lines[3]);
1184:                response = conversation.getResponse(request);
1185:
1186:                assertEquals("after chained call 2\n"
1187:                        + "after chained call 1\n", response.getText());
1188:
1189:                request = new GetMethodWebRequest(
1190:                        "http://localhost:8181/chained_call1?"
1191:                                + ReservedParameters.CONTID + "=" + lines[1]);
1192:                response = conversation.getResponse(request);
1193:
1194:                assertEquals("after chained call 1\n", response.getText());
1195:            }
1196:
1197:            public void testCallAnswer() throws Exception {
1198:                setupSite("site/continuations.xml");
1199:
1200:                WebConversation conversation = new WebConversation();
1201:                WebRequest request = null;
1202:                WebResponse response = null;
1203:
1204:                request = new GetMethodWebRequest(
1205:                        "http://localhost:8181/call_answer");
1206:                response = conversation.getResponse(request);
1207:
1208:                String text = response.getText();
1209:                String[] lines = StringUtils.splitToArray(text, "\n");
1210:                assertEquals(6, lines.length);
1211:                assertEquals("before call", lines[0]);
1212:                assertEquals("the data:somevalue", lines[2]);
1213:                assertEquals("before answer", lines[3]);
1214:                assertEquals("the exit's answer", lines[4]);
1215:                assertEquals("after call", lines[5]);
1216:
1217:                request = new GetMethodWebRequest(
1218:                        "http://localhost:8181/call_answer?"
1219:                                + ReservedParameters.CONTID + "=" + lines[1]);
1220:                response = conversation.getResponse(request);
1221:
1222:                assertEquals("after call", response.getText());
1223:            }
1224:
1225:            public void testCallSubmission() throws Exception {
1226:                setupSite("site/continuations.xml");
1227:
1228:                WebConversation conversation = new WebConversation();
1229:                WebRequest request = null;
1230:                WebResponse response = null;
1231:                WebLink link = null;
1232:
1233:                request = new GetMethodWebRequest(
1234:                        "http://localhost:8181/call_submission?input1=value1");
1235:                response = conversation.getResponse(request);
1236:
1237:                link = response.getLinkWith("submission");
1238:                response = link.click();
1239:
1240:                link = response.getLinkWith("yes");
1241:                assertEquals("received yes" + "value1", link.click().getText());
1242:
1243:                link = response.getLinkWith("no");
1244:                assertEquals("received no" + "value1", link.click().getText());
1245:            }
1246:
1247:            public void testCallSubmissionArrival() throws Exception {
1248:                setupSite("site/continuations.xml");
1249:
1250:                WebConversation conversation = new WebConversation();
1251:                WebRequest request = null;
1252:                WebResponse response = null;
1253:                WebLink link = null;
1254:
1255:                request = new GetMethodWebRequest(
1256:                        "http://localhost:8181/?input1=value2");
1257:                response = conversation.getResponse(request);
1258:
1259:                link = response.getLinkWith("submission");
1260:                response = link.click();
1261:
1262:                link = response.getLinkWith("yes");
1263:                assertEquals("received yes" + "value2", link.click().getText());
1264:
1265:                link = response.getLinkWith("no");
1266:                assertEquals("received no" + "value2", link.click().getText());
1267:            }
1268:
1269:            public void testCallSubmissionNoPause() throws Exception {
1270:                setupSite("site/continuations.xml");
1271:
1272:                WebConversation conversation = new WebConversation();
1273:                WebRequest request = null;
1274:                WebResponse response = null;
1275:                WebLink link = null;
1276:
1277:                request = new GetMethodWebRequest(
1278:                        "http://localhost:8181/call_submission/nopause?input1=value1");
1279:                response = conversation.getResponse(request);
1280:
1281:                link = response.getLinkWith("submission");
1282:                response = link.click();
1283:
1284:                link = response.getLinkWith("yes");
1285:                assertEquals("received yes" + "value1", link.click().getText());
1286:
1287:                link = response.getLinkWith("no");
1288:                assertEquals("received no" + "value1", link.click().getText());
1289:            }
1290:
1291:            public void testAnswerWithoutCall() throws Exception {
1292:                setupSite("site/continuations.xml");
1293:                WebConversation conversation = new WebConversation();
1294:                WebRequest request = null;
1295:                WebResponse response = null;
1296:
1297:                request = new GetMethodWebRequest(
1298:                        "http://localhost:8181/answer_without_call");
1299:                response = conversation.getResponse(request);
1300:                assertEquals("the first value" + "2rda-2rdd-2rdc-2rdb",
1301:                        response.getText());
1302:            }
1303:
1304:            public void testCallAnswerGlobalvar() throws Exception {
1305:                setupSite("site/continuations.xml");
1306:
1307:                WebConversation conversation = new WebConversation();
1308:                WebRequest request = null;
1309:                WebResponse response = null;
1310:
1311:                request = new GetMethodWebRequest(
1312:                        "http://localhost:8181/call_answer_globalvar");
1313:                response = conversation.getResponse(request);
1314:
1315:                String text = response.getText();
1316:                String[] lines = StringUtils.splitToArray(text, "\n");
1317:                assertEquals(7, lines.length);
1318:                assertEquals("before call", lines[0]);
1319:                assertEquals("the data:beforecall", lines[2]);
1320:                assertEquals("before answer", lines[3]);
1321:                assertEquals("the exit's answer", lines[4]);
1322:                assertEquals("the data:beforecall,beforeanswer", lines[5]);
1323:                assertEquals("after call", lines[6]);
1324:
1325:                request = new GetMethodWebRequest(
1326:                        "http://localhost:8181/call_answer_globalvar?"
1327:                                + ReservedParameters.CONTID + "=" + lines[1]);
1328:                response = conversation.getResponse(request);
1329:
1330:                // output values aren't part of the state of a continuation, they belong to the response of one particular request
1331:                assertEquals("the data:null\nafter call", response.getText());
1332:            }
1333:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.