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 HashMap<String, String> urlMap = new HashMap<String, String>()
46 put("TEST","http://someurl.blah/$DB_ACCESSION$");
47 put("ANOTHER","http://test/t$SEQUENCE_ID$");
48 put("TEST2", "http://address/$SEQUENCE_ID$");
49 put("SRS", "http://theSRSlink/$SEQUENCE_ID$");
53 private static final String[] dlinks = {
54 "TEST|http://someurl.blah/$DB_ACCESSION$",
55 "ANOTHER|http://test/t$SEQUENCE_ID$",
56 "TEST2|http://address/$SEQUENCE_ID$",
57 UrlConstants.DEFAULT_STRING };
59 private static final Vector<String> displayLinks = new Vector<String>(
60 Arrays.asList(dlinks));
62 private static final String[] dlinks2 = { "a|http://x.y.z/$SEQUENCE_ID$" };
64 private static final Vector<String> displayLinks2 = new Vector<String>(
65 Arrays.asList(dlinks2));
67 private static final String[] list1 = { "a" };
69 private static final String[] list2 = { "http://x.y.z/$SEQUENCE_ID$" };
71 private static final Vector<String> names = new Vector<String>(
72 Arrays.asList(list1));
74 private static final Vector<String> urls = new Vector<String>(
75 Arrays.asList(list2));
78 * Test default url is set and returned correctly
80 @Test(groups = { "Functional" })
81 public void testDefaultUrl()
83 UrlProviderI customProv = new CustomUrlProvider(cachedList);
85 // default url can be set
86 assertTrue(customProv.setDefaultUrl("ANOTHER"));
88 // supplied replacement id must be more than 4 chars
89 String result = customProv.getDefaultUrl("123");
90 assertEquals(null, result);
92 // default url can be retrieved given a sequence id
93 result = customProv.getDefaultUrl("seqid");
94 assertEquals("http://test/tseqid", result);
96 // if there is no default url it sets the default to null
97 assertFalse(customProv.setDefaultUrl("No default"));
98 result = customProv.getDefaultUrl("testid");
99 assertEquals(null, result);
101 // choosing the default picks the DEFAULT_STRING option
102 customProv.chooseDefaultUrl();
103 result = customProv.getDefaultUrl("seqid");
105 UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
111 * Test urls are set and returned correctly
113 @Test(groups = { "Functional" })
114 public void testUrlLinks()
116 // creation from cached url list works + old links upgraded
117 UrlProviderI customProv = new CustomUrlProvider(cachedList);
118 assertTrue(displayLinks.containsAll(customProv.getLinksForMenu()));
120 // creation from map works + old links upgraded
121 UrlProviderI customProv2 = new CustomUrlProvider(urlMap);
122 assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu()));
124 // writing url links as a string works
125 // because UrlProvider does not guarantee order of links, we can't just
126 // compare the output of writeUrlsAsString to a string, hence the hoops here
127 String result = customProv.writeUrlsAsString();
128 UrlProviderI up = new CustomUrlProvider(result);
129 assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
131 result = customProv2.writeUrlsAsString();
132 UrlProviderI up2 = new CustomUrlProvider(result);
133 assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));