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