JAL-1960 updated unit test to include the test case where a sequences has no PDBId...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 24 Jun 2016 10:08:59 +0000 (11:08 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 24 Jun 2016 10:08:59 +0000 (11:08 +0100)
src/jalview/gui/StructureChooser.java
test/jalview/gui/StructureChooserTest.java

index c83f264..8bccc6b 100644 (file)
@@ -45,6 +45,7 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JCheckBox;
@@ -249,7 +250,7 @@ public class StructureChooser extends GStructureChooser implements
     boolean isPDBRefsFound = false;
     boolean isUniProtRefsFound = false;
     StringBuilder queryBuilder = new StringBuilder();
-    HashSet<String> seqRefs = new LinkedHashSet<String>();
+    Set<String> seqRefs = new LinkedHashSet<String>();
 
     if (seq.getAllPDBEntries() != null)
     {
@@ -257,9 +258,8 @@ public class StructureChooser extends GStructureChooser implements
       {
         if (isValidSeqName(entry.getId()))
         {
-          queryBuilder.append("pdb_id")
-                  .append(":")
-.append(entry.getId().toLowerCase())
+          queryBuilder.append("pdb_id:")
+                  .append(entry.getId().toLowerCase())
                   .append(" OR ");
           isPDBRefsFound = true;
           // seqRefs.add(entry.getId());
@@ -275,21 +275,18 @@ public class StructureChooser extends GStructureChooser implements
         {
           if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
           {
-            queryBuilder
-.append("uniprot_accession").append(":")
+            queryBuilder.append("uniprot_accession:")
                     .append(getDBRefId(dbRef))
                     .append(" OR ");
-            queryBuilder
-.append("uniprot_id")
-                    .append(":")
-                    .append(getDBRefId(dbRef)).append(" OR ");
+            queryBuilder.append("uniprot_id:").append(getDBRefId(dbRef))
+                    .append(" OR ");
             isUniProtRefsFound = true;
           }
           else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
           {
 
-            queryBuilder.append("pdb_id")
-                    .append(":").append(getDBRefId(dbRef).toLowerCase())
+            queryBuilder.append("pdb_id:")
+                    .append(getDBRefId(dbRef).toLowerCase())
                     .append(" OR ");
             isPDBRefsFound = true;
           }
index da2cde5..bad536b 100644 (file)
@@ -24,6 +24,7 @@ import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
@@ -80,6 +81,27 @@ public class StructureChooserTest
     seq.setDBRefs(null);
     query = StructureChooser.buildQuery(seq);
     assertEquals("text:4kqy", query);
+
+    DBRefEntry uniprotDBRef = new DBRefEntry();
+    uniprotDBRef.setAccessionId("P12345");
+    uniprotDBRef.setSource(DBRefSource.UNIPROT);
+    seq.addDBRef(uniprotDBRef);
+
+    DBRefEntry pdbDBRef = new DBRefEntry();
+    pdbDBRef.setAccessionId("1XYZ");
+    pdbDBRef.setSource(DBRefSource.PDB);
+    seq.addDBRef(pdbDBRef);
+
+    for (int x = 1; x < 5; x++)
+    {
+      DBRefEntry dbRef = new DBRefEntry();
+      dbRef.setAccessionId("XYZ_" + x);
+      seq.addDBRef(dbRef);
+    }
+    query = StructureChooser.buildQuery(seq);
+    assertEquals(
+            "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
+            query);
   }
 
   @Test(groups = { "Functional" })