JAL-1803 JAL-2106 patch tests for tighter PDB Primary DBRef definition
[jalview.git] / test / jalview / datamodel / SequenceTest.java
index fcd24dd..0a1ca67 100644 (file)
@@ -31,6 +31,7 @@ import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
 import jalview.datamodel.PDBEntry.Type;
 import jalview.util.MapList;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -452,6 +453,8 @@ public class SequenceTest
     
     DBRefEntry pdb1pdb = new DBRefEntry("PDB", "version1", "1PDB");
     DBRefEntry pdb2pdb = new DBRefEntry("PDB", "version1", "2PDB");
+
+    
     List<DBRefEntry> primRefs = Arrays.asList(new DBRefEntry[] { pdb1pdb,
         pdb2pdb });
 
@@ -763,4 +766,34 @@ public class SequenceTest
     assertSame(dbref3, sq.getDBRefs()[2]);
     assertEquals("3", dbref2.getVersion());
   }
+
+  @Test(groups = { "Functional" })
+  public void testGetPrimaryDBRefs()
+  {
+    /*
+     * test PDB relationships for for getPrimaryDBRefs
+     */
+    SequenceI seq = new Sequence("aseq", "ASDF");
+    DBRefEntry upentry = new DBRefEntry("UNIPROT", "0", "1qip");
+    // primary - uniprot
+    seq.addDBRef(upentry);
+    // primary - type is PDB
+    DBRefEntry pdbentry = new DBRefEntry("PDB", "0", "1qip");
+    seq.addDBRef(pdbentry);
+    // not primary - PDBEntry has no file
+    seq.addDBRef(new DBRefEntry("PDB", "0", "1AAA"));
+    // not primary - no PDBEntry
+    seq.addDBRef(new DBRefEntry("PDB", "0", "1DDD"));
+    // add corroborating PDB entry for primary DBref - needs to have a file as
+    // well as matching ID
+    seq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah")
+            .toString()));
+    // not valid DBRef - no file..
+    seq.addPDBId(new PDBEntry("1AAA", null, null, null));
+    assertTrue("Couldn't find simple primary reference (UNIPROT)", seq
+            .getPrimaryDBRefs().contains(upentry));
+    assertTrue("Couldn't find expected PDB primary reference", seq
+            .getPrimaryDBRefs().contains(pdbentry));
+    assertEquals(2, seq.getPrimaryDBRefs().size());
+  }
 }