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.
24 import static org.testng.AssertJUnit.assertEquals;
25 import static org.testng.AssertJUnit.assertFalse;
26 import static org.testng.AssertJUnit.assertTrue;
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.Vector;
32 import org.testng.annotations.Test;
34 public class IdentifiersUrlProviderTest
36 // Test identifiers.org download file
37 private static final String testIdOrgFile = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
38 + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
39 + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
40 + "\"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+)?$\","
41 + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
42 + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
43 + "\"url\":\"http://identifiers.org/interpro\"},"
44 + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
45 + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
47 private static final String[] dlinks = {
48 "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$",
49 "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
50 "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$"};
52 private static final String stringLinks = "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$"
53 + "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$"
54 + "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$";
57 private static final Vector<String> displayLinks = new Vector<String>(
58 Arrays.asList(dlinks));
60 private static final HashMap<String, String> urlMap = new HashMap<String, String>()
63 put("MIR:00000005", "http://identifiers.org/uniprot/$DB_ACCESSION$");
64 put("MIR:00000011", "http://identifiers.org/interpro/$DB_ACCESSION$");
65 put("MIR:00000372", "http://identifiers.org/ena.embl/$DB_ACCESSION$");
70 * Test urls are set and returned correctly
72 @Test(groups = { "Functional" })
73 public void testUrlLinks()
75 // creation from cached id list
76 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
77 UrlProviderI idProv = new IdentifiersUrlProvider(idList, testIdOrgFile);
79 assertTrue(displayLinks.containsAll(idProv.getLinksForDisplay()));
81 // because UrlProvider does not guarantee order of links, we can't just
82 // compare the output of writeUrlsAsString to a string, hence the hoops here
83 String result = idProv.writeUrlsAsString();
84 UrlProviderI up = new IdentifiersUrlProvider(result, testIdOrgFile);
85 assertTrue(displayLinks.containsAll(up.getLinksForDisplay()));
90 * Test default is set and returned correctly
92 @Test(groups = { "Functional" })
93 public void testDefaultUrl()
95 // creation from cached id list
96 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
97 UrlProviderI idProv = new IdentifiersUrlProvider(idList, testIdOrgFile);
99 // initially no default
100 assertEquals(null, idProv.getDefaultUrl());
102 // set and then retrieve default
103 assertTrue(idProv.setDefaultUrl("MIR:00000005"));
104 assertEquals("MIR:00000005", idProv.getDefaultUrl());
105 assertEquals("http://identifiers.org/uniprot/id",
106 idProv.getDefaultUrl("id"));
108 // attempt to set bad default
109 assertFalse(idProv.setDefaultUrl("MIR:00001234"));
110 // default set to null (as default should have been set elsewhere)
111 assertEquals(null, idProv.getDefaultUrl());
113 // chooseDefaultUrl not implemented for IdentifiersUrlProvider
114 assertEquals(null, idProv.chooseDefaultUrl());
118 * Test url setting works
120 @Test(groups = { "Functional" })
121 public void testSetUrlLinks()
123 // creation from cached id list
124 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
125 UrlProviderI idProv = new IdentifiersUrlProvider(idList, testIdOrgFile);
128 String[] ids = { "MIR:00000372", "MIR:00000011" };
129 Vector<String> names = new Vector<String>(Arrays.asList(ids));
130 Vector<String> urls = null;
131 idProv.setUrlLinks(names, urls);
132 assertEquals(names, idProv.getLinksForDisplay());
134 //set default url then reset url links, default should be unset if not present
135 String[] moreids = { "MIR:00000005", "MIR:00000011" };
136 names = new Vector<String>(Arrays.asList(moreids));
137 idProv.setDefaultUrl("MIR:00000372");
138 idProv.setUrlLinks(names, urls);
139 assertEquals(names, idProv.getLinksForDisplay());
140 assertEquals(null, idProv.getDefaultUrl());