Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.urls

File UrlProviderTest.java

 

Code metrics

0
32
4
1
120
90
5
0.16
8
4
1.25

Classes

Class Line # Actions
UrlProviderTest 18 32 5 1
0.972222297.2%
 

Contributing tests

This file is covered by 3 tests. .

Source view

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