2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.datamodel.DBRefEntry;
28 import jalview.datamodel.DBRefSource;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceI;
32 import jalview.fts.api.FTSData;
33 import jalview.fts.api.FTSRestClientI;
34 import jalview.fts.core.FTSRestClient;
35 import jalview.fts.core.FTSRestRequest;
36 import jalview.fts.service.pdb.PDBFTSRestClient;
37 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
38 import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest;
39 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
40 import jalview.gui.structurechooser.StructureChooserQuerySource;
41 import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
42 import jalview.jbgui.FilterOption;
43 import jalview.ws.params.InvalidArgumentException;
45 import java.util.Collection;
46 import java.util.Vector;
48 import org.junit.Assert;
49 import org.testng.annotations.AfterMethod;
50 import org.testng.annotations.BeforeClass;
51 import org.testng.annotations.BeforeMethod;
52 import org.testng.annotations.Test;
54 import junit.extensions.PA;
56 public class StructureChooserTest
59 @BeforeClass(alwaysRun = true)
60 public void setUpJvOptionPane()
62 JvOptionPane.setInteractiveMode(false);
63 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
68 @BeforeMethod(alwaysRun = true)
69 public void setUp() throws Exception
71 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
73 seq.createDatasetSequence();
74 for (int x = 1; x < 5; x++)
76 DBRefEntry dbRef = new DBRefEntry();
77 dbRef.setAccessionId("XYZ_" + x);
81 PDBEntry dbRef = new PDBEntry();
84 Vector<PDBEntry> pdbIds = new Vector<>();
89 // Uniprot sequence for 3D-Beacons mocks
90 upSeq = new Sequence("P38398",
91 "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n"
92 + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n"
93 + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n"
94 + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTNTHASSLQHENS\n"
95 + "SLLLTKDRMNVEKAEFCNKSKQPGLARSQHNRWAGSKETCNDRRTPSTEKKVDLNADPLCERKEWNKQKLPC\n"
96 + "SENPRDTEDVPWITLNSSIQKVNEWFSRSDELLGSDDSHDGESESNAKVADVLDVLNEVDEYSGSSEKIDLL\n"
97 + "ASDPHEALICKSERVHSKSVESNIEDKIFGKTYRKKASLPNLSHVTENLIIGAFVTEPQIIQERPLTNKLKR\n"
98 + "KRRPTSGLHPEDFIKKADLAVQKTPEMINQGTNQTEQNGQVMNITNSGHENKTKGDSIQNEKNPNPIESLEK\n"
99 + "ESAFKTKAEPISSSISNMELELNIHNSKAPKKNRLRRKSSTRHIHALELVVSRNLSPPNCTELQIDSCSSSE\n"
100 + "EIKKKKYNQMPVRHSRNLQLMEGKEPATGAKKSNKPNEQTSKRHDSDTFPELKLTNAPGSFTKCSNTSELKE\n"
101 + "FVNPSLPREEKEEKLETVKVSNNAEDPKDLMLSGERVLQTERSVESSSISLVPGTDYGTQESISLLEVSTLG\n"
102 + "KAKTEPNKCVSQCAAFENPKGLIHGCSKDNRNDTEGFKYPLGHEVNHSRETSIEMEESELDAQYLQNTFKVS\n"
103 + "KRQSFAPFSNPGNAEEECATFSAHSGSLKKQSPKVTFECEQKEENQGKNESNIKPVQTVNITAGFPVVGQKD\n"
104 + "KPVDNAKCSIKGGSRFCLSSQFRGNETGLITPNKHGLLQNPYRIPPLFPIKSFVKTKCKKNLLEENFEEHSM\n"
105 + "SPEREMGNENIPSTVSTISRNNIRENVFKEASSSNINEVGSSTNEVGSSINEIGSSDENIQAELGRNRGPKL\n"
106 + "NAMLRLGVLQPEVYKQSLPGSNCKHPEIKKQEYEEVVQTVNTDFSPYLISDNLEQPMGSSHASQVCSETPDD\n"
107 + "LLDDGEIKEDTSFAENDIKESSAVFSKSVQKGELSRSPSPFTHTHLAQGYRRGAKKLESSEENLSSEDEELP\n"
108 + "CFQHLLFGKVNNIPSQSTRHSTVATECLSKNTEENLLSLKNSLNDCSNQVILAKASQEHHLSEETKCSASLF\n"
109 + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n"
110 + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n"
111 + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n"
112 + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n"
113 + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n"
114 + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n"
115 + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n"
116 + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n"
119 upSeq.createDatasetSequence();
120 upSeq.setDescription("Breast cancer type 1 susceptibility protein");
121 upSeq.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,true));
124 @AfterMethod(alwaysRun = true)
125 public void tearDown() throws Exception
131 @Test(groups = { "Functional" })
132 public void populateFilterComboBoxTest() throws InterruptedException
134 TDBeaconsFTSRestClientTest.setMock();
135 PDBFTSRestClient.setMock();
137 SequenceI[] selectedSeqs = new SequenceI[] { seq };
138 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
139 sc.populateFilterComboBox(false, false);
140 int optionsSize = sc.getCmbFilterOption().getItemCount();
141 assertEquals(2, optionsSize); // if structures are not discovered then don't
142 // populate filter options
144 sc.populateFilterComboBox(true, false);
145 optionsSize = sc.getCmbFilterOption().getItemCount();
146 assertTrue(optionsSize > 3); // if structures are found, filter options
147 // should be populated
149 sc.populateFilterComboBox(true, true);
150 assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
151 FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
153 assertEquals("Cached Structures", filterOpt.getName());
154 FTSRestClient.unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
155 FTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
159 @Test(groups = { "Network" })
160 public void fetchStructuresInfoTest()
162 FTSRestClient.unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
163 PDBFTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
164 SequenceI[] selectedSeqs = new SequenceI[] { seq };
165 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
166 sc.fetchStructuresMetaData();
167 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
168 "discoveredStructuresSet");
170 assertTrue(ss.size() > 0);
173 @Test(groups = { "Functional" })
174 public void fetchStructuresInfoMockedTest()
176 TDBeaconsFTSRestClientTest.setMock();
177 PDBFTSRestClient.setMock();
178 SequenceI[] selectedSeqs = new SequenceI[] { upSeq };
179 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
180 sc.fetchStructuresMetaData();
181 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
182 "discoveredStructuresSet");
184 assertTrue(ss.size() > 0);
187 @Test(groups = { "Functional" })
188 public void sanitizeSeqNameTest()
190 String name = "ab_cdEF|fwxyz012349";
191 assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name));
193 // remove a [nn] substring
194 name = "abcde12[345]fg";
195 assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
197 // remove characters other than a-zA-Z0-9 | or _
198 name = "ab[cd],.\t£$*!- \\\"@:e";
199 assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name));
201 name = "abcde12[345a]fg";
202 assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name));