Source Code Cross Referenced for StiqSuiteTest.java in  » Testing » StoryTestIQ » fitnesse » html » 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.html 
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.html;
004:
005:        import fitnesse.FitNesseContext;
006:        import fitnesse.runner.SuiteExporter;
007:        import fitnesse.testutil.AbstractRegex;
008:        import fitnesse.util.FileUtil;
009:        import fitnesse.wiki.InMemoryPage;
010:        import fitnesse.wiki.PageCrawler;
011:        import fitnesse.wiki.PageData;
012:        import fitnesse.wiki.PathParser;
013:        import fitnesse.wiki.WikiPage;
014:        import fitnesse.wiki.WikiPagePath;
015:
016:        public class StiqSuiteTest extends AbstractRegex {
017:            private static final String TEST_TWO_PAGE_NAME = "ChildTwo";
018:            private static final String TEST_ONE_PAGE_NAME = "ChildOne";
019:            private static final String SUITE_PAGE_NAME = "SuiTe";
020:            private static final String OUTPUT_DIR = "testDir";
021:            private FitNesseContext context;
022:            private WikiPage root;
023:            private PageCrawler crawler;
024:            private String TITLE_BEGIN = "<title>";
025:            private String TITLE_END = "</title>";
026:
027:            public void setUp() throws Exception {
028:                root = InMemoryPage.makeRoot("RooT");
029:                crawler = root.getPageCrawler();
030:            }
031:
032:            public void testCreateSuiteBadPageName() throws Exception {
033:                String badPageName = "BadPageName";
034:                WikiPagePath wikiPagePath = PathParser.parse(badPageName);
035:                context = getTypicalSuiteContext();
036:                try {
037:                    StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
038:                    stiqSuite.cleanHtml();
039:                    fail("Attempt to create a StiqSuite with a bad page name should throw an exception.");
040:                } catch (Exception e) {
041:                    assertNotNull(e);
042:                    String message = e.getMessage();
043:                    assertNotNull(message);
044:                    assertSubString("Unable to locate Wiki Page ["
045:                            + badPageName + "] in repository.", message);
046:                }
047:            }
048:
049:            public void testCreateSuiteBadPageNameEmptyString()
050:                    throws Exception {
051:                String badPageName = "";
052:                WikiPagePath wikiPagePath = PathParser.parse(badPageName);
053:                context = getTypicalSuiteContext();
054:                try {
055:                    StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
056:                    stiqSuite.cleanHtml();
057:                    fail("Attempt to create a StiqSuite with a empty page name should throw an exception.");
058:                } catch (IllegalArgumentException e) {
059:                    assertNotNull(e);
060:                    String message = e.getMessage();
061:                    assertNotNull(message);
062:                    assertSubString("Unable to locate Wiki Page ["
063:                            + badPageName + "] in repository.", message);
064:                }
065:            }
066:
067:            public void testWriteTestsTypicalSuite() throws Exception {
068:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
069:                context = getTypicalSuiteContext();
070:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
071:
072:                FileUtil.makeDir(OUTPUT_DIR);
073:                stiqSuite.writeTests(OUTPUT_DIR);
074:
075:                String testName = SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME;
076:                String testFileName = testName + SuiteExporter.FILE_EXTENSION;
077:                String testFilePath = OUTPUT_DIR + "/" + testFileName;
078:                String testContents = FileUtil.getFileContent(testFilePath);
079:                String pageTitle = TITLE_BEGIN + testName + TITLE_END;
080:                assertSubString(pageTitle, testContents);
081:
082:                testName = SUITE_PAGE_NAME + "." + TEST_TWO_PAGE_NAME;
083:                testFileName = testName + SuiteExporter.FILE_EXTENSION;
084:                testFilePath = OUTPUT_DIR + "/" + testFileName;
085:                testContents = FileUtil.getFileContent(testFilePath);
086:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
087:                assertSubString(pageTitle, testContents);
088:
089:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
090:            }
091:
092:            public void testWriteSuiteTypicalSuite() throws Exception {
093:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
094:                context = getTypicalSuiteContext();
095:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
096:
097:                FileUtil.makeDir(OUTPUT_DIR);
098:                stiqSuite.writeSuite(OUTPUT_DIR);
099:
100:                String suiteFilePath = OUTPUT_DIR + "/" + SUITE_PAGE_NAME
101:                        + SuiteExporter.FILE_EXTENSION;
102:                String suiteContents = FileUtil.getFileContent(suiteFilePath);
103:                String pageTitle = TITLE_BEGIN + SUITE_PAGE_NAME + TITLE_END;
104:                assertSubString(pageTitle, suiteContents);
105:
106:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
107:            }
108:
109:            public void testWriteSuiteLocalizesLinks() throws Exception {
110:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
111:                context = getTypicalSuiteContext();
112:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
113:
114:                FileUtil.makeDir(OUTPUT_DIR);
115:                stiqSuite.writeSuite(OUTPUT_DIR);
116:
117:                String suiteFilePath = OUTPUT_DIR + "/" + SUITE_PAGE_NAME
118:                        + SuiteExporter.FILE_EXTENSION;
119:                String suiteContents = FileUtil.getFileContent(suiteFilePath);
120:
121:                String testLink = SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME
122:                        + SuiteExporter.FILE_EXTENSION;
123:                assertSubString(testLink, suiteContents);
124:                testLink = SUITE_PAGE_NAME + "." + TEST_TWO_PAGE_NAME
125:                        + SuiteExporter.FILE_EXTENSION;
126:                assertSubString(testLink, suiteContents);
127:
128:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
129:            }
130:
131:            public void testPrepareHtmlForExport() throws Exception {
132:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
133:                context = getTypicalSuiteContext();
134:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
135:
136:                FileUtil.makeDir(OUTPUT_DIR);
137:                stiqSuite.writeSuite(OUTPUT_DIR);
138:
139:                String suiteFilePath = OUTPUT_DIR + "/" + SUITE_PAGE_NAME
140:                        + SuiteExporter.FILE_EXTENSION;
141:                String suiteContents = FileUtil.getFileContent(suiteFilePath);
142:
143:                // Verify the stuff we expect is there
144:                String pageTitle = TITLE_BEGIN + SUITE_PAGE_NAME + TITLE_END;
145:                assertSubString(pageTitle, suiteContents);
146:                String testName = SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME;
147:                String testFileName = testName + SuiteExporter.FILE_EXTENSION;
148:                assertSubString(testFileName, suiteContents);
149:
150:                // All the stuff we don't want should be gone
151:                String docType = "<!DOCTYPE HTML PUBLIC ";
152:                assertNotSubString(docType, suiteContents);
153:
154:                String linkTags = "<link rel=\"stylesheet";
155:                assertNotSubString(linkTags, suiteContents);
156:
157:                String scriptTags = "<script src=\"/files/";
158:                assertNotSubString(scriptTags, suiteContents);
159:
160:                String actionsStart = "<div class=\"actions\"";
161:                assertNotSubString(actionsStart, suiteContents);
162:
163:                String actionsEnd = "id=\"RefreshTool\" class=\"toolbarImage\"/></a></div>";
164:                assertNotSubString(actionsEnd, suiteContents);
165:
166:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
167:            }
168:
169:            public void testWriteSuiteAndTestsTypicalSuite() throws Exception {
170:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
171:                context = getTypicalSuiteContext();
172:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
173:
174:                FileUtil.makeDir(OUTPUT_DIR);
175:                stiqSuite.writeSuiteAndTests(OUTPUT_DIR);
176:
177:                String suiteFilePath = OUTPUT_DIR + "/" + SUITE_PAGE_NAME
178:                        + SuiteExporter.FILE_EXTENSION;
179:                String suiteContents = FileUtil.getFileContent(suiteFilePath);
180:                String pageTitle = TITLE_BEGIN + SUITE_PAGE_NAME + TITLE_END;
181:                assertSubString(pageTitle, suiteContents);
182:
183:                String testName = SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME;
184:                String testFileName = testName + SuiteExporter.FILE_EXTENSION;
185:                String testFilePath = OUTPUT_DIR + "/" + testFileName;
186:                String testContents = FileUtil.getFileContent(testFilePath);
187:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
188:                assertSubString(pageTitle, testContents);
189:
190:                testName = SUITE_PAGE_NAME + "." + TEST_TWO_PAGE_NAME;
191:                testFileName = testName + SuiteExporter.FILE_EXTENSION;
192:                testFilePath = OUTPUT_DIR + "/" + testFileName;
193:                testContents = FileUtil.getFileContent(testFilePath);
194:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
195:                assertSubString(pageTitle, testContents);
196:
197:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
198:            }
199:
200:            public void testGetWikiPageName() throws Exception {
201:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
202:
203:                StiqSuite stiqSuite = new StiqSuite(getTypicalSuiteContext(),
204:                        wikiPagePath);
205:                assertEquals(wikiPagePath, stiqSuite.getWikiPagePath());
206:            }
207:
208:            public void testGetTestsTypicalSuite() throws Exception {
209:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
210:                context = getTypicalSuiteContext();
211:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
212:
213:                StiqTest[] tests = stiqSuite.getTests();
214:                String pagePath = SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME;
215:                assertEquals(pagePath, tests[0].getWikiPageName());
216:                String pageTitle = TITLE_BEGIN + pagePath + TITLE_END;
217:                assertSubString(pageTitle, tests[0].getHtml());
218:
219:                pagePath = SUITE_PAGE_NAME + "." + TEST_TWO_PAGE_NAME;
220:                assertEquals(pagePath, tests[1].getWikiPageName());
221:                pageTitle = TITLE_BEGIN + pagePath + TITLE_END;
222:                assertSubString(pageTitle, tests[1].getHtml());
223:            }
224:
225:            public void testLocalizeTestLinks() throws Exception {
226:
227:                WikiPagePath wikiPagePath = PathParser.parse(SUITE_PAGE_NAME);
228:                context = getTypicalSuiteContext();
229:                StiqSuite stiqSuite = new StiqSuite(context, wikiPagePath);
230:
231:                String htmlWithLocalizedTestLinks = "";
232:                htmlWithLocalizedTestLinks = stiqSuite.localizeTestLinks();
233:
234:                String localizedTestLink = "<a href=\"" + SUITE_PAGE_NAME + "."
235:                        + TEST_TWO_PAGE_NAME + SuiteExporter.FILE_EXTENSION
236:                        + "\">";
237:                assertSubString(localizedTestLink, htmlWithLocalizedTestLinks);
238:
239:            }
240:
241:            // Get Test Links
242:            public void testGetTestLinksEmptySuite() throws Exception {
243:                WikiPagePath pagePath = PathParser.parse(SUITE_PAGE_NAME);
244:                StiqSuite stiqSuite = new StiqSuite(getEmptySuiteContext(),
245:                        pagePath);
246:                String[] testLinks = stiqSuite.getTestLinks();
247:                assertNotNull(testLinks);
248:                assertEquals(0, testLinks.length);
249:            }
250:
251:            public void testGetTestLinksSingleTestSuite() throws Exception {
252:                WikiPagePath pagePath = PathParser.parse(SUITE_PAGE_NAME);
253:                StiqSuite stiqSuite = new StiqSuite(
254:                        getSingleTestSuiteContext(), pagePath);
255:                String[] testLinks = stiqSuite.getTestLinks();
256:                assertNotNull(testLinks);
257:                assertEquals(SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME,
258:                        testLinks[0]);
259:            }
260:
261:            public void testGetTestLinksTypicalSuite() throws Exception {
262:                WikiPagePath pagePath = PathParser.parse(SUITE_PAGE_NAME);
263:                StiqSuite stiqSuite = new StiqSuite(getTypicalSuiteContext(),
264:                        pagePath);
265:                String[] testLinks = stiqSuite.getTestLinks();
266:                assertEquals(SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME,
267:                        testLinks[0]);
268:                assertEquals(SUITE_PAGE_NAME + "." + TEST_TWO_PAGE_NAME,
269:                        testLinks[1]);
270:            }
271:
272:            public void testMakeStiqTestFromLink() throws Exception {
273:                WikiPagePath suiteWikiPagePath = PathParser
274:                        .parse(SUITE_PAGE_NAME);
275:                context = getTypicalSuiteContext();
276:                StiqSuite stiqSuite = new StiqSuite(context, suiteWikiPagePath);
277:                String[] testLinks = stiqSuite.getTestLinks();
278:
279:                String testPagePath = testLinks[0];
280:                WikiPagePath testWikiPagePath = PathParser.parse(testPagePath);
281:                assertEquals(SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME,
282:                        testPagePath);
283:                StiqTest stiqTest = new StiqTest(context, testWikiPagePath);
284:                assertEquals(stiqTest.getWikiPageName(), testPagePath);
285:            }
286:
287:            //
288:            // Helper methods
289:            //
290:            private FitNesseContext getEmptySuiteContext() throws Exception {
291:                String parentName = SUITE_PAGE_NAME;
292:                crawler.addPage(root, PathParser.parse(parentName), "!suite");
293:                return new FitNesseContext(root);
294:            }
295:
296:            private FitNesseContext getSingleTestSuiteContext()
297:                    throws Exception {
298:                String parentName = SUITE_PAGE_NAME;
299:                WikiPage parentOne = crawler.addPage(root, PathParser
300:                        .parse(parentName), "!suite");
301:                setSTIQTestProperty(crawler.addPage(parentOne, PathParser
302:                        .parse(TEST_ONE_PAGE_NAME), "a test"));
303:                return new FitNesseContext(root);
304:            }
305:
306:            private FitNesseContext getTypicalSuiteContext() throws Exception {
307:                String parentName = SUITE_PAGE_NAME;
308:                WikiPage parentOne = crawler.addPage(root, PathParser
309:                        .parse(parentName), "!suite");
310:                setSTIQTestProperty(crawler.addPage(parentOne, PathParser
311:                        .parse(TEST_ONE_PAGE_NAME), "a test"));
312:                setSTIQTestProperty(crawler.addPage(parentOne, PathParser
313:                        .parse(TEST_TWO_PAGE_NAME), "a test"));
314:                crawler.addPage(parentOne, PathParser.parse("ChildThree"),
315:                        "nothing");
316:                return new FitNesseContext(root);
317:            }
318:
319:            private WikiPage setSTIQTestProperty(WikiPage page)
320:                    throws Exception {
321:                PageData pageDataToModify = page.getData();
322:                pageDataToModify.getProperties().set(WikiPage.STIQ_TEST);
323:                page.commit(pageDataToModify);
324:                assertTrue(page.isSTIQTest());
325:                return page;
326:            }
327:
328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.