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