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