1 12 13 package com.openedit.page.manage; 14 import java.io.File ; 15 import java.io.FileReader ; 16 import java.io.IOException ; 17 import java.io.StringWriter ; 18 19 import com.openedit.BaseTestCase; 20 import com.openedit.page.Page; 21 import com.openedit.util.OutputFiller; 22 23 24 29 public class FileSystemPageManagerTest extends BaseTestCase 30 { 31 public static final String PATH_WITH_CONFIG = "withconfig.html"; 32 public static final String PATH_WITH_DEFAULT = "/withdefault/index.html"; 33 public static final String PATH_WITH_MERGE = "/withdefault/merge.html"; 34 public static final String PATH_WITH_SITE = "/withdefault/site/merge.html"; 35 public static final String PATH_WITHOUT_CONFIG = "withoutconfig.html"; 36 public static final String NONEXISTENT_PATH = "this/does/not/exist.html"; 37 public static final String NEW_CONFIG = "<page><hi-mom/></page>"; 38 39 40 public FileSystemPageManagerTest(String inName) 41 { 42 super(inName); 43 } 44 45 50 public void testDirectoryWithDefaultConfig() throws Exception 51 { 52 Page page = getPage(PATH_WITH_DEFAULT); 53 assertNotNull(page); 54 assertEquals( PATH_WITH_DEFAULT, page.getPath() ); 55 } 56 57 74 79 public void testGetPage_Exists() throws Exception 80 { 81 Page page = getPage(PATH_WITH_CONFIG); 82 assertTrue( page.exists() ); 83 assertEquals("/" + PATH_WITH_CONFIG,page.getPath() ); 84 } 85 86 91 public void testGetPage_NoConfig() throws Exception 92 { 93 assertNotNull(getPage(PATH_WITHOUT_CONFIG)); 94 } 95 96 101 public void testGetPage_NoSuchPath() throws Exception 102 { 103 assertNotNull(getPage(NONEXISTENT_PATH)); 104 } 105 106 111 public void testMergeConfig() throws Exception 112 { 113 Page page = getPage(PATH_WITH_MERGE); 114 assertNotNull(page); 115 assertEquals( PATH_WITH_MERGE, page.getPath() ); 116 } 117 public void testSiteXconf() throws Exception 118 { 119 Page page = getPage(PATH_WITH_SITE); 120 assertNotNull(page); 121 assertEquals("subsales", page.get("section")); 122 assertEquals("Open Edit",page.get("productName")); 123 124 assertEquals( PATH_WITH_SITE, page.getPath() ); 125 } 126 public void testRemovePage_NoConfig() throws Exception 127 { 128 PageManager pageManager = getFixture().getPageManager(); 129 pageManager.removePage(getPage(PATH_WITHOUT_CONFIG)); 130 assertTrue(!getConfigFile(PATH_WITHOUT_CONFIG).exists()); 131 } 132 133 134 public void testRemovePage_NoSuchPath() throws Exception 135 { 136 PageManager pageManager = getFixture().getPageManager(); 137 pageManager.removePage(getPage(NONEXISTENT_PATH)); 138 assertTrue(!getConfigFile(NONEXISTENT_PATH).exists()); 139 } 140 141 201 202 public void testSiteConfig() throws Exception 203 { 204 Page withSite = getPage(PATH_WITH_CONFIG); 205 assertNotNull(withSite); 206 assertEquals("Open Edit",withSite.get("productName")); 207 } 208 209 protected File getConfigFile(String inPath) throws Exception 210 { 211 String baseName = inPath; 212 int dotPos = inPath.lastIndexOf("."); 213 214 if (dotPos >= 0) 215 { 216 baseName = inPath.substring(0, dotPos); 217 } 218 219 return new File (getRoot(), baseName + ".xconf"); 220 } 221 222 protected String getFileContents(File inFile) throws IOException 223 { 224 FileReader reader = new FileReader (inFile); 225 StringWriter writer = new StringWriter (); 226 227 try 228 { 229 new OutputFiller().fill(reader, writer); 230 } 231 finally 232 { 233 reader.close(); 234 writer.close(); 235 } 236 237 return writer.toString(); 238 } 239 } 240 | Popular Tags |