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.components;
004:
005: import fitnesse.wiki.*;
006: import fitnesse.testutil.*;
007: import fitnesse.util.WildcardTest;
008:
009: public class ClassPathBuilderTest extends AbstractRegex {
010: private WikiPage root;
011:
012: private ClassPathBuilder builder;
013:
014: String pathSeparator = System.getProperty("path.separator");
015:
016: private PageCrawler crawler;
017:
018: private WikiPagePath somePagePath;
019:
020: public void setUp() throws Exception {
021: root = InMemoryPage.makeRoot("RooT");
022: crawler = root.getPageCrawler();
023: builder = new ClassPathBuilder();
024: somePagePath = PathParser.parse("SomePage");
025: }
026:
027: public void testGetClasspath() throws Exception {
028: crawler.addPage(root, PathParser.parse("TestPage"),
029: "!path fitnesse.jar\n" + "!path my.jar");
030: String expected = "fitnesse.jar" + pathSeparator + "my.jar";
031: assertEquals(expected, builder.getClasspath(root
032: .getChildPage("TestPage")));
033: }
034:
035: public void testGetPaths_OneLevel() throws Exception {
036: String pageContent = "This is some content\n" + "!path aPath\n"
037: + "end of conent\n";
038: WikiPage root = InMemoryPage.makeRoot("RooT");
039: WikiPage page = crawler.addPage(root, PathParser
040: .parse("ClassPath"), pageContent);
041: String path = builder.getClasspath(page);
042: assertEquals("aPath", path);
043: }
044:
045: public void testGetClassPathMultiLevel() throws Exception {
046: WikiPage root = InMemoryPage.makeRoot("RooT");
047: crawler.addPage(root, PathParser.parse("ProjectOne"),
048: "!path path2\n" + "!path path 3");
049: crawler.addPage(root, PathParser.parse("ProjectOne.TesT"),
050: "!path path1");
051:
052: String cp = builder.getClasspath(crawler.getPage(root,
053: PathParser.parse("ProjectOne.TesT")));
054: assertSubString("path1", cp);
055: assertSubString("path2", cp);
056: assertSubString("\"path 3\"", cp);
057: }
058:
059: public void testLinearClassPath() throws Exception {
060: WikiPage root = InMemoryPage.makeRoot("RooT");
061: WikiPage super Page = crawler.addPage(root, PathParser
062: .parse("SuperPage"), "!path superPagePath");
063: WikiPage subPage = crawler.addPage(super Page, PathParser
064: .parse("SubPage"), "!path subPagePath");
065: String cp = builder.getClasspath(subPage);
066: assertEquals("subPagePath" + pathSeparator + "superPagePath",
067: cp);
068:
069: }
070:
071: public void testGetClassPathFromPageThatDoesntExist()
072: throws Exception {
073: String classPath = makeClassPathFromSimpleStructure("somePath");
074:
075: assertEquals("somePath", classPath);
076: }
077:
078: private String makeClassPathFromSimpleStructure(String path)
079: throws Exception {
080: PageData data = root.getData();
081: data.setContent("!path " + path);
082: root.commit(data);
083: crawler = root.getPageCrawler();
084: crawler.setDeadEndStrategy(new MockingPageCrawler());
085: WikiPage page = crawler.getPage(root, somePagePath);
086: String classPath = builder.getClasspath(page);
087: return classPath;
088: }
089:
090: public void testThatPathsWithSpacesGetQuoted() throws Exception {
091: crawler.addPage(root, somePagePath, "!path Some File.jar");
092: crawler = root.getPageCrawler();
093: crawler.setDeadEndStrategy(new MockingPageCrawler());
094: WikiPage page = crawler.getPage(root, somePagePath);
095:
096: assertEquals("\"Some File.jar\"", builder.getClasspath(page));
097:
098: crawler.addPage(root, somePagePath,
099: "!path somefile.jar\n!path Some Dir/someFile.jar");
100: assertEquals("somefile.jar" + pathSeparator
101: + "\"Some Dir/someFile.jar\"", builder
102: .getClasspath(page));
103: }
104:
105: public void testWildCardExpansion() throws Exception {
106: try {
107: WildcardTest.makeSampleFiles();
108:
109: String classPath = makeClassPathFromSimpleStructure("testDir/*.jar");
110: assertHasRegexp("one\\.jar", classPath);
111: assertHasRegexp("two\\.jar", classPath);
112:
113: classPath = makeClassPathFromSimpleStructure("testDir/*.dll");
114: assertHasRegexp("one\\.dll", classPath);
115: assertHasRegexp("two\\.dll", classPath);
116:
117: classPath = makeClassPathFromSimpleStructure("testDir/one*");
118: assertHasRegexp("one\\.dll", classPath);
119: assertHasRegexp("one\\.jar", classPath);
120: assertHasRegexp("oneA", classPath);
121: } finally {
122: WildcardTest.deleteSampleFiles();
123: }
124: }
125: }
|