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;
34 import jalview.gui.JvOptionPane;
36 //import org.testng.Assert;
37 import org.testng.annotations.AfterMethod;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 public class PDBEntryTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 @BeforeMethod(alwaysRun = true)
53 public void setUp() throws Exception
57 @AfterMethod(alwaysRun = true)
58 public void tearDown() throws Exception
62 @Test(groups = { "Functional" })
63 public void testEquals()
65 PDBEntry pdbEntry = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB,
68 // id comparison is not case sensitive
69 PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB,
71 // chain code comparison is not case sensitive
72 PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB,
75 PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE,
77 // different everything
78 PDBEntry case4 = new PDBEntry(null, null, null, null);
80 PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB,
83 PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
86 PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
88 PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
90 PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
91 // different file only
92 PDBEntry case10 = new PDBEntry("1xyz", "A", null, "a/b/c/File");
95 * assertEquals will invoke PDBEntry.equals()
97 assertFalse(pdbEntry.equals(null));
98 assertFalse(pdbEntry.equals("a"));
99 assertEquals(case1, pdbEntry);
100 assertEquals(case2, pdbEntry);
101 assertNotEquals(case3, pdbEntry);
102 assertNotEquals(case4, pdbEntry);
103 assertNotEquals(case5, pdbEntry);
104 assertNotEquals(case6, pdbEntry);
105 assertNotEquals(case7, pdbEntry);
106 assertNotEquals(case8, pdbEntry);
107 assertEquals(case7, case9);
108 assertNotEquals(case9, case10);
111 case7.setProperty("hello", "world");
112 assertNotEquals(case7, case9);
113 case9.setProperty("hello", "world");
114 assertEquals(case7, case9);
115 case9.setProperty("hello", "WORLD");
116 assertNotEquals(case7, case9);
119 * change string wrapper property to string...
121 case1.setProperty("chain_code", "a");
122 assertFalse(pdbEntry.equals(case1));
123 assertFalse(case1.equals(pdbEntry));
126 @Test(groups = { "Functional" })
127 public void testSetChainCode()
129 PDBEntry pdbEntry = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
131 assertNull(pdbEntry.getChainCode());
133 pdbEntry.setChainCode("a");
134 assertEquals("a", pdbEntry.getChainCode());
136 pdbEntry.setChainCode(null);
137 assertNull(pdbEntry.getChainCode());
140 @Test(groups = { "Functional" })
141 public void testGetType()
143 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("FILE"));
144 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("File"));
145 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file"));
146 assertNotSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file "));
149 @Test(groups = { "Functional" })
150 public void testTypeMatches()
152 // TODO Type.matches() is not used - delete?
153 assertTrue(PDBEntry.Type.FILE.matches("FILE"));
154 assertTrue(PDBEntry.Type.FILE.matches("File"));
155 assertTrue(PDBEntry.Type.FILE.matches("file"));
156 assertFalse(PDBEntry.Type.FILE.matches("FILE "));
159 @Test(groups = { "Functional" })
160 public void testUpdateFrom()
162 PDBEntry pdb1 = new PDBEntry("3A6S", null, null, null);
163 PDBEntry pdb2 = new PDBEntry("3A6S", null, null, null);
164 assertTrue(pdb1.updateFrom(pdb2));
167 * mismatch of pdb id not allowed
169 pdb2 = new PDBEntry("1A70", "A", null, null);
170 assertFalse(pdb1.updateFrom(pdb2));
171 assertNull(pdb1.getChainCode());
174 * match of pdb id is not case sensitive
176 pdb2 = new PDBEntry("3a6s", "A", null, null);
177 assertTrue(pdb1.updateFrom(pdb2));
178 assertEquals(pdb1.getChainCode(), "A");
179 assertEquals(pdb1.getId(), "3A6S");
182 * add chain - with differing case for id
184 pdb1 = new PDBEntry("3A6S", null, null, null);
185 pdb2 = new PDBEntry("3a6s", "A", null, null);
186 assertTrue(pdb1.updateFrom(pdb2));
187 assertEquals(pdb1.getChainCode(), "A");
190 * change of chain is not allowed
192 pdb2 = new PDBEntry("3A6S", "B", null, null);
193 assertFalse(pdb1.updateFrom(pdb2));
194 assertEquals(pdb1.getChainCode(), "A");
197 * change chain from null
199 pdb1 = new PDBEntry("3A6S", null, null, null);
200 pdb2 = new PDBEntry("3A6S", "B", null, null);
201 assertTrue(pdb1.updateFrom(pdb2));
202 assertEquals(pdb1.getChainCode(), "B");
207 pdb2 = new PDBEntry("3A6S", "B", Type.FILE, "filePath");
208 assertTrue(pdb1.updateFrom(pdb2));
209 assertEquals(pdb1.getFile(), "filePath");
210 assertEquals(pdb1.getType(), Type.FILE.toString());
213 * change of file is not allowed
215 pdb1 = new PDBEntry("3A6S", null, null, "file1");
216 pdb2 = new PDBEntry("3A6S", "A", null, "file2");
217 assertFalse(pdb1.updateFrom(pdb2));
218 assertNull(pdb1.getChainCode());
219 assertEquals(pdb1.getFile(), "file1");
222 * set type without change of file
224 pdb1 = new PDBEntry("3A6S", null, null, "file1");
225 pdb2 = new PDBEntry("3A6S", null, Type.PDB, "file1");
226 assertTrue(pdb1.updateFrom(pdb2));
227 assertEquals(pdb1.getType(), Type.PDB.toString());
230 * set file with differing case of id and chain code
232 pdb1 = new PDBEntry("3A6S", "A", null, null);
233 pdb2 = new PDBEntry("3a6s", "a", Type.PDB, "file1");
234 assertTrue(pdb1.updateFrom(pdb2));
235 assertEquals(pdb1.getType(), Type.PDB.toString());
236 assertEquals(pdb1.getId(), "3A6S"); // unchanged
237 assertEquals(pdb1.getFile(), "file1"); // updated
238 assertEquals(pdb1.getChainCode(), "A"); // unchanged
241 * changing nothing returns true
243 pdb1 = new PDBEntry("3A6S", "A", Type.PDB, "file1");
244 pdb2 = new PDBEntry("3A6S", null, null, null);
245 assertTrue(pdb1.updateFrom(pdb2));
246 assertEquals(pdb1.getChainCode(), "A");
247 assertEquals(pdb1.getType(), Type.PDB.toString());
248 assertEquals(pdb1.getFile(), "file1");
251 * add and update properties only
253 pdb1 = new PDBEntry("3A6S", null, null, null);
254 pdb2 = new PDBEntry("3A6S", null, null, null);
255 pdb1.setProperty("destination", "mars");
256 pdb1.setProperty("hello", "world");
257 pdb2.setProperty("hello", "moon");
258 pdb2.setProperty("goodbye", "world");
259 assertTrue(pdb1.updateFrom(pdb2));
260 assertEquals(pdb1.getProperty("destination"), "mars");
261 assertEquals(pdb1.getProperty("hello"), "moon");
262 assertEquals(pdb1.getProperty("goodbye"), "world");
265 * add properties only
267 pdb1 = new PDBEntry("3A6S", null, null, null);
268 pdb2 = new PDBEntry("3A6S", null, null, null);
269 pdb2.setProperty("hello", "moon");
270 assertTrue(pdb1.updateFrom(pdb2));
271 assertEquals(pdb1.getProperty("hello"), "moon");
274 @Test(groups = { "Functional" })
275 public void testConstructor_fromDbref()
277 PDBEntry pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70"));
278 assertEquals(pdb.getId(), "1A70");
279 assertNull(pdb.getChainCode());
280 assertNull(pdb.getType());
281 assertNull(pdb.getFile());
284 * from dbref with chain code appended
286 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70B"));
287 assertEquals(pdb.getId(), "1A70");
288 assertEquals(pdb.getChainCode(), "B");
291 * from dbref with overlong accession
293 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70BC"));
294 assertEquals(pdb.getId(), "1A70BC");
295 assertNull(pdb.getChainCode());
298 * from dbref which is not for PDB
302 pdb = new PDBEntry(new DBRefEntry("PDBe", "0", "1A70"));
303 fail("Expected exception");
304 } catch (IllegalArgumentException e)