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 java.io.BufferedWriter;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.util.List;
28 import java.util.Vector;
30 import org.testng.Assert;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.Test;
34 public class DesktopUrlProviderFactoryTest
36 // Test identifiers.org download file
37 private static final String testIdOrgString = "[{\"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 @BeforeMethod(alwaysRun = true)
50 // make a dummy identifiers.org download file
55 temp = File.createTempFile("tempfile", ".tmp");
57 BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
58 bw.write(testIdOrgString);
60 } catch (IOException e)
63 .println("Error initialising DesktopUrlProviderFactoryTest test: "
67 IdOrgSettings.setDownloadLocation(temp.getPath());
70 @Test(groups = { "Functional" })
71 public void testCreateUrlProvider()
73 String defaultUrlString = "Test1";
74 String defaultUrl = "http://blah.blah/$SEQUENCE_ID$";
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 UrlProviderI prov = factory.createUrlProvider();
83 // default url correctly set
84 Assert.assertEquals(prov.getDefaultUrlId(), "Test1");
85 Assert.assertEquals(prov.getDefaultUrl("FER_CAPAN"),
86 defaultUrl.replace("$SEQUENCE_ID$", "FER_CAPAN"));
88 Vector<String> menulinks = prov.getLinksForMenu();
89 List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
91 // 8 links in provider - 4 from id file, 4 custom links
92 Assert.assertEquals(allLinks.size(), 8);
94 // 5 links in menu (cachedUrlList)
95 Assert.assertEquals(menulinks.size(), 5);
97 Assert.assertTrue(menulinks
98 .contains("Test1|http://blah.blah/$SEQUENCE_ID$"));
99 Assert.assertTrue(menulinks
100 .contains("Test2|http://test2/$DB_ACCESSION$"));
101 Assert.assertTrue(menulinks
102 .contains("Test3|http://test3/$SEQUENCE_ID$"));
103 Assert.assertTrue(menulinks
104 .contains("UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$"));
105 Assert.assertTrue(menulinks
106 .contains("InterPro|http://identifiers.org/interpro/$DB_ACCESSION$"));