Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:12:26 GMT
  2. Package jalview.urls

File IdentifiersUrlProviderTest.java

 

Code metrics

0
31
4
1
171
101
5
0.16
7.75
4
1.25

Classes

Class Line # Actions
IdentifiersUrlProviderTest 39 31 5
0.971428697.1%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21   
22    package jalview.urls;
23   
24    import static org.testng.AssertJUnit.assertEquals;
25    import static org.testng.AssertJUnit.assertFalse;
26    import static org.testng.AssertJUnit.assertTrue;
27   
28    import jalview.urls.api.UrlProviderI;
29   
30    import java.io.File;
31    import java.io.FileWriter;
32    import java.util.Arrays;
33    import java.util.HashMap;
34    import java.util.Vector;
35   
36    import org.testng.annotations.BeforeClass;
37    import org.testng.annotations.Test;
38   
 
39    public class IdentifiersUrlProviderTest
40    {
41    private static final String testIdOrgFile = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
42    + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
43    + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
44    + "\"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+)?$\","
45    + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
46    + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
47    + "\"url\":\"http://identifiers.org/interpro\"},"
48    + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
49    + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
50   
51    private static final String[] dlinks = {
52    "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot",
53    "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro",
54    "ENA|http://identifiers.org/ena.embl/$DB_ACCESSION$|ena.embl" };
55   
56    private static final String[] dlinks1 = {
57    "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
58    "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$" };
59   
60    private static final String[] dlinks2 = {
61    "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$",
62    "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$" };
63   
64    private static final String stringLinks = "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$"
65    + "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$"
66    + "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$";
67   
68    private static final String[] unselDlinks = {
69    "ChEBI|http://identifiers.org/chebi/$DB_ACCESSION$" };
70   
71    private static final Vector<String> displayLinks = new Vector<String>(
72    Arrays.asList(dlinks));
73   
74    private static final Vector<String> unselDisplayLinks = new Vector<String>(
75    Arrays.asList(unselDlinks));
76   
77    private static final Vector<String> displayLinks1 = new Vector<String>(
78    Arrays.asList(dlinks1));
79   
80    private static final Vector<String> displayLinks2 = new Vector<String>(
81    Arrays.asList(dlinks2));
82   
83    private static final HashMap<String, String> urlMap = new HashMap<String, String>()
84    {
 
85  4 toggle {
86  4 put("MIR:00000005", "http://identifiers.org/uniprot/$DB_ACCESSION$");
87  4 put("MIR:00000011", "http://identifiers.org/interpro/$DB_ACCESSION$");
88  4 put("MIR:00000372", "http://identifiers.org/ena.embl/$DB_ACCESSION$");
89    }
90    };
91   
92    private String testfile = "";
93   
 
94  1 toggle @BeforeClass(alwaysRun = true)
95    public void setup()
96    {
97    // setup test ids in a file
98  1 File outFile = null;
99  1 try
100    {
101  1 outFile = File.createTempFile("testidsfile", "txt");
102  1 outFile.deleteOnExit();
103   
104  1 FileWriter fw = new FileWriter(outFile);
105  1 fw.write(testIdOrgFile);
106  1 fw.close();
107   
108  1 testfile = outFile.getAbsolutePath();
109   
110    } catch (Exception ex)
111    {
112  0 System.err.println(ex);
113    }
114   
115  1 IdOrgSettings.setDownloadLocation(testfile);
116    }
117   
118    /*
119    * Test urls are set and returned correctly
120    */
 
121  1 toggle @Test(groups = { "Functional" })
122    public void testUrlLinks()
123    {
124    // creation from cached id list
125  1 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
126  1 UrlProviderI idProv = new IdentifiersUrlProvider(idList);
127   
128  1 assertTrue(displayLinks.containsAll(idProv.getLinksForMenu()));
129   
130    // because UrlProvider does not guarantee order of links, we can't just
131    // compare the output of writeUrlsAsString to a string, hence the hoops here
132  1 String result = idProv.writeUrlsAsString(true);
133  1 UrlProviderI up = new IdentifiersUrlProvider(result);
134  1 assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
135   
136  1 result = idProv.writeUrlsAsString(false);
137  1 up = new IdentifiersUrlProvider(result);
138  1 assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
139   
140    }
141   
142    /*
143    * Test default is set and returned correctly
144    */
 
145  1 toggle @Test(groups = { "Functional" })
146    public void testDefaultUrl()
147    {
148    // creation from cached id list
149  1 String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
150  1 UrlProviderI idProv = new IdentifiersUrlProvider(idList);
151   
152    // initially no default
153  1 assertEquals(null, idProv.getPrimaryUrl("seqid"));
154   
155    // set and then retrieve default
156  1 assertTrue(idProv.setPrimaryUrl("MIR:00000005"));
157  1 assertEquals("http://identifiers.org/uniprot/seqid",
158    idProv.getPrimaryUrl("seqid"));
159   
160    // ids less than length 4 return null
161  1 assertEquals(null, idProv.getPrimaryUrl("123"));
162   
163    // attempt to set bad default
164  1 assertFalse(idProv.setPrimaryUrl("MIR:00001234"));
165    // default set to null (as default should have been set elsewhere)
166  1 assertEquals(null, idProv.getPrimaryUrl("seqid"));
167   
168    // chooseDefaultUrl not implemented for IdentifiersUrlProvider
169  1 assertEquals(null, idProv.choosePrimaryUrl());
170    }
171    }