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 jalview.util.UrlConstants.DELIM; |
25 |
|
import static jalview.util.UrlConstants.SEP; |
26 |
|
import static jalview.util.UrlConstants.SEQUENCE_ID; |
27 |
|
|
28 |
|
import jalview.urls.api.UrlProviderI; |
29 |
|
import jalview.util.MessageManager; |
30 |
|
|
31 |
|
import java.io.BufferedWriter; |
32 |
|
import java.io.File; |
33 |
|
import java.io.FileWriter; |
34 |
|
import java.io.IOException; |
35 |
|
import java.util.ArrayList; |
36 |
|
import java.util.List; |
37 |
|
|
38 |
|
import javax.swing.event.TableModelListener; |
39 |
|
|
40 |
|
import org.testng.Assert; |
41 |
|
import org.testng.annotations.BeforeMethod; |
42 |
|
import org.testng.annotations.Test; |
43 |
|
|
|
|
| 99.3% |
Uncovered Elements: 1 (136) |
Complexity: 25 |
Complexity Density: 0.24 |
|
44 |
|
public class UrlLinkTableModelTest { |
45 |
|
|
46 |
|
private static final String inmenu = "TEST|http://someurl.blah/$DB_ACCESSION$|" |
47 |
|
+ "ANOTHER|http://test/t$SEQUENCE_ID$|" |
48 |
|
+ "TEST2|http://address/$SEQUENCE_ID$|SRS|" |
49 |
|
+ "http://theSRSlink/$SEQUENCE_ID$|" |
50 |
|
+ "MIR:00000005|MIR:00000011|MIR:00000372"; |
51 |
|
|
52 |
|
private static final String notinmenu = "Not1|http://not.in.menu/$DB_ACCESSION$|" |
53 |
|
+ "Not2|http://not.in.menu.either/$DB_ACCESSION$"; |
54 |
|
|
55 |
|
private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\"," |
56 |
|
+ "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\"," |
57 |
|
+ "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\"," |
58 |
|
+ "\"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+)?$\"," |
59 |
|
+ "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"}," |
60 |
|
+ "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\"," |
61 |
|
+ "\"url\":\"http://identifiers.org/interpro\"}," |
62 |
|
+ "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\"" |
63 |
|
+ "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}"; |
64 |
|
|
65 |
|
private UrlProviderI prov; |
66 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 2 |
Complexity Density: 0.13 |
|
67 |
9 |
@BeforeMethod(alwaysRun = true)... |
68 |
|
public void setup() |
69 |
|
{ |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
9 |
File temp = null; |
76 |
9 |
try |
77 |
|
{ |
78 |
9 |
temp = File.createTempFile("tempfile", ".tmp"); |
79 |
9 |
temp.deleteOnExit(); |
80 |
9 |
BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); |
81 |
9 |
bw.write(testIdOrgString); |
82 |
9 |
bw.close(); |
83 |
|
} catch (IOException e) |
84 |
|
{ |
85 |
0 |
System.out.println("Error initialising UrlLinkTableModel test: " |
86 |
|
+ e.getMessage()); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
9 |
IdOrgSettings.setDownloadLocation(temp.getPath()); |
91 |
9 |
IdentifiersUrlProvider idprov = new IdentifiersUrlProvider(inmenu); |
92 |
9 |
CustomUrlProvider cprov = new CustomUrlProvider(inmenu, notinmenu); |
93 |
9 |
List<UrlProviderI> provlist = new ArrayList<UrlProviderI>(); |
94 |
9 |
provlist.add(idprov); |
95 |
9 |
provlist.add(cprov); |
96 |
|
|
97 |
9 |
prov = new UrlProvider("TEST2", provlist); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
1PASS
|
|
104 |
1 |
@Test(groups = { "Functional" })... |
105 |
|
public void testInitialisation() |
106 |
|
{ |
107 |
1 |
int defaultCol = 4; |
108 |
1 |
int dbCol = 0; |
109 |
1 |
int descCol = 1; |
110 |
|
|
111 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
112 |
|
|
113 |
|
|
114 |
1 |
TableModelListener[] listeners = m |
115 |
|
.getListeners(TableModelListener.class); |
116 |
1 |
Assert.assertEquals(listeners.length, 1); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
1 |
int count = 0; |
121 |
11 |
for (int row = 0; row < m.getRowCount(); row++) |
122 |
|
{ |
123 |
10 |
boolean isDefault = (boolean) m.getValueAt(row, defaultCol); |
124 |
10 |
if (isDefault) |
125 |
|
{ |
126 |
1 |
count++; |
127 |
1 |
String defaultDBName = (String) m.getValueAt(row, dbCol); |
128 |
1 |
Assert.assertEquals(defaultDBName, "TEST2"); |
129 |
|
|
130 |
1 |
String defaultDesc = (String) m.getValueAt(row, descCol); |
131 |
1 |
Assert.assertEquals(defaultDesc, "TEST2"); |
132 |
|
} |
133 |
|
} |
134 |
1 |
Assert.assertEquals(count, 1); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
140 |
1 |
@Test(groups = { "Functional" })... |
141 |
|
public void testCounts() |
142 |
|
{ |
143 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
144 |
|
|
145 |
|
|
146 |
1 |
Assert.assertEquals(m.getColumnCount(), 5); |
147 |
1 |
Assert.assertEquals(m.getRowCount(), 10); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
153 |
1 |
@Test(groups = { "Functional" })... |
154 |
|
public void testColumns() |
155 |
|
{ |
156 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
157 |
|
|
158 |
|
|
159 |
1 |
Assert.assertEquals(m.getColumnName(0), |
160 |
|
MessageManager.formatMessage("label.database")); |
161 |
1 |
Assert.assertEquals(m.getColumnName(1), |
162 |
|
MessageManager.formatMessage("label.name")); |
163 |
1 |
Assert.assertEquals(m.getColumnName(2), |
164 |
|
MessageManager.formatMessage("label.url")); |
165 |
1 |
Assert.assertEquals(m.getColumnName(3), |
166 |
|
MessageManager.formatMessage("label.inmenu")); |
167 |
1 |
Assert.assertEquals(m.getColumnName(4), |
168 |
|
MessageManager.formatMessage("label.primary")); |
169 |
|
|
170 |
|
|
171 |
1 |
Assert.assertEquals(m.getColumnClass(0), String.class); |
172 |
1 |
Assert.assertEquals(m.getColumnClass(1), String.class); |
173 |
1 |
Assert.assertEquals(m.getColumnClass(2), String.class); |
174 |
1 |
Assert.assertEquals(m.getColumnClass(3), Boolean.class); |
175 |
1 |
Assert.assertEquals(m.getColumnClass(4), Boolean.class); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
181 |
1 |
@Test(groups = { "Functional" })... |
182 |
|
public void testRowInsert() |
183 |
|
{ |
184 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
185 |
|
|
186 |
1 |
m.insertRow("newname", "newurl"); |
187 |
|
|
188 |
|
|
189 |
1 |
Assert.assertEquals(m.getValueAt(10, 0), "newname"); |
190 |
1 |
Assert.assertEquals(m.getValueAt(10, 1), "newname"); |
191 |
1 |
Assert.assertEquals(m.getValueAt(10, 2), "newurl"); |
192 |
1 |
Assert.assertEquals(m.getValueAt(10, 3), true); |
193 |
1 |
Assert.assertEquals(m.getValueAt(10, 4), false); |
194 |
|
|
195 |
|
|
196 |
1 |
Assert.assertTrue(prov.getLinksForMenu().contains( |
197 |
|
"newname" + SEP + "newurl")); |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
203 |
1 |
@Test(groups = { "Functional" })... |
204 |
|
public void testRowDelete() |
205 |
|
{ |
206 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
207 |
|
|
208 |
|
|
209 |
1 |
String name = (String) m.getValueAt(0, 0); |
210 |
1 |
String url = (String) m.getValueAt(0, 1); |
211 |
|
|
212 |
1 |
m.removeRow(0); |
213 |
|
|
214 |
|
|
215 |
10 |
for (int row = 0; row < m.getRowCount(); row++) |
216 |
|
{ |
217 |
9 |
Assert.assertNotEquals(m.getValueAt(row, 0), name); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
1 |
Assert.assertFalse(prov.getLinksForMenu().contains(name + SEP + url)); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 4 |
Complexity Density: 0.16 |
1PASS
|
|
227 |
1 |
@Test(groups = { "Functional" })... |
228 |
|
public void testValues() |
229 |
|
{ |
230 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
231 |
|
|
232 |
|
|
233 |
1 |
int olddefault; |
234 |
1 |
boolean isDefault = false; |
235 |
2 |
for (olddefault = 0; olddefault < m.getRowCount() && !isDefault; olddefault++) |
236 |
|
{ |
237 |
1 |
isDefault = (boolean) m.getValueAt(olddefault, 3); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
1 |
m.setValueAt("dbnamechanged", 6, 0); |
242 |
1 |
m.setValueAt("descchanged", 6, 1); |
243 |
1 |
m.setValueAt("urlchanged", 7, 2); |
244 |
1 |
m.setValueAt(false, 8, 3); |
245 |
1 |
m.setValueAt(true, 6, 4); |
246 |
|
|
247 |
1 |
m.setValueAt("dbnamechanged", 5, 0); |
248 |
|
|
249 |
|
|
250 |
1 |
Assert.assertEquals(m.getValueAt(6, 0), "descchanged"); |
251 |
|
|
252 |
1 |
Assert.assertEquals(m.getValueAt(6, 1), "descchanged"); |
253 |
1 |
Assert.assertEquals(m.getValueAt(7, 2), "urlchanged"); |
254 |
1 |
Assert.assertFalse((boolean) m.getValueAt(8, 3)); |
255 |
1 |
Assert.assertTrue((boolean) m.getValueAt(6, 4)); |
256 |
1 |
Assert.assertFalse((boolean) m.getValueAt(olddefault, 4)); |
257 |
|
|
258 |
1 |
Assert.assertEquals(m.getValueAt(5, 0), "dbnamechanged"); |
259 |
|
|
260 |
|
|
261 |
11 |
for (int row = 0; row < m.getRowCount(); row++) |
262 |
|
{ |
263 |
10 |
isDefault = (boolean) m.getValueAt(row, 4); |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
10 |
Assert.assertFalse(isDefault && !(row == 6)); |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
1 |
Assert.assertTrue(prov.writeUrlsAsString(true).contains( |
272 |
|
"descchanged" + SEP + m.getValueAt(6, 2))); |
273 |
1 |
Assert.assertTrue(prov.writeUrlsAsString(true).contains( |
274 |
|
m.getValueAt(7, 1) + SEP + "urlchanged")); |
275 |
1 |
Assert.assertTrue(prov.writeUrlsAsString(false).contains( |
276 |
|
(String) m.getValueAt(8, 1))); |
277 |
1 |
Assert.assertEquals(prov.getPrimaryUrl("seqid"), m.getValueAt(6, 2) |
278 |
|
.toString().replace(DELIM + SEQUENCE_ID + DELIM, "seqid")); |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
1PASS
|
|
284 |
1 |
@Test(groups = { "Functional" })... |
285 |
|
public void testEditable() |
286 |
|
{ |
287 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
288 |
|
|
289 |
11 |
for (int row = 0; row < m.getRowCount(); row++) |
290 |
|
{ |
291 |
10 |
Assert.assertFalse(m.isCellEditable(row, 0)); |
292 |
10 |
Assert.assertFalse(m.isCellEditable(row, 1)); |
293 |
10 |
Assert.assertFalse(m.isCellEditable(row, 2)); |
294 |
10 |
Assert.assertTrue(m.isCellEditable(row, 3)); |
295 |
|
|
296 |
10 |
if ((row == 4) || (row == 6) || (row == 7)) |
297 |
|
{ |
298 |
3 |
Assert.assertTrue(m.isCellEditable(row, 4)); |
299 |
|
} |
300 |
|
else |
301 |
|
{ |
302 |
7 |
Assert.assertFalse(m.isCellEditable(row, 4)); |
303 |
|
} |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
1PASS
|
|
310 |
1 |
@Test(groups = { "Functional" })... |
311 |
|
public void testDeletable() |
312 |
|
{ |
313 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
314 |
|
|
315 |
11 |
for (int row = 0; row < m.getRowCount(); row++) |
316 |
|
{ |
317 |
10 |
if (row > 4) |
318 |
|
{ |
319 |
5 |
Assert.assertTrue(m.isRowDeletable(row)); |
320 |
|
} |
321 |
|
else |
322 |
|
{ |
323 |
5 |
Assert.assertFalse(m.isRowDeletable(row)); |
324 |
|
} |
325 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
1PASS
|
|
331 |
1 |
@Test(groups = { "Functional" })... |
332 |
|
public void testRowEditable() |
333 |
|
{ |
334 |
1 |
UrlLinkTableModel m = new UrlLinkTableModel(prov); |
335 |
|
|
336 |
11 |
for (int row = 0; row < m.getRowCount(); row++) |
337 |
|
{ |
338 |
10 |
if (row > 3) |
339 |
|
{ |
340 |
6 |
Assert.assertTrue(m.isRowEditable(row)); |
341 |
|
} |
342 |
|
else |
343 |
|
{ |
344 |
4 |
Assert.assertFalse(m.isRowEditable(row)); |
345 |
|
} |
346 |
|
} |
347 |
|
} |
348 |
|
} |