+ @Test(groups = { "Functional" })
+ public void testUpdateFrom()
+ {
+ PDBEntry pdb1 = new PDBEntry("3A6S", null, null, null);
+ PDBEntry pdb2 = new PDBEntry("3A6S", null, null, null);
+ assertTrue(pdb1.updateFrom(pdb2));
+
+ /*
+ * mismatch of pdb id not allowed
+ */
+ pdb2 = new PDBEntry("1A70", "A", null, null);
+ assertFalse(pdb1.updateFrom(pdb2));
+ assertNull(pdb1.getChainCode());
+
+ /*
+ * match of pdb id is not case sensitive
+ */
+ pdb2 = new PDBEntry("3a6s", "A", null, null);
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getChainCode(), "A");
+ assertEquals(pdb1.getId(), "3A6S");
+
+ /*
+ * add chain - with differing case for id
+ */
+ pdb1 = new PDBEntry("3A6S", null, null, null);
+ pdb2 = new PDBEntry("3a6s", "A", null, null);
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getChainCode(), "A");
+
+ /*
+ * change of chain is not allowed
+ */
+ pdb2 = new PDBEntry("3A6S", "B", null, null);
+ assertFalse(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getChainCode(), "A");
+
+ /*
+ * change chain from null
+ */
+ pdb1 = new PDBEntry("3A6S", null, null, null);
+ pdb2 = new PDBEntry("3A6S", "B", null, null);
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getChainCode(), "B");
+
+ /*
+ * set file and type
+ */
+ pdb2 = new PDBEntry("3A6S", "B", Type.FILE, "filePath");
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getFile(), "filePath");
+ assertEquals(pdb1.getType(), Type.FILE.toString());
+ assertEquals(pdb1.getChainCode(),"B");
+ /*
+ * change of file is not allowed
+ */
+ pdb1 = new PDBEntry("3A6S", null, null, "file1");
+ pdb2 = new PDBEntry("3A6S", "A", null, "file2");
+ assertFalse(pdb1.updateFrom(pdb2));
+ assertNull(pdb1.getChainCode());
+ assertEquals(pdb1.getFile(), "file1");
+
+ /*
+ * set type without change of file
+ */
+ pdb1 = new PDBEntry("3A6S", null, null, "file1");
+ pdb2 = new PDBEntry("3A6S", null, Type.PDB, "file1");
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getType(), Type.PDB.toString());
+
+ /*
+ * set file with differing case of id and chain code
+ */
+ pdb1 = new PDBEntry("3A6S", "A", null, null);
+ pdb2 = new PDBEntry("3a6s", "a", Type.PDB, "file1");
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getType(), Type.PDB.toString());
+ assertEquals(pdb1.getId(), "3A6S"); // unchanged
+ assertEquals(pdb1.getFile(), "file1"); // updated
+ assertEquals(pdb1.getChainCode(), "A"); // unchanged
+
+ /*
+ * changing nothing returns true
+ */
+ pdb1 = new PDBEntry("3A6S", "A", Type.PDB, "file1");
+ pdb2 = new PDBEntry("3A6S", null, null, null);
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getChainCode(), "A");
+ assertEquals(pdb1.getType(), Type.PDB.toString());
+ assertEquals(pdb1.getFile(), "file1");
+
+ /*
+ * add and update properties only
+ */
+ pdb1 = new PDBEntry("3A6S", null, null, null);
+ pdb2 = new PDBEntry("3A6S", null, null, null);
+ pdb1.setProperty("destination", "mars");
+ pdb1.setProperty("hello", "world");
+ pdb2.setProperty("hello", "moon");
+ pdb2.setProperty("goodbye", "world");
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getProperty("destination"), "mars");
+ assertEquals(pdb1.getProperty("hello"), "moon");
+ assertEquals(pdb1.getProperty("goodbye"), "world");
+
+ /*
+ * add properties only
+ */
+ pdb1 = new PDBEntry("3A6S", null, null, null);
+ pdb2 = new PDBEntry("3A6S", null, null, null);
+ pdb2.setProperty("hello", "moon");
+ assertTrue(pdb1.updateFrom(pdb2));
+ assertEquals(pdb1.getProperty("hello"), "moon");