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 jalview.util.UrlConstants;
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.Vector;
33 import org.testng.annotations.Test;
35 public class CustomUrlProviderTest
38 private static final String cachedList = "TEST|http://someurl.blah/$DB_ACCESSION$|"
39 + "ANOTHER|http://test/t$SEQUENCE_ID$|"
40 + "TEST2|http://address/$SEQUENCE_ID$|SRS|"
41 + "http://theSRSlink/$SEQUENCE_ID$";
43 private static final String unselectedList = "NON1|http://x/y/$DB_ACCESSION$|"
44 + "NON2|http://a/b/c/$DB_ACCESSION";
46 private static final HashMap<String, String> urlMap = new HashMap<String, String>()
49 put("TEST","http://someurl.blah/$DB_ACCESSION$");
50 put("ANOTHER","http://test/t$SEQUENCE_ID$");
51 put("TEST2", "http://address/$SEQUENCE_ID$");
52 put("SRS", "http://theSRSlink/$SEQUENCE_ID$");
56 private static final HashMap<String, String> unselUrlMap = new HashMap<String, String>()
59 put("NON1", "http://x/y/$DB_ACCESSION$");
60 put("NON2", "http://a/b/c/$DB_ACCESSION");
64 private static final String[] dlinks = {
65 "TEST|http://someurl.blah/$DB_ACCESSION$",
66 "ANOTHER|http://test/t$SEQUENCE_ID$",
67 "TEST2|http://address/$SEQUENCE_ID$",
68 UrlConstants.DEFAULT_STRING };
70 private static final String[] unselDlinks = {
71 "NON1|http://x/y/$DB_ACCESSION$", "NON2|http://a/b/c/$DB_ACCESSION" };
73 private static final Vector<String> displayLinks = new Vector<String>(
74 Arrays.asList(dlinks));
76 private static final Vector<String> unselDisplayLinks = new Vector<String>(
77 Arrays.asList(unselDlinks));
79 private static final String[] dlinks2 = { "a|http://x.y.z/$SEQUENCE_ID$" };
81 private static final Vector<String> displayLinks2 = new Vector<String>(
82 Arrays.asList(dlinks2));
84 private static final String[] list1 = { "a" };
86 private static final String[] list2 = { "http://x.y.z/$SEQUENCE_ID$" };
88 private static final Vector<String> names = new Vector<String>(
89 Arrays.asList(list1));
91 private static final Vector<String> urls = new Vector<String>(
92 Arrays.asList(list2));
95 * Test default url is set and returned correctly
97 @Test(groups = { "Functional" })
98 public void testDefaultUrl()
100 UrlProviderI customProv = new CustomUrlProvider(cachedList,
103 // default url can be set
104 assertTrue(customProv.setDefaultUrl("ANOTHER"));
106 // supplied replacement id must be more than 4 chars
107 String result = customProv.getDefaultUrl("123");
108 assertEquals(null, result);
110 // default url can be retrieved given a sequence id
111 result = customProv.getDefaultUrl("seqid");
112 assertEquals("http://test/tseqid", result);
114 // if there is no default url it sets the default to null
115 assertFalse(customProv.setDefaultUrl("No default"));
116 result = customProv.getDefaultUrl("testid");
117 assertEquals(null, result);
119 // choosing the default picks the DEFAULT_STRING option
120 customProv.chooseDefaultUrl();
121 result = customProv.getDefaultUrl("seqid");
123 UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
129 * Test urls are set and returned correctly
131 @Test(groups = { "Functional" })
132 public void testUrlLinks()
134 // creation from cached url list works + old links upgraded
135 UrlProviderI customProv = new CustomUrlProvider(cachedList,
137 assertTrue(displayLinks.containsAll(customProv.getLinksForMenu()));
139 // creation from map works + old links upgraded
140 UrlProviderI customProv2 = new CustomUrlProvider(urlMap, unselUrlMap);
141 assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu()));
143 // writing url links as a string works
144 // because UrlProvider does not guarantee order of links, we can't just
145 // compare the output of writeUrlsAsString to a string, hence the hoops here
146 String result = customProv.writeUrlsAsString(true);
147 UrlProviderI up = new CustomUrlProvider(result, "");
148 assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
150 result = customProv.writeUrlsAsString(false);
151 up = new CustomUrlProvider("", result);
152 assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
154 result = customProv2.writeUrlsAsString(true);
155 UrlProviderI up2 = new CustomUrlProvider(result, "");
156 assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
158 result = customProv2.writeUrlsAsString(false);
159 up2 = new CustomUrlProvider("", result);
160 assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));