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