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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.Vector;
31 import org.testng.annotations.Test;
33 public class CustomUrlProviderTest
36 private static final String cachedList = "TEST|http://someurl.blah/$DB_ACCESSION$|"
37 + "ANOTHER|http://test/t$SEQUENCE_ID$|"
38 + "TEST2|http://address/$SEQUENCE_ID$|SRS|"
39 + "http://theSRSlink/$SEQUENCE_ID$";
41 private static final HashMap<String, String> urlMap = new HashMap<String, String>()
44 put("TEST","http://someurl.blah/$DB_ACCESSION$");
45 put("ANOTHER","http://test/t$SEQUENCE_ID$");
46 put("TEST2", "http://address/$SEQUENCE_ID$");
47 put("SRS", "http://theSRSlink/$SEQUENCE_ID$");
51 private static final String[] dlinks = {
52 "TEST|http://someurl.blah/$DB_ACCESSION$",
53 "ANOTHER|http://test/t$SEQUENCE_ID$",
54 "TEST2|http://address/$SEQUENCE_ID$",
55 UrlProviderI.DEFAULT_STRING };
57 private static final Vector<String> displayLinks = new Vector<String>(
58 Arrays.asList(dlinks));
60 private static final String[] dlinks2 = { "a|http://x.y.z/$SEQUENCE_ID$" };
62 private static final Vector<String> displayLinks2 = new Vector<String>(
63 Arrays.asList(dlinks2));
65 private static final String[] list1 = { "a" };
67 private static final String[] list2 = { "http://x.y.z/$SEQUENCE_ID$" };
69 private static final Vector<String> names = new Vector<String>(
70 Arrays.asList(list1));
72 private static final Vector<String> urls = new Vector<String>(
73 Arrays.asList(list2));
76 * Test default url is set and returned correctly
78 @Test(groups = { "Functional" })
79 public void testDefaultUrl()
81 UrlProviderI customProv = new CustomUrlProvider(cachedList);
83 // default url can be set
84 assertTrue(customProv.setDefaultUrl("ANOTHER"));
85 String result = customProv.getDefaultUrl();
86 assertEquals("ANOTHER", result);
88 // default url can be retrieved given a sequence id
89 result = customProv.getDefaultUrl("seqid");
90 assertEquals("http://test/tseqid", result);
92 // if there is no default url it sets the default to null
93 assertFalse(customProv.setDefaultUrl("No default"));
94 result = customProv.getDefaultUrl();
95 assertEquals(null, result);
97 // choosing the default picks the DEFAULT_STRING option
98 customProv.chooseDefaultUrl();
99 result = customProv.getDefaultUrl("seqid");
101 UrlProviderI.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
107 * Test urls are set and returned correctly
109 @Test(groups = { "Functional" })
110 public void testUrlLinks()
112 // creation from cached url list works + old links upgraded
113 UrlProviderI customProv = new CustomUrlProvider(cachedList);
114 assertTrue(displayLinks.containsAll(customProv.getLinksForDisplay()));
116 // creation from map works + old links upgraded
117 UrlProviderI customProv2 = new CustomUrlProvider(urlMap);
118 assertTrue(displayLinks.containsAll(customProv2.getLinksForDisplay()));
120 // writing url links as a string works
121 String result = customProv.writeUrlsAsString();
122 UrlProviderI up = new CustomUrlProvider(result);
123 assertTrue(displayLinks.containsAll(up.getLinksForDisplay()));
125 result = customProv2.writeUrlsAsString();
126 UrlProviderI up2 = new CustomUrlProvider(result);
127 assertTrue(displayLinks.containsAll(up2.getLinksForDisplay()));
129 // resetting urls from a pair of lists works
130 customProv.setUrlLinks(names, urls);
131 assertTrue(displayLinks2.containsAll(customProv.getLinksForDisplay()));
133 customProv2.setUrlLinks(names, urls);
134 assertTrue(displayLinks2.containsAll(customProv2.getLinksForDisplay()));