Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
PDBEntryTest | 42 | 132 | 10 |
1 | /* | |
2 | assertEquals(case7, case9); | |
3 | * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) | |
4 | * Copyright (C) $$Year-Rel$$ The Jalview Authors | |
5 | * | |
6 | * This file is part of Jalview. | |
7 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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. | |
21 | */ | |
22 | package jalview.datamodel; | |
23 | ||
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; | |
32 | ||
33 | import jalview.datamodel.PDBEntry.Type; | |
34 | import jalview.gui.JvOptionPane; | |
35 | ||
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; | |
41 | ||
42 | public class PDBEntryTest | |
43 | { | |
44 | ||
45 | 1 | @BeforeClass(alwaysRun = true) |
46 | public void setUpJvOptionPane() | |
47 | { | |
48 | 1 | JvOptionPane.setInteractiveMode(false); |
49 | 1 | JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
50 | } | |
51 | ||
52 | 6 | @BeforeMethod(alwaysRun = true) |
53 | public void setUp() throws Exception | |
54 | { | |
55 | } | |
56 | ||
57 | 6 | @AfterMethod(alwaysRun = true) |
58 | public void tearDown() throws Exception | |
59 | { | |
60 | } | |
61 | ||
62 | 1 | @Test(groups = { "Functional" }) |
63 | public void testEquals() | |
64 | { | |
65 | 1 | PDBEntry pdbEntry = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, |
66 | "x/y/z/File"); | |
67 | ||
68 | // id comparison is not case sensitive | |
69 | 1 | PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB, |
70 | "x/y/z/File"); | |
71 | // chain code comparison is not case sensitive | |
72 | 1 | PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB, |
73 | "x/y/z/File"); | |
74 | // different type | |
75 | 1 | PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE, |
76 | "x/y/z/File"); | |
77 | // different everything | |
78 | 1 | PDBEntry case4 = new PDBEntry(null, null, null, null); |
79 | // null id | |
80 | 1 | PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB, |
81 | "x/y/z/File"); | |
82 | // null chain | |
83 | 1 | PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB, |
84 | "x/y/z/File"); | |
85 | // null type | |
86 | 1 | PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File"); |
87 | // null file | |
88 | 1 | PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null); |
89 | // identical to case7 | |
90 | 1 | PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File"); |
91 | // different file only | |
92 | 1 | PDBEntry case10 = new PDBEntry("1xyz", "A", null, "a/b/c/File"); |
93 | ||
94 | /* | |
95 | * assertEquals will invoke PDBEntry.equals() | |
96 | */ | |
97 | 1 | assertFalse(pdbEntry.equals(null)); |
98 | 1 | assertFalse(pdbEntry.equals("a")); |
99 | 1 | assertEquals(case1, pdbEntry); |
100 | 1 | assertEquals(case2, pdbEntry); |
101 | 1 | assertNotEquals(case3, pdbEntry); |
102 | 1 | assertNotEquals(case4, pdbEntry); |
103 | 1 | assertNotEquals(case5, pdbEntry); |
104 | 1 | assertNotEquals(case6, pdbEntry); |
105 | 1 | assertNotEquals(case7, pdbEntry); |
106 | 1 | assertNotEquals(case8, pdbEntry); |
107 | 1 | assertEquals(case7, case9); |
108 | 1 | assertNotEquals(case9, case10); |
109 | ||
110 | // add properties | |
111 | 1 | case7.setProperty("hello", "world"); |
112 | 1 | assertNotEquals(case7, case9); |
113 | 1 | case9.setProperty("hello", "world"); |
114 | 1 | assertEquals(case7, case9); |
115 | 1 | case9.setProperty("hello", "WORLD"); |
116 | 1 | assertNotEquals(case7, case9); |
117 | ||
118 | /* | |
119 | * change string wrapper property to string... | |
120 | */ | |
121 | 1 | case1.setProperty("chain_code", "a"); |
122 | 1 | assertFalse(pdbEntry.equals(case1)); |
123 | 1 | assertFalse(case1.equals(pdbEntry)); |
124 | } | |
125 | ||
126 | 1 | @Test(groups = { "Functional" }) |
127 | public void testSetChainCode() | |
128 | { | |
129 | 1 | PDBEntry pdbEntry = new PDBEntry("1xyz", null, PDBEntry.Type.PDB, |
130 | "x/y/z/File"); | |
131 | 1 | assertNull(pdbEntry.getChainCode()); |
132 | ||
133 | 1 | pdbEntry.setChainCode("a"); |
134 | 1 | assertEquals("a", pdbEntry.getChainCode()); |
135 | ||
136 | 1 | pdbEntry.setChainCode(null); |
137 | 1 | assertNull(pdbEntry.getChainCode()); |
138 | } | |
139 | ||
140 | 1 | @Test(groups = { "Functional" }) |
141 | public void testGetType() | |
142 | { | |
143 | 1 | assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("FILE")); |
144 | 1 | assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("File")); |
145 | 1 | assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file")); |
146 | 1 | assertNotSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file ")); |
147 | } | |
148 | ||
149 | 1 | @Test(groups = { "Functional" }) |
150 | public void testTypeMatches() | |
151 | { | |
152 | // TODO Type.matches() is not used - delete? | |
153 | 1 | assertTrue(PDBEntry.Type.FILE.matches("FILE")); |
154 | 1 | assertTrue(PDBEntry.Type.FILE.matches("File")); |
155 | 1 | assertTrue(PDBEntry.Type.FILE.matches("file")); |
156 | 1 | assertFalse(PDBEntry.Type.FILE.matches("FILE ")); |
157 | } | |
158 | ||
159 | 1 | @Test(groups = { "Functional" }) |
160 | public void testUpdateFrom() | |
161 | { | |
162 | 1 | PDBEntry pdb1 = new PDBEntry("3A6S", null, null, null); |
163 | 1 | PDBEntry pdb2 = new PDBEntry("3A6S", null, null, null); |
164 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
165 | ||
166 | /* | |
167 | * mismatch of pdb id not allowed | |
168 | */ | |
169 | 1 | pdb2 = new PDBEntry("1A70", "A", null, null); |
170 | 1 | assertFalse(pdb1.updateFrom(pdb2)); |
171 | 1 | assertNull(pdb1.getChainCode()); |
172 | ||
173 | /* | |
174 | * match of pdb id is not case sensitive | |
175 | */ | |
176 | 1 | pdb2 = new PDBEntry("3a6s", "A", null, null); |
177 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
178 | 1 | assertEquals(pdb1.getChainCode(), "A"); |
179 | 1 | assertEquals(pdb1.getId(), "3A6S"); |
180 | ||
181 | /* | |
182 | * add chain - with differing case for id | |
183 | */ | |
184 | 1 | pdb1 = new PDBEntry("3A6S", null, null, null); |
185 | 1 | pdb2 = new PDBEntry("3a6s", "A", null, null); |
186 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
187 | 1 | assertEquals(pdb1.getChainCode(), "A"); |
188 | ||
189 | /* | |
190 | * change of chain is not allowed | |
191 | */ | |
192 | 1 | pdb2 = new PDBEntry("3A6S", "B", null, null); |
193 | 1 | assertFalse(pdb1.updateFrom(pdb2)); |
194 | 1 | assertEquals(pdb1.getChainCode(), "A"); |
195 | ||
196 | /* | |
197 | * change chain from null | |
198 | */ | |
199 | 1 | pdb1 = new PDBEntry("3A6S", null, null, null); |
200 | 1 | pdb2 = new PDBEntry("3A6S", "B", null, null); |
201 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
202 | 1 | assertEquals(pdb1.getChainCode(), "B"); |
203 | ||
204 | /* | |
205 | * set file and type | |
206 | */ | |
207 | 1 | pdb2 = new PDBEntry("3A6S", "B", Type.FILE, "filePath"); |
208 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
209 | 1 | assertEquals(pdb1.getFile(), "filePath"); |
210 | 1 | assertEquals(pdb1.getType(), Type.FILE.toString()); |
211 | 1 | assertEquals(pdb1.getChainCode(), "B"); |
212 | /* | |
213 | * change of file is not allowed | |
214 | */ | |
215 | 1 | pdb1 = new PDBEntry("3A6S", null, null, "file1"); |
216 | 1 | pdb2 = new PDBEntry("3A6S", "A", null, "file2"); |
217 | 1 | assertFalse(pdb1.updateFrom(pdb2)); |
218 | 1 | assertNull(pdb1.getChainCode()); |
219 | 1 | assertEquals(pdb1.getFile(), "file1"); |
220 | ||
221 | /* | |
222 | * set type without change of file | |
223 | */ | |
224 | 1 | pdb1 = new PDBEntry("3A6S", null, null, "file1"); |
225 | 1 | pdb2 = new PDBEntry("3A6S", null, Type.PDB, "file1"); |
226 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
227 | 1 | assertEquals(pdb1.getType(), Type.PDB.toString()); |
228 | ||
229 | /* | |
230 | * set file with differing case of id and chain code | |
231 | */ | |
232 | 1 | pdb1 = new PDBEntry("3A6S", "A", null, null); |
233 | 1 | pdb2 = new PDBEntry("3a6s", "a", Type.PDB, "file1"); |
234 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
235 | 1 | assertEquals(pdb1.getType(), Type.PDB.toString()); |
236 | 1 | assertEquals(pdb1.getId(), "3A6S"); // unchanged |
237 | 1 | assertEquals(pdb1.getFile(), "file1"); // updated |
238 | 1 | assertEquals(pdb1.getChainCode(), "A"); // unchanged |
239 | ||
240 | /* | |
241 | * changing nothing returns true | |
242 | */ | |
243 | 1 | pdb1 = new PDBEntry("3A6S", "A", Type.PDB, "file1"); |
244 | 1 | pdb2 = new PDBEntry("3A6S", null, null, null); |
245 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
246 | 1 | assertEquals(pdb1.getChainCode(), "A"); |
247 | 1 | assertEquals(pdb1.getType(), Type.PDB.toString()); |
248 | 1 | assertEquals(pdb1.getFile(), "file1"); |
249 | ||
250 | /* | |
251 | * add and update properties only | |
252 | */ | |
253 | 1 | pdb1 = new PDBEntry("3A6S", null, null, null); |
254 | 1 | pdb2 = new PDBEntry("3A6S", null, null, null); |
255 | 1 | pdb1.setProperty("destination", "mars"); |
256 | 1 | pdb1.setProperty("hello", "world"); |
257 | 1 | pdb2.setProperty("hello", "moon"); |
258 | 1 | pdb2.setProperty("goodbye", "world"); |
259 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
260 | 1 | assertEquals(pdb1.getProperty("destination"), "mars"); |
261 | 1 | assertEquals(pdb1.getProperty("hello"), "moon"); |
262 | 1 | assertEquals(pdb1.getProperty("goodbye"), "world"); |
263 | ||
264 | /* | |
265 | * add properties only | |
266 | */ | |
267 | 1 | pdb1 = new PDBEntry("3A6S", null, null, null); |
268 | 1 | pdb2 = new PDBEntry("3A6S", null, null, null); |
269 | 1 | pdb2.setProperty("hello", "moon"); |
270 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
271 | 1 | assertEquals(pdb1.getProperty("hello"), "moon"); |
272 | ||
273 | /* | |
274 | * different id but authoritative | |
275 | */ | |
276 | 1 | pdb1 = new PDBEntry("af:1xyz", "A", null, "a/b/c/File"); |
277 | 1 | pdb2 = new PDBEntry("af-1xyz", "A", null, "a/b/c/File"); |
278 | 1 | pdb1.setAuthoritative(true); |
279 | ||
280 | 1 | assertTrue(pdb1.isAuthoritative()); |
281 | 1 | assertFalse(pdb2.isAuthoritative()); |
282 | // can update pdb1 (authoritative) from pdb2 (non-authoritative) | |
283 | 1 | assertTrue(pdb1.updateFrom(pdb2)); |
284 | // but the ID must remain the same | |
285 | 1 | assertEquals(pdb1.getId(), "af:1xyz"); |
286 | ||
287 | } | |
288 | ||
289 | 1 | @Test(groups = { "Functional" }) |
290 | public void testConstructor_fromDbref() | |
291 | { | |
292 | 1 | PDBEntry pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70")); |
293 | 1 | assertEquals(pdb.getId(), "1A70"); |
294 | 1 | assertNull(pdb.getChainCode()); |
295 | 1 | assertNull(pdb.getType()); |
296 | 1 | assertNull(pdb.getFile()); |
297 | ||
298 | /* | |
299 | * from dbref with chain code appended | |
300 | */ | |
301 | 1 | pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70B")); |
302 | 1 | assertEquals(pdb.getId(), "1A70"); |
303 | 1 | assertEquals(pdb.getChainCode(), "B"); |
304 | ||
305 | /* | |
306 | * from dbref with overlong accession | |
307 | */ | |
308 | 1 | pdb = new PDBEntry(new DBRefEntry("PDB", "0", "1A70BC")); |
309 | 1 | assertEquals(pdb.getId(), "1A70BC"); |
310 | 1 | assertNull(pdb.getChainCode()); |
311 | ||
312 | /* | |
313 | * from dbref which is not for PDB | |
314 | */ | |
315 | 1 | try |
316 | { | |
317 | 1 | pdb = new PDBEntry(new DBRefEntry("PDBe", "0", "1A70")); |
318 | 0 | fail("Expected exception"); |
319 | } catch (IllegalArgumentException e) | |
320 | { | |
321 | // expected; | |
322 | } | |
323 | } | |
324 | ||
325 | } |