1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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 ******************************************************************************/
23 import static org.testng.AssertJUnit.assertEquals;
25 import org.testng.annotations.Test;
27 public class ParseHtmlBodyAndLinksTest
29 @Test(groups = { "Functional" })
30 public void testParseHtml_noLinks()
32 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
33 "<html>something here</html>", false, "\n");
34 assertEquals("something here", testee.getContent());
35 assertEquals("something here", testee.getNonHtmlContent());
37 // second argument makes no difference??
38 testee = new ParseHtmlBodyAndLinks("<html>something here</html>", true,
40 assertEquals("something here", testee.getContent());
41 assertEquals("something here", testee.getNonHtmlContent());
44 @Test(groups = { "Functional" })
45 public void testParseHtml_withLinks()
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>",
51 "Please click on this%LINK% to learn more about this%LINK%",
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()
62 @Test(groups = { "Functional" })
63 public void testParseHtml_withLinksWithParameters()
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>",
68 assertEquals("Please click on this%LINK% to learn more",
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));
77 @Test(groups = { "Functional" })
78 public void testParseHtml_withLinksWithEncoding()
80 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
81 "<html>Please click <a href=\"http://www.nowhere.com?id=234&taxon=human&id>3&id<10\">on this</a> to learn &<>more</html>",
83 // html encoding in the text body is translated
84 assertEquals("Please click on this%LINK% to learn &<>more",
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
91 "on this|http://www.nowhere.com?id=234&taxon=human&id>3&id<10",
92 testee.getLinks().get(0));