JAL-2246 basic sanity test of fetching example accessions
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 3 May 2017 14:51:36 +0000 (15:51 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 3 May 2017 14:51:36 +0000 (15:51 +0100)
test/jalview/ws/dbsources/RemoteFormatTest.java

index c390efc..90d4472 100644 (file)
@@ -1,15 +1,16 @@
 package jalview.ws.dbsources;
 
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
 
+import jalview.analysis.AlignSeq;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.SequenceI;
+import jalview.ext.ensembl.EnsemblGenomes;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
@@ -22,7 +23,8 @@ import jalview.ws.seqfetcher.DbSourceProxy;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 /**
@@ -39,70 +41,52 @@ public class RemoteFormatTest
 {
   SequenceFetcher sf;
 
-  @Test(groups = "Network")
-  public void testFetchUniprot() throws Exception
-  {
-    List<DbSourceProxy> sps = sf.getSourceProxy(DBRefSource.UNIPROT);
-    assertFalse(sps.isEmpty());
-    AlignmentI response = sps.get(0).getSequenceRecords("P30419");
-    assertNotNull(response);
-    assertEquals(response.getHeight(), 1);
-    SequenceI sq = response.getSequenceAt(0);
-    assertTrue("No PDBEntry on sequence.", sq.getAllPDBEntries().size() > 0);
-    assertTrue("No DBRef on sequence.", sq.getDBRefs().length > 0);
-    List<DBRefEntry> dbr = sq.getPrimaryDBRefs();
-    assertFalse(dbr.isEmpty());
-    assertEquals(
-            "Sequence start/end doesn't match number of residues in sequence",
-            sq.getEnd() - sq.getStart() + 1, sq.getLength());
-  }
-
-  @Test(groups = "Network")
-  public void testFetchPdb()
-  {
-    // 1QIP
-  }
-
-  @Test(groups = "Network")
-  public void testFetchEmbl()
-  {
-    // X53828
-  }
-
-  @Test(groups = "Network")
-  public void testFetchEmblCDS()
-  {
-    // CAA37824
-  }
-
-  @Test(groups = "Network")
-  public void testFetchEnsembl()
-  {
-    // ENSG00000157764
-  }
-
-  @Test(groups = "Network")
-  public void testFetchEnsemblGenomes()
+  @BeforeTest(alwaysRun = true)
+  public void setUp() throws Exception
   {
-    // DDB_G0283883
-  }
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+    // ensure 'add annotation from structure' is selected
+    Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
+            Boolean.TRUE.toString());
+    Cache.applicationProperties.setProperty("ADD_SS_ANN",
+            Boolean.TRUE.toString());
 
-  @Test(groups = "Network")
-  public void testFetchPfamSeed()
-  {
-    // PF03760
+    sf = new SequenceFetcher(false);
   }
 
-  @Test(groups = "Network")
-  public void testFetchPfamFull()
+  @DataProvider(name = "AccessionData")
+  protected Object[][] getAccessions()
   {
-    // PF03760
+    return new Object[][] { { DBRefSource.UNIPROT, "P30419" },
+        { DBRefSource.PDB, "1QIP" }, { DBRefSource.EMBL, "X53828" },
+        { DBRefSource.EMBLCDS, "CAA37824" },
+        { DBRefSource.ENSEMBL, "ENSG00000157764" },
+        { new EnsemblGenomes().getDbSource(), "DDB_G0283883" },
+        { new PfamFull().getDbSource(), "PF03760" },
+        { new PfamSeed().getDbSource(), "PF03760" },
+        { new RfamSeed().getDbSource(), "RF00014" } };
   }
 
-  @Test(groups = "Network")
-  public void testFetchRfamSeed()
+  @Test(groups = "Network", dataProvider = "AccessionData")
+  public void testFetchAccession(String dbSource, String accessionId)
+          throws Exception
   {
-    // RF00014
+    System.out.println("Fetching " + accessionId + " from " + dbSource);
+    List<DbSourceProxy> sps = sf.getSourceProxy(dbSource);
+    assertFalse(sps.isEmpty());
+    AlignmentI al = sps.get(0).getSequenceRecords(accessionId);
+    assertNotNull(al);
+    assertTrue(al.getHeight() > 0);
+    SequenceI sq = al.getSequenceAt(0);
+    // suppress this check as only Uniprot and PDB acquire PDB refs
+    // assertTrue(sq.getAllPDBEntries().size() > 0, "No PDBEntry on sequence.");
+    assertTrue(sq.getDBRefs().length > 0, "No DBRef on sequence.");
+    // suppress this test as only certain databases provide 'primary' dbrefs
+    // assertFalse(sq.getPrimaryDBRefs().isEmpty());
+    int length = AlignSeq.extractGaps("-. ", sq.getSequenceAsString())
+            .length();
+    assertEquals(sq.getEnd() - sq.getStart() + 1, length,
+            "Sequence start/end doesn't match number of residues in sequence");
   }
 
   @Test(groups = { "Network" })
@@ -130,20 +114,8 @@ public class RemoteFormatTest
     assertTrue(response.getSearchSummary().size() > 20);
     // verify we successfully filtered out the header row (JAL-2485)
     FTSData header = response.getSearchSummary().iterator().next();
-    assertFalse("Failed to filter out summary header row",
-            header.getSummaryData()[0].toString().equalsIgnoreCase("Entry"));
-  }
-
-  @BeforeMethod(alwaysRun = true)
-  public void setUp() throws Exception
-  {
-    Cache.loadProperties("test/jalview/io/testProps.jvprops");
-    // ensure 'add annotation from structure' is selected
-    Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("ADD_SS_ANN",
-            Boolean.TRUE.toString());
-  
-    sf = new SequenceFetcher(false);
+    assertFalse(
+            header.getSummaryData()[0].toString().equalsIgnoreCase("Entry"),
+            "Failed to filter out summary header row");
   }
 }