JAL-1905 parse url including & correctly
[jalview.git] / test / jalview / util / ParseHtmlBodyAndLinksTest.java
1 package jalview.util;
2
3 import static org.testng.AssertJUnit.assertEquals;
4
5 import org.testng.annotations.Test;
6
7 public class ParseHtmlBodyAndLinksTest
8 {
9   @Test(groups = { "Functional" })
10   public void testParseHtml_noLinks()
11   {
12     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
13             "<html>something here</html>", false, "\n");
14     assertEquals("something here", testee.getContent());
15     assertEquals("something here", testee.getNonHtmlContent());
16
17     // second argument makes no difference??
18     testee = new ParseHtmlBodyAndLinks("<html>something here</html>", true,
19             "\n");
20     assertEquals("something here", testee.getContent());
21     assertEquals("something here", testee.getNonHtmlContent());
22   }
23
24   @Test(groups = { "Functional" })
25   public void testParseHtml_withLinks()
26   {
27     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
28             "<html>Please click <a href=\"http://www.nowhere.com\">on this</a> to learn more about <a href=\"http://www.somewhere.com/here\">this</a></html>",
29             false, "\n");
30     assertEquals(
31             "Please click on this%LINK% to learn more about this%LINK%",
32             testee.getContent());
33     assertEquals(
34             "Please click on this%LINK% to learn more about this%LINK%",
35             testee.getNonHtmlContent());
36     assertEquals(2, testee.getLinks().size());
37     assertEquals("on this|http://www.nowhere.com", testee.getLinks().get(0));
38     assertEquals("this|http://www.somewhere.com/here", testee.getLinks()
39             .get(1));
40   }
41
42   @Test(groups = { "Functional" })
43   public void testParseHtml_withLinksWithParameters()
44   {
45     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
46             "<html>Please click <a href=\"http://www.nowhere.com?id=234&taxon=human\">on this</a> to learn more</html>",
47             false, "\n");
48     assertEquals("Please click on this%LINK% to learn more",
49             testee.getContent());
50     assertEquals("Please click on this%LINK% to learn more",
51             testee.getNonHtmlContent());
52     assertEquals(1, testee.getLinks().size());
53     assertEquals("on this|http://www.nowhere.com?id=234&taxon=human",
54             testee.getLinks().get(0));
55   }
56
57   @Test(groups = { "Functional" })
58   public void testParseHtml_withLinksWithEncoding()
59   {
60     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
61             "<html>Please click <a href=\"http://www.nowhere.com?id=234&amp;taxon=human&amp;id&gt;3&amp;id&lt;10\">on this</a> to learn &amp;&lt;&gt;more</html>",
62             false, "\n");
63     // html encoding in the text body is translated
64     assertEquals("Please click on this%LINK% to learn &<>more",
65             testee.getContent());
66     assertEquals("Please click on this%LINK% to learn &<>more",
67             testee.getNonHtmlContent());
68     assertEquals(1, testee.getLinks().size());
69     // html encoding in the url links is not translated
70     assertEquals(
71             "on this|http://www.nowhere.com?id=234&amp;taxon=human&amp;id&gt;3&amp;id&lt;10",
72             testee.getLinks().get(0));
73   }
74 }