Source Code Cross Referenced for FitNesseServerTest.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 java.util.regex.Pattern;
006:
007:        import fitnesse.components.LogData;
008:        import fitnesse.http.MockRequest;
009:        import fitnesse.http.SimpleResponse;
010:        import fitnesse.responders.ResponderFactory;
011:        import fitnesse.responders.files.SampleFileUtility;
012:        import fitnesse.testutil.AbstractRegex;
013:        import fitnesse.testutil.MockSocket;
014:        import fitnesse.util.FileUtil;
015:        import fitnesse.wiki.InMemoryPage;
016:        import fitnesse.wiki.MockWikiPage;
017:        import fitnesse.wiki.PageCrawler;
018:        import fitnesse.wiki.PathParser;
019:        import fitnesse.wiki.WikiPage;
020:        import fitnesse.wiki.WikiPagePath;
021:
022:        public class FitNesseServerTest extends AbstractRegex {
023:            private PageCrawler crawler;
024:
025:            private WikiPage root;
026:
027:            private WikiPagePath pageOnePath;
028:
029:            private WikiPagePath pageOneTwoPath;
030:
031:            public FitNesseServerTest() {
032:            }
033:
034:            public void setUp() throws Exception {
035:                SampleFileUtility.makeSampleFiles();
036:                root = InMemoryPage.makeRoot("RootPage");
037:                crawler = root.getPageCrawler();
038:                pageOnePath = PathParser.parse("PageOne");
039:                pageOneTwoPath = PathParser.parse("PageOne.PageTwo");
040:            }
041:
042:            public void tearDown() throws Exception {
043:                FileUtil
044:                        .deleteFileSystemDirectory(SampleFileUtility.TEMP_TEST_DIR);
045:            }
046:
047:            public void testSimple() throws Exception {
048:                crawler.addPage(root, PathParser.parse("SomePage"),
049:                        "some string");
050:                String output = getSocketOutput(
051:                        "GET /SomePage HTTP/1.1\r\n\r\n", root);
052:                String statusLine = "HTTP/1.1 200 OK\r\n";
053:                assertTrue("Should have statusLine", Pattern.compile(
054:                        statusLine, Pattern.MULTILINE).matcher(output).find());
055:                assertTrue("Should have canned Content", hasSubString(
056:                        "some string", output));
057:            }
058:
059:            public void testNotFound() throws Exception {
060:                String output = getSocketOutput(
061:                        "GET /WikiWord HTTP/1.1\r\n\r\n", new MockWikiPage());
062:
063:                assertSubString("404 Not Found", output);
064:            }
065:
066:            public void testBadRequest() throws Exception {
067:                String output = getSocketOutput("Bad Request \r\n\r\n",
068:                        new MockWikiPage());
069:
070:                assertSubString("400 Bad Request", output);
071:                assertSubString(
072:                        "The request string is malformed and can not be parsed",
073:                        output);
074:            }
075:
076:            public void testFrontPageRequest() throws Exception {
077:                crawler.addPage(root, PathParser.parse("FrontPage"),
078:                        "This is the FrontPage content");
079:                String output = getSocketOutput("GET / HTTP/1.1\r\n\r\n", root);
080:                String expected = "This is the .* content";
081:                assertTrue("Should have content",
082:                        hasSubString(expected, output));
083:            }
084:
085:            public void testSomeOtherPage() throws Exception {
086:                crawler.addPage(root, pageOnePath, "Page One Content");
087:                String output = getSocketOutput(
088:                        "GET /PageOne HTTP/1.1\r\n\r\n", root);
089:                String expected = "Page One Content";
090:                assertTrue("Should have page one", hasSubString(expected,
091:                        output));
092:            }
093:
094:            public void testSecondLevelPage() throws Exception {
095:                crawler.addPage(root, pageOnePath, "Page One Content");
096:                crawler.addPage(root, pageOneTwoPath, "Page Two Content");
097:                String output = getSocketOutput(
098:                        "GET /PageOne.PageTwo HTTP/1.1\r\n\r\n", root);
099:
100:                String expected = "Page Two Content";
101:                assertTrue("Should have page Two", hasSubString(expected,
102:                        output));
103:            }
104:
105:            public void testRelativeAndAbsoluteLinks() throws Exception {
106:                WikiPage root = InMemoryPage.makeRoot("RootPage");
107:                crawler.addPage(root, pageOnePath, "PageOne");
108:                crawler.addPage(root, pageOneTwoPath, "PageTwo");
109:                String output = getSocketOutput(
110:                        "GET /PageOne.PageTwo HTTP/1.1\r\n\r\n", root);
111:                String expected = "href=\"PageOne.PageTwo\".*PageTwo";
112:                assertTrue("Should have relative link", hasSubString(expected,
113:                        output));
114:
115:                crawler.addPage(root, PathParser.parse("PageTwo"),
116:                        "PageTwo at root");
117:                crawler.addPage(root, PathParser.parse("PageOne.PageThree"),
118:                        "PageThree has link to .PageTwo at the root");
119:                output = getSocketOutput(
120:                        "GET /PageOne.PageThree HTTP/1.1\r\n\r\n", root);
121:                expected = "href=\"PageTwo\".*[.]PageTwo";
122:                assertTrue("Should have absolute link", hasSubString(expected,
123:                        output));
124:            }
125:
126:            // Removed since /files is now served from jar on classpath
127:            public void XtestServingRegularFiles() throws Exception {
128:                String output = getSocketOutput(
129:                        "GET /files/testDir/testFile2 HTTP/1.1\r\n\r\n",
130:                        new MockWikiPage());
131:                assertHasRegexp("file2 content", output);
132:            }
133:
134:            public void testLoggingDataCreation() throws Exception {
135:                MockRequest request = new MockRequest();
136:                SimpleResponse response = new SimpleResponse(200);
137:                MockSocket socket = new MockSocket("something");
138:
139:                socket.setHost("1.2.3.4");
140:                request.setRequestLine("GET / HTTP/1.1");
141:                response.setContent("abc");
142:
143:                LogData data = FitNesseExpediter.makeLogData(socket, request,
144:                        response);
145:
146:                assertEquals("1.2.3.4", data.host);
147:                assertNotNull(data.time);
148:                assertEquals("GET / HTTP/1.1", data.requestLine);
149:                assertEquals(200, data.status);
150:                assertEquals(3, data.size);
151:            }
152:
153:            public void xtestVirtualDirectoryCreation() {
154:                String output = "";
155:                try {
156:                    output = getSocketFitnessiumOutput("GET /fitnessium/TestRunner.hta HTTP/1.1\r\n\r\n");
157:                } catch (Exception e) {
158:                    // TODO Auto-generated catch block
159:                    e.printStackTrace();
160:                }
161:                assertHasRegexp("STIQ", output);
162:            }
163:
164:            private String getSocketFitnessiumOutput(String requestLine)
165:                    throws Exception {
166:                MockSocket s = new MockSocket(requestLine);
167:                FitNesseContext context = new FitNesseContext();
168:                context.rootPagePath = SampleFileUtility.TEMP_TEST_DIR;
169:                context.responderFactory = new ResponderFactory(
170:                        SampleFileUtility.TEMP_TEST_DIR);
171:                FitNesseServer server = new FitNesseServer(context);
172:                server.serve(s, 1000);
173:                String output = s.getOutput();
174:                return output;
175:            }
176:
177:            private String getSocketOutput(String requestLine, WikiPage page)
178:                    throws Exception {
179:                MockSocket s = new MockSocket(requestLine);
180:                FitNesseContext context = new FitNesseContext();
181:                context.rootPagePath = SampleFileUtility.TEMP_TEST_DIR;
182:                context.responderFactory = new ResponderFactory(
183:                        SampleFileUtility.TEMP_TEST_DIR);
184:                context.root = page;
185:                FitNesseServer server = new FitNesseServer(context);
186:                server.serve(s, 1000);
187:                String output = s.getOutput();
188:                return output;
189:            }
190:
191:            private static boolean hasSubString(String expected, String output) {
192:                return Pattern.compile(expected, Pattern.MULTILINE).matcher(
193:                        output).find();
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.