JAL-2154 canonical dbsources are lowercased before matching
[jalview.git] / test / jalview / ext / ensembl / EnsemblXrefTest.java
1 package jalview.ext.ensembl;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5
6 import jalview.datamodel.DBRefEntry;
7
8 import java.io.BufferedReader;
9 import java.io.IOException;
10 import java.io.StringReader;
11 import java.net.URL;
12 import java.util.List;
13
14 import org.testng.annotations.Test;
15
16 public class EnsemblXrefTest
17 {
18   //@formatter:off
19   private static final String JSON = 
20           "[{\"primary_id\":\"CCDS5863\",\"dbname\":\"CCDS\"}," +
21            "{\"primary_id\":\"P15056\",\"dbname\":\"Uniprot/SWISSPROT\",\"synonyms\":[\"C21\"]}," +
22            "{\"primary_id\":\"GO:0000165\",\"dbname\":\"GO\"}]";
23   //@formatter:on
24
25   @Test(groups = "Functional")
26   public void testGetCrossReferences()
27   {
28     String dbName = "ENSEMBL";
29     String dbVers = "0.6.2b1";
30     System.out.println(JSON);
31     EnsemblXref testee = new EnsemblXref("http://rest.ensembl.org", dbName,
32             dbVers)
33     {
34       @Override
35       protected BufferedReader getHttpResponse(URL url, List<String> ids)
36               throws IOException
37       {
38         return new BufferedReader(new StringReader(JSON));
39       }
40     };
41
42     // synonyms and GO terms are not returned
43     List<DBRefEntry> dbrefs = testee.getCrossReferences("ABCDE");
44     assertEquals(2, dbrefs.size());
45     assertEquals("CCDS", dbrefs.get(0).getSource());
46     assertEquals("CCDS5863", dbrefs.get(0).getAccessionId());
47     assertFalse(dbrefs.get(0).isPrimary());
48     assertEquals(dbName + ":" + dbVers, dbrefs.get(0).getVersion());
49     // Uniprot name should get converted to Jalview canonical form
50     assertEquals("UNIPROT", dbrefs.get(1).getSource());
51     assertEquals("P15056", dbrefs.get(1).getAccessionId());
52     assertEquals(dbName + ":" + dbVers, dbrefs.get(1).getVersion());
53     assertFalse(dbrefs.get(1).isPrimary());
54   }
55 }