Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.datamodel

File PDBEntryTest.java

 

Code metrics

0
134
10
1
332
204
11
0.08
13.4
10
1.1

Classes

Class Line # Actions
PDBEntryTest 43 134 11
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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