JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / test / jalview / util / ParseHtmlBodyAndLinksTest.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  ******************************************************************************/
21 package jalview.util;
22
23 import static org.testng.AssertJUnit.assertEquals;
24
25 import org.testng.annotations.Test;
26
27 public class ParseHtmlBodyAndLinksTest
28 {
29   @Test(groups = { "Functional" })
30   public void testParseHtml_noLinks()
31   {
32     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
33             "<html>something here</html>", false, "\n");
34     assertEquals("something here", testee.getContent());
35     assertEquals("something here", testee.getNonHtmlContent());
36
37     // second argument makes no difference??
38     testee = new ParseHtmlBodyAndLinks("<html>something here</html>", true,
39             "\n");
40     assertEquals("something here", testee.getContent());
41     assertEquals("something here", testee.getNonHtmlContent());
42   }
43
44   @Test(groups = { "Functional" })
45   public void testParseHtml_withLinks()
46   {
47     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
48             "<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>",
49             false, "\n");
50     assertEquals(
51             "Please click on this%LINK% to learn more about this%LINK%",
52             testee.getContent());
53     assertEquals(
54             "Please click on this%LINK% to learn more about this%LINK%",
55             testee.getNonHtmlContent());
56     assertEquals(2, testee.getLinks().size());
57     assertEquals("on this|http://www.nowhere.com", testee.getLinks().get(0));
58     assertEquals("this|http://www.somewhere.com/here", testee.getLinks()
59             .get(1));
60   }
61
62   @Test(groups = { "Functional" })
63   public void testParseHtml_withLinksWithParameters()
64   {
65     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
66             "<html>Please click <a href=\"http://www.nowhere.com?id=234&taxon=human\">on this</a> to learn more</html>",
67             false, "\n");
68     assertEquals("Please click on this%LINK% to learn more",
69             testee.getContent());
70     assertEquals("Please click on this%LINK% to learn more",
71             testee.getNonHtmlContent());
72     assertEquals(1, testee.getLinks().size());
73     assertEquals("on this|http://www.nowhere.com?id=234&taxon=human",
74             testee.getLinks().get(0));
75   }
76
77   @Test(groups = { "Functional" })
78   public void testParseHtml_withLinksWithEncoding()
79   {
80     ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
81             "<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>",
82             false, "\n");
83     // html encoding in the text body is translated
84     assertEquals("Please click on this%LINK% to learn &<>more",
85             testee.getContent());
86     assertEquals("Please click on this%LINK% to learn &<>more",
87             testee.getNonHtmlContent());
88     assertEquals(1, testee.getLinks().size());
89     // html encoding in the url links is not translated
90     assertEquals(
91             "on this|http://www.nowhere.com?id=234&amp;taxon=human&amp;id&gt;3&amp;id&lt;10",
92             testee.getLinks().get(0));
93   }
94 }