2 assertEquals(case7, case9);
3 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
4 * Copyright (C) $$Year-Rel$$ The Jalview Authors
6 * This file is part of Jalview.
8 * Jalview is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation, either version 3
11 * of the License, or (at your option) any later version.
13 * Jalview is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 package jalview.datamodel;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertFalse;
26 import static org.testng.Assert.assertNotEquals;
27 import static org.testng.Assert.assertNotSame;
28 import static org.testng.Assert.assertNull;
29 import static org.testng.Assert.assertSame;
30 import static org.testng.Assert.assertTrue;
31 import static org.testng.Assert.fail;
33 import jalview.datamodel.PDBEntry.Type;
35 import java.util.Hashtable;
37 //import org.testng.Assert;
38 import org.testng.annotations.AfterMethod;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 public class PDBEntryTest
45 @BeforeMethod(alwaysRun = true)
46 public void setUp() throws Exception
50 @AfterMethod(alwaysRun = true)
51 public void tearDown() throws Exception
55 @Test(groups = { "Functional" })
56 public void testEquals()
58 PDBEntry pdbEntry = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB,
61 // id comparison is not case sensitive
62 PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB,
64 // chain code comparison is not case sensitive
65 PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB,
68 PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE,
70 // different everything
71 PDBEntry case4 = new PDBEntry(null, null, null, null);
73 PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB,
76 PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
79 PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
81 PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
83 PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
84 // different file only
85 PDBEntry case10 = new PDBEntry("1xyz", "A", null, "a/b/c/File");
88 * assertEquals will invoke PDBEntry.equals()
90 assertFalse(pdbEntry.equals(null));
91 assertFalse(pdbEntry.equals("a"));
92 assertEquals(case1, pdbEntry);
93 assertEquals(case2, pdbEntry);
94 assertNotEquals(case3, pdbEntry);
95 assertNotEquals(case4, pdbEntry);
96 assertNotEquals(case5, pdbEntry);
97 assertNotEquals(case6, pdbEntry);
98 assertNotEquals(case7, pdbEntry);
99 assertNotEquals(case8, pdbEntry);
100 assertEquals(case7, case9);
101 assertNotEquals(case9, case10);
104 case7.getProperty().put("hello", "world");
105 assertNotEquals(case7, case9);
106 case9.getProperty().put("hello", "world");
107 assertEquals(case7, case9);
108 case9.getProperty().put("hello", "WORLD");
109 assertNotEquals(case7, case9);
112 * change string wrapper property to string...
114 case1.getProperty().put("chain_code", "a");
115 assertFalse(pdbEntry.equals(case1));
116 assertFalse(case1.equals(pdbEntry));
119 @Test(groups = { "Functional" })
120 public void testSetChainCode()
122 PDBEntry pdbEntry = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
124 assertNull(pdbEntry.getChainCode());
126 pdbEntry.setChainCode("a");
127 assertEquals("a", pdbEntry.getChainCode());
129 pdbEntry.setChainCode(null);
130 assertNull(pdbEntry.getChainCode());
133 @Test(groups = { "Functional" })
134 public void testGetType()
136 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("FILE"));
137 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("File"));
138 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file"));
139 assertNotSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file "));
142 @Test(groups = { "Functional" })
143 public void testTypeMatches()
145 // TODO Type.matches() is not used - delete?
146 assertTrue(PDBEntry.Type.FILE.matches("FILE"));
147 assertTrue(PDBEntry.Type.FILE.matches("File"));
148 assertTrue(PDBEntry.Type.FILE.matches("file"));
149 assertFalse(PDBEntry.Type.FILE.matches("FILE "));
152 @Test(groups = { "Functional" })
153 public void testUpdateFrom()
155 PDBEntry pdb1 = new PDBEntry("3A6S", null, null, null);
156 PDBEntry pdb2 = new PDBEntry("3A6S", null, null, null);
157 assertTrue(pdb1.updateFrom(pdb2));
160 * mismatch of pdb id not allowed
162 pdb2 = new PDBEntry("1A70", "A", null, null);
163 assertFalse(pdb1.updateFrom(pdb2));
164 assertNull(pdb1.getChainCode());
167 * match of pdb id is not case sensitive
169 pdb2 = new PDBEntry("3a6s", "A", null, null);
170 assertTrue(pdb1.updateFrom(pdb2));
171 assertEquals(pdb1.getChainCode(), "A");
172 assertEquals(pdb1.getId(), "3A6S");
175 * add chain - with differing case for id
177 pdb1 = new PDBEntry("3A6S", null, null, null);
178 pdb2 = new PDBEntry("3a6s", "A", null, null);
179 assertTrue(pdb1.updateFrom(pdb2));
180 assertEquals(pdb1.getChainCode(), "A");
183 * change of chain is not allowed
185 pdb2 = new PDBEntry("3A6S", "B", null, null);
186 assertFalse(pdb1.updateFrom(pdb2));
187 assertEquals(pdb1.getChainCode(), "A");
190 * change chain from null
192 pdb1 = new PDBEntry("3A6S", null, null, null);
193 pdb2 = new PDBEntry("3A6S", "B", null, null);
194 assertTrue(pdb1.updateFrom(pdb2));
195 assertEquals(pdb1.getChainCode(), "B");
200 pdb2 = new PDBEntry("3A6S", "B", Type.FILE, "filePath");
201 assertTrue(pdb1.updateFrom(pdb2));
202 assertEquals(pdb1.getFile(), "filePath");
203 assertEquals(pdb1.getType(), Type.FILE.toString());
206 * change of file is not allowed
208 pdb1 = new PDBEntry("3A6S", null, null, "file1");
209 pdb2 = new PDBEntry("3A6S", "A", null, "file2");
210 assertFalse(pdb1.updateFrom(pdb2));
211 assertNull(pdb1.getChainCode());
212 assertEquals(pdb1.getFile(), "file1");
215 * set type without change of file
217 pdb1 = new PDBEntry("3A6S", null, null, "file1");
218 pdb2 = new PDBEntry("3A6S", null, Type.PDB, "file1");
219 assertTrue(pdb1.updateFrom(pdb2));
220 assertEquals(pdb1.getType(), Type.PDB.toString());
223 * set file with differing case of id and chain code
225 pdb1 = new PDBEntry("3A6S", "A", null, null);
226 pdb2 = new PDBEntry("3a6s", "a", Type.PDB, "file1");
227 assertTrue(pdb1.updateFrom(pdb2));
228 assertEquals(pdb1.getType(), Type.PDB.toString());
229 assertEquals(pdb1.getId(), "3A6S"); // unchanged
230 assertEquals(pdb1.getFile(), "file1"); // updated
231 assertEquals(pdb1.getChainCode(), "A"); // unchanged
234 * changing nothing returns true
236 pdb1 = new PDBEntry("3A6S", "A", Type.PDB, "file1");
237 pdb2 = new PDBEntry("3A6S", null, null, null);
238 assertTrue(pdb1.updateFrom(pdb2));
239 assertEquals(pdb1.getChainCode(), "A");
240 assertEquals(pdb1.getType(), Type.PDB.toString());
241 assertEquals(pdb1.getFile(), "file1");
244 * add and update properties only
246 pdb1 = new PDBEntry("3A6S", null, null, null);
247 pdb2 = new PDBEntry("3A6S", null, null, null);
248 // ughh properties not null if chain code has been set...
249 // JAL-2196 addresses this
250 pdb1.properties = new Hashtable();
251 pdb2.properties = new Hashtable();
252 pdb1.properties.put("destination", "mars");
253 pdb1.properties.put("hello", "world");
254 pdb2.properties.put("hello", "moon");
255 pdb2.properties.put("goodbye", "world");
256 assertTrue(pdb1.updateFrom(pdb2));
257 assertEquals(pdb1.properties.get("destination"), "mars");
258 assertEquals(pdb1.properties.get("hello"), "moon");
259 assertEquals(pdb1.properties.get("goodbye"), "world");
262 * add properties only
264 pdb1 = new PDBEntry("3A6S", null, null, null);
265 pdb2 = new PDBEntry("3A6S", null, null, null);
266 pdb2.properties = new Hashtable();
267 pdb2.properties.put("hello", "moon");
268 assertTrue(pdb1.updateFrom(pdb2));
269 assertEquals(pdb1.properties.get("hello"), "moon");
272 @Test(groups = { "Functional" })
273 public void testConstructor_fromDbref()
275 PDBEntry pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70"));
276 assertEquals(pdb.getId(), "1A70");
277 assertNull(pdb.getChainCode());
278 assertNull(pdb.getType());
279 assertNull(pdb.getFile());
282 * from dbref with chain code appended
284 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70B"));
285 assertEquals(pdb.getId(), "1A70");
286 assertEquals(pdb.getChainCode(), "B");
289 * from dbref with overlong accession
291 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70BC"));
292 assertEquals(pdb.getId(), "1A70BC");
293 assertNull(pdb.getChainCode());
296 * from dbref which is not for PDB
300 pdb = new PDBEntry(new DBRefEntry("PDBe", "0", "1A70"));
301 fail("Expected exception");
302 } catch (IllegalArgumentException e)