X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fws%2FSequenceFetcherTest.java;h=1706870c061b454441333e4db6ef4e84ac58f35b;hb=fe350265127bd31fd149b2a4b23e51d2d0bd9ef5;hp=94bf9793132e3f20c9486b9ce25832c7a5919833;hpb=47aa21d5e079664930a91d4e48d1564f4417c6ba;p=jalview.git
diff --git a/test/jalview/ws/SequenceFetcherTest.java b/test/jalview/ws/SequenceFetcherTest.java
index 94bf979..1706870 100644
--- a/test/jalview/ws/SequenceFetcherTest.java
+++ b/test/jalview/ws/SequenceFetcherTest.java
@@ -1,3 +1,23 @@
+/*
+ * 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.ws;
import jalview.analysis.CrossRef;
@@ -5,43 +25,81 @@ import jalview.datamodel.Alignment;
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> seen = new HashMap<>();
+ jalview.ws.SequenceFetcher sfetcher = new jalview.ws.SequenceFetcher();
+ String dupes = "";
+ // for (String src : sfetcher.getOrderedSupportedSources())
+ for (String src : sfetcher.getNonAlignmentSources())
+ {
+ List 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.
*
* @param argv
+ * @j2sIgnore
*/
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] [ []]\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 and retrieve 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 and retrieve 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 sps = new SequenceFetcher(withDas)
+ List sps = new SequenceFetcher()
.getSourceProxy(argv[0]);
if (sps != null)
@@ -52,8 +110,7 @@ public class SequenceFetcherTest
try
{
testRetrieval(argv[0], sp,
- argv.length > 1 ? argv[1] : sp
- .getTestQuery());
+ argv.length > 1 ? argv[1] : sp.getTestQuery());
} catch (Exception e)
{
e.printStackTrace();
@@ -73,7 +130,7 @@ public class SequenceFetcherTest
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++)
{
@@ -95,7 +152,7 @@ public class SequenceFetcherTest
String testQuery)
{
AlignmentI ds = null;
- Vector