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,
67 assertTrue(pdbEntry.equals(pdbEntry));
69 // id comparison is not case sensitive
70 PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB,
72 // chain code comparison is not case sensitive
73 PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB,
76 PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE,
78 // different everything
79 PDBEntry case4 = new PDBEntry(null, null, null, null);
81 PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB,
84 PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
87 PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
89 PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
91 PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
92 // different file only
93 PDBEntry case10 = new PDBEntry("1xyz", "A", null, "a/b/c/File");
96 * assertEquals will invoke PDBEntry.equals()
98 assertFalse(pdbEntry.equals(null));
99 assertFalse(pdbEntry.equals("a"));
100 assertEquals(case1, pdbEntry);
101 assertEquals(case2, pdbEntry);
102 assertNotEquals(case3, pdbEntry);
103 assertNotEquals(case4, pdbEntry);
104 assertNotEquals(case5, pdbEntry);
105 assertNotEquals(case6, pdbEntry);
106 assertNotEquals(case7, pdbEntry);
107 assertNotEquals(case8, pdbEntry);
108 assertEquals(case7, case9);
109 assertNotEquals(case9, case10);
112 case7.setProperty("hello", "world");
113 assertNotEquals(case7, case9);
114 case9.setProperty("hello", "world");
115 assertEquals(case7, case9);
116 case9.setProperty("hello", "WORLD");
117 assertNotEquals(case7, case9);
120 * change string wrapper property to string...
122 case1.setProperty("chain_code", "a");
123 assertFalse(pdbEntry.equals(case1));
124 assertFalse(case1.equals(pdbEntry));
127 @Test(groups = { "Functional" })
128 public void testSetChainCode()
130 PDBEntry pdbEntry = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
132 assertNull(pdbEntry.getChainCode());
134 pdbEntry.setChainCode("a");
135 assertEquals("a", pdbEntry.getChainCode());
137 pdbEntry.setChainCode(null);
138 assertNull(pdbEntry.getChainCode());
141 @Test(groups = { "Functional" })
142 public void testGetType()
144 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("FILE"));
145 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("File"));
146 assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file"));
147 assertNotSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file "));
150 @Test(groups = { "Functional" })
151 public void testTypeMatches()
153 // TODO Type.matches() is not used - delete?
154 assertTrue(PDBEntry.Type.FILE.matches("FILE"));
155 assertTrue(PDBEntry.Type.FILE.matches("File"));
156 assertTrue(PDBEntry.Type.FILE.matches("file"));
157 assertFalse(PDBEntry.Type.FILE.matches("FILE "));
160 @Test(groups = { "Functional" })
161 public void testUpdateFrom()
163 PDBEntry pdb1 = new PDBEntry("3A6S", null, null, null);
164 PDBEntry pdb2 = new PDBEntry("3A6S", null, null, null);
165 assertTrue(pdb1.updateFrom(pdb2));
168 * mismatch of pdb id not allowed
170 pdb2 = new PDBEntry("1A70", "A", null, null);
171 assertFalse(pdb1.updateFrom(pdb2));
172 assertNull(pdb1.getChainCode());
175 * match of pdb id is not case sensitive
177 pdb2 = new PDBEntry("3a6s", "A", null, null);
178 assertTrue(pdb1.updateFrom(pdb2));
179 assertEquals(pdb1.getChainCode(), "A");
180 assertEquals(pdb1.getId(), "3A6S");
183 * add chain - with differing case for id
185 pdb1 = new PDBEntry("3A6S", null, null, null);
186 pdb2 = new PDBEntry("3a6s", "A", null, null);
187 assertTrue(pdb1.updateFrom(pdb2));
188 assertEquals(pdb1.getChainCode(), "A");
191 * change of chain is not allowed
193 pdb2 = new PDBEntry("3A6S", "B", null, null);
194 assertFalse(pdb1.updateFrom(pdb2));
195 assertEquals(pdb1.getChainCode(), "A");
198 * change chain from null
200 pdb1 = new PDBEntry("3A6S", null, null, null);
201 pdb2 = new PDBEntry("3A6S", "B", null, null);
202 assertTrue(pdb1.updateFrom(pdb2));
203 assertEquals(pdb1.getChainCode(), "B");
208 pdb2 = new PDBEntry("3A6S", "B", Type.FILE, "filePath");
209 assertTrue(pdb1.updateFrom(pdb2));
210 assertEquals(pdb1.getFile(), "filePath");
211 assertEquals(pdb1.getType(), Type.FILE.toString());
214 * change of file is not allowed
216 pdb1 = new PDBEntry("3A6S", null, null, "file1");
217 pdb2 = new PDBEntry("3A6S", "A", null, "file2");
218 assertFalse(pdb1.updateFrom(pdb2));
219 assertNull(pdb1.getChainCode());
220 assertEquals(pdb1.getFile(), "file1");
223 * set type without change of file
225 pdb1 = new PDBEntry("3A6S", null, null, "file1");
226 pdb2 = new PDBEntry("3A6S", null, Type.PDB, "file1");
227 assertTrue(pdb1.updateFrom(pdb2));
228 assertEquals(pdb1.getType(), Type.PDB.toString());
231 * set file with differing case of id and chain code
233 pdb1 = new PDBEntry("3A6S", "A", null, null);
234 pdb2 = new PDBEntry("3a6s", "a", Type.PDB, "file1");
235 assertTrue(pdb1.updateFrom(pdb2));
236 assertEquals(pdb1.getType(), Type.PDB.toString());
237 assertEquals(pdb1.getId(), "3A6S"); // unchanged
238 assertEquals(pdb1.getFile(), "file1"); // updated
239 assertEquals(pdb1.getChainCode(), "A"); // unchanged
242 * changing nothing returns true
244 pdb1 = new PDBEntry("3A6S", "A", Type.PDB, "file1");
245 pdb2 = new PDBEntry("3A6S", null, null, null);
246 assertTrue(pdb1.updateFrom(pdb2));
247 assertEquals(pdb1.getChainCode(), "A");
248 assertEquals(pdb1.getType(), Type.PDB.toString());
249 assertEquals(pdb1.getFile(), "file1");
252 * add and update properties only
254 pdb1 = new PDBEntry("3A6S", null, null, null);
255 pdb2 = new PDBEntry("3A6S", null, null, null);
256 pdb1.setProperty("destination", "mars");
257 pdb1.setProperty("hello", "world");
258 pdb2.setProperty("hello", "moon");
259 pdb2.setProperty("goodbye", "world");
260 assertTrue(pdb1.updateFrom(pdb2));
261 assertEquals(pdb1.getProperty("destination"), "mars");
262 assertEquals(pdb1.getProperty("hello"), "moon");
263 assertEquals(pdb1.getProperty("goodbye"), "world");
266 * add properties only
268 pdb1 = new PDBEntry("3A6S", null, null, null);
269 pdb2 = new PDBEntry("3A6S", null, null, null);
270 pdb2.setProperty("hello", "moon");
271 assertTrue(pdb1.updateFrom(pdb2));
272 assertEquals(pdb1.getProperty("hello"), "moon");
275 @Test(groups = { "Functional" })
276 public void testConstructor_fromDbref()
278 PDBEntry pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70"));
279 assertEquals(pdb.getId(), "1A70");
280 assertNull(pdb.getChainCode());
281 assertNull(pdb.getType());
282 assertNull(pdb.getFile());
285 * from dbref with chain code appended
287 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70B"));
288 assertEquals(pdb.getId(), "1A70");
289 assertEquals(pdb.getChainCode(), "B");
292 * from dbref with overlong accession
294 pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70BC"));
295 assertEquals(pdb.getId(), "1A70BC");
296 assertNull(pdb.getChainCode());
299 * from dbref which is not for PDB
303 pdb = new PDBEntry(new DBRefEntry("PDBe", "0", "1A70"));
304 fail("Expected exception");
305 } catch (IllegalArgumentException e)