X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2FSequenceFetcher.java;h=10a2b282ddaefeefa447880c2f494ede691cf325;hb=6f2c3b8cb30d8ccf7ff9ab949a7b244f0c415bc1;hp=0d9a92676e2a7d557a00c2de08f9681275f74180;hpb=5721b73c6d5de84b21a989a8734e4c161f5dc630;p=jalview.git diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index 0d9a926..10a2b28 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -20,6 +20,8 @@ */ package jalview.ws; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.datamodel.DBRefSource; import jalview.ext.ensembl.EnsemblGene; import jalview.ws.dbsources.Uniprot; @@ -31,15 +33,51 @@ import java.util.Collections; import java.util.List; /** - * This implements the run-time discovery of sequence database clients. + * Thread safe construction of database proxies. This implements the run-time + * discovery of sequence database clients. * + * TODO: extend to a configurable database plugin mechanism where classes are + * instantiated by reflection and queried for their DbRefSource and version + * association. */ -public class SequenceFetcher extends ASequenceFetcher +public class SequenceFetcher extends ASequenceFetcher implements ApplicationSingletonI { + /* + * set a mock fetcher here for testing only - reset to null afterwards + */ + private static SequenceFetcher mockFetcher; + + /** + * Returns a new SequenceFetcher singleton, or a mock object if one has been + * set. + * + * @return + */ + public static SequenceFetcher getInstance() + { + return mockFetcher != null ? mockFetcher + : (SequenceFetcher) ApplicationSingletonProvider + .getInstance(SequenceFetcher.class); + } + + /** + * Set the instance object to use (intended for unit testing with mock + * objects). + * + * Be sure to reset to null in the tearDown method of any tests! + * + * @param sf + */ + public static void setSequenceFetcher(SequenceFetcher sf) + { + mockFetcher = sf; + } + /** - * Thread safe construction of database proxies TODO: extend to a configurable - * database plugin mechanism where classes are instantiated by reflection and - * queried for their DbRefSource and version association. + * + * This public constructor is only is for use by testng to anonymously + * subclass SequenceFetcher. + * * */ public SequenceFetcher() @@ -71,30 +109,25 @@ public class SequenceFetcher extends ASequenceFetcher } /** - * return an ordered list of database sources excluding alignment only databases + * return an ordered list of database sources excluding alignment only + * databases */ public String[] getNonAlignmentSources() { String[] srcs = this.getSupportedDb(); List src = new ArrayList<>(); - - for (int i = 0; i < srcs.length; i++) + outer: for (int i = 0; i < srcs.length; i++) { - boolean accept = true; for (DbSourceProxy dbs : getSourceProxy(srcs[i])) { // Skip the alignment databases for the moment - they're not useful for // verifying a single sequence against its reference source if (dbs.isAlignmentSource()) { - accept = false; - break; + continue outer; } } - if (accept) - { - src.add(srcs[i]); - } + src.add(srcs[i]); } Collections.sort(src, String.CASE_INSENSITIVE_ORDER); return src.toArray(new String[src.size()]);