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 static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertFalse; |
25 |
|
import static org.testng.AssertJUnit.assertTrue; |
26 |
|
|
27 |
|
import jalview.urls.api.UrlProviderI; |
28 |
|
import jalview.util.UrlConstants; |
29 |
|
|
30 |
|
import java.util.Arrays; |
31 |
|
import java.util.HashMap; |
32 |
|
import java.util.Vector; |
33 |
|
|
34 |
|
import org.testng.annotations.Test; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 4 |
Complexity Density: 0.12 |
|
36 |
|
public class CustomUrlProviderTest |
37 |
|
{ |
38 |
|
|
39 |
|
private static final String cachedList = "TEST|http://someurl.blah/$DB_ACCESSION$|" |
40 |
|
+ "ANOTHER|http://test/t$SEQUENCE_ID$|" |
41 |
|
+ "TEST2|http://address/$SEQUENCE_ID$|SRS|" |
42 |
|
+ "http://theSRSlink/$SEQUENCE_ID$"; |
43 |
|
|
44 |
|
private static final String unselectedList = "NON1|http://x/y/$DB_ACCESSION$|" |
45 |
|
+ "NON2|http://a/b/c/$DB_ACCESSION"; |
46 |
|
|
47 |
|
private static final HashMap<String, String> urlMap = new HashMap<String, String>() |
48 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
49 |
4 |
{... |
50 |
4 |
put("TEST", "http://someurl.blah/$DB_ACCESSION$"); |
51 |
4 |
put("ANOTHER", "http://test/t$SEQUENCE_ID$"); |
52 |
4 |
put("TEST2", "http://address/$SEQUENCE_ID$"); |
53 |
4 |
put("SRS", "http://theSRSlink/$SEQUENCE_ID$"); |
54 |
|
} |
55 |
|
}; |
56 |
|
|
57 |
|
private static final HashMap<String, String> unselUrlMap = new HashMap<String, String>() |
58 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
59 |
4 |
{... |
60 |
4 |
put("NON1", "http://x/y/$DB_ACCESSION$"); |
61 |
4 |
put("NON2", "http://a/b/c/$DB_ACCESSION"); |
62 |
|
} |
63 |
|
}; |
64 |
|
|
65 |
|
private static final String[] dlinks = { |
66 |
|
"TEST|http://someurl.blah/$DB_ACCESSION$", |
67 |
|
"ANOTHER|http://test/t$SEQUENCE_ID$", |
68 |
|
"TEST2|http://address/$SEQUENCE_ID$", UrlConstants.DEFAULT_STRING }; |
69 |
|
|
70 |
|
private static final String[] unselDlinks = { |
71 |
|
"NON1|http://x/y/$DB_ACCESSION$", "NON2|http://a/b/c/$DB_ACCESSION" }; |
72 |
|
|
73 |
|
private static final Vector<String> displayLinks = new Vector<String>( |
74 |
|
Arrays.asList(dlinks)); |
75 |
|
|
76 |
|
private static final Vector<String> unselDisplayLinks = new Vector<String>( |
77 |
|
Arrays.asList(unselDlinks)); |
78 |
|
|
79 |
|
private static final String[] dlinks2 = { |
80 |
|
"a|http://x.y.z/$SEQUENCE_ID$" }; |
81 |
|
|
82 |
|
private static final Vector<String> displayLinks2 = new Vector<String>( |
83 |
|
Arrays.asList(dlinks2)); |
84 |
|
|
85 |
|
private static final String[] list1 = { "a" }; |
86 |
|
|
87 |
|
private static final String[] list2 = { "http://x.y.z/$SEQUENCE_ID$" }; |
88 |
|
|
89 |
|
private static final Vector<String> names = new Vector<String>( |
90 |
|
Arrays.asList(list1)); |
91 |
|
|
92 |
|
private static final Vector<String> urls = new Vector<String>( |
93 |
|
Arrays.asList(list2)); |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
98 |
1 |
@Test(groups = { "Functional" })... |
99 |
|
public void testDefaultUrl() |
100 |
|
{ |
101 |
1 |
UrlProviderI customProv = new CustomUrlProvider(cachedList, |
102 |
|
unselectedList); |
103 |
|
|
104 |
|
|
105 |
1 |
assertTrue(customProv.setPrimaryUrl("ANOTHER")); |
106 |
|
|
107 |
|
|
108 |
1 |
String result = customProv.getPrimaryUrl("123"); |
109 |
1 |
assertEquals(null, result); |
110 |
|
|
111 |
|
|
112 |
1 |
result = customProv.getPrimaryUrl("seqid"); |
113 |
1 |
assertEquals("http://test/tseqid", result); |
114 |
|
|
115 |
|
|
116 |
1 |
assertFalse(customProv.setPrimaryUrl("No default")); |
117 |
1 |
result = customProv.getPrimaryUrl("testid"); |
118 |
1 |
assertEquals(null, result); |
119 |
|
|
120 |
|
|
121 |
1 |
customProv.choosePrimaryUrl(); |
122 |
1 |
result = customProv.getPrimaryUrl("seqid"); |
123 |
1 |
assertEquals(UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0] |
124 |
|
+ "seqid", result); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
130 |
1 |
@Test(groups = { "Functional" })... |
131 |
|
public void testUrlLinks() |
132 |
|
{ |
133 |
|
|
134 |
1 |
UrlProviderI customProv = new CustomUrlProvider(cachedList, |
135 |
|
unselectedList); |
136 |
1 |
assertTrue(displayLinks.containsAll(customProv.getLinksForMenu())); |
137 |
|
|
138 |
|
|
139 |
1 |
UrlProviderI customProv2 = new CustomUrlProvider(urlMap, unselUrlMap); |
140 |
1 |
assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu())); |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
1 |
String result = customProv.writeUrlsAsString(true); |
146 |
1 |
UrlProviderI up = new CustomUrlProvider(result, ""); |
147 |
1 |
assertTrue(displayLinks.containsAll(up.getLinksForMenu())); |
148 |
|
|
149 |
1 |
result = customProv.writeUrlsAsString(false); |
150 |
1 |
up = new CustomUrlProvider("", result); |
151 |
1 |
assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu())); |
152 |
|
|
153 |
1 |
result = customProv2.writeUrlsAsString(true); |
154 |
1 |
UrlProviderI up2 = new CustomUrlProvider(result, ""); |
155 |
1 |
assertTrue(displayLinks.containsAll(up2.getLinksForMenu())); |
156 |
|
|
157 |
1 |
result = customProv2.writeUrlsAsString(false); |
158 |
1 |
up2 = new CustomUrlProvider("", result); |
159 |
1 |
assertTrue(displayLinks.containsAll(up2.getLinksForMenu())); |
160 |
|
} |
161 |
|
} |