Merge branch 'features/JAL-2885UniprotHttps' into releases/Release_2_10_4_Branch
authorJim Procter <jprocter@issues.jalview.org>
Fri, 23 Feb 2018 16:01:42 +0000 (16:01 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 23 Feb 2018 16:01:42 +0000 (16:01 +0000)
20 files changed:
src/jalview/bin/Cache.java
src/jalview/ext/ensembl/EnsemblGenomes.java
src/jalview/ext/ensembl/EnsemblLookup.java
src/jalview/ext/ensembl/EnsemblRestClient.java
src/jalview/ext/ensembl/EnsemblSequenceFetcher.java
src/jalview/fts/service/uniprot/UniProtFTSRestClient.java
src/jalview/ws/dbsources/Pfam.java
src/jalview/ws/dbsources/PfamFull.java
src/jalview/ws/dbsources/PfamSeed.java
src/jalview/ws/dbsources/Rfam.java
src/jalview/ws/dbsources/RfamFull.java
src/jalview/ws/dbsources/RfamSeed.java
src/jalview/ws/dbsources/Uniprot.java
src/jalview/ws/dbsources/Xfam.java
test/jalview/ext/ensembl/EnsemblGeneTest.java
test/jalview/ws/dbsources/PfamFullTest.java [new file with mode: 0644]
test/jalview/ws/dbsources/PfamSeedTest.java [new file with mode: 0644]
test/jalview/ws/dbsources/RfamFullTest.java [new file with mode: 0644]
test/jalview/ws/dbsources/RfamSeedTest.java [new file with mode: 0644]
test/jalview/ws/dbsources/XfamFetcherTest.java

index dc50843..dcd6546 100755 (executable)
@@ -281,7 +281,7 @@ public class Cache
     @Override
     public synchronized Enumeration<Object> keys()
     {
-      return Collections.enumeration(new TreeSet<Object>(super.keySet()));
+      return Collections.enumeration(new TreeSet<>(super.keySet()));
     }
   };
 
@@ -334,7 +334,10 @@ public class Cache
     }
   }
 
-  /** Called when Jalview is started */
+  /**
+   * Loads properties from the given properties file. Any existing properties
+   * are first cleared.
+   */
   public static void loadProperties(String propsFile)
   {
     propertiesFile = propsFile;
@@ -369,6 +372,7 @@ public class Cache
       {
         fis = new FileInputStream(propertiesFile);
       }
+      applicationProperties.clear();
       applicationProperties.load(fis);
 
       // remove any old build properties
@@ -621,14 +625,14 @@ public class Cache
    * @param obj
    *          String value of property
    * 
-   * @return String value of property
+   * @return previous value of property (or null)
    */
-  public static String setProperty(String key, String obj)
+  public static Object setProperty(String key, String obj)
   {
-
+    Object oldValue = null;
     try
     {
-      applicationProperties.setProperty(key, obj);
+      oldValue = applicationProperties.setProperty(key, obj);
       if (!propsAreReadOnly)
       {
         FileOutputStream out = new FileOutputStream(propertiesFile);
@@ -640,7 +644,7 @@ public class Cache
       System.out.println(
               "Error setting property: " + key + " " + obj + "\n" + ex);
     }
-    return obj;
+    return oldValue;
   }
 
   /**
index bbd1f26..6dd69a8 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.ext.ensembl;
 
+import jalview.bin.Cache;
+
 /**
  * A class to behave much like EnsemblGene but referencing the ensemblgenomes
  * domain and data
@@ -35,7 +37,9 @@ public class EnsemblGenomes extends EnsemblGene
    */
   public EnsemblGenomes()
   {
-    super(ENSEMBL_GENOMES_REST);
+    super();
+    setDomain(Cache.getDefault(ENSEMBL_GENOMES_BASEURL,
+            DEFAULT_ENSEMBL_GENOMES_BASEURL));
   }
 
   @Override
index 92763a1..0ddef2b 100644 (file)
@@ -41,6 +41,19 @@ import org.json.simple.parser.ParseException;
  */
 public class EnsemblLookup extends EnsemblRestClient
 {
+
+  private static final String OBJECT_TYPE_TRANSLATION = "Translation";
+  private static final String PARENT = "Parent";
+  private static final String OBJECT_TYPE_TRANSCRIPT = "Transcript";
+  private static final String ID = "id";
+  private static final String OBJECT_TYPE_GENE = "Gene";
+  private static final String OBJECT_TYPE = "object_type";
+
+  /**
+   * keep track of last identifier retrieved to break loops
+   */
+  private String lastId;
+
   /**
    * Default constructor (to use rest.ensembl.org)
    */
@@ -150,7 +163,18 @@ public class EnsemblLookup extends EnsemblRestClient
     BufferedReader br = null;
     try
     {
+
       URL url = getUrl(identifier, objectType);
+
+      if (identifier.equals(lastId))
+      {
+        System.err.println("** Ensembl lookup " + url.toString()
+                + " looping on Parent!");
+        return null;
+      }
+
+      lastId = identifier;
+
       if (url != null)
       {
         br = getHttpResponse(url, ids);
index b1bc8e5..b19f557 100644 (file)
@@ -72,10 +72,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
 
   private static final String REST_CHANGE_LOG = "https://github.com/Ensembl/ensembl-rest/wiki/Change-log";
 
-  private static Map<String, EnsemblInfo> domainData;
-
-  // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
-  private static final String PING_URL = "http://rest.ensembl.org/info/ping.json";
+  private static Map<String, EnsemblInfo> domainData = new HashMap<>();
 
   private final static long AVAILABILITY_RETEST_INTERVAL = 10000L; // 10 seconds
 
@@ -85,11 +82,11 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
 
   static
   {
-    domainData = new HashMap<>();
-    domainData.put(ENSEMBL_REST,
-            new EnsemblInfo(ENSEMBL_REST, LATEST_ENSEMBL_REST_VERSION));
-    domainData.put(ENSEMBL_GENOMES_REST, new EnsemblInfo(
-            ENSEMBL_GENOMES_REST, LATEST_ENSEMBLGENOMES_REST_VERSION));
+    domainData.put(DEFAULT_ENSEMBL_BASEURL,
+            new EnsemblInfo(DEFAULT_ENSEMBL_BASEURL, LATEST_ENSEMBL_REST_VERSION));
+    domainData.put(DEFAULT_ENSEMBL_GENOMES_BASEURL,
+            new EnsemblInfo(
+            DEFAULT_ENSEMBL_GENOMES_BASEURL, LATEST_ENSEMBLGENOMES_REST_VERSION));
   }
 
   protected volatile boolean inProgress = false;
@@ -99,7 +96,21 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
    */
   public EnsemblRestClient()
   {
-    this(ENSEMBL_REST);
+    super();
+
+    /*
+     * initialise domain info lazily
+     */
+    if (!domainData.containsKey(ensemblDomain))
+    {
+      domainData.put(ensemblDomain,
+              new EnsemblInfo(ensemblDomain, LATEST_ENSEMBL_REST_VERSION));
+    }
+    if (!domainData.containsKey(ensemblGenomesDomain))
+    {
+      domainData.put(ensemblGenomesDomain, new EnsemblInfo(
+              ensemblGenomesDomain, LATEST_ENSEMBLGENOMES_REST_VERSION));
+    }
   }
 
   /**
@@ -169,11 +180,12 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
   boolean checkEnsembl()
   {
     BufferedReader br = null;
+    String pingUrl = getDomain() + "/info/ping" + CONTENT_TYPE_JSON;
     try
     {
       // note this format works for both ensembl and ensemblgenomes
       // info/ping.json works for ensembl only (March 2016)
-      URL ping = new URL(getDomain() + "/info/ping" + CONTENT_TYPE_JSON);
+      URL ping = new URL(pingUrl);
 
       /*
        * expect {"ping":1} if ok
@@ -192,7 +204,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
     } catch (Throwable t)
     {
       System.err.println(
-              "Error connecting to " + PING_URL + ": " + t.getMessage());
+              "Error connecting to " + pingUrl + ": " + t.getMessage());
     } finally
     {
       if (br != null)
index c4abb20..0aaaf93 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ext.ensembl;
 
+import jalview.bin.Cache;
 import jalview.datamodel.DBRefSource;
 import jalview.ws.seqfetcher.DbSourceProxyImpl;
 
@@ -32,6 +33,16 @@ import com.stevesoft.pat.Regex;
  */
 abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
 {
+  // domain properties lookup keys:
+  protected static final String ENSEMBL_BASEURL = "ENSEMBL_BASEURL";
+
+  protected static final String ENSEMBL_GENOMES_BASEURL = "ENSEMBL_GENOMES_BASEURL";
+
+  // domain properties default values:
+  protected static final String DEFAULT_ENSEMBL_BASEURL = "https://rest.ensembl.org";
+
+  protected static final String DEFAULT_ENSEMBL_GENOMES_BASEURL = "https://rest.ensemblgenomes.org";
+
   /*
    * accepts ENSG/T/E/P with 11 digits
    * or ENSMUSP or similar for other species
@@ -41,9 +52,9 @@ abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
           "(ENS([A-Z]{3}|)[GTEP]{1}[0-9]{11}$)" + "|"
                   + "(CCDS[0-9.]{3,}$)");
 
-  protected static final String ENSEMBL_GENOMES_REST = "http://rest.ensemblgenomes.org";
+  protected final String ensemblGenomesDomain;
 
-  protected static final String ENSEMBL_REST = "http://rest.ensembl.org";
+  protected final String ensemblDomain;
 
   protected static final String OBJECT_TYPE_TRANSLATION = "Translation";
 
@@ -68,13 +79,29 @@ abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
     constrained, regulatory
   }
 
-  private String domain = ENSEMBL_REST;
+  private String domain;
+
+  /**
+   * Constructor
+   */
+  public EnsemblSequenceFetcher()
+  {
+    /*
+     * the default domain names may be overridden in .jalview_properties;
+     * this allows an easy change from http to https in future if needed
+     */
+    ensemblDomain = Cache.getDefault(ENSEMBL_BASEURL,
+            DEFAULT_ENSEMBL_BASEURL);
+    ensemblGenomesDomain = Cache.getDefault(ENSEMBL_GENOMES_BASEURL,
+            DEFAULT_ENSEMBL_GENOMES_BASEURL);
+    domain = ensemblDomain;
+  }
 
   @Override
   public String getDbSource()
   {
     // NB ensure Uniprot xrefs are canonicalised from "Ensembl" to "ENSEMBL"
-    if (ENSEMBL_GENOMES_REST.equals(getDomain()))
+    if (ensemblGenomesDomain.equals(getDomain()))
     {
       return DBRefSource.ENSEMBLGENOMES;
     }
index 250fba0..262ed86 100644 (file)
@@ -21,6 +21,7 @@
 
 package jalview.fts.service.uniprot;
 
+import jalview.bin.Cache;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
@@ -44,9 +45,18 @@ import com.sun.jersey.api.client.config.DefaultClientConfig;
 
 public class UniProtFTSRestClient extends FTSRestClient
 {
+  private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
+
   private static FTSRestClientI instance = null;
 
-  public static final String UNIPROT_SEARCH_ENDPOINT = "http://www.uniprot.org/uniprot/?";
+  public final String uniprotSearchEndpoint;
+
+  public UniProtFTSRestClient()
+  {
+    super();
+    uniprotSearchEndpoint = Cache.getDefault("UNIPROT_DOMAIN",
+            DEFAULT_UNIPROT_DOMAIN) + "/uniprot/?";
+  }
 
   @Override
   public FTSRestResponse executeRequest(FTSRestRequest uniportRestRequest)
@@ -81,7 +91,7 @@ public class UniProtFTSRestClient extends FTSRestClient
       }
 
       WebResource webResource = null;
-      webResource = client.resource(UNIPROT_SEARCH_ENDPOINT)
+      webResource = client.resource(uniprotSearchEndpoint)
               .queryParam("format", "tab")
               .queryParam("columns", wantedFields)
               .queryParam("limit", String.valueOf(responseSize))
@@ -158,7 +168,7 @@ public class UniProtFTSRestClient extends FTSRestClient
     String[] foundDataRow = uniProtTabDelimittedResponseString.split("\n");
     if (foundDataRow != null && foundDataRow.length > 0)
     {
-      result = new ArrayList<FTSData>();
+      result = new ArrayList<>();
       boolean firstRow = true;
       for (String dataRow : foundDataRow)
       {
index 0227e35..62e59c9 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ws.dbsources;
 
+import jalview.bin.Cache;
 import jalview.datamodel.DBRefSource;
 
 import com.stevesoft.pat.Regex;
@@ -34,6 +35,9 @@ import com.stevesoft.pat.Regex;
  */
 abstract public class Pfam extends Xfam
 {
+  private static final String PFAM_BASEURL_KEY = "PFAM_BASEURL";
+
+  private static final String DEFAULT_PFAM_BASEURL = "https://pfam.xfam.org";
 
   public Pfam()
   {
@@ -48,7 +52,6 @@ abstract public class Pfam extends Xfam
   @Override
   public String getAccessionSeparator()
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
@@ -60,7 +63,6 @@ abstract public class Pfam extends Xfam
   @Override
   public Regex getAccessionValidator()
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
@@ -91,17 +93,14 @@ abstract public class Pfam extends Xfam
   @Override
   public String getDbVersion()
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
-  /**
-   * Returns base URL for selected Pfam alignment type
-   * 
-   * @return PFAM URL stub for this DbSource
-   */
   @Override
-  protected abstract String getXFAMURL();
+  protected String getURLPrefix()
+  {
+    return Cache.getDefault(PFAM_BASEURL_KEY, DEFAULT_PFAM_BASEURL);
+  }
 
   /*
    * (non-Javadoc)
index ec9fcbb..0600427 100644 (file)
@@ -31,20 +31,8 @@ public class PfamFull extends Pfam
     super();
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see jalview.ws.dbsources.Pfam#getPFAMURL()
-   */
-  @Override
-  protected String getXFAMURL()
-  {
-    return "http://pfam.xfam.org/family/";
-
-  }
-
   @Override
-  public String getXFAMURLSUFFIX()
+  public String getURLSuffix()
   {
     return "/alignment/full";
   }
index 33c39b1..dff8a17 100644 (file)
@@ -33,19 +33,8 @@ public class PfamSeed extends Pfam
     super();
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see jalview.ws.dbsources.Pfam#getPFAMURL()
-   */
-  @Override
-  protected String getXFAMURL()
-  {
-    return "http://pfam.xfam.org/family/";
-  }
-
   @Override
-  public String getXFAMURLSUFFIX()
+  public String getURLSuffix()
   {
     return "/alignment/seed";
   }
index 97f73d0..51edb05 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ws.dbsources;
 
+import jalview.bin.Cache;
 import jalview.datamodel.DBRefSource;
 
 import com.stevesoft.pat.Regex;
@@ -31,6 +32,15 @@ import com.stevesoft.pat.Regex;
  */
 abstract public class Rfam extends Xfam
 {
+  private static final String RFAM_BASEURL_KEY = "RFAM_BASEURL";
+
+  private static final String DEFAULT_RFAM_BASEURL = "https://rfam.xfam.org";
+
+  @Override
+  protected String getURLPrefix()
+  {
+    return Cache.getDefault(RFAM_BASEURL_KEY, DEFAULT_RFAM_BASEURL);
+  }
 
   public Rfam()
   {
@@ -46,7 +56,6 @@ abstract public class Rfam extends Xfam
   @Override
   public String getAccessionSeparator()
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
@@ -58,7 +67,6 @@ abstract public class Rfam extends Xfam
   @Override
   public Regex getAccessionValidator()
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
@@ -82,18 +90,9 @@ abstract public class Rfam extends Xfam
   @Override
   public String getDbVersion()
   {
-    // TODO Auto-generated method stub
     return null;
   }
 
-  /**
-   * Returns base URL for selected Rfam alignment type
-   * 
-   * @return RFAM URL stub for this DbSource
-   */
-  @Override
-  protected abstract String getXFAMURL();
-
   /*
    * (non-Javadoc)
    * 
index b2ca31a..d815336 100644 (file)
@@ -33,20 +33,8 @@ public class RfamFull extends Rfam
     super();
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see jalview.ws.dbsources.Rfam#getXFAMURL()
-   */
-  @Override
-  protected String getXFAMURL()
-  {
-    return "http://rfam.xfam.org/family/";
-
-  }
-
   @Override
-  public String getXFAMURLSUFFIX()
+  public String getURLSuffix()
   {
     return "/alignment/full";
   }
index f714547..a74e829 100644 (file)
@@ -33,19 +33,8 @@ public class RfamSeed extends Rfam
     super();
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see jalview.ws.dbsources.Rfam#getRFAMURL()
-   */
-  @Override
-  protected String getXFAMURL()
-  {
-    return "http://rfam.xfam.org/family/";
-  }
-
   @Override
-  public String getXFAMURLSUFFIX()
+  public String getURLSuffix()
   {
     // to download gzipped file add '?gzip=1'
     return "/alignment/stockholm";
index 73775cf..6b09eb6 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ws.dbsources;
 
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
@@ -52,6 +53,8 @@ import com.stevesoft.pat.Regex;
  */
 public class Uniprot extends DbSourceProxyImpl
 {
+  private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
+
   private static final String BAR_DELIMITER = "|";
 
   /*
@@ -67,6 +70,11 @@ public class Uniprot extends DbSourceProxyImpl
     super();
   }
 
+  private String getDomain()
+  {
+    return Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN);
+  }
+
   /*
    * (non-Javadoc)
    * 
@@ -163,7 +171,7 @@ public class Uniprot extends DbSourceProxyImpl
               "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
       AlignmentI al = null;
 
-      String downloadstring = "http://www.uniprot.org/uniprot/" + queries
+      String downloadstring = getDomain() + "/uniprot/" + queries
               + ".xml";
       URL url = null;
       URLConnection urlconn = null;
index 26291eb..b83f558 100644 (file)
@@ -42,7 +42,12 @@ public abstract class Xfam extends DbSourceProxyImpl
     super();
   }
 
-  protected abstract String getXFAMURL();
+  /**
+   * the base URL for this Xfam-like service
+   * 
+   * @return
+   */
+  protected abstract String getURLPrefix();
 
   @Override
   public abstract String getDbVersion();
@@ -57,8 +62,7 @@ public abstract class Xfam extends DbSourceProxyImpl
     // retrieved.
     startQuery();
     // TODO: trap HTTP 404 exceptions and return null
-    String xfamUrl = getXFAMURL() + queries.trim().toUpperCase()
-            + getXFAMURLSUFFIX();
+    String xfamUrl = getURL(queries);
 
     if (Cache.log != null)
     {
@@ -83,6 +87,12 @@ public abstract class Xfam extends DbSourceProxyImpl
     return rcds;
   }
 
+  String getURL(String queries)
+  {
+    return getURLPrefix() + "/family/" + queries.trim().toUpperCase()
+            + getURLSuffix();
+  }
+
   /**
    * Pfam and Rfam provide alignments
    */
@@ -97,7 +107,7 @@ public abstract class Xfam extends DbSourceProxyImpl
    * 
    * @return "" for most Xfam sources
    */
-  public String getXFAMURLSUFFIX()
+  public String getURLSuffix()
   {
     return "";
   }
index 1b1a2b4..217742d 100644 (file)
@@ -25,6 +25,7 @@ import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.api.FeatureSettingsModelI;
+import jalview.bin.Cache;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
@@ -53,6 +54,7 @@ public class EnsemblGeneTest
   @BeforeClass(alwaysRun = true)
   public void setUp()
   {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
     SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
   }
 
diff --git a/test/jalview/ws/dbsources/PfamFullTest.java b/test/jalview/ws/dbsources/PfamFullTest.java
new file mode 100644 (file)
index 0000000..d675fbe
--- /dev/null
@@ -0,0 +1,30 @@
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class PfamFullTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+  }
+
+  @Test(groups = "Functional")
+  public void testGetURL()
+  {
+    // with default value for domain
+    String url = new PfamFull().getURL(" abc ");
+    assertEquals(url, "http://pfam.xfam.org/family/ABC/alignment/full");
+
+    // with override in properties
+    Cache.setProperty("PFAM_DOMAIN", "https://pfam.xfam.org");
+    url = new PfamFull().getURL(" abc ");
+    assertEquals(url, "https://pfam.xfam.org/family/ABC/alignment/full");
+  }
+}
diff --git a/test/jalview/ws/dbsources/PfamSeedTest.java b/test/jalview/ws/dbsources/PfamSeedTest.java
new file mode 100644 (file)
index 0000000..537c97e
--- /dev/null
@@ -0,0 +1,30 @@
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class PfamSeedTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+  }
+
+  @Test(groups = "Functional")
+  public void testGetURL()
+  {
+    // with default value for domain
+    String url = new PfamSeed().getURL(" abc ");
+    assertEquals(url, "http://pfam.xfam.org/family/ABC/alignment/seed");
+
+    // with override in properties
+    Cache.setProperty("PFAM_DOMAIN", "https://pfam.xfam.org");
+    url = new PfamSeed().getURL(" abc ");
+    assertEquals(url, "https://pfam.xfam.org/family/ABC/alignment/seed");
+  }
+}
diff --git a/test/jalview/ws/dbsources/RfamFullTest.java b/test/jalview/ws/dbsources/RfamFullTest.java
new file mode 100644 (file)
index 0000000..344aee6
--- /dev/null
@@ -0,0 +1,30 @@
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class RfamFullTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+  }
+
+  @Test(groups = "Functional")
+  public void testGetURL()
+  {
+    // with default value for domain
+    String url = new RfamFull().getURL(" abc ");
+    assertEquals(url, "http://rfam.xfam.org/family/ABC/alignment/full");
+
+    // with override in properties
+    Cache.setProperty("RFAM_DOMAIN", "https://rfam.xfam.org");
+    url = new RfamFull().getURL(" abc ");
+    assertEquals(url, "https://rfam.xfam.org/family/ABC/alignment/full");
+  }
+}
diff --git a/test/jalview/ws/dbsources/RfamSeedTest.java b/test/jalview/ws/dbsources/RfamSeedTest.java
new file mode 100644 (file)
index 0000000..e45fff1
--- /dev/null
@@ -0,0 +1,32 @@
+package jalview.ws.dbsources;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.bin.Cache;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class RfamSeedTest
+{
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+  }
+
+  @Test(groups = "Functional")
+  public void testGetURL()
+  {
+    // with default value for domain
+    String url = new RfamSeed().getURL(" abc ");
+    assertEquals(url,
+            "http://rfam.xfam.org/family/ABC/alignment/stockholm");
+
+    // with override in properties
+    Cache.setProperty("RFAM_DOMAIN", "https://rfam.xfam.org");
+    url = new RfamSeed().getURL(" abc ");
+    assertEquals(url,
+            "https://rfam.xfam.org/family/ABC/alignment/stockholm");
+  }
+}
index 573022d..51cff6e 100644 (file)
@@ -58,7 +58,7 @@ public class XfamFetcherTest
   @Test(groups = { "External" })
   public void testPfamFullAndSeed() throws Exception
   {
-    PfamFull pff = new PfamFull();
+    Pfam pff = new PfamFull();
     PfamSeed pfseed = new PfamSeed();
 
     AlignmentI fullpf = pff.getSequenceRecords(pff.getTestQuery());