JAL-2189 apply license
[jalview.git] / test / jalview / ws / ebi / EBIFetchClientTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.ebi;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNull;
25
26 import org.testng.annotations.Test;
27
28 public class EBIFetchClientTest
29 {
30   /**
31    * Test method that constructs URL to fetch from
32    */
33   @Test(groups = "Functional")
34   public void testBuildUrl()
35   {
36     /*
37      * EMBL
38      */
39     assertEquals("http://www.ebi.ac.uk/ena/data/view/x53838&display=xml",
40             EBIFetchClient.buildUrl("X53838", "EMBL", "display=xml"));
41
42     /*
43      * EMBLCDS
44      */
45     assertEquals("http://www.ebi.ac.uk/ena/data/view/caa37824&display=xml",
46             EBIFetchClient.buildUrl("CAA37824", "EMBL", "display=xml"));
47
48     /*
49      * Uniprot
50      */
51     assertEquals(
52             "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/uniprot/p00340/uniprotxml",
53             EBIFetchClient.buildUrl("P00340", "UNIPROT", "uniprotxml"));
54
55     /*
56      * PDB / pdb
57      */
58     assertEquals("http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/pdb/3a6s/pdb",
59             EBIFetchClient.buildUrl("3A6S", "PDB", "pdb"));
60
61     /*
62      * PDB / mmCIF
63      */
64     assertEquals(
65             "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/pdb/3a6s/mmCIF",
66             EBIFetchClient.buildUrl("3A6S", "PDB", "mmCIF"));
67   }
68
69   /**
70    * Test method that parses db:id;id;id
71    */
72   @Test(groups = "Functional")
73   public void testParseIds()
74   {
75     /*
76      * pdb, two accessions
77      */
78     StringBuilder queries = new StringBuilder();
79     String db = EBIFetchClient.parseIds("pdb:3a6s;1A70", queries);
80     assertEquals("pdb", db);
81     assertEquals("3a6s,1A70", queries.toString());
82
83     /*
84      * pdb specified on second accession
85      */
86     queries.setLength(0);
87     queries = new StringBuilder();
88     db = EBIFetchClient.parseIds("3a6s;pdb:1A70", queries);
89     assertEquals("pdb", db);
90     assertEquals("3a6s,1A70", queries.toString());
91
92     /*
93      * uniprot, one accession
94      */
95     queries.setLength(0);
96     db = EBIFetchClient.parseIds("uniprot:P00340", queries);
97     assertEquals("uniprot", db);
98     assertEquals("P00340", queries.toString());
99
100     /*
101      * uniprot, one accession, appending to existing queries
102      */
103     queries.setLength(0);
104     queries.append("P30419");
105     db = EBIFetchClient.parseIds("uniprot:P00340", queries);
106     assertEquals("uniprot", db);
107     assertEquals("P30419,P00340", queries.toString());
108
109     /*
110      * pdb and uniprot mixed - rejected
111      */
112     queries.setLength(0);
113     db = EBIFetchClient.parseIds("pdb:3a6s;1a70;uniprot:P00340", queries);
114     assertNull(db);
115     assertEquals("3a6s,1a70", queries.toString());
116
117     /*
118      * pdb and PDB mixed - ok
119      */
120     queries.setLength(0);
121     db = EBIFetchClient.parseIds("pdb:3a6s;pdb:1a70;PDB:1QIP", queries);
122     assertEquals("PDB", db);
123     assertEquals("3a6s,1a70,1QIP", queries.toString());
124
125     /*
126      * no database (improper format)
127      */
128     queries.setLength(0);
129     db = EBIFetchClient.parseIds("P00340", queries);
130     assertNull(db);
131     assertEquals("P00340", queries.toString());
132   }
133 }