Source Code Cross Referenced for FitNesseExpediterTest.java in  » Testing » StoryTestIQ » fitnesse » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


001:        // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:        package fitnesse;
004:
005:        import fitnesse.testutil.*;
006:        import fitnesse.http.*;
007:        import fitnesse.wiki.InMemoryPage;
008:        import fitnesse.responders.*;
009:        import fitnesse.authentication.Authenticator;
010:        import java.io.*;
011:
012:        public class FitNesseExpediterTest extends AbstractRegex {
013:            private FitNesseExpediter expediter;
014:
015:            private MockSocket socket;
016:
017:            private FitNesseContext context;
018:
019:            private InMemoryPage root;
020:
021:            PipedInputStream clientInput;
022:
023:            private PipedOutputStream clientOutput;
024:
025:            ResponseParser response;
026:
027:            public void setUp() throws Exception {
028:                root = (InMemoryPage) InMemoryPage.makeRoot("RooT");
029:                root.addChildPage("FrontPage");
030:                socket = new MockSocket();
031:                context = new FitNesseContext(root);
032:                context.responderFactory = new ResponderFactory(".");
033:                expediter = new FitNesseExpediter(socket, context);
034:            }
035:
036:            public void tearDown() throws Exception {
037:            }
038:
039:            public void testAuthenticationGetsCalled() throws Exception {
040:                context.authenticator = new StoneWallAuthenticator();
041:                MockRequest request = new MockRequest();
042:                Response response = expediter.createGoodResponse(request);
043:                assertEquals(401, response.getStatus());
044:            }
045:
046:            public void testClosedSocketMidResponse() throws Exception {
047:                try {
048:                    MockRequest request = new MockRequest();
049:                    Response response = expediter.createGoodResponse(request);
050:                    socket.close();
051:                    response.readyToSend(expediter);
052:                } catch (IOException e) {
053:                    fail("no IOException should be thrown");
054:                }
055:            }
056:
057:            public void testIncompleteRequestsTimeOut() throws Exception {
058:                final FitNesseExpediter sender = preparePipedFitNesseExpediter();
059:
060:                Thread senderThread = makeSendingThread(sender);
061:                senderThread.start();
062:                Thread parseResponseThread = makeParsingThread();
063:                parseResponseThread.start();
064:                Thread.sleep(sender.requestParsingTimeLimit + 100);
065:
066:                parseResponseThread.join();
067:
068:                assertEquals(408, response.getStatus());
069:            }
070:
071:            private FitNesseExpediter preparePipedFitNesseExpediter()
072:                    throws Exception {
073:                PipedInputStream socketInput = new PipedInputStream();
074:                clientOutput = new PipedOutputStream(socketInput);
075:                clientInput = new PipedInputStream();
076:                PipedOutputStream socketOutput = new PipedOutputStream(
077:                        clientInput);
078:                MockSocket socket = new MockSocket(socketInput, socketOutput);
079:                final FitNesseExpediter sender = new FitNesseExpediter(socket,
080:                        context);
081:                sender.requestParsingTimeLimit = 200;
082:                return sender;
083:            }
084:
085:            public void testCompleteRequest() throws Exception {
086:                final FitNesseExpediter sender = preparePipedFitNesseExpediter();
087:
088:                Thread senderThread = makeSendingThread(sender);
089:                senderThread.start();
090:                Thread parseResponseThread = makeParsingThread();
091:                parseResponseThread.start();
092:
093:                clientOutput.write("GET /root HTTP/1.1\r\n\r\n".getBytes());
094:                clientOutput.flush();
095:
096:                parseResponseThread.join();
097:
098:                assertEquals(200, response.getStatus());
099:            }
100:
101:            public void testSlowButCompleteRequest() throws Exception {
102:                final FitNesseExpediter sender = preparePipedFitNesseExpediter();
103:
104:                Thread senderThread = makeSendingThread(sender);
105:                senderThread.start();
106:                Thread parseResponseThread = makeParsingThread();
107:                parseResponseThread.start();
108:
109:                byte[] bytes = "GET /root HTTP/1.1\r\n\r\n".getBytes();
110:                try {
111:                    for (int i = 0; i < bytes.length; i++) {
112:                        byte aByte = bytes[i];
113:                        clientOutput.write(aByte);
114:                        clientOutput.flush();
115:                        Thread.sleep(20);
116:                    }
117:                } catch (IOException pipedClosed) {
118:                }
119:
120:                parseResponseThread.join();
121:
122:                assertEquals(200, response.getStatus());
123:            }
124:
125:            private Thread makeSendingThread(final FitNesseExpediter sender) {
126:                Thread senderThread = new Thread(new Runnable() {
127:                    public void run() {
128:                        try {
129:                            sender.start();
130:                        } catch (Exception e) {
131:                            e.printStackTrace();
132:                        }
133:                    }
134:                });
135:                return senderThread;
136:            }
137:
138:            private Thread makeParsingThread() {
139:                Thread parseResponseThread = new Thread(new Runnable() {
140:                    public void run() {
141:                        try {
142:                            response = new ResponseParser(clientInput);
143:                        } catch (Exception e) {
144:                            e.printStackTrace();
145:                        }
146:                    }
147:                });
148:                return parseResponseThread;
149:            }
150:
151:            class StoneWallAuthenticator extends Authenticator {
152:                public Responder authenticate(FitNesseContext context,
153:                        Request request, Responder privilegedResponder)
154:                        throws Exception {
155:                    return new UnauthorizedResponder();
156:                }
157:
158:                public boolean isAuthenticated(String username, String password) {
159:                    return false;
160:                }
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.