01: package fitnesse.updates;
02:
03: import fitnesse.wiki.*;
04: import fitnesse.util.FileUtil;
05: import java.io.*;
06:
07: public class SymLinkPropertyFormatUpdateTest extends UpdateTest {
08: private static String badPropertiesFormat = "<?xml version=\"1.0\"?>\n"
09: + "<properties>\n"
10: + " <Edit/>\n"
11: + " <symbolicLink>\n"
12: + " <name>SomePage</name>\n"
13: + " <path>RecentChanges</path>\n"
14: + " </symbolicLink>\n"
15: + " <symbolicLink>\n"
16: + " <name>PageTwo</name>\n"
17: + " <path>PageHeader</path>\n"
18: + " </symbolicLink>\n" + "</properties>";
19:
20: private void setupPropertiesFilesThatNeedsFixing() throws Exception {
21: PageData data = pageOne.getData();
22: WikiPageProperties properties = new WikiPageProperties();
23: properties.loadFromXmlStream(new ByteArrayInputStream(
24: badPropertiesFormat.getBytes()));
25: data.setProperties(properties);
26: pageOne.commit(data);
27:
28: File propertiesFile = getSamplePropertiesFile();
29: FileUtil.createFile(propertiesFile, badPropertiesFormat);
30: }
31:
32: private File getSamplePropertiesFile() throws Exception {
33: FileSystemPage page = (FileSystemPage) pageOne;
34: return new File(page.getFileSystemPath()
35: + FileSystemPage.propertiesFilename);
36: }
37:
38: public void testPropertiesFixed() throws Exception {
39: setupPropertiesFilesThatNeedsFixing();
40: update.doUpdate();
41:
42: String newContent = FileUtil
43: .getFileContent(getSamplePropertiesFile());
44: newContent = newContent.replace("\r", "");
45:
46: WikiPageProperties properties = pageOne.getData()
47: .getProperties();
48: assertFalse(properties.has("symbolicLink"));
49: assertTrue(properties.has(SymbolicPage.PROPERTY_NAME));
50: assertEquals("RecentChanges", properties.getProperty(
51: SymbolicPage.PROPERTY_NAME).get("SomePage"));
52: assertEquals("PageHeader", properties.getProperty(
53: SymbolicPage.PROPERTY_NAME).get("PageTwo"));
54: assertTrue(properties.has("Edit"));
55: }
56:
57: protected Update makeUpdate() throws Exception {
58: return new SymLinkPropertyFormatUpdate(updater);
59: }
60: }
|