+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.ws;
import jalview.analysis.CrossRef;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefSource;
import jalview.datamodel.SequenceI;
+import jalview.gui.JvOptionPane;
import jalview.ws.seqfetcher.ASequenceFetcher;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
public class SequenceFetcherTest
{
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @Test(groups = "Functional")
+ public void testNoDuplicatesInFetchDbRefs()
+ {
+ Map<String, List<DbSourceProxy>> seen = new HashMap<>();
+ jalview.ws.SequenceFetcher sfetcher = new jalview.ws.SequenceFetcher();
+ String dupes = "";
+ for (String src : sfetcher.getOrderedSupportedSources())
+ {
+ List<DbSourceProxy> seenitem = seen.get(src);
+ if (seenitem != null)
+ {
+ dupes += (dupes.length() > 0 ? "," : "") + src;
+ }
+ else
+ {
+ seen.put(src, sfetcher.getSourceProxy(src));
+ }
+ }
+ if (dupes.length() > 0)
+ {
+ Assert.fail("Duplicate sources : " + dupes);
+ }
+ }
+
/**
* simple run method to test dbsources.
*
*/
public static void main(String[] argv)
{
- // TODO: extracted from SequenceFetcher - convert to proper unit test with
+ // TODO: extracted from SequenceFetcher - convert to network dependent
+ // functional integration test with
// assertions
String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
+ "With no arguments, all DbSources will be queried with their test Accession number.\n"
+ "With one argument, the argument will be resolved to one or more db sources and each will be queried with their test accession only.\n"
- + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"
- + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";
- boolean withDas = true;
- if (argv != null && argv.length > 0
- && argv[0].toLowerCase().startsWith("-nodas"))
+ + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.";
+
+ if (argv != null && argv.length > 0)
{
- withDas = false;
String targs[] = new String[argv.length - 1];
System.arraycopy(argv, 1, targs, 0, targs.length);
argv = targs;
}
if (argv != null && argv.length > 0)
{
- List<DbSourceProxy> sps = new SequenceFetcher(withDas)
+ List<DbSourceProxy> sps = new SequenceFetcher()
.getSourceProxy(argv[0]);
if (sps != null)
System.out.println(usage);
return;
}
- ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
+ ASequenceFetcher sfetcher = new SequenceFetcher();
String[] dbSources = sfetcher.getSupportedDb();
for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
{
String testQuery)
{
AlignmentI ds = null;
- Vector<Object[]> noProds = new Vector<Object[]>();
+ Vector<Object[]> noProds = new Vector<>();
System.out.println("Source: " + sp.getDbName() + " (" + db
+ "): retrieving test:" + sp.getTestQuery());
{