1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.urls; |
22 |
|
|
23 |
|
import jalview.urls.api.UrlProviderI; |
24 |
|
import jalview.urls.desktop.DesktopUrlProviderFactory; |
25 |
|
|
26 |
|
import java.io.BufferedWriter; |
27 |
|
import java.io.File; |
28 |
|
import java.io.FileWriter; |
29 |
|
import java.io.IOException; |
30 |
|
import java.util.List; |
31 |
|
|
32 |
|
import org.testng.Assert; |
33 |
|
import org.testng.annotations.BeforeMethod; |
34 |
|
import org.testng.annotations.Test; |
35 |
|
|
|
|
| 96.4% |
Uncovered Elements: 1 (28) |
Complexity: 3 |
Complexity Density: 0.12 |
|
36 |
|
public class DesktopUrlProviderFactoryTest |
37 |
|
{ |
38 |
|
private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\"," |
39 |
|
+ "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\"," |
40 |
|
+ "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\"," |
41 |
|
+ "\"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+)?$\"," |
42 |
|
+ "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"}," |
43 |
|
+ "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\"," |
44 |
|
+ "\"url\":\"http://identifiers.org/interpro\"}," |
45 |
|
+ "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\"" |
46 |
|
+ "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}"; |
47 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
48 |
1 |
@BeforeMethod(alwaysRun = true)... |
49 |
|
public void setup() |
50 |
|
{ |
51 |
|
|
52 |
1 |
File temp = null; |
53 |
|
|
54 |
1 |
try |
55 |
|
{ |
56 |
1 |
temp = File.createTempFile("tempfile", ".tmp"); |
57 |
1 |
temp.deleteOnExit(); |
58 |
1 |
BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); |
59 |
1 |
bw.write(testIdOrgString); |
60 |
1 |
bw.close(); |
61 |
|
} catch (IOException e) |
62 |
|
{ |
63 |
0 |
System.out.println( |
64 |
|
"Error initialising DesktopUrlProviderFactoryTest test: " |
65 |
|
+ e.getMessage()); |
66 |
|
} |
67 |
|
|
68 |
1 |
IdOrgSettings.setDownloadLocation(temp.getPath()); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
71 |
1 |
@Test(groups = { "Functional" })... |
72 |
|
public void testCreateUrlProvider() |
73 |
|
{ |
74 |
1 |
String defaultUrlString = "Test1"; |
75 |
1 |
String defaultUrl = "http://blah.blah/$SEQUENCE_ID$"; |
76 |
1 |
String cachedUrlList = "MIR:00000005|MIR:00000011|Test1|http://blah.blah/$SEQUENCE_ID$|" |
77 |
|
+ "Test2|http://test2/$DB_ACCESSION$|Test3|http://test3/$SEQUENCE_ID$"; |
78 |
1 |
String userUrlList = "MIR:00000372|Test4|httpL//another.url/$SEQUENCE_ID$"; |
79 |
|
|
80 |
1 |
DesktopUrlProviderFactory factory = new DesktopUrlProviderFactory( |
81 |
|
defaultUrlString, cachedUrlList, userUrlList); |
82 |
1 |
UrlProviderI prov = factory.createUrlProvider(); |
83 |
|
|
84 |
|
|
85 |
1 |
Assert.assertEquals(prov.getPrimaryUrlId(), "Test1"); |
86 |
1 |
Assert.assertEquals(prov.getPrimaryUrl("FER_CAPAN"), |
87 |
|
defaultUrl.replace("$SEQUENCE_ID$", "FER_CAPAN")); |
88 |
|
|
89 |
1 |
List<String> menulinks = prov.getLinksForMenu(); |
90 |
1 |
List<UrlLinkDisplay> allLinks = prov.getLinksForTable(); |
91 |
|
|
92 |
|
|
93 |
1 |
Assert.assertEquals(allLinks.size(), 8); |
94 |
|
|
95 |
|
|
96 |
1 |
Assert.assertEquals(menulinks.size(), 5); |
97 |
|
|
98 |
1 |
Assert.assertTrue( |
99 |
|
menulinks.contains("Test1|http://blah.blah/$SEQUENCE_ID$")); |
100 |
1 |
Assert.assertTrue( |
101 |
|
menulinks.contains("Test2|http://test2/$DB_ACCESSION$")); |
102 |
1 |
Assert.assertTrue( |
103 |
|
menulinks.contains("Test3|http://test3/$SEQUENCE_ID$")); |
104 |
1 |
Assert.assertTrue(menulinks.contains( |
105 |
|
"UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot")); |
106 |
1 |
Assert.assertTrue(menulinks.contains( |
107 |
|
"InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro")); |
108 |
|
} |
109 |
|
} |