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 jalview.gui.JvOptionPane;
27 import org.testng.annotations.BeforeClass;
28 import org.testng.annotations.Test;
30 public class ParseHtmlBodyAndLinksTest
33 @BeforeClass(alwaysRun = true)
34 public void setUpJvOptionPane()
36 JvOptionPane.setInteractiveMode(false);
37 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
40 @Test(groups = { "Functional" })
41 public void testParseHtml_noLinks()
43 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
44 "<html>something here</html>", false, "\n");
45 assertEquals("something here", testee.getContent());
46 assertEquals("something here", testee.getNonHtmlContent());
48 // second argument makes no difference??
49 testee = new ParseHtmlBodyAndLinks("<html>something here</html>", true,
51 assertEquals("something here", testee.getContent());
52 assertEquals("something here", testee.getNonHtmlContent());
55 @Test(groups = { "Functional" })
56 public void testParseHtml_withLinks()
58 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
59 "<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>",
62 "Please click on this%LINK% to learn more about this%LINK%",
65 "Please click on this%LINK% to learn more about this%LINK%",
66 testee.getNonHtmlContent());
67 assertEquals(2, testee.getLinks().size());
68 assertEquals("on this|http://www.nowhere.com", testee.getLinks().get(0));
69 assertEquals("this|http://www.somewhere.com/here", testee.getLinks()
73 @Test(groups = { "Functional" })
74 public void testParseHtml_withLinksWithParameters()
76 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
77 "<html>Please click <a href=\"http://www.nowhere.com?id=234&taxon=human\">on this</a> to learn more</html>",
79 assertEquals("Please click on this%LINK% to learn more",
81 assertEquals("Please click on this%LINK% to learn more",
82 testee.getNonHtmlContent());
83 assertEquals(1, testee.getLinks().size());
84 assertEquals("on this|http://www.nowhere.com?id=234&taxon=human",
85 testee.getLinks().get(0));
88 @Test(groups = { "Functional" })
89 public void testParseHtml_withLinksWithEncoding()
91 ParseHtmlBodyAndLinks testee = new ParseHtmlBodyAndLinks(
92 "<html>Please click <a href=\"http://www.nowhere.com?id=234&taxon=human&id>3&id<10\">on this</a> to learn &<>more</html>",
94 // html encoding in the text body is translated
95 assertEquals("Please click on this%LINK% to learn &<>more",
97 assertEquals("Please click on this%LINK% to learn &<>more",
98 testee.getNonHtmlContent());
99 assertEquals(1, testee.getLinks().size());
100 // html encoding in the url links is not translated
102 "on this|http://www.nowhere.com?id=234&taxon=human&id>3&id<10",
103 testee.getLinks().get(0));