3 import jalview.urls.api.UrlProviderI;
4 import jalview.urls.desktop.DesktopUrlProviderFactory;
5 import jalview.util.UrlConstants;
7 import java.io.BufferedWriter;
9 import java.io.FileWriter;
10 import java.io.IOException;
11 import java.util.List;
12 import java.util.Vector;
14 import org.testng.Assert;
15 import org.testng.annotations.BeforeMethod;
16 import org.testng.annotations.Test;
19 public class UrlProviderTest {
21 // Test identifiers.org download file
22 private static final String testIdOrgString = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
23 + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
24 + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
25 + "\"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+)?$\","
26 + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
27 + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
28 + "\"url\":\"http://identifiers.org/interpro\"},"
29 + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
30 + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
32 private UrlProviderI prov;
34 @BeforeMethod(alwaysRun = true)
37 // make a dummy identifiers.org download file
42 temp = File.createTempFile("tempfile", ".tmp");
44 BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
45 bw.write(testIdOrgString);
47 } catch (IOException e)
49 System.out.println("Error initialising UrlProviderTest test: "
53 IdOrgSettings.setDownloadLocation(temp.getPath());
55 String defaultUrlString = "No default";
56 String cachedUrlList = "MIR:00000005|MIR:00000011|Test1|http://blah.blah/$SEQUENCE_ID$|"
57 + "Test2|http://test2/$DB_ACCESSION$|Test3|http://test3/$SEQUENCE_ID$";
58 String userUrlList = "MIR:00000372|Test4|httpL//another.url/$SEQUENCE_ID$";
60 DesktopUrlProviderFactory factory = new DesktopUrlProviderFactory(
61 defaultUrlString, cachedUrlList, userUrlList);
62 prov = factory.createUrlProvider();
65 @Test(groups = { "Functional" })
66 public void testInitUrlProvider()
68 String emblUrl = UrlConstants.DEFAULT_STRING.substring(
69 UrlConstants.DEFAULT_STRING.indexOf(UrlConstants.SEP) + 1,
70 UrlConstants.DEFAULT_STRING.length());
72 // chooses EMBL url when default Url id does not exist in provided url lists
73 Assert.assertEquals(prov.getDefaultUrlId(), UrlConstants.DEFAULT_LABEL);
74 Assert.assertEquals(prov.getDefaultUrl("FER_CAPAN"),
75 emblUrl.replace("$SEQUENCE_ID$", "FER_CAPAN"));
77 Vector<String> menulinks = prov.getLinksForMenu();
78 List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
80 // 9 links in provider - 4 from id file, 4 custom links, 1 additional
82 Assert.assertEquals(allLinks.size(), 9);
84 // 6 links in menu (cachedUrlList) + new default
85 Assert.assertEquals(menulinks.size(), 6);
87 Assert.assertTrue(menulinks
88 .contains("Test1|http://blah.blah/$SEQUENCE_ID$"));
89 Assert.assertTrue(menulinks
90 .contains("Test2|http://test2/$DB_ACCESSION$"));
91 Assert.assertTrue(menulinks
92 .contains("Test3|http://test3/$SEQUENCE_ID$"));
93 Assert.assertTrue(menulinks
94 .contains("UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$"));
95 Assert.assertTrue(menulinks
96 .contains("InterPro|http://identifiers.org/interpro/$DB_ACCESSION$"));
97 Assert.assertTrue(menulinks.contains(UrlConstants.DEFAULT_LABEL
98 + UrlConstants.SEP + emblUrl));
101 @Test(groups = { "Functional" })
102 public void testSetDefaultUrl()
104 // set custom url as default
105 Assert.assertTrue(prov.setDefaultUrl("Test1"));
106 Assert.assertEquals(prov.getDefaultUrlId(), "Test1");
108 // set identifiers url as default
109 Assert.assertTrue(prov.setDefaultUrl("MIR:00000011"));
110 Assert.assertEquals(prov.getDefaultUrlId(), "MIR:00000011");
114 groups = { "Functional" },
115 expectedExceptions = { IllegalArgumentException.class })
116 public void testSetDefaultUrlWrongly()
118 // don't allow default to be a non-key
119 prov.setDefaultUrl("not-a-key");