X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FStructureChooserTest.java;h=f183e5cbbac0c32a230076d57435bbe309fb54c2;hb=ee942237fe5155b25f5419ece71a4084a47e2f41;hp=d1eda0f47922eab33a6c91221d80ca2a54b8c95f;hpb=52288466dd1e71946a06fd1e6ea15fa8e652c693;p=jalview.git
diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java
index d1eda0f..f183e5c 100644
--- a/test/jalview/gui/StructureChooserTest.java
+++ b/test/jalview/gui/StructureChooserTest.java
@@ -1,29 +1,71 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
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 jalview.datamodel.DBRefEntry;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.Sequence;
-import jalview.datamodel.SequenceI;
-
+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.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.jbgui.FilterOption;
+import junit.extensions.PA;
+
+@Test(singleThreaded = true)
public class StructureChooserTest
{
- Sequence seq;
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ Sequence seq,upSeq,upSeq_nocanonical;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
26);
- seq.setDatasetSequence(seq);
+ seq.createDatasetSequence();
for (int x = 1; x < 5; x++)
{
DBRefEntry dbRef = new DBRefEntry();
@@ -34,53 +76,178 @@ public class StructureChooserTest
PDBEntry dbRef = new PDBEntry();
dbRef.setId("1tim");
- Vector pdbIds = new Vector();
+ Vector pdbIds = new Vector<>();
pdbIds.add(dbRef);
seq.setPDBId(pdbIds);
+
+ // Uniprot sequence for 3D-Beacons mocks
+ upSeq = new Sequence("P38398",
+ "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n"
+ + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n"
+ + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n"
+ + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTN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SLNDCSNQVILAKASQEHHLSEETKCSASLF\n"
+ + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n"
+ + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n"
+ + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n"
+ + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n"
+ + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n"
+ + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n"
+ + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n"
+ + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n"
+ + "", 1,
+1863);
+ upSeq.setDescription("Breast cancer type 1 susceptibility protein");
+ upSeq_nocanonical = new Sequence(upSeq);
+ upSeq.createDatasetSequence();
+ upSeq.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,true));
+
+ upSeq_nocanonical.createDatasetSequence();
+ // not a canonical reference
+ upSeq_nocanonical.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,false));
+
}
- @AfterMethod
+ @AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
seq = null;
+ upSeq=null;
+ upSeq_nocanonical=null;
}
@Test(groups = { "Functional" })
- public void buildQueryTest()
+ public void populateFilterComboBoxTest() throws InterruptedException
{
- String query = StructureChooser.buildQuery(seq);
- System.out.println(">>>>>>>>>> query : " + query);
- assertEquals(
- "4kqy OR text:1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4",
- query);
- }
+ TDBeaconsFTSRestClientTest.setMock();
+ PDBFTSRestClientTest.setMock();
- @Test(groups = { "Functional" })
- public void populateFilterComboBoxTest()
- {
SequenceI[] selectedSeqs = new SequenceI[] { seq };
StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
- sc.populateFilterComboBox();
+ ThreadwaitFor(200, sc);
+
+ // if structures are not discovered then don't
+ // populate filter options
+ sc.populateFilterComboBox(false, false);
int optionsSize = sc.getCmbFilterOption().getItemCount();
- assertEquals(3, 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 3); // if structures are found, filter options
// should be populated
+
+ sc.populateFilterComboBox(true, true);
+ assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
+ FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
+ .getSelectedItem();
+ assertEquals("Cached Structures", filterOpt.getName());
+ FTSRestClient.unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
+ FTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
+
}
@Test(groups = { "Functional" })
+ public void displayTDBQueryTest() throws InterruptedException
+ {
+ TDBeaconsFTSRestClientTest.setMock();
+ PDBFTSRestClientTest.setMock();
+
+ SequenceI[] selectedSeqs = new SequenceI[] { upSeq_nocanonical };
+ StructureChooser sc = new StructureChooser(selectedSeqs, upSeq_nocanonical, null);
+ // mock so should be quick. Exceptions from mocked PDBFTS are expected too
+ ThreadwaitFor(500, sc);
+
+ assertTrue(sc.isCanQueryTDB() && sc.isNotQueriedTDBYet());
+ }
+
+ @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();
- assertTrue(sc.getDiscoveredStructuresSet() != null);
- assertTrue(sc.getDiscoveredStructuresSet().size() > 0);
+ Collection ss = (Collection) 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 ss = (Collection) 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()
+ {
+ String name = "ab_cdEF|fwxyz012349";
+ assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name));
+
+ // remove a [nn] substring
+ name = "abcde12[345]fg";
+ assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
+
+ // remove characters other than a-zA-Z0-9 | or _
+ name = "ab[cd],.\t£$*!- \\\"@:e";
+ assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name));
+ name = "abcde12[345a]fg";
+ assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
}
}