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 jalview.urls.api.UrlProviderI;
31 import java.io.FileWriter;
32 import java.util.Arrays;
33 import java.util.HashMap;
34 import java.util.Vector;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.Test;
39 public class IdentifiersUrlProviderTest
41 // Test identifiers.org download file
42 private static final String testIdOrgFile = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
43 + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
44 + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
45 + "\"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+)?$\","
46 + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
47 + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
48 + "\"url\":\"http://identifiers.org/interpro\"},"
49 + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
50 + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
52 private static final String[] dlinks = {
53 "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$",
54 "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$",
55 "ENA|http://identifiers.org/ena.embl/$DB_ACCESSION$" };
57 private static final String[] dlinks1 = {
58 "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
59 "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$" };
61 private static final String[] dlinks2 = {
62 "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$",
63 "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$" };
65 private static final String stringLinks = "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$"
66 + "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$"
67 + "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$";
69 private static final String[] unselDlinks = { "ChEBI|http://identifiers.org/chebi/$DB_ACCESSION$" };
71 private static final Vector<String> displayLinks = new Vector<String>(
72 Arrays.asList(dlinks));
74 private static final Vector<String> unselDisplayLinks = new Vector<String>(
75 Arrays.asList(unselDlinks));
77 private static final Vector<String> displayLinks1 = new Vector<String>(
78 Arrays.asList(dlinks1));
80 private static final Vector<String> displayLinks2 = new Vector<String>(
81 Arrays.asList(dlinks2));
83 private static final HashMap<String, String> urlMap = new HashMap<String, String>()
86 put("MIR:00000005", "http://identifiers.org/uniprot/$DB_ACCESSION$");
87 put("MIR:00000011", "http://identifiers.org/interpro/$DB_ACCESSION$");
88 put("MIR:00000372", "http://identifiers.org/ena.embl/$DB_ACCESSION$");
92 private String testfile = "";
95 @BeforeClass(alwaysRun = true)
98 // setup test ids in a file
102 outFile = File.createTempFile("testidsfile", "txt");
103 outFile.deleteOnExit();
105 FileWriter fw = new FileWriter(outFile);
106 fw.write(testIdOrgFile);
109 testfile = outFile.getAbsolutePath();
111 } catch (Exception ex)
113 System.err.println(ex);
116 IdOrgSettings.setDownloadLocation(testfile);
120 * Test urls are set and returned correctly
122 @Test(groups = { "Functional" })
123 public void testUrlLinks()
125 // creation from cached id list
126 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
127 UrlProviderI idProv = new IdentifiersUrlProvider(idList);
129 assertTrue(displayLinks.containsAll(idProv.getLinksForMenu()));
131 // because UrlProvider does not guarantee order of links, we can't just
132 // compare the output of writeUrlsAsString to a string, hence the hoops here
133 String result = idProv.writeUrlsAsString(true);
134 UrlProviderI up = new IdentifiersUrlProvider(result);
135 assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
137 result = idProv.writeUrlsAsString(false);
138 up = new IdentifiersUrlProvider(result);
139 assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
144 * Test default is set and returned correctly
146 @Test(groups = { "Functional" })
147 public void testDefaultUrl()
149 // creation from cached id list
150 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
151 UrlProviderI idProv = new IdentifiersUrlProvider(idList);
153 // initially no default
154 assertEquals(null, idProv.getDefaultUrl("seqid"));
156 // set and then retrieve default
157 assertTrue(idProv.setDefaultUrl("MIR:00000005"));
158 assertEquals("http://identifiers.org/uniprot/seqid",
159 idProv.getDefaultUrl("seqid"));
161 // ids less than length 4 return null
163 idProv.getDefaultUrl("123"));
165 // attempt to set bad default
166 assertFalse(idProv.setDefaultUrl("MIR:00001234"));
167 // default set to null (as default should have been set elsewhere)
168 assertEquals(null, idProv.getDefaultUrl("seqid"));
170 // chooseDefaultUrl not implemented for IdentifiersUrlProvider
171 assertEquals(null, idProv.chooseDefaultUrl());