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 org.testng.Assert;
36 import org.testng.annotations.AfterMethod;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
40 public class PDBEntryTest
43 @BeforeMethod(alwaysRun = true)
44 public void setUp() throws Exception
48 @AfterMethod(alwaysRun = true)
49 public void tearDown() throws Exception
53 @Test(groups = { "Functional" })
54 public void testEquals()
56 PDBEntry pdbEntry = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB,
59 // id comparison is not case sensitive
60 PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB,
62 // chain code comparison is not case sensitive
63 PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB,
66 PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE,
68 // different everything
69 PDBEntry case4 = new PDBEntry(null, null, null, null);
71 PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB,
74 PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
77 PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
79 PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
81 PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
82 // different file only
83 PDBEntry case10 = new PDBEntry("1xyz", "A", null, "a/b/c/File");
86 * assertEquals will invoke PDBEntry.equals()
88 assertFalse(pdbEntry.equals(null));
89 assertFalse(pdbEntry.equals("a"));
90 assertEquals(case1, pdbEntry);
91 assertEquals(case2, pdbEntry);
92 assertNotEquals(case3, pdbEntry);
93 assertNotEquals(case4, pdbEntry);
94 assertNotEquals(case5, pdbEntry);
95 assertNotEquals(case6, pdbEntry);
96 assertNotEquals(case7, pdbEntry);
97 assertNotEquals(case8, pdbEntry);
98 assertEquals(case7, case9);
99 assertNotEquals(case9, case10);
102 case7.setProperty("hello", "world");
103 assertNotEquals(case7, case9);
104 case9.setProperty("hello", "world");
105 assertEquals(case7, case9);
106 case9.setProperty("hello", "WORLD");
107 assertNotEquals(case7, case9);
110 * change string wrapper property to string...
112 case1.setProperty("chain_code", "a");
113 assertFalse(pdbEntry.equals(case1));
114 assertFalse(case1.equals(pdbEntry));
117 @Test(groups = { "Functional" })
118 public void testSetChainCode()
120 PDBEntry pdbEntry = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
122 assertNull(pdbEntry.getChainCode());
124 pdbEntry.setChainCode("a");
125 assertEquals("a", pdbEntry.getChainCode());
127 pdbEntry.setChainCode(null);
128 assertNull(pdbEntry.getChainCode());
131 @Test(groups = { "Functional" })
132 public void testGetType()
134 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("FILE"));
135 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("File"));
136 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file"));
137 assertNotSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file "));
140 @Test(groups = { "Functional" })
141 public void testTypeMatches()
143 // TODO Type.matches() is not used - delete?
144 assertTrue(PDBEntry.Type.FILE.matches("FILE"));
145 assertTrue(PDBEntry.Type.FILE.matches("File"));
146 assertTrue(PDBEntry.Type.FILE.matches("file"));
147 assertFalse(PDBEntry.Type.FILE.matches("FILE "));
150 @Test(groups = { "Functional" })
151 public void testUpdateFrom()
153 PDBEntry pdb1 = new PDBEntry("3A6S", null, null, null);
154 PDBEntry pdb2 = new PDBEntry("3A6S", null, null, null);
155 assertTrue(pdb1.updateFrom(pdb2));
158 * mismatch of pdb id not allowed
160 pdb2 = new PDBEntry("1A70", "A", null, null);
161 assertFalse(pdb1.updateFrom(pdb2));
162 assertNull(pdb1.getChainCode());
165 * match of pdb id is not case sensitive
167 pdb2 = new PDBEntry("3a6s", "A", null, null);
168 assertTrue(pdb1.updateFrom(pdb2));
169 assertEquals(pdb1.getChainCode(), "A");
170 assertEquals(pdb1.getId(), "3A6S");
173 * add chain - with differing case for id
175 pdb1 = new PDBEntry("3A6S", null, null, null);
176 pdb2 = new PDBEntry("3a6s", "A", null, null);
177 assertTrue(pdb1.updateFrom(pdb2));
178 assertEquals(pdb1.getChainCode(), "A");
181 * change of chain is not allowed
183 pdb2 = new PDBEntry("3A6S", "B", null, null);
184 assertFalse(pdb1.updateFrom(pdb2));
185 assertEquals(pdb1.getChainCode(), "A");
188 * change chain from null
190 pdb1 = new PDBEntry("3A6S", null, null, null);
191 pdb2 = new PDBEntry("3A6S", "B", null, null);
192 assertTrue(pdb1.updateFrom(pdb2));
193 assertEquals(pdb1.getChainCode(), "B");
198 pdb2 = new PDBEntry("3A6S", "B", Type.FILE, "filePath");
199 assertTrue(pdb1.updateFrom(pdb2));
200 assertEquals(pdb1.getFile(), "filePath");
201 assertEquals(pdb1.getType(), Type.FILE.toString());
204 * change of file is not allowed
206 pdb1 = new PDBEntry("3A6S", null, null, "file1");
207 pdb2 = new PDBEntry("3A6S", "A", null, "file2");
208 assertFalse(pdb1.updateFrom(pdb2));
209 assertNull(pdb1.getChainCode());
210 assertEquals(pdb1.getFile(), "file1");
213 * set type without change of file
215 pdb1 = new PDBEntry("3A6S", null, null, "file1");
216 pdb2 = new PDBEntry("3A6S", null, Type.PDB, "file1");
217 assertTrue(pdb1.updateFrom(pdb2));
218 assertEquals(pdb1.getType(), Type.PDB.toString());
221 * set file with differing case of id and chain code
223 pdb1 = new PDBEntry("3A6S", "A", null, null);
224 pdb2 = new PDBEntry("3a6s", "a", Type.PDB, "file1");
225 assertTrue(pdb1.updateFrom(pdb2));
226 assertEquals(pdb1.getType(), Type.PDB.toString());
227 assertEquals(pdb1.getId(), "3A6S"); // unchanged
228 assertEquals(pdb1.getFile(), "file1"); // updated
229 assertEquals(pdb1.getChainCode(), "A"); // unchanged
232 * changing nothing returns true
234 pdb1 = new PDBEntry("3A6S", "A", Type.PDB, "file1");
235 pdb2 = new PDBEntry("3A6S", null, null, null);
236 assertTrue(pdb1.updateFrom(pdb2));
237 assertEquals(pdb1.getChainCode(), "A");
238 assertEquals(pdb1.getType(), Type.PDB.toString());
239 assertEquals(pdb1.getFile(), "file1");
242 * add and update properties only
244 pdb1 = new PDBEntry("3A6S", null, null, null);
245 pdb2 = new PDBEntry("3A6S", null, null, null);
246 pdb1.setProperty("destination", "mars");
247 pdb1.setProperty("hello", "world");
248 pdb2.setProperty("hello", "moon");
249 pdb2.setProperty("goodbye", "world");
250 assertTrue(pdb1.updateFrom(pdb2));
251 assertEquals(pdb1.getProperty("destination"), "mars");
252 assertEquals(pdb1.getProperty("hello"), "moon");
253 assertEquals(pdb1.getProperty("goodbye"), "world");
256 * add properties only
258 pdb1 = new PDBEntry("3A6S", null, null, null);
259 pdb2 = new PDBEntry("3A6S", null, null, null);
260 pdb2.setProperty("hello", "moon");
261 assertTrue(pdb1.updateFrom(pdb2));
262 assertEquals(pdb1.getProperty("hello"), "moon");
265 @Test(groups = { "Functional" })
266 public void testConstructor_fromDbref()
268 PDBEntry pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70"));
269 assertEquals(pdb.getId(), "1A70");
270 assertNull(pdb.getChainCode());
271 assertNull(pdb.getType());
272 assertNull(pdb.getFile());
275 * from dbref with chain code appended
277 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70B"));
278 assertEquals(pdb.getId(), "1A70");
279 assertEquals(pdb.getChainCode(), "B");
282 * from dbref with overlong accession
284 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70BC"));
285 assertEquals(pdb.getId(), "1A70BC");
286 assertNull(pdb.getChainCode());
289 * from dbref which is not for PDB
293 pdb = new PDBEntry(new DBRefEntry("PDBe", "0", "1A70"));
294 fail("Expected exception");
295 } catch (IllegalArgumentException e)