package fitnesse.wiki;
import fitnesse.ComponentFactory;
import fitnesse.WikiPageFactory;
import util.FileSystem;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import util.MemoryFileSystem;
public class PageRepositoryTest {
private FileSystem fileSystem;
private PageRepository pageRepository;
private FileSystemPage rootPage;
@Before
public void SetUp() throws Exception {
fileSystem = new MemoryFileSystem();
pageRepository = new PageRepository(fileSystem);
rootPage = (FileSystemPage)new WikiPageFactory(fileSystem).makeRootPage(".", "somepath", new ComponentFactory()) ;
}
@Test
public void DirectoryOfHtmlFilesIsExternalSuitePage() throws Exception {
fileSystem.makeFile("./somepath/ExternalSuite/myfile.html", "stuff");
WikiPage page = pageRepository.makeChildPage("ExternalSuite", rootPage);
assertEquals(ExternalSuitePage.class, page.getClass());
}
@Test
public void DirectoryOfDirectoryOfHtmlFilesIsExternalSuitePage() throws Exception {
fileSystem.makeFile("./somepath/ExternalSuite/subsuite/myfile.html", "stuff");
WikiPage page = pageRepository.makeChildPage("ExternalSuite", rootPage);
assertEquals(ExternalSuitePage.class, page.getClass());
}
@Test
public void DirectoryWithoutHtmlFilesIsFileSystemPage() throws Exception {
fileSystem.makeFile("./somepath/WikiPage/myfile.txt", "stuff");
fileSystem.makeFile("./somepath/OtherPage/myfile.html", "stuff");
WikiPage page = pageRepository.makeChildPage("WikiPage", rootPage);
assertEquals(FileSystemPage.class, page.getClass());
}
@Test
public void DirectoryWithContentIsFileSystemPage() throws Exception {
fileSystem.makeFile("./somepath/WikiPage/content.txt", "stuff");
fileSystem.makeFile("./somepath/WikiPage/subsuite/myfile.html", "stuff");
WikiPage page = pageRepository.makeChildPage("WikiPage", rootPage);
assertEquals(FileSystemPage.class, page.getClass());
}
@Test
public void HtmlFileIsExternalSuitePageChild() throws Exception {
fileSystem.makeFile("./somepath/ExternalSuite/myfile.html", "stuff");
ExternalSuitePage page = (ExternalSuitePage)pageRepository.makeChildPage("ExternalSuite", rootPage);
WikiPage child = pageRepository.findChildren(page).get(0);
assertEquals(ExternalTestPage.class, child.getClass());
assertEquals("MyfilE", child.getName());
}
@Test
public void DirectoryOfHtmlFilesIsExternalSuitePageChild() throws Exception {
fileSystem.makeFile("./somepath/ExternalSuite/subsuite/myfile.html", "stuff");
ExternalSuitePage page = (ExternalSuitePage)pageRepository.makeChildPage("ExternalSuite", rootPage);
WikiPage child = pageRepository.findChildren(page).get(0);
assertEquals(ExternalSuitePage.class, child.getClass());
assertEquals("SubsuitE", child.getName());
}
}