PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/atlassian/uwc/converters/dokuwiki/HierarchyLinkConverterTest.java

https://bitbucket.org/atlassianlabs/universal-wiki-connector
Java | 216 lines | 194 code | 22 blank | 0 comment | 0 complexity | dcd4dfa82bb3ec7c295db3e7f8b3effa MD5 | raw file
  1. package com.atlassian.uwc.converters.dokuwiki;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Properties;
  5. import junit.framework.TestCase;
  6. import org.apache.log4j.Logger;
  7. import org.apache.log4j.PropertyConfigurator;
  8. import com.atlassian.uwc.ui.FileUtils;
  9. import com.atlassian.uwc.ui.Page;
  10. import com.atlassian.uwc.ui.VersionPage;
  11. public class HierarchyLinkConverterTest extends TestCase {
  12. HierarchyLinkConverter tester = null;
  13. Logger log = Logger.getLogger(this.getClass());
  14. protected void setUp() throws Exception {
  15. tester = new HierarchyLinkConverter();
  16. tester.clear();
  17. PropertyConfigurator.configure("log4j.properties");
  18. Properties props = new Properties();
  19. props.setProperty("spacekey", "food");
  20. props.setProperty("collision-titles-food", "Apple,Fruit");
  21. props.setProperty("collision-titles-otherspace", "Testing 123");
  22. props.setProperty("space-food","food,drink");
  23. props.setProperty("space-otherspace","otherspace");
  24. props.setProperty("space-abcdef", "abc_def");
  25. props.put("filepath-hierarchy-ext", "");
  26. props.put("filepath-hierarchy-ignorable-ancestors", "sampleData/hierarchy/dokuwiki");
  27. tester.setProperties(props);
  28. tester.getProperties().setProperty("meta-dir", HierarchyTitleConverterTest.METADIR);
  29. tester.getProperties().setProperty("filepath-hierarchy-ignorable-ancestors", HierarchyTitleConverterTest.PAGESDIR);
  30. }
  31. protected void tearDown() {
  32. tester.getProperties().setProperty("page-history-load-as-ancestors-dir", "");
  33. }
  34. public void testConvertLink() {
  35. String input, expected, actual;
  36. input = "[[drink:start]]\n" +
  37. "[[:drink:start]]\n" +
  38. "[[.drink|Alias]]\n" +
  39. "[[drink:juice:start|Alias for the juice link]]\n" +
  40. "[[drink:juice:apple]]\n" +
  41. "[[drink:water]]\n" +
  42. "[[food:start|Food]]\n" +
  43. "[[food:Baklava]]\n" +
  44. "[[food:fruit:start]]\n" +
  45. "[[food:fruit:apple]]\n" +
  46. "[[food:pie:start]]\n" +
  47. "[[food:pie:apple]]\n" +
  48. "[[food:pie:fruit:start]]\n" +
  49. "[[food:pie:fruit:apple]]\n" +
  50. "[[food:pie:start:apple]]\n" +
  51. "[[food:pie:fruit:apple:chiffon]]\n" +
  52. "[[otherspace:Testing 123]]\n" +
  53. "[[ food:pie:fruit | Alias ]]\n" +
  54. "[[ http://abc.com| alias]]\n" +
  55. "[[abc_def:tada]]\n" +
  56. "";
  57. expected = "[food:Drink]\n" +
  58. "[food:Drink]\n" +
  59. "[Alias|food:Drink]\n" +
  60. "[Alias for the juice link|food:Juice]\n" +
  61. "[food:Juice Apple]\n" +
  62. "[food:Water]\n" +
  63. "[Food|food:Start]\n" +
  64. "[food:Baklava]\n" +
  65. "[food:Food Fruit]\n" +
  66. "[food:Food Fruit Apple]\n" +
  67. "[food:Pie]\n" +
  68. "[food:Pie Apple]\n" +
  69. "[food:Pie Fruit]\n" +
  70. "[food:Pie Fruit Apple]\n" +
  71. "[food:Start Apple]\n" +
  72. "[food:Chiffon]\n" +
  73. "[otherspace:Testing 123]\n" +
  74. "[Alias|food:Pie Fruit]\n" +
  75. "[alias|http://abc.com]\n" +
  76. "[abcdef:Tada]\n";
  77. actual = tester.convertLink(input);
  78. assertNotNull(actual);
  79. assertEquals(expected, actual);
  80. }
  81. public void testConvertLinks_wCurrentPath() {
  82. String input, expected, actual;
  83. input =
  84. "[[.drink|Alias]]\n" +
  85. "[[.fruit|Fruit Drink]]\n" +
  86. "[[.cranberry]]" +
  87. "";
  88. expected =
  89. "[Alias|food:Drink]\n" +
  90. "[Fruit Drink|food:Drink Fruit]\n" +
  91. "[food:Cranberry]";
  92. String spacekey = "food";
  93. actual = tester.convertLink(input, "drink/", spacekey, "");
  94. assertNotNull(actual);
  95. assertEquals(expected, actual);
  96. }
  97. public void testConvertUNC() {
  98. String input, expected, actual;
  99. input = "[[\\\\path\\to\\unc\\file.jpg]]\n";
  100. expected = input;
  101. actual = tester.convertLink(input);
  102. assertNotNull(actual);
  103. assertEquals(expected, actual);
  104. }
  105. public void testConvertWithPageByPageSpaces() {
  106. Page page = new Page(new File(HierarchyTitleConverterTest.PAGESDIR+"/SampleDokuwiki-InputTitle.txt"));
  107. page.setOriginalText("[[.:home]]\n" +
  108. "[[drink:start]]\n");
  109. String spacekey = "otherspace";
  110. page.setSpacekey(spacekey);//default spacekey is 'food'
  111. tester.convert(page);
  112. String actual = page.getConvertedText();
  113. String expected = "[" + spacekey + ":Home]\n" + //this one users the current home
  114. "[food:Drink]\n"; //this one uses the mapping (drink points to food)
  115. assertNotNull(actual);
  116. assertEquals(expected, actual);
  117. }
  118. public void testConvertWithPageByPageSpaces_2() {
  119. tester.getProperties().setProperty("space-lala","ns/tada");
  120. tester.getProperties().setProperty("space-foo","ns/tada/other");
  121. Page page = new Page(new File(HierarchyTitleConverterTest.PAGESDIR+"/SampleDokuwiki-InputTitle.txt"));
  122. page.setOriginalText("[[.:home]]\n" +
  123. "[[ns:tada]]\n" +
  124. "[[ns:tada:subchild]]\n" +
  125. "[[ns:tada:other:subchild]]\n" +
  126. "[[ns:tada:Other:subchild]]\n" +
  127. "[[ns:tada:other:sub:subsubchild]]\n");
  128. String spacekey = "otherspace";
  129. page.setSpacekey(spacekey);//default spacekey is 'food'
  130. tester.convert(page);
  131. String actual = page.getConvertedText();
  132. String expected = "[" + spacekey + ":Home]\n" + //this one users the current home
  133. "[lala:Tada]\n" +
  134. "[lala:Subchild]\n" +
  135. "[foo:Subchild]\n" +
  136. "[foo:Subchild]\n" +
  137. "[foo:Subsubchild]\n"; //this one uses the mapping (drink points to food)
  138. assertNotNull(actual);
  139. assertEquals(expected, actual);
  140. }
  141. public void testConvertWithMetaTitle() throws IOException {
  142. String input, expected, actual;
  143. input = "[[.:foo]]\n" +
  144. "[[:foo:bar]]\n";
  145. expected = "[xyz:Foo Tralala]\n" +
  146. "[xyz:Harumph BAr]\n";
  147. tester.getProperties().setProperty("filepath-hierarchy-ignorable-ancestors", "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/pages");
  148. String pretendthispagepath = "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/pages/test.txt";
  149. actual = tester.convertLink(input, "", "xyz", pretendthispagepath);
  150. assertNotNull(actual);
  151. assertEquals(expected, actual);
  152. }
  153. public void testConvertWithMetaTitle_Ancestor() throws IOException {
  154. tester.getProperties().setProperty("page-history-load-as-ancestors-dir", "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/attic/");
  155. String input, expected, actual;
  156. input = "[[.:foo]]\n" +
  157. "[[:foo:bar]]\n";
  158. expected = "[xyz:Foo Tralala]\n" +
  159. "[xyz:Harumph BAr]\n";
  160. tester.getProperties().setProperty("filepath-hierarchy-ignorable-ancestors", "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/pages");
  161. String pretendthispagepath = "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/pages/test.txt";
  162. actual = tester.convertLink(input, "", "xyz", pretendthispagepath);
  163. assertNotNull(actual);
  164. assertEquals(expected, actual);
  165. }
  166. public void testGetTargetMetaFilename() {
  167. String input, expected, actual;
  168. input = "foo";
  169. String filename = HierarchyTitleConverterTest.METADIR+"/home.meta";
  170. expected = HierarchyTitleConverterTest.METADIR+"/foo.meta";
  171. actual = tester.getTargetMetaFilename(input, filename, true);
  172. assertNotNull(actual);
  173. assertEquals(expected, actual);
  174. input = "abc:def:ghi::jkl";
  175. filename = HierarchyTitleConverterTest.METADIR+"/abc/def/ghi/home.meta";
  176. expected = HierarchyTitleConverterTest.METADIR+"/abc/def/ghi/jkl.meta";
  177. actual = tester.getTargetMetaFilename(input, filename, false);
  178. assertNotNull(actual);
  179. assertEquals(expected, actual);
  180. }
  181. public void testConvertWithCollision() {
  182. tester.getProperties().setProperty("collision-titles-xyz", "Harumph BAr");
  183. String input, expected, actual;
  184. input = "[[.:foo]]\n" +
  185. "[[:foo:bar]]\n";
  186. expected = "[xyz:Foo Tralala]\n" +
  187. "[xyz:Foo Tralala Harumph BAr]\n";
  188. tester.getProperties().setProperty("filepath-hierarchy-ignorable-ancestors", "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/pages");
  189. String pretendthispagepath = "/Users/laura/Code/Git/uwc/sampleData/dokuwiki/junit_resources/pages/test.txt";
  190. actual = tester.convertLink(input, "", "xyz", pretendthispagepath);
  191. assertNotNull(actual);
  192. assertEquals(expected, actual);
  193. }
  194. }