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