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.urls.api.UrlProviderI;
28 import jalview.util.UrlConstants;
30 import java.util.Arrays;
31 import java.util.HashMap;
32 import java.util.Vector;
34 import org.testng.annotations.Test;
36 public class CustomUrlProviderTest
39 private static final String cachedList = "TEST|http://someurl.blah/$DB_ACCESSION$|"
40 + "ANOTHER|http://test/t$SEQUENCE_ID$|"
41 + "TEST2|http://address/$SEQUENCE_ID$|SRS|"
42 + "http://theSRSlink/$SEQUENCE_ID$";
44 private static final String unselectedList = "NON1|http://x/y/$DB_ACCESSION$|"
45 + "NON2|http://a/b/c/$DB_ACCESSION";
47 private static final HashMap<String, String> urlMap = new HashMap<String, String>()
50 put("TEST","http://someurl.blah/$DB_ACCESSION$");
51 put("ANOTHER","http://test/t$SEQUENCE_ID$");
52 put("TEST2", "http://address/$SEQUENCE_ID$");
53 put("SRS", "http://theSRSlink/$SEQUENCE_ID$");
57 private static final HashMap<String, String> unselUrlMap = new HashMap<String, String>()
60 put("NON1", "http://x/y/$DB_ACCESSION$");
61 put("NON2", "http://a/b/c/$DB_ACCESSION");
65 private static final String[] dlinks = {
66 "TEST|http://someurl.blah/$DB_ACCESSION$",
67 "ANOTHER|http://test/t$SEQUENCE_ID$",
68 "TEST2|http://address/$SEQUENCE_ID$",
69 UrlConstants.DEFAULT_STRING };
71 private static final String[] unselDlinks = {
72 "NON1|http://x/y/$DB_ACCESSION$", "NON2|http://a/b/c/$DB_ACCESSION" };
74 private static final Vector<String> displayLinks = new Vector<String>(
75 Arrays.asList(dlinks));
77 private static final Vector<String> unselDisplayLinks = new Vector<String>(
78 Arrays.asList(unselDlinks));
80 private static final String[] dlinks2 = { "a|http://x.y.z/$SEQUENCE_ID$" };
82 private static final Vector<String> displayLinks2 = new Vector<String>(
83 Arrays.asList(dlinks2));
85 private static final String[] list1 = { "a" };
87 private static final String[] list2 = { "http://x.y.z/$SEQUENCE_ID$" };
89 private static final Vector<String> names = new Vector<String>(
90 Arrays.asList(list1));
92 private static final Vector<String> urls = new Vector<String>(
93 Arrays.asList(list2));
96 * Test default url is set and returned correctly
98 @Test(groups = { "Functional" })
99 public void testDefaultUrl()
101 UrlProviderI customProv = new CustomUrlProvider(cachedList,
104 // default url can be set
105 assertTrue(customProv.setPrimaryUrl("ANOTHER"));
107 // supplied replacement id must be more than 4 chars
108 String result = customProv.getPrimaryUrl("123");
109 assertEquals(null, result);
111 // default url can be retrieved given a sequence id
112 result = customProv.getPrimaryUrl("seqid");
113 assertEquals("http://test/tseqid", result);
115 // if there is no default url it sets the default to null
116 assertFalse(customProv.setPrimaryUrl("No default"));
117 result = customProv.getPrimaryUrl("testid");
118 assertEquals(null, result);
120 // choosing the default picks the DEFAULT_STRING option
121 customProv.choosePrimaryUrl();
122 result = customProv.getPrimaryUrl("seqid");
124 UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
130 * Test urls are set and returned correctly
132 @Test(groups = { "Functional" })
133 public void testUrlLinks()
135 // creation from cached url list works + old links upgraded
136 UrlProviderI customProv = new CustomUrlProvider(cachedList,
138 assertTrue(displayLinks.containsAll(customProv.getLinksForMenu()));
140 // creation from map works + old links upgraded
141 UrlProviderI customProv2 = new CustomUrlProvider(urlMap, unselUrlMap);
142 assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu()));
144 // writing url links as a string works
145 // because UrlProvider does not guarantee order of links, we can't just
146 // compare the output of writeUrlsAsString to a string, hence the hoops here
147 String result = customProv.writeUrlsAsString(true);
148 UrlProviderI up = new CustomUrlProvider(result, "");
149 assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
151 result = customProv.writeUrlsAsString(false);
152 up = new CustomUrlProvider("", result);
153 assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
155 result = customProv2.writeUrlsAsString(true);
156 UrlProviderI up2 = new CustomUrlProvider(result, "");
157 assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
159 result = customProv2.writeUrlsAsString(false);
160 up2 = new CustomUrlProvider("", result);
161 assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));