1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
|
|
| 97.1% |
Uncovered Elements: 1 (35) |
Complexity: 5 |
Complexity Density: 0.16 |
|
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 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
85 |
4 |
{... |
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 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
94 |
1 |
@BeforeClass(alwaysRun = true)... |
95 |
|
public void setup() |
96 |
|
{ |
97 |
|
|
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 |
|
|
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
121 |
1 |
@Test(groups = { "Functional" })... |
122 |
|
public void testUrlLinks() |
123 |
|
{ |
124 |
|
|
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 |
|
|
131 |
|
|
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 |
|
|
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
145 |
1 |
@Test(groups = { "Functional" })... |
146 |
|
public void testDefaultUrl() |
147 |
|
{ |
148 |
|
|
149 |
1 |
String idList = "MIR:00000005|MIR:00000011|MIR:00000372"; |
150 |
1 |
UrlProviderI idProv = new IdentifiersUrlProvider(idList); |
151 |
|
|
152 |
|
|
153 |
1 |
assertEquals(null, idProv.getPrimaryUrl("seqid")); |
154 |
|
|
155 |
|
|
156 |
1 |
assertTrue(idProv.setPrimaryUrl("MIR:00000005")); |
157 |
1 |
assertEquals("http://identifiers.org/uniprot/seqid", |
158 |
|
idProv.getPrimaryUrl("seqid")); |
159 |
|
|
160 |
|
|
161 |
1 |
assertEquals(null, idProv.getPrimaryUrl("123")); |
162 |
|
|
163 |
|
|
164 |
1 |
assertFalse(idProv.setPrimaryUrl("MIR:00001234")); |
165 |
|
|
166 |
1 |
assertEquals(null, idProv.getPrimaryUrl("seqid")); |
167 |
|
|
168 |
|
|
169 |
1 |
assertEquals(null, idProv.choosePrimaryUrl()); |
170 |
|
} |
171 |
|
} |