Clover icon

Coverage Report

  1. Project Clover database Fri Nov 15 2024 13:56:46 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.993055699.3%
 

Contributing tests

This file is covered by 7 tests. .

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