/src/com/atlassian/uwc/converters/trac/FilenameHierarchyLinkConverterTest.java

https://bitbucket.org/atlassianlabs/universal-wiki-connector · Java · 101 lines · 84 code · 16 blank · 1 comment · 0 complexity · 7156ee9c61539b861101ad1762b19c46 MD5 · raw file

  1. package com.atlassian.uwc.converters.trac;
  2. import junit.framework.TestCase;
  3. import org.apache.log4j.Logger;
  4. import org.apache.log4j.PropertyConfigurator;
  5. //at this stage we're done alot of link handling already, so this is really confluence link handling
  6. public class FilenameHierarchyLinkConverterTest extends TestCase {
  7. FilenameHierarchyLinkConverter tester = null;
  8. Logger log = Logger.getLogger(this.getClass());
  9. protected void setUp() throws Exception {
  10. super.setUp();
  11. tester = new FilenameHierarchyLinkConverter();
  12. PropertyConfigurator.configure("log4j.properties");
  13. }
  14. public void testConvertLinks_simple() {
  15. String input, expected, actual;
  16. input = "[WikiPage/SubWikiPage]";
  17. expected = "[SubWikiPage]";
  18. actual = tester.convertLink(input);
  19. assertNotNull(actual);
  20. assertEquals(expected, actual);
  21. }
  22. public void testConvertLinks_alias() {
  23. String input, expected, actual;
  24. input = "[alias|WikiPage/SubWikiPage]";
  25. expected = "[alias|SubWikiPage]";
  26. actual = tester.convertLink(input);
  27. assertNotNull(actual);
  28. assertEquals(expected, actual);
  29. }
  30. public void testConvertLinks_sibling() {
  31. String input, expected, actual;
  32. input = "[../Sibling]\n" +
  33. "[alias|../Sibling]";
  34. expected = "[Sibling]\n" +
  35. "[alias|Sibling]";
  36. actual = tester.convertLink(input);
  37. assertNotNull(actual);
  38. assertEquals(expected, actual);
  39. }
  40. public void testConvertLinks_notattachment() {
  41. String input, expected, actual;
  42. input = "[alias/with dangerous chars|^file/wouldthisevenhappen.pdf]";
  43. expected = input;
  44. actual = tester.convertLink(input);
  45. assertNotNull(actual);
  46. assertEquals(expected, actual);
  47. }
  48. public void testConvertLinks_notanchor() {
  49. String input, expected, actual;
  50. input = "[alias/foobar|#foo/bar]";
  51. expected = input;
  52. actual = tester.convertLink(input);
  53. assertNotNull(actual);
  54. assertEquals(expected, actual);
  55. }
  56. public void testConvertLinks_notexternal() {
  57. String input, expected, actual;
  58. input = "[alias/foobar|http://lalala.com]";
  59. expected = input;
  60. actual = tester.convertLink(input);
  61. assertNotNull(actual);
  62. assertEquals(expected, actual);
  63. }
  64. public void testConvertLinks_handleimage() {
  65. String input, expected, actual;
  66. input = "!PageTitle/file.png!\n" +
  67. "!PageTitle/Subpage/file.png!\n" +
  68. "";
  69. expected = "!PageTitle^file.png!\n" +
  70. "!Subpage^file.png!\n" +
  71. "";
  72. actual = tester.handleImage(input);
  73. assertNotNull(actual);
  74. assertEquals(expected, actual);
  75. }
  76. public void testConvertLinks_nothtmlcomment() {
  77. String input, expected, actual;
  78. input = "<!--PageTitle/file.png-->\n" +
  79. "<!--lalala-->";
  80. expected = input;
  81. actual = tester.handleImage(input);
  82. assertNotNull(actual);
  83. assertEquals(expected, actual);
  84. }
  85. }