Source Code Cross Referenced for IncludeWidgetTest.java in  » Testing » StoryTestIQ » fitnesse » wikitext » widgets » 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.wikitext.widgets 
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.wikitext.widgets;
004:
005:        import fitnesse.html.HtmlUtil;
006:        import fitnesse.testutil.FitNesseUtil;
007:        import fitnesse.wiki.*;
008:        import fitnesse.wikitext.WidgetBuilder;
009:
010:        public class IncludeWidgetTest extends AbstractWidget {
011:
012:            protected WikiPage root;
013:
014:            protected WikiPage page1;
015:
016:            protected PageCrawler crawler;
017:
018:            public void setUp() throws Exception {
019:                root = InMemoryPage.makeRoot("RooT");
020:                crawler = root.getPageCrawler();
021:                crawler.setDeadEndStrategy(new VirtualEnabledPageCrawler());
022:                page1 = crawler.addPage(root, PathParser.parse("PageOne"),
023:                        "page one");
024:                crawler.addPage(root, PathParser.parse("PageTwo"),
025:                        "page '''two'''");
026:                crawler.addPage(root, PathParser.parse("PageTwo.ChildOne"),
027:                        "child page");
028:            }
029:
030:            public void tearDown() throws Exception {
031:            }
032:
033:            private IncludeWidget createIncludeWidget(WikiPage wikiPage,
034:                    String includedPageName) throws Exception {
035:                return createIncludeWidget(new WidgetRoot(wikiPage),
036:                        includedPageName);
037:            }
038:
039:            private IncludeWidget createIncludeWidget(WidgetRoot widgetRoot,
040:                    String includedPageName) throws Exception {
041:                return new IncludeWidget(widgetRoot, "!include "
042:                        + includedPageName);
043:            }
044:
045:            protected String getRegexp() {
046:                return IncludeWidget.REGEXP;
047:            }
048:
049:            public void testIsCollapsable() throws Exception {
050:                IncludeWidget widget = createIncludeWidget(page1, "PageOne");
051:                final String result = widget.render();
052:                assertSubString("class=\"collapsable\"", result);
053:            }
054:
055:            public void testSeamlessIsNotCollapsable() throws Exception {
056:                IncludeWidget widget = createIncludeWidget(page1,
057:                        "-seamless PageOne");
058:                final String result = widget.render();
059:                assertNotSubString("class=\"collapsable\"", result);
060:            }
061:
062:            public void testRegexp() throws Exception {
063:                assertMatchEquals("!include SomePage", "!include SomePage");
064:                assertMatchEquals("!include SomePage\n", "!include SomePage\n");
065:                assertMatchEquals("abc\n" + "!include SomePage\nxyz",
066:                        "!include SomePage\n");
067:                assertMatchEquals("!include .SomePage.ChildPage",
068:                        "!include .SomePage.ChildPage");
069:                assertNoMatch("!include nonWikiWord");
070:                assertNoMatch(" " + "!include WikiWord");
071:            }
072:
073:            public void testRegexpWithOptions() throws Exception {
074:                assertMatchEquals("!include -setup SomePage",
075:                        "!include -setup SomePage");
076:                assertMatchEquals("!include  -setup SomePage",
077:                        "!include  -setup SomePage");
078:                assertMatchEquals("!include -teardown SomePage",
079:                        "!include -teardown SomePage");
080:                assertMatchEquals("!include  -teardown SomePage",
081:                        "!include  -teardown SomePage");
082:                assertMatchEquals("!include -seamless SomePage",
083:                        "!include -seamless SomePage");
084:                assertMatchEquals("!include  -seamless SomePage",
085:                        "!include  -seamless SomePage");
086:            }
087:
088:            public void testSetUpParts() throws Exception {
089:                IncludeWidget widget = new IncludeWidget(new WidgetRoot(root),
090:                        "!include -setup SomePage");
091:                assertSubString("class=\"setup\"", widget.render());
092:                assertSubString("Set Up: ", widget.render());
093:            }
094:
095:            public void testTearDownParts() throws Exception {
096:                IncludeWidget widget = new IncludeWidget(new WidgetRoot(root),
097:                        "!include -teardown SomePage");
098:                assertSubString("class=\"teardown\"", widget.render());
099:                assertSubString("Tear Down: ", widget.render());
100:            }
101:
102:            public void testLiteralsGetRendered() throws Exception {
103:                verifyLiteralsGetRendered("", "LiteralPage");
104:            }
105:
106:            public void testLiteralsGetRenderedSeamless() throws Exception {
107:                verifyLiteralsGetRendered("-seamless ", "LiteralPage");
108:            }
109:
110:            private void verifyLiteralsGetRendered(String option,
111:                    String pageName) throws Exception {
112:                crawler.addPage(root, PathParser.parse(pageName),
113:                        "!-one-!, !-two-!, !-three-!");
114:                WidgetRoot widgetRoot = new WidgetRoot(page1);
115:                IncludeWidget widget = createIncludeWidget(widgetRoot, option
116:                        + pageName);
117:                final String result = widget.render();
118:                assertSubString("one, two, three", result);
119:                assertEquals("one", widgetRoot.getLiteral(0));
120:                assertEquals("two", widgetRoot.getLiteral(1));
121:                assertEquals("three", widgetRoot.getLiteral(2));
122:            }
123:
124:            public void testRenderWhenMissing() throws Exception {
125:                verifyRenderWhenMissing("MissingPage");
126:            }
127:
128:            public void testRenderWhenMissingSeamless() throws Exception {
129:                verifyRenderWhenMissing("-seamless MissingPage");
130:            }
131:
132:            private void verifyRenderWhenMissing(String optionAndPageName)
133:                    throws Exception {
134:                IncludeWidget widget = createIncludeWidget(page1,
135:                        optionAndPageName);
136:                assertHasRegexp("MissingPage.*does not exist", widget.render());
137:            }
138:
139:            public void testNoNullPointerWhenIncludingFromRootPage()
140:                    throws Exception {
141:                verifyNoNullPointerWhenIncludingFromRootPage(".PageOne");
142:            }
143:
144:            public void testNoNullPointerWhenIncludingFromRootPageSeamless()
145:                    throws Exception {
146:                verifyNoNullPointerWhenIncludingFromRootPage("-seamless .PageOne");
147:            }
148:
149:            private void verifyNoNullPointerWhenIncludingFromRootPage(
150:                    String optionAndPageName) throws Exception {
151:                IncludeWidget widget = createIncludeWidget(root,
152:                        optionAndPageName);
153:                assertHasRegexp("page one", widget.render());
154:            }
155:
156:            public void testIncludingVariables() throws Exception {
157:                verifyIncludingVariables("");
158:            }
159:
160:            public void testIncludingVariablesSeamless() throws Exception {
161:                verifyIncludingVariables("-seamless ");
162:            }
163:
164:            private void verifyIncludingVariables(String option)
165:                    throws Exception {
166:                crawler.addPage(root, PathParser.parse("VariablePage"),
167:                        "This is VariablePage\n!define X {blah!}\n");
168:                crawler.addPage(root, PathParser.parse("IncludingPage"));
169:                WidgetRoot widgetRoot = new WidgetRoot(
170:                        "This is IncludingPage\n" + "!include " + option
171:                                + ".VariablePage\nX=${X}", root
172:                                .getChildPage("IncludingPage"),
173:                        WidgetBuilder.htmlWidgetBuilder);
174:                String content = widgetRoot.render();
175:                assertHasRegexp("X=blah!", content);
176:            }
177:
178:            public void testVirtualIncludeNotFound() throws Exception {
179:                verifyVirtualIncludeNotFound("IncludedPage");
180:            }
181:
182:            public void testVirtualIncludeNotFoundSeamless() throws Exception {
183:                verifyVirtualIncludeNotFound("-seamless IncludedPage");
184:            }
185:
186:            private void verifyVirtualIncludeNotFound(String optionAndPageName)
187:                    throws Exception {
188:                ProxyPage virtualPage = new ProxyPage("VirtualPage", root,
189:                        "localhost", 9999, PathParser
190:                                .parse("RealPage.VirtualPage"));
191:                IncludeWidget widget = createIncludeWidget(virtualPage,
192:                        optionAndPageName);
193:                String output = widget.render();
194:                assertHasRegexp("IncludedPage.* does not exist", output);
195:            }
196:
197:            public void testVirtualInclude() throws Exception {
198:                String virtualWikiURL = "http://localhost:" + FitNesseUtil.port
199:                        + "/PageTwo";
200:                VirtualCouplingExtensionTest.setVirtualWiki(page1,
201:                        virtualWikiURL);
202:                FitNesseUtil.startFitnesse(root);
203:                try {
204:                    IncludeWidget widget = createIncludeWidget(page1,
205:                            ".PageOne.ChildOne");
206:                    String result = widget.render();
207:                    verifySubstrings(new String[] { "child page",
208:                            ".PageOne.ChildOne" }, result);
209:                } finally {
210:                    FitNesseUtil.stopFitnesse();
211:                }
212:            }
213:
214:            public void testDeepVirtualInclude() throws Exception {
215:                WikiPagePath atPath = PathParser.parse("AcceptanceTestPage");
216:                WikiPagePath includedPagePath = PathParser
217:                        .parse("AcceptanceTestPage.IncludedPage");
218:                WikiPagePath includingPagePath = PathParser
219:                        .parse("AcceptanceTestPage.IncludingPage");
220:                WikiPagePath childOfIncludingPagePath = PathParser
221:                        .parse("AcceptanceTestPage.IncludingPage.ChildIncludingPage");
222:                crawler.addPage(root, atPath);
223:                crawler.addPage(root, includedPagePath, "included page");
224:                crawler.addPage(root, includingPagePath,
225:                        "!include .AcceptanceTestPage.IncludedPage");
226:                crawler.addPage(root, childOfIncludingPagePath,
227:                        "!include .AcceptanceTestPage.IncludedPage");
228:
229:                String virtualWikiURL = "http://localhost:" + FitNesseUtil.port
230:                        + "/AcceptanceTestPage";
231:                WikiPage alternateRoot = InMemoryPage.makeRoot("RooT");
232:                WikiPagePath virtualPagePath = PathParser.parse("VirtualPage");
233:                WikiPage virtualHost = crawler.addPage(alternateRoot,
234:                        virtualPagePath, "virtual host\n!contents\n");
235:                VirtualCouplingExtensionTest.setVirtualWiki(virtualHost,
236:                        virtualWikiURL);
237:
238:                FitNesseUtil.startFitnesse(root);
239:                try {
240:                    WikiPage virtualChild = crawler.getPage(alternateRoot,
241:                            PathParser.parse("VirtualPage.IncludingPage"));
242:                    PageData data = virtualChild.getData();
243:                    String result = data.getHtml();
244:                    verifySubstrings(new String[] { "included page",
245:                            "AcceptanceTestPage.IncludedPage" }, result);
246:                } finally {
247:                    FitNesseUtil.stopFitnesse();
248:                }
249:            }
250:
251:            public void testRenderIncludedSibling() throws Exception {
252:                IncludeWidget widget = createIncludeWidget(page1, "PageOne");
253:                final String result = widget.render();
254:                verifyRegexes(new String[] { "page one", ".*PageOne" }, result);
255:            }
256:
257:            public void testRenderIncludedSiblingSeamless() throws Exception {
258:                IncludeWidget widget = createIncludeWidget(page1,
259:                        "-seamless PageOne");
260:                final String result = widget.render();
261:                verifySubstrings(new String[] { "page one" + HtmlUtil.BR },
262:                        result);
263:            }
264:
265:            public void testRenderIncludedNephew() throws Exception {
266:                IncludeWidget widget = createIncludeWidget(page1,
267:                        ".PageTwo.ChildOne");
268:                String result = widget.render();
269:                verifyRegexes(
270:                        new String[] { "child page", "class=\"included\"" },
271:                        result);
272:            }
273:
274:            private void verifySubstrings(String[] subStrings, String result) {
275:                for (int i = 0; i < subStrings.length; i++) {
276:                    assertSubString(subStrings[i], result);
277:                }
278:            }
279:
280:            private void verifyRegexes(String[] regexes, String result) {
281:                for (int i = 0; i < regexes.length; i++) {
282:                    assertHasRegexp(regexes[i], result);
283:                }
284:            }
285:
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.