Source Code Cross Referenced for SuiteExporterTest.java in  » Testing » StoryTestIQ » fitnesse » runner » 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.runner 
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.runner;
004:
005:        import fitnesse.Arguments;
006:        import fitnesse.ComponentFactory;
007:        import fitnesse.FitNesseContext;
008:        import fitnesse.SuiteExporterArguments;
009:        import fitnesse.testutil.AbstractRegex;
010:        import fitnesse.util.FileUtil;
011:        import fitnesse.wiki.FileSystemPage;
012:        import fitnesse.wiki.InMemoryPage;
013:        import fitnesse.wiki.PageCrawler;
014:        import fitnesse.wiki.PageData;
015:        import fitnesse.wiki.PathParser;
016:        import fitnesse.wiki.WikiPage;
017:
018:        public class SuiteExporterTest extends AbstractRegex {
019:            private FitNesseContext context;
020:            private WikiPage root;
021:            private PageCrawler crawler;
022:
023:            private static final String SUITE_WIKI_PAGE_PATH = "IntegrationTests";
024:            private static final String USER_PASSWORD = "default:pass";
025:            private static final String ROOT_DIRECTORY = "theRoot";
026:            private static final String ROOT_PATH = "theDir";
027:            private static final int EXPIRATION_DAYS = 42;
028:            private static final int PORT = SuiteExporter.DEFAULT_PORT;
029:
030:            private static final String SUITE_PAGE_NAME = "SuiTe";
031:            private static final String TEST_TWO_PAGE_NAME = "ChildTwo";
032:            private static final String TEST_ONE_PAGE_NAME = "ChildOne";
033:            private static final String OUTPUT_DIR = "testDir";
034:            private static final String NESTING_PARENT = "NestingParent";
035:            private String TITLE_BEGIN = "<title>";
036:            private String TITLE_END = "</title>";
037:
038:            protected void setUp() throws Exception {
039:                root = InMemoryPage.makeRoot("RooT");
040:                crawler = root.getPageCrawler();
041:            }
042:
043:            // ExportSuite
044:            public void testExportSuite() throws Exception {
045:                context = getTypicalSuiteContext();
046:                SuiteExporter suiteExporter = new SuiteExporter(context);
047:
048:                FileUtil.makeDir(OUTPUT_DIR);
049:                suiteExporter.exportSuite(SUITE_PAGE_NAME, OUTPUT_DIR);
050:
051:                String suiteFilePath = OUTPUT_DIR + "/" + SUITE_PAGE_NAME
052:                        + SuiteExporter.FILE_EXTENSION;
053:                String suiteContents = FileUtil.getFileContent(suiteFilePath);
054:                String pageTitle = TITLE_BEGIN + SUITE_PAGE_NAME + TITLE_END;
055:                assertSubString(pageTitle, suiteContents);
056:
057:                String testName = SUITE_PAGE_NAME + "." + TEST_ONE_PAGE_NAME;
058:                String testFileName = testName + SuiteExporter.FILE_EXTENSION;
059:                String testFilePath = OUTPUT_DIR + "/" + testFileName;
060:                String testContents = FileUtil.getFileContent(testFilePath);
061:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
062:                assertSubString(pageTitle, testContents);
063:
064:                testName = SUITE_PAGE_NAME + "." + TEST_TWO_PAGE_NAME;
065:                testFileName = testName + SuiteExporter.FILE_EXTENSION;
066:                testFilePath = OUTPUT_DIR + "/" + testFileName;
067:                testContents = FileUtil.getFileContent(testFilePath);
068:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
069:                assertSubString(pageTitle, testContents);
070:
071:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
072:            }
073:
074:            public void testExportSuiteBadPageNameDoesNotThrowException()
075:                    throws Exception {
076:                context = getTypicalSuiteContext();
077:                SuiteExporter suiteExporter = new SuiteExporter(context);
078:
079:                String badPageName = "JunK";
080:                FileUtil.makeDir(OUTPUT_DIR);
081:                try {
082:                    suiteExporter.exportSuite(badPageName, OUTPUT_DIR);
083:                } catch (IllegalArgumentException e) {
084:                    String message = e.getMessage();
085:                    assertSubString("Unable to locate Wiki Page ["
086:                            + badPageName + "] in repository.", message);
087:                }
088:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
089:            }
090:
091:            public void testExportSuiteNestedPage() throws Exception {
092:                context = getNestedSuiteContext();
093:                SuiteExporter suiteExporter = new SuiteExporter(context);
094:
095:                FileUtil.makeDir(OUTPUT_DIR);
096:                String nestedSuiteName = SUITE_PAGE_NAME + "." + NESTING_PARENT;
097:                suiteExporter.exportSuite(nestedSuiteName, OUTPUT_DIR);
098:
099:                String suiteFilePath = OUTPUT_DIR + "/" + nestedSuiteName
100:                        + SuiteExporter.FILE_EXTENSION;
101:                String suiteContents = FileUtil.getFileContent(suiteFilePath);
102:                String pageTitle = TITLE_BEGIN + nestedSuiteName + TITLE_END;
103:                assertSubString(pageTitle, suiteContents);
104:
105:                String testName = nestedSuiteName + "." + TEST_ONE_PAGE_NAME;
106:                String testFileName = testName + SuiteExporter.FILE_EXTENSION;
107:                String testFilePath = OUTPUT_DIR + "/" + testFileName;
108:                String testContents = FileUtil.getFileContent(testFilePath);
109:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
110:                assertSubString(pageTitle, testContents);
111:
112:                testName = nestedSuiteName + "." + TEST_TWO_PAGE_NAME;
113:                testFileName = testName + SuiteExporter.FILE_EXTENSION;
114:                testFilePath = OUTPUT_DIR + "/" + testFileName;
115:                testContents = FileUtil.getFileContent(testFilePath);
116:                pageTitle = TITLE_BEGIN + testName + TITLE_END;
117:                assertSubString(pageTitle, testContents);
118:
119:                FileUtil.deleteFileSystemDirectory(OUTPUT_DIR);
120:            }
121:
122:            // ParseCommandLine
123:            public void testParseCommandLineAllArguments() throws Exception {
124:                String[] argArray = getAllArgumentsArray();
125:                SuiteExporterArguments arguments = SuiteExporter
126:                        .parseCommandLine(argArray);
127:                assertEquals(PORT, arguments.getPort());
128:                assertEquals(ROOT_PATH, arguments.getRootPath());
129:                assertEquals(ROOT_DIRECTORY, arguments.getRootDirectory());
130:                assertEquals(EXPIRATION_DAYS, arguments
131:                        .getDaysTillVersionsExpire());
132:                assertEquals(true, arguments.isOmittingUpdates());
133:                assertEquals(USER_PASSWORD, arguments.getUserpass());
134:                assertEquals(SUITE_WIKI_PAGE_PATH, arguments
135:                        .getSuiteWikiPagePath());
136:                assertEquals(OUTPUT_DIR, arguments.getOutputDir());
137:            }
138:
139:            public void testParseCommandLineExportPagePathArgument()
140:                    throws Exception {
141:                String[] argArray = { "-" + SuiteExporter.OPTION_SUITE,
142:                        SUITE_WIKI_PAGE_PATH };
143:                SuiteExporterArguments arguments = SuiteExporter
144:                        .parseCommandLine(argArray);
145:                assertEquals(SUITE_WIKI_PAGE_PATH, arguments
146:                        .getSuiteWikiPagePath());
147:            }
148:
149:            public void testParseCommandLineOutputFilePathArgument()
150:                    throws Exception {
151:                String[] argArray = { "-" + SuiteExporter.OPTION_DIR,
152:                        OUTPUT_DIR };
153:                SuiteExporterArguments arguments = SuiteExporter
154:                        .parseCommandLine(argArray);
155:                assertEquals(OUTPUT_DIR, arguments.getOutputDir());
156:            }
157:
158:            public void testParseCommandLineDefaultValues() throws Exception {
159:                String[] argArray = {};
160:                SuiteExporterArguments arguments = SuiteExporter
161:                        .parseCommandLine(argArray);
162:                assertEquals(Arguments.DEFAULT_PORT, arguments.getPort());
163:                assertEquals(Arguments.DEFAULT_ROOT, arguments
164:                        .getRootDirectory());
165:            }
166:
167:            public void testParseCommandLineExportPagePathDefault()
168:                    throws Exception {
169:                String[] argArray = {};
170:                SuiteExporterArguments arguments = SuiteExporter
171:                        .parseCommandLine(argArray);
172:                assertEquals(
173:                        SuiteExporterArguments.DEFAULT_SUITE_WIKI_PAGE_PATH,
174:                        arguments.getSuiteWikiPagePath());
175:            }
176:
177:            public void testParseCommandLineOutputFilePathDefault()
178:                    throws Exception {
179:                String[] argArray = {};
180:                SuiteExporterArguments arguments = SuiteExporter
181:                        .parseCommandLine(argArray);
182:                assertEquals(SuiteExporterArguments.DEFAULT_OUTPUT_DIR,
183:                        arguments.getOutputDir());
184:            }
185:
186:            // LoadContext
187:            public void testLoadContext() throws Exception {
188:                context = getSimpleContext();
189:                SuiteExporterArguments arguments = getAllArguments();
190:                FitNesseContext context = SuiteExporter.loadContext(arguments);
191:                assertEquals(PORT, context.port);
192:                assertEquals(ROOT_PATH, context.rootPath);
193:                assertEquals(ROOT_DIRECTORY, context.rootPageName);
194:                assertEquals(ROOT_PATH + "/" + ROOT_DIRECTORY,
195:                        context.rootPagePath);
196:
197:                ComponentFactory componentFactory = new ComponentFactory(
198:                        ROOT_PATH);
199:                WikiPage rootWikiPage = componentFactory
200:                        .getRootPage(FileSystemPage.makeRoot(ROOT_PATH,
201:                                ROOT_DIRECTORY));
202:                assertEquals(rootWikiPage.getName(), context.root.getName());
203:
204:                // There are additional context parameters that are very hard for non-FitNesse folks to test
205:                // which have been passed over herewith...
206:                //		MockRequest request = new MockRequest();
207:                //		request.setResource("SimplePage");
208:                //		ResponderFactory responderFactory = new ResponderFactory(ROOT_PATH + "/" + ROOT_DIRECTORY);
209:                //		WikiPageResponder expectedResponder = (WikiPageResponder)responderFactory.makeResponder(request, rootWikiPage);
210:                //		WikiPageResponder actualResponder = (WikiPageResponder)context.responderFactory.makeResponder(request, rootWikiPage);
211:                //		assertEquals(expectedResponder.makeHtml(context), actualResponder.makeHtml(context));
212:            }
213:
214:            public void testLoadContextWithMinArguments() throws Exception {
215:                context = getSimpleContext();
216:                SuiteExporterArguments arguments = getMinArguments();
217:                FitNesseContext context = SuiteExporter.loadContext(arguments);
218:                assertEquals(PORT, context.port);
219:                assertEquals(ROOT_DIRECTORY, context.rootPageName);
220:
221:                ComponentFactory componentFactory = new ComponentFactory(
222:                        ROOT_PATH);
223:                WikiPage rootWikiPage = componentFactory
224:                        .getRootPage(FileSystemPage.makeRoot(ROOT_PATH,
225:                                ROOT_DIRECTORY));
226:                assertEquals(rootWikiPage.getName(), context.root.getName());
227:            }
228:
229:            private SuiteExporterArguments getMinArguments() {
230:                return SuiteExporter.parseCommandLine(getMinArgumentsArray());
231:            }
232:
233:            //
234:            // Helper methods
235:            //
236:            private String[] getAllArgumentsArray() {
237:                String[] args = { "-p", String.valueOf(PORT), "-d", ROOT_PATH,
238:                        "-r", ROOT_DIRECTORY, "-e",
239:                        String.valueOf(EXPIRATION_DAYS), "-o", "-a",
240:                        USER_PASSWORD, "-" + SuiteExporter.OPTION_SUITE,
241:                        SUITE_WIKI_PAGE_PATH, "-" + SuiteExporter.OPTION_DIR,
242:                        OUTPUT_DIR };
243:                return args;
244:            }
245:
246:            private String[] getMinArgumentsArray() {
247:                String[] args = { "-p", String.valueOf(PORT), "-r",
248:                        ROOT_DIRECTORY, "-" + SuiteExporter.OPTION_SUITE,
249:                        SUITE_WIKI_PAGE_PATH, "-" + SuiteExporter.OPTION_DIR,
250:                        OUTPUT_DIR };
251:                return args;
252:            }
253:
254:            private SuiteExporterArguments getAllArguments() {
255:                return SuiteExporter.parseCommandLine(getAllArgumentsArray());
256:            }
257:
258:            private FitNesseContext getSimpleContext() throws Exception {
259:                String pageName = "SimplePage";
260:                this .crawler.addPage(root, PathParser.parse(pageName),
261:                        "empty content");
262:                return new FitNesseContext(root);
263:            }
264:
265:            private FitNesseContext getTypicalSuiteContext() throws Exception {
266:                WikiPage parentOne = crawler.addPage(root, PathParser
267:                        .parse(SUITE_PAGE_NAME), "!suite");
268:                setSTIQTestProperty(crawler.addPage(parentOne, PathParser
269:                        .parse(TEST_ONE_PAGE_NAME), "a test"));
270:                setSTIQTestProperty(crawler.addPage(parentOne, PathParser
271:                        .parse(TEST_TWO_PAGE_NAME), "a test"));
272:                crawler.addPage(parentOne, PathParser.parse("ChildThree"),
273:                        "nothing");
274:                return new FitNesseContext(root);
275:            }
276:
277:            private FitNesseContext getNestedSuiteContext() throws Exception {
278:                WikiPage parentOne = crawler.addPage(root, PathParser
279:                        .parse(SUITE_PAGE_NAME), "nesting parent");
280:                WikiPage parentTwo = crawler.addPage(parentOne, PathParser
281:                        .parse(NESTING_PARENT), "!suite");
282:                setSTIQTestProperty(crawler.addPage(parentTwo, PathParser
283:                        .parse(TEST_ONE_PAGE_NAME), "a test"));
284:                setSTIQTestProperty(crawler.addPage(parentTwo, PathParser
285:                        .parse(TEST_TWO_PAGE_NAME), "a test"));
286:                crawler.addPage(parentTwo, PathParser.parse("ChildThree"),
287:                        "nothing");
288:                return new FitNesseContext(root);
289:            }
290:
291:            private WikiPage setSTIQTestProperty(WikiPage page)
292:                    throws Exception {
293:                PageData pageDataToModify = page.getData();
294:                pageDataToModify.getProperties().set(WikiPage.STIQ_TEST);
295:                page.commit(pageDataToModify);
296:                assertTrue(page.isSTIQTest());
297:                return page;
298:            }
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.