PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/atlassian/uwc/converters/xwiki/LinkConverterTest.java

https://bitbucket.org/dodok1/uwc
Java | 344 lines | 285 code | 43 blank | 16 comment | 0 complexity | ca4212842207f3e7d6cb2701777580f7 MD5 | raw file
  1. package com.atlassian.uwc.converters.xwiki;
  2. import java.util.Vector;
  3. import junit.framework.TestCase;
  4. import org.apache.log4j.Logger;
  5. import org.apache.log4j.PropertyConfigurator;
  6. public class LinkConverterTest extends TestCase {
  7. LinkConverter tester = null;
  8. Logger log = Logger.getLogger(this.getClass());
  9. protected void setUp() throws Exception {
  10. tester = new LinkConverter();
  11. PropertyConfigurator.configure("log4j.properties");
  12. }
  13. public void testConvertLinks_Base() {
  14. String input, expected, actual;
  15. input = "[WebHome]";
  16. expected = input;
  17. actual = tester.convertLinks(input);
  18. assertNotNull(actual);
  19. assertEquals(expected, actual);
  20. input = "[http://www.google.com]";
  21. expected = input;
  22. actual = tester.convertLinks(input);
  23. assertNotNull(actual);
  24. assertEquals(expected, actual);
  25. input = "http://www.google.com";
  26. expected = input;
  27. actual = tester.convertLinks(input);
  28. assertNotNull(actual);
  29. assertEquals(expected, actual);
  30. }
  31. public void testConvertLinks_Alias() {
  32. String input, expected, actual;
  33. input = "[alias>Home]\n" +
  34. "[alias|Home]\n" +
  35. "";
  36. expected = "[alias|Home]\n" +
  37. "[alias|Home]\n";
  38. actual = tester.convertLinks(input);
  39. assertNotNull(actual);
  40. assertEquals(expected, actual);
  41. }
  42. public void testConvertLinks_Virtual() {
  43. String input, expected, actual;
  44. input = "[virtual:Home]\n" +
  45. "";
  46. expected = input;
  47. actual = tester.convertLinks(input);
  48. assertNotNull(actual);
  49. assertEquals(expected, actual);
  50. }
  51. public void testConvertLinks_Space() {
  52. String input, expected, actual;
  53. input = "[Sandbox.Home]\n" +
  54. "";
  55. expected = "[Sandbox:Home]\n" +
  56. "";
  57. actual = tester.convertLinks(input);
  58. assertNotNull(actual);
  59. assertEquals(expected, actual);
  60. }
  61. public void testConvertLinks_VirtualAndSpace() {
  62. String input, expected, actual;
  63. input = "[virtual:Sandbox.Home]\n" +
  64. "";
  65. expected = "[virtualSandbox:Home]\n" +
  66. "";
  67. actual = tester.convertLinks(input);
  68. assertNotNull(actual);
  69. assertEquals(expected, actual);
  70. }
  71. public void testConvertLinks_Query() {
  72. String input, expected, actual;
  73. input = "[http://www.google.com/search?q=xwiki]\n" +
  74. "";
  75. expected = input;
  76. actual = tester.convertLinks(input);
  77. assertNotNull(actual);
  78. assertEquals(expected, actual);
  79. }
  80. public void testConvertLinks_Section() {
  81. String input, expected, actual;
  82. input = "[Home#Section]\n" +
  83. "";
  84. expected = input;
  85. actual = tester.convertLinks(input);
  86. assertNotNull(actual);
  87. assertEquals(expected, actual);
  88. }
  89. public void testConvertLinks_Interwiki() {
  90. String input, expected, actual;
  91. input = "[xwiki@Wikipedia]\n" +
  92. "";
  93. expected = input;
  94. actual = tester.convertLinks(input);
  95. assertNotNull(actual);
  96. assertEquals(expected, actual);
  97. }
  98. public void testConvertLinks_Target() {
  99. String input, expected, actual;
  100. input = "[Home|_blank]";
  101. expected = "{link-window:Home}Home{link-window}";
  102. actual = tester.convertLinks(input);
  103. assertNotNull(actual);
  104. assertEquals(expected, actual);
  105. input = "[Home>_blank]";
  106. expected = "{link-window:Home}Home{link-window}";
  107. actual = tester.convertLinks(input);
  108. assertNotNull(actual);
  109. assertEquals(expected, actual);
  110. input = "[Home|_self]";
  111. expected = "[Home]";
  112. actual = tester.convertLinks(input);
  113. assertNotNull(actual);
  114. assertEquals(expected, actual);
  115. input = "[Home>_self]";
  116. expected = "[Home]";
  117. actual = tester.convertLinks(input);
  118. assertNotNull(actual);
  119. assertEquals(expected, actual);
  120. input = "[Home>_someothertarget]";
  121. expected = "[Home]";
  122. actual = tester.convertLinks(input);
  123. assertNotNull(actual);
  124. assertEquals(expected, actual);
  125. }
  126. public void testConvertLinks1() {
  127. String input, expected, actual;
  128. input = "[alias|virtual:Home#TestSection>_blank]";
  129. expected = "{link-window:virtual:Home#TestSection}alias{link-window}";
  130. actual = tester.convertLinks(input);
  131. assertNotNull(actual);
  132. assertEquals(expected, actual);
  133. }
  134. public void testConvertLinks2() {
  135. String input, expected, actual;
  136. input = "[alias>test@Test]\n" +
  137. "";
  138. expected = "[alias|test@Test]\n" +
  139. "";
  140. actual = tester.convertLinks(input);
  141. assertNotNull(actual);
  142. assertEquals(expected, actual);
  143. }
  144. public void testConvertLinks3() {
  145. String input, expected, actual;
  146. input = "[Sandbox.Home|_self]\n" +
  147. "";
  148. expected = "[Sandbox:Home]\n" +
  149. "";
  150. actual = tester.convertLinks(input);
  151. assertNotNull(actual);
  152. assertEquals(expected, actual);
  153. }
  154. public void testConvertLinks4() {
  155. String input, expected, actual;
  156. input = "[alias|http://www.google.com>_blank]";
  157. expected = "{link-window:http://www.google.com}alias{link-window}";
  158. actual = tester.convertLinks(input);
  159. assertNotNull(actual);
  160. assertEquals(expected, actual);
  161. }
  162. public void testConvertLinks5() {
  163. String input, expected, actual;
  164. input = "[alias|http://www.google.com]";
  165. expected = input;
  166. actual = tester.convertLinks(input);
  167. assertNotNull(actual);
  168. assertEquals(expected, actual);
  169. }
  170. public void testGetLink() {
  171. String input, expected, actual;
  172. input = "abc";
  173. expected = input;
  174. actual = tester.getLink(input);
  175. assertNotNull(actual);
  176. assertEquals(expected, actual);
  177. input = "abc|def";
  178. expected = "def";
  179. actual = tester.getLink(input);
  180. assertNotNull(actual);
  181. assertEquals(expected, actual);
  182. input = "abc|def|ghi";
  183. expected = "def";
  184. actual = tester.getLink(input);
  185. assertNotNull(actual);
  186. assertEquals(expected, actual);
  187. input = "alias|http://www.google.com";
  188. expected = "http://www.google.com";
  189. actual = tester.getLink(input);
  190. assertNotNull(actual);
  191. assertEquals(expected, actual);
  192. }
  193. public void testProblemSyntax() {
  194. String input, expected, actual;
  195. input = "[||]";
  196. expected = "[||]";
  197. actual = tester.convertLinks(input);
  198. assertNotNull(actual);
  199. assertEquals(expected, actual);
  200. }
  201. //Xwiki appears to actually use a #H delimiter.
  202. //XWikiSyntax explanation does not describe this, but
  203. //Sections used in XWikiSyntax do.
  204. //I'll try to handle both syntaxes
  205. public void testHSection() {
  206. String input, expected, actual;
  207. input = "[Home#HSection]\n" +
  208. "";
  209. expected = "[Home#Section]\n" +
  210. "";
  211. actual = tester.convertLinks(input);
  212. assertNotNull(actual);
  213. assertEquals(expected, actual);
  214. }
  215. //XWiki appears to remove ws from section derived anchors
  216. public void testCondensedSection() {
  217. String input, expected, actual;
  218. input = "[Link to Section 2>Testing Sections#HSection2]\n" +
  219. "h6. Section 2";
  220. expected = "[Link to Section 2|Testing Sections#Section 2]\n" +
  221. "h6. Section 2";
  222. actual = tester.convertLinks(input);
  223. assertNotNull(actual);
  224. assertEquals(expected, actual);
  225. }
  226. public void testFixAnchors() {
  227. String input, expected, actual;
  228. input = "Home#HSection";
  229. expected = "Home#Section";
  230. actual = tester.fixAnchors(input, "");
  231. assertNotNull(actual);
  232. assertEquals(expected, actual);
  233. input = "Home#section";
  234. expected = input;
  235. actual = tester.fixAnchors(input, "");
  236. assertNotNull(actual);
  237. assertEquals(expected, actual);
  238. String link = "Home#HSectionWhitespaceHere";
  239. input = "[" + link + "]\n" +
  240. "h1. Section Whitespace Here";
  241. expected = "Home#Section Whitespace Here";
  242. actual = tester.fixAnchors(link, input);
  243. assertNotNull(actual);
  244. assertEquals(expected, actual);
  245. link = "Home#HSectionWhitespacehere";
  246. input = "[" + link + "]\n" +
  247. "h1. SectionWhitespace here";
  248. expected = "Home#SectionWhitespace here";
  249. actual = tester.fixAnchors(link, input);
  250. assertNotNull(actual);
  251. assertEquals(expected, actual);
  252. link = "Link to Section 2>Testing Sections#HSection2";
  253. input = "[Link to Section 2>Testing Sections#HSection2]\n" +
  254. "h3. Section 2";
  255. expected = "Link to Section 2>Testing Sections#Section 2";
  256. actual = tester.fixAnchors(link, input);
  257. assertNotNull(actual);
  258. assertEquals(expected, actual);
  259. }
  260. public void testGetHeaders() {
  261. String input;
  262. input = "nothing";
  263. Vector<String> actual = tester.getHeaders(input);
  264. assertNull(actual);
  265. input = "h1. Something";
  266. actual = tester.getHeaders(input);
  267. assertNotNull(actual);
  268. assertEquals(1, actual.size());
  269. assertEquals("Something", actual.get(0));
  270. input = "something\n" +
  271. "h2. Something";
  272. actual = tester.getHeaders(input);
  273. assertNotNull(actual);
  274. assertEquals(1, actual.size());
  275. assertEquals("Something", actual.get(0));
  276. input = "something\n" +
  277. "h2. Something1\n" +
  278. "h3. Something2";
  279. actual = tester.getHeaders(input);
  280. assertNotNull(actual);
  281. assertEquals(2, actual.size());
  282. assertEquals("Something1", actual.get(0));
  283. assertEquals("Something2", actual.get(1));
  284. input = "h2. Something With WS";
  285. actual = tester.getHeaders(input);
  286. assertNotNull(actual);
  287. assertEquals(1, actual.size());
  288. assertEquals("Something With WS", actual.get(0));
  289. }
  290. //XXX True this is a problem, but I don't think that there will be a lot of files with periods in the
  291. //pagename to interfere with Space syntax
  292. // public void testLinksWithDots() {
  293. // String input, expected, actual;
  294. // input = "[Link to Section 2>SampleXwiki-InputAnchors.txt#HSection]\n" +
  295. // "";
  296. // expected = "[Link to Section 2|SampleXwiki-InputAnchors.txt#Section]\n";
  297. // actual = tester.convertLinks(input);
  298. // assertNotNull(actual);
  299. // assertEquals(expected, actual);
  300. // }
  301. }