*/
package jalview.gui;
-import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
+import java.util.Collection;
+import java.util.Vector;
+
+import org.junit.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.fts.api.FTSData;
+import jalview.fts.core.FTSRestClient;
+import jalview.fts.service.pdb.PDBFTSRestClient;
+import jalview.fts.service.pdb.PDBFTSRestClientTest;
import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest;
import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
-import jalview.gui.structurechooser.StructureChooserQuerySource;
-import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
import jalview.jbgui.FilterOption;
-import jalview.ws.params.InvalidArgumentException;
-
-import java.util.Collection;
-import java.util.Vector;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
import junit.extensions.PA;
+@Test(singleThreaded = true)
public class StructureChooserTest
{
upSeq=null;
}
- @SuppressWarnings("deprecation")
- @Test(groups = { "Functional" })
- public void buildQueryTest()
- {
- System.out.println("seq >>>> " + seq);
-
- StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { seq});
- assertTrue(scquery instanceof PDBStructureChooserQuerySource);
- String query = scquery.buildQuery(seq);
- assertEquals("pdb_id:1tim", query);
- seq.getAllPDBEntries().clear();
- query = scquery.buildQuery(seq);
- assertEquals(
- "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
- query);
- seq.setDBRefs(null);
- query = scquery.buildQuery(seq);
- System.out.println(query);
- 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);
- }
- System.out.println("");
- System.out.println(seq.getDBRefs());
- System.out.println(query);
- query = scquery.buildQuery(seq);
- assertEquals(
- "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
- query);
- }
-
- @SuppressWarnings("deprecation")
@Test(groups = { "Functional" })
- public void buildThreeDBQueryTest()
+ public void populateFilterComboBoxTest() throws InterruptedException
{
- System.out.println("seq >>>> " + upSeq);
TDBeaconsFTSRestClientTest.setMock();
- StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
- assertTrue(scquery instanceof ThreeDBStructureChooserQuerySource);
- String query = scquery.buildQuery(upSeq);
- assertEquals("P38398", query);
-
- // query shouldn't change regardless of additional entries
- // because 3DBeacons requires canonical entries.
- upSeq.getAllPDBEntries().clear();
- query = scquery.buildQuery(upSeq);
- assertEquals("P38398", query);
- upSeq.setDBRefs(null);
- query = scquery.buildQuery(upSeq);
- /*
- * legacy projects/datasets will not have canonical flags set for uniprot dbrefs
- * graceful behaviour would be to
- * - pick one ? not possible
- * - iterate through all until a 200 is obtained ?
- * ---> ideal but could be costly
- * ---> better to do a direct retrieval from uniprot to work out which is the canonical identifier..
- * ----> need a test to check that accessions can be promoted to canonical!
- */
- assertEquals(null, query);
-
- // TODO:
-//
-// DBRefEntry uniprotDBRef = new DBRefEntry();
-// uniprotDBRef.setAccessionId("P12345");
-// uniprotDBRef.setSource(DBRefSource.UNIPROT);
-// upSeq.addDBRef(uniprotDBRef);
-//
-// DBRefEntry pdbDBRef = new DBRefEntry();
-// pdbDBRef.setAccessionId("1XYZ");
-// pdbDBRef.setSource(DBRefSource.PDB);
-// upSeq.addDBRef(pdbDBRef);
-//
-// for (int x = 1; x < 5; x++)
-// {
-// DBRefEntry dbRef = new DBRefEntry();
-// dbRef.setAccessionId("XYZ_" + x);
-// seq.addDBRef(dbRef);
-// }
-// System.out.println("");
-// System.out.println(seq.getDBRefs());
-// System.out.println(query);
-// query = scquery.buildQuery(seq);
-// assertEquals(
-// "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
-// query);
- }
-
+ PDBFTSRestClientTest.setMock();
- @Test(groups = { "Functional" })
- public void populateFilterComboBoxTest() throws InterruptedException
- {
SequenceI[] selectedSeqs = new SequenceI[] { seq };
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
+ ThreadwaitFor(200, sc);
+
+ // if structures are not discovered then don't
+ // populate filter options
sc.populateFilterComboBox(false, false);
int optionsSize = sc.getCmbFilterOption().getItemCount();
- assertEquals(2, optionsSize); // if structures are not discovered then don't
- // populate filter options
+ System.out.println("Items (no data, no cache): ");
+ StringBuilder items = new StringBuilder();
+ for (int p=0;p<optionsSize;p++)
+ {
+ items.append
+ ("- ").append(sc.getCmbFilterOption().getItemAt(p).getName()).append("\n");
+
+ }
+ // report items when this fails - seems to be a race condition
+ Assert.assertEquals(items.toString(),optionsSize,2);
sc.populateFilterComboBox(true, false);
optionsSize = sc.getCmbFilterOption().getItemCount();
FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
.getSelectedItem();
assertEquals("Cached Structures", filterOpt.getName());
+ FTSRestClient.unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
+ FTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
+
}
@Test(groups = { "Network" })
public void fetchStructuresInfoTest()
{
+ FTSRestClient.unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
+ PDBFTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
SequenceI[] selectedSeqs = new SequenceI[] { seq };
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
+ // not mocked, wait for 2s
+ ThreadwaitFor(2000, sc);
+
sc.fetchStructuresMetaData();
Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
"discoveredStructuresSet");
assertNotNull(ss);
assertTrue(ss.size() > 0);
+ }
+ @Test(groups = { "Functional" })
+ public void fetchStructuresInfoMockedTest()
+ {
+ TDBeaconsFTSRestClientTest.setMock();
+ PDBFTSRestClientTest.setMock();
+ SequenceI[] selectedSeqs = new SequenceI[] { upSeq };
+ StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
+ ThreadwaitFor(500, sc);
+
+ sc.fetchStructuresMetaData();
+ Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
+ "discoveredStructuresSet");
+ assertNotNull(ss);
+ assertTrue(ss.size() > 0);
}
+ private void ThreadwaitFor(int i, StructureChooser sc)
+ {
+ long timeout = i+System.currentTimeMillis();
+ while (!sc.isDialogVisible() && timeout > System.currentTimeMillis())
+ {
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException x)
+ {
+
+ }
+ }
+
+ }
+
+
@Test(groups = { "Functional" })
public void sanitizeSeqNameTest()
{