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 jalview.urls.api.UrlProviderI;
24 import jalview.urls.desktop.DesktopUrlProviderFactory;
25 import jalview.util.UrlConstants;
27 import java.io.BufferedWriter;
29 import java.io.FileWriter;
30 import java.io.IOException;
31 import java.util.List;
33 import org.testng.Assert;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
37 public class UrlProviderTest
40 // Test identifiers.org download file
41 private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
42 + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
43 + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
44 + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
45 + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
46 + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
47 + "\"url\":\"http://identifiers.org/interpro\"},"
48 + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
49 + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
51 private UrlProviderI prov;
53 @BeforeMethod(alwaysRun = true)
56 // make a dummy identifiers.org download file
61 temp = File.createTempFile("tempfile", ".tmp");
63 BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
64 bw.write(testIdOrgString);
66 } catch (IOException e)
69 "Error initialising UrlProviderTest test: " + e.getMessage());
72 IdOrgSettings.setDownloadLocation(temp.getPath());
74 String defaultUrlString = "No default";
75 String cachedUrlList = "MIR:00000005|MIR:00000011|Test1|http://blah.blah/$SEQUENCE_ID$|"
76 + "Test2|http://test2/$DB_ACCESSION$|Test3|http://test3/$SEQUENCE_ID$";
77 String userUrlList = "MIR:00000372|Test4|httpL//another.url/$SEQUENCE_ID$";
79 DesktopUrlProviderFactory factory = new DesktopUrlProviderFactory(
80 defaultUrlString, cachedUrlList, userUrlList);
81 prov = factory.createUrlProvider();
84 @Test(groups = { "Functional" })
85 public void testInitUrlProvider()
87 String emblUrl = UrlConstants.DEFAULT_STRING.substring(
88 UrlConstants.DEFAULT_STRING.indexOf(UrlConstants.SEP) + 1,
89 UrlConstants.DEFAULT_STRING.length());
91 // chooses EMBL url when default Url id does not exist in provided url lists
92 Assert.assertEquals(prov.getPrimaryUrlId(), UrlConstants.DEFAULT_LABEL);
93 Assert.assertEquals(prov.getPrimaryUrl("FER_CAPAN"),
94 emblUrl.replace("$SEQUENCE_ID$", "FER_CAPAN"));
96 List<String> menulinks = prov.getLinksForMenu();
97 List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
99 // 9 links in provider - 4 from id file, 4 custom links, 1 additional
101 Assert.assertEquals(allLinks.size(), 9);
103 // 6 links in menu (cachedUrlList) + new default
104 Assert.assertEquals(menulinks.size(), 6);
107 menulinks.contains("Test1|http://blah.blah/$SEQUENCE_ID$"));
109 menulinks.contains("Test2|http://test2/$DB_ACCESSION$"));
111 menulinks.contains("Test3|http://test3/$SEQUENCE_ID$"));
112 Assert.assertTrue(menulinks.contains(
113 "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot"));
114 Assert.assertTrue(menulinks.contains(
115 "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro"));
116 Assert.assertTrue(menulinks.contains(
117 UrlConstants.DEFAULT_LABEL + UrlConstants.SEP + emblUrl));
120 @Test(groups = { "Functional" })
121 public void testSetDefaultUrl()
123 // set custom url as default
124 Assert.assertTrue(prov.setPrimaryUrl("Test1"));
125 Assert.assertEquals(prov.getPrimaryUrlId(), "Test1");
127 // set identifiers url as default
128 Assert.assertTrue(prov.setPrimaryUrl("MIR:00000011"));
129 Assert.assertEquals(prov.getPrimaryUrlId(), "MIR:00000011");
136 { IllegalArgumentException.class })
137 public void testSetDefaultUrlWrongly()
139 // don't allow default to be a non-key
140 prov.setPrimaryUrl("not-a-key");