--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.testng.annotations.Test;
+
+public class IdentifiersUrlProviderTest
+{
+ // Test identifiers.org download file
+ private static final String testIdOrgFile = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+ + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
+ + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
+ + "\"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+)?$\","
+ + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
+ + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
+ + "\"url\":\"http://identifiers.org/interpro\"},"
+ + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
+ + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
+
+ private static final String[] dlinks = {
+ "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$",
+ "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
+ "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$"};
+
+ private static final String stringLinks = "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$"
+ + "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$"
+ + "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$";
+
+
+ private static final Vector<String> displayLinks = new Vector<String>(
+ Arrays.asList(dlinks));
+
+ private static final HashMap<String, String> urlMap = new HashMap<String, String>()
+ {
+ {
+ put("MIR:00000005", "http://identifiers.org/uniprot/$DB_ACCESSION$");
+ put("MIR:00000011", "http://identifiers.org/interpro/$DB_ACCESSION$");
+ put("MIR:00000372", "http://identifiers.org/ena.embl/$DB_ACCESSION$");
+ }
+ };
+
+ /*
+ * Test urls are set and returned correctly
+ */
+ @Test(groups = { "Functional" })
+ public void testUrlLinks()
+ {
+ // creation from cached id list
+ String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList, testIdOrgFile);
+
+ assertTrue(displayLinks.containsAll(idProv.getLinksForDisplay()));
+
+ // because UrlProvider does not guarantee order of links, we can't just
+ // compare the output of writeUrlsAsString to a string, hence the hoops here
+ String result = idProv.writeUrlsAsString();
+ UrlProviderI up = new IdentifiersUrlProvider(result, testIdOrgFile);
+ assertTrue(displayLinks.containsAll(up.getLinksForDisplay()));
+
+ }
+
+ /*
+ * Test default is set and returned correctly
+ */
+ @Test(groups = { "Functional" })
+ public void testDefaultUrl()
+ {
+ // creation from cached id list
+ String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList, testIdOrgFile);
+
+ // initially no default
+ assertEquals(null, idProv.getDefaultUrl());
+
+ // set and then retrieve default
+ assertTrue(idProv.setDefaultUrl("MIR:00000005"));
+ assertEquals("MIR:00000005", idProv.getDefaultUrl());
+ assertEquals("http://identifiers.org/uniprot/id",
+ idProv.getDefaultUrl("id"));
+
+ // attempt to set bad default
+ assertFalse(idProv.setDefaultUrl("MIR:00001234"));
+ // default set to null (as default should have been set elsewhere)
+ assertEquals(null, idProv.getDefaultUrl());
+
+ // chooseDefaultUrl not implemented for IdentifiersUrlProvider
+ assertEquals(null, idProv.chooseDefaultUrl());
+ }
+
+ /*
+ * Test url setting works
+ */
+ @Test(groups = { "Functional" })
+ public void testSetUrlLinks()
+ {
+ // creation from cached id list
+ String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList, testIdOrgFile);
+
+ // set url links
+ String[] ids = { "MIR:00000372", "MIR:00000011" };
+ Vector<String> names = new Vector<String>(Arrays.asList(ids));
+ Vector<String> urls = null;
+ idProv.setUrlLinks(names, urls);
+ assertEquals(names, idProv.getLinksForDisplay());
+
+ //set default url then reset url links, default should be unset if not present
+ String[] moreids = { "MIR:00000005", "MIR:00000011" };
+ names = new Vector<String>(Arrays.asList(moreids));
+ idProv.setDefaultUrl("MIR:00000372");
+ idProv.setUrlLinks(names, urls);
+ assertEquals(names, idProv.getLinksForDisplay());
+ assertEquals(null, idProv.getDefaultUrl());
+
+ }
+}