JAL-2189 format help
[jalview.git] / test / jalview / ws / ebi / EBIFetchClientTest.java
1 package jalview.ws.ebi;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNull;
5
6 import org.testng.annotations.Test;
7
8 public class EBIFetchClientTest
9 {
10   /**
11    * Test method that constructs URL to fetch from
12    */
13   @Test(groups = "Functional")
14   public void testBuildUrl()
15   {
16     /*
17      * EMBL
18      */
19     assertEquals("http://www.ebi.ac.uk/ena/data/view/x53838&display=xml",
20             EBIFetchClient.buildUrl("X53838", "EMBL", "display=xml"));
21
22     /*
23      * EMBLCDS
24      */
25     assertEquals("http://www.ebi.ac.uk/ena/data/view/caa37824&display=xml",
26             EBIFetchClient.buildUrl("CAA37824", "EMBL", "display=xml"));
27
28     /*
29      * Uniprot
30      */
31     assertEquals(
32             "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/uniprot/p00340/uniprotxml",
33             EBIFetchClient.buildUrl("P00340", "UNIPROT", "uniprotxml"));
34
35     /*
36      * PDB / pdb
37      */
38     assertEquals("http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/pdb/3a6s/pdb",
39             EBIFetchClient.buildUrl("3A6S", "PDB", "pdb"));
40
41     /*
42      * PDB / mmCIF
43      */
44     assertEquals(
45             "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/pdb/3a6s/mmCIF",
46             EBIFetchClient.buildUrl("3A6S", "PDB", "mmCIF"));
47   }
48
49   /**
50    * Test method that parses db:id;id;id
51    */
52   @Test(groups = "Functional")
53   public void testParseIds()
54   {
55     /*
56      * pdb, two accessions
57      */
58     StringBuilder queries = new StringBuilder();
59     String db = EBIFetchClient.parseIds("pdb:3a6s;1A70", queries);
60     assertEquals("pdb", db);
61     assertEquals("3a6s,1A70", queries.toString());
62
63     /*
64      * pdb specified on second accession
65      */
66     queries.setLength(0);
67     queries = new StringBuilder();
68     db = EBIFetchClient.parseIds("3a6s;pdb:1A70", queries);
69     assertEquals("pdb", db);
70     assertEquals("3a6s,1A70", queries.toString());
71
72     /*
73      * uniprot, one accession
74      */
75     queries.setLength(0);
76     db = EBIFetchClient.parseIds("uniprot:P00340", queries);
77     assertEquals("uniprot", db);
78     assertEquals("P00340", queries.toString());
79
80     /*
81      * uniprot, one accession, appending to existing queries
82      */
83     queries.setLength(0);
84     queries.append("P30419");
85     db = EBIFetchClient.parseIds("uniprot:P00340", queries);
86     assertEquals("uniprot", db);
87     assertEquals("P30419,P00340", queries.toString());
88
89     /*
90      * pdb and uniprot mixed - rejected
91      */
92     queries.setLength(0);
93     db = EBIFetchClient.parseIds("pdb:3a6s;1a70;uniprot:P00340", queries);
94     assertNull(db);
95     assertEquals("3a6s,1a70", queries.toString());
96
97     /*
98      * pdb and PDB mixed - ok
99      */
100     queries.setLength(0);
101     db = EBIFetchClient.parseIds("pdb:3a6s;pdb:1a70;PDB:1QIP", queries);
102     assertEquals("PDB", db);
103     assertEquals("3a6s,1a70,1QIP", queries.toString());
104
105     /*
106      * no database (improper format)
107      */
108     queries.setLength(0);
109     db = EBIFetchClient.parseIds("P00340", queries);
110     assertNull(db);
111     assertEquals("P00340", queries.toString());
112   }
113 }