From a889a61789f15e79ecde7043cddfdea18ad00166 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 5 Dec 2016 10:02:46 +0000 Subject: [PATCH] JAL-2316 Adjusted unit tests. Tidied UrlLinkProviderI interface. --- src/jalview/appletgui/IdPanel.java | 51 ++----------------- src/jalview/gui/Desktop.java | 6 +-- src/jalview/gui/IdPanel.java | 4 +- src/jalview/gui/Preferences.java | 17 ++----- src/jalview/urls/CustomUrlProvider.java | 51 +++---------------- src/jalview/urls/IdentifiersUrlProvider.java | 34 +++++++------ src/jalview/urls/UrlLinkTableModel.java | 9 +--- src/jalview/urls/UrlProvider.java | 52 +++++++++----------- src/jalview/urls/UrlProviderI.java | 43 +++------------- src/jalview/urls/UrlProviderImpl.java | 25 +++++----- src/jalview/util/UrlConstants.java | 11 +++++ test/jalview/urls/CustomUrlProviderTest.java | 29 +++++------ test/jalview/urls/IdentifiersUrlProviderTest.java | 54 +++++---------------- 13 files changed, 119 insertions(+), 267 deletions(-) diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index d2947e4..feca846 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -209,7 +209,7 @@ public class IdPanel extends Panel implements MouseListener, return; } - // DEFAULT LINK IS FIRST IN THE LINK LIST + // get the sequence details int seq = alignPanel.seqPanel.findSeq(e); SequenceI sq = av.getAlignment().getSequenceAt(seq); if (sq == null) @@ -217,53 +217,10 @@ public class IdPanel extends Panel implements MouseListener, return; } String id = sq.getName(); + + // get the default url with the sequence details filled in String url = urlProvider.getDefaultUrl(id); String target = urlProvider.getDefaultTarget(id); - - /* String target = null; - String url = null; - int i = 0; - while (url == null && i < links.size()) - { - // DEFAULT LINK IS FIRST IN THE LINK LIST - // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED - url = links.elementAt(i++).toString(); - jalview.util.UrlLink urlLink = null; - try - { - urlLink = new UrlLink(url); - target = urlLink.getTarget(); - } catch (Exception foo) - { - System.err.println("Exception for URLLink '" + url + "'"); - foo.printStackTrace(); - url = null; - continue; - } - - if (urlLink.usesDBAccession()) - { - // this URL requires an accession id, not the name of a sequence - url = null; - continue; - } - - if (!urlLink.isValid()) - { - System.err.println(urlLink.getInvalidMessage()); - url = null; - continue; - } - - String urls[] = urlLink.makeUrls(id, true); - if (urls == null || urls[0] == null || urls[0].length() < 1) - { - url = null; - continue; - } - // just take first URL made from regex - url = urls[1]; - }*/ try { alignPanel.alignFrame.showURL(url, target); @@ -324,7 +281,7 @@ public class IdPanel extends Panel implements MouseListener, // build a new links menu based on the current links + any non-positional // features - Vector nlinks = urlProvider.getLinksForDisplay(); + Vector nlinks = urlProvider.getLinksForMenu(); SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures(); for (int sl = 0; sf != null && sl < sf.length; sl++) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 92e5019..e0abe93 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -34,10 +34,10 @@ import jalview.io.JalviewFileView; import jalview.jbgui.GSplitFrame; import jalview.jbgui.GStructureViewer; import jalview.structure.StructureSelectionManager; -import jalview.urls.UrlProviderI; import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.util.UrlConstants; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.ParamManager; @@ -2278,7 +2278,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // check what the actual links are - if it's just the default don't // bother with the warning Vector links = Preferences.sequenceUrlLinks - .getLinksForDisplay(); + .getLinksForMenu(); // only need to check links if there is one with a // SEQUENCE_ID which is not the default EMBL_EBI link @@ -2289,7 +2289,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { String link = li.next(); if (link.contains(SEQUENCE_ID) - && !link.equals(UrlProviderI.DEFAULT_STRING)) + && !link.equals(UrlConstants.DEFAULT_STRING)) { check = true; int barPos = link.indexOf("|"); diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 7170d04..fb9bcbb 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -328,9 +328,7 @@ public class IdPanel extends JPanel implements MouseListener, Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq2); // build a new links menu based on the current links + any non-positional // features - Vector nlinks = Preferences.sequenceUrlLinks - .getLinksForDisplay(); // new - // Vector(Preferences.sequenceURLLinks); + Vector nlinks = Preferences.sequenceUrlLinks.getLinksForMenu(); SequenceFeature sfs[] = sq == null ? null : sq.getSequenceFeatures(); if (sfs != null) { diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 7a24aeb..d129898 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -34,6 +34,7 @@ import jalview.urls.UrlProvider; import jalview.urls.UrlProviderI; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.util.UrlConstants; import jalview.ws.sifts.SiftsSettings; import java.awt.BorderLayout; @@ -127,16 +128,9 @@ public class Preferences extends GPreferences static { String string = Cache.getDefault("SEQUENCE_LINKS", - UrlProviderI.DEFAULT_STRING); - sequenceUrlLinks = new UrlProvider(UrlProviderI.DEFAULT_LABEL, string); - - List colNames = new ArrayList(); - // colNames.add("ID"); - // TODO KM add to properties file - colNames.add("URL"); - colNames.add("In Menu"); - colNames.add("Default"); - dataModel = new UrlLinkTableModel(sequenceUrlLinks, colNames, "ID"); + UrlConstants.DEFAULT_STRING); + sequenceUrlLinks = new UrlProvider(UrlConstants.DEFAULT_LABEL, string); + dataModel = new UrlLinkTableModel(sequenceUrlLinks); /** * TODO: reformulate groupURL encoding so two or more can be stored in the @@ -828,7 +822,6 @@ public class Preferences extends GPreferences @Override public void newLink_actionPerformed(ActionEvent e) { - GSequenceLink link = new GSequenceLink(); boolean valid = false; while (!valid) @@ -873,14 +866,12 @@ public class Preferences extends GPreferences boolean valid = false; while (!valid) { - if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link, MessageManager.getString("label.new_sequence_url_link"), JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION) { if (link.checkValid()) { - linkUrlTable.setValueAt(link.getName(), index, 0); linkUrlTable.setValueAt(link.getURL(), index, 1); valid = true; diff --git a/src/jalview/urls/CustomUrlProvider.java b/src/jalview/urls/CustomUrlProvider.java index fb0d676..a178ed6 100644 --- a/src/jalview/urls/CustomUrlProvider.java +++ b/src/jalview/urls/CustomUrlProvider.java @@ -27,6 +27,7 @@ import static jalview.util.UrlConstants.SEP; import static jalview.util.UrlConstants.SEQUENCE_ID; import jalview.util.MessageManager; +import jalview.util.UrlConstants; import jalview.util.UrlLink; import java.util.ArrayList; @@ -48,10 +49,6 @@ import java.util.Vector; */ public class CustomUrlProvider extends UrlProviderImpl { - - // minimum length of substitution in url link string - private static final int MIN_SUBST_LENGTH = 4; - // Default sequence URL link label for SRS private static final String SRS_LABEL = "SRS"; @@ -138,12 +135,12 @@ public class CustomUrlProvider extends UrlProviderImpl if (urls.containsKey(SRS_LABEL)) { urls.remove(SRS_LABEL); - urls.put(DEFAULT_LABEL, new UrlLink(DEFAULT_STRING)); + urls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(UrlConstants.DEFAULT_STRING)); } } @Override - public Vector getLinksForDisplay() + public Vector getLinksForMenu() { Vector links = new Vector(); Iterator> it = urls.entrySet().iterator(); @@ -243,40 +240,6 @@ public class CustomUrlProvider extends UrlProviderImpl } @Override - public void setUrlLinks(Vector names, Vector urlstrings) - { - HashMap newurls = new HashMap(); - - // should check that lists are same length but this function is likely - // to change once the Preferences dialog is rebuilt - - for (int i = 0; i < names.size(); ++i) - { - // don't allow MIRIAM ids as custom url names (as the links will overwrite - // each other) - // unlikely user would try to do this, but... - if (isMiriamId(names.elementAt(i))) - { - throw new IllegalArgumentException(MessageManager.formatMessage( - "exception.url_cannot_have_miriam_id", names.elementAt(i))); - } - // don't allow duplicate key names as entries will be overwritten - if (newurls.containsKey(names.elementAt(i))) - { - throw new IllegalArgumentException(MessageManager.formatMessage( - "exception.url_cannot_have_duplicate_id", - names.elementAt(i))); - } - newurls.put(names.elementAt(i), new UrlLink(names.elementAt(i) + SEP - + urlstrings.elementAt(i))); - } - - // don't update until we're sure this set is ok - urls = newurls; - - } - - @Override public void setUrlData(List links) { HashMap newurls = new HashMap(); @@ -320,12 +283,12 @@ public class CustomUrlProvider extends UrlProviderImpl { // unilaterally set the default id to the EMBL_EBI link - if (!urls.containsKey(DEFAULT_LABEL)) + if (!urls.containsKey(UrlConstants.DEFAULT_LABEL)) { - urls.put(DEFAULT_LABEL, new UrlLink(DEFAULT_STRING)); + urls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(UrlConstants.DEFAULT_STRING)); } - defaultUrl = DEFAULT_LABEL; - return DEFAULT_LABEL; + defaultUrl = UrlConstants.DEFAULT_LABEL; + return UrlConstants.DEFAULT_LABEL; } } diff --git a/src/jalview/urls/IdentifiersUrlProvider.java b/src/jalview/urls/IdentifiersUrlProvider.java index a74ad07..3501169 100644 --- a/src/jalview/urls/IdentifiersUrlProvider.java +++ b/src/jalview/urls/IdentifiersUrlProvider.java @@ -62,6 +62,12 @@ public class IdentifiersUrlProvider extends UrlProviderImpl // list of selected urls private ArrayList selectedUrls; + /* + * Location of file for identifiers.org download + */ + public static final String ID_ORG_FILE = System.getProperty("user.home") + + File.separatorChar + ".jalview_identifiers"; + public IdentifiersUrlProvider(String cachedUrlList, String idFileName) { try @@ -165,12 +171,6 @@ public class IdentifiersUrlProvider extends UrlProviderImpl } @Override - public String getDefaultUrl() - { - return defaultUrl; - } - - @Override public boolean setDefaultUrl(String id) { if (selectedUrls.contains(id)) @@ -203,7 +203,7 @@ public class IdentifiersUrlProvider extends UrlProviderImpl } @Override - public Vector getLinksForDisplay() + public Vector getLinksForMenu() { Vector links = new Vector(); for (String key : selectedUrls) @@ -267,7 +267,18 @@ public class IdentifiersUrlProvider extends UrlProviderImpl @Override public String getDefaultUrl(String seqid) { - return urls.get(defaultUrl).get("url") + "/" + seqid; + if (seqid.length() < MIN_SUBST_LENGTH) + { + return null; + } + else if (defaultUrl == null) + { + return null; + } + else + { + return urls.get(defaultUrl).get("url") + "/" + seqid; + } } @Override @@ -278,13 +289,6 @@ public class IdentifiersUrlProvider extends UrlProviderImpl } @Override - public void setUrlLinks(Vector names, Vector urls) - { - // ignores urls, only uses names (as ids) - checkSelectionMatchesUrls(names); - } - - @Override public String chooseDefaultUrl() { // TODO Auto-generated method stub diff --git a/src/jalview/urls/UrlLinkTableModel.java b/src/jalview/urls/UrlLinkTableModel.java index 103454b..b2c64f1 100644 --- a/src/jalview/urls/UrlLinkTableModel.java +++ b/src/jalview/urls/UrlLinkTableModel.java @@ -21,7 +21,6 @@ package jalview.urls; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -61,15 +60,11 @@ public class UrlLinkTableModel extends AbstractTableModel * @param keyColName * name of column corresponding to keys in baseData */ - public UrlLinkTableModel(UrlProviderI baseData, - List displayColNames, - String keyColName) + public UrlLinkTableModel(UrlProviderI baseData) { dataProvider = baseData; data = baseData.getLinksForTable(); - displayColumns = new ArrayList(); - displayColumns.add(keyColName); - displayColumns.addAll(displayColNames); + displayColumns = baseData.getDisplayColumnNames(); // find the default row defaultRow = 0; diff --git a/src/jalview/urls/UrlProvider.java b/src/jalview/urls/UrlProvider.java index 37e95e2..9e8d7bc 100644 --- a/src/jalview/urls/UrlProvider.java +++ b/src/jalview/urls/UrlProvider.java @@ -42,6 +42,9 @@ public class UrlProvider implements UrlProviderI // Specific reference to custom URL link provider private UrlProviderI customProvider; + // List of columns which this provider will supply + private List colNames = new ArrayList(); + /** * Construct URL provider from string of cached URLs, and set default URL * @@ -57,11 +60,13 @@ public class UrlProvider implements UrlProviderI providers = new ArrayList(); UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList, - ID_ORG_FILE); + IdentifiersUrlProvider.ID_ORG_FILE); customProvider = new CustomUrlProvider(cachedUrlList); providers.add(idProvider); providers.add(customProvider); + setUpColumns(); + // check that the defaultUrl still exists if (!setDefaultUrl(defaultUrlString)) { @@ -83,11 +88,13 @@ public class UrlProvider implements UrlProviderI providers = new ArrayList(); UrlProviderI idProvider = new IdentifiersUrlProvider(null, - ID_ORG_FILE); + IdentifiersUrlProvider.ID_ORG_FILE); customProvider = new CustomUrlProvider(urlList); providers.add(idProvider); providers.add(customProvider); + setUpColumns(); + // check that the defaultUrl still exists if (!setDefaultUrl(defaultUrlString)) { @@ -95,25 +102,13 @@ public class UrlProvider implements UrlProviderI } } - @Override - public String getDefaultUrl() + private void setUpColumns() { - String defaultUrl = null; - for (UrlProviderI p : providers) - { - defaultUrl = p.getDefaultUrl(); - if (defaultUrl != null) - { - return defaultUrl; - } - } - - // no provider has a default set, just choose one - if (defaultUrl == null) - { - defaultUrl = chooseDefaultUrl(); - } - return defaultUrl; + colNames.add("Name"); + colNames.add("URL"); + colNames.add("In Menu"); + colNames.add("Default"); + colNames.add("ID"); } @Override @@ -144,12 +139,12 @@ public class UrlProvider implements UrlProviderI } @Override - public Vector getLinksForDisplay() + public Vector getLinksForMenu() { Vector fullLinks = new Vector(); for (UrlProviderI p : providers) { - List links = p.getLinksForDisplay(); + List links = p.getLinksForMenu(); if (links != null) { // will obliterate links with same keys from different providers @@ -217,13 +212,6 @@ public class UrlProvider implements UrlProviderI } return target; } - - @Override - public void setUrlLinks(Vector names, Vector urls) - { - // only allow custom urls to be updated by user - customProvider.setUrlLinks(names, urls); - } @Override public String chooseDefaultUrl() @@ -237,4 +225,10 @@ public class UrlProvider implements UrlProviderI { return customProvider.isUserEntry(id); } + + @Override + public List getDisplayColumnNames() + { + return colNames.subList(0, 4); + } } diff --git a/src/jalview/urls/UrlProviderI.java b/src/jalview/urls/UrlProviderI.java index 3841a50..0a02ca0 100644 --- a/src/jalview/urls/UrlProviderI.java +++ b/src/jalview/urls/UrlProviderI.java @@ -20,7 +20,6 @@ */ package jalview.urls; -import java.io.File; import java.util.List; import java.util.Vector; @@ -33,28 +32,11 @@ import java.util.Vector; public interface UrlProviderI { - /* - * Default sequence URL link label for EMBL-EBI search - */ - public static final String DEFAULT_LABEL = "EMBL-EBI Search"; - - /* - * Default sequence URL link string for EMBL-EBI search - */ - public static final String DEFAULT_STRING = DEFAULT_LABEL - + "|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"; - - /* - * Location of file for identifiers.org download - */ - public static final String ID_ORG_FILE = System.getProperty("user.home") - + File.separatorChar + ".jalview_identifiers"; - /** * Get names and urls in as strings for display * */ - Vector getLinksForDisplay(); + Vector getLinksForMenu(); /** * Get names and urls as strings for display @@ -68,13 +50,6 @@ public interface UrlProviderI void setUrlData(List links); /** - * Get the id of the default URL - * - * @return id of the default URL - */ - String getDefaultUrl(); - - /** * Get the link for the default URL * * @seqid sequence id for which to build link @@ -107,15 +82,6 @@ public interface UrlProviderI String writeUrlsAsString(); /** - * Set URL links from pair of collections - * - * @param names - * @param urls - */ - void setUrlLinks(Vector names, Vector urls) - throws IllegalArgumentException; - - /** * Choose the default URL in the event of the selected default being * unavailable * @@ -127,4 +93,11 @@ public interface UrlProviderI * Determine if id is for a user-defined URL */ boolean isUserEntry(String id); + + /** + * Get list of column names to display in UI + * + * @return column names + */ + List getDisplayColumnNames(); } diff --git a/src/jalview/urls/UrlProviderImpl.java b/src/jalview/urls/UrlProviderImpl.java index 4511919..0fae392 100644 --- a/src/jalview/urls/UrlProviderImpl.java +++ b/src/jalview/urls/UrlProviderImpl.java @@ -35,22 +35,20 @@ public class UrlProviderImpl implements UrlProviderI { private static final Pattern MIRIAM_PATTERN = Pattern .compile("^MIR:\\d{8}$"); + + // minimum length of substitution in url link string + protected static final int MIN_SUBST_LENGTH = 4; + protected String defaultUrl; @Override - public Vector getLinksForDisplay() + public Vector getLinksForMenu() { // TODO Auto-generated method stub return null; } @Override - public String getDefaultUrl() - { - return defaultUrl; - } - - @Override public String getDefaultUrl(String seqid) { // TODO Auto-generated method stub @@ -79,13 +77,6 @@ public class UrlProviderImpl implements UrlProviderI } @Override - public void setUrlLinks(Vector names, Vector urls) - { - // TODO Auto-generated method stub - - } - - @Override public String chooseDefaultUrl() { // TODO Auto-generated method stub @@ -115,4 +106,10 @@ public class UrlProviderImpl implements UrlProviderI return !isMiriamId(id); } + @Override + public List getDisplayColumnNames() + { + return null; + } + } diff --git a/src/jalview/util/UrlConstants.java b/src/jalview/util/UrlConstants.java index 8b3f9b0..3347cc7 100644 --- a/src/jalview/util/UrlConstants.java +++ b/src/jalview/util/UrlConstants.java @@ -47,6 +47,17 @@ public class UrlConstants public static final String DELIM = "$"; /* + * Default sequence URL link label for EMBL-EBI search + */ + public static final String DEFAULT_LABEL = "EMBL-EBI Search"; + + /* + * Default sequence URL link string for EMBL-EBI search + */ + public static final String DEFAULT_STRING = DEFAULT_LABEL + + "|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"; + + /* * not instantiable */ private UrlConstants() diff --git a/test/jalview/urls/CustomUrlProviderTest.java b/test/jalview/urls/CustomUrlProviderTest.java index 62d7806..35ec5ff 100644 --- a/test/jalview/urls/CustomUrlProviderTest.java +++ b/test/jalview/urls/CustomUrlProviderTest.java @@ -24,6 +24,8 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; +import jalview.util.UrlConstants; + import java.util.Arrays; import java.util.HashMap; import java.util.Vector; @@ -52,7 +54,7 @@ public class CustomUrlProviderTest "TEST|http://someurl.blah/$DB_ACCESSION$", "ANOTHER|http://test/t$SEQUENCE_ID$", "TEST2|http://address/$SEQUENCE_ID$", - UrlProviderI.DEFAULT_STRING }; + UrlConstants.DEFAULT_STRING }; private static final Vector displayLinks = new Vector( Arrays.asList(dlinks)); @@ -82,8 +84,10 @@ public class CustomUrlProviderTest // default url can be set assertTrue(customProv.setDefaultUrl("ANOTHER")); - String result = customProv.getDefaultUrl(); - assertEquals("ANOTHER", result); + + // supplied replacement id must be more than 4 chars + String result = customProv.getDefaultUrl("123"); + assertEquals(null, result); // default url can be retrieved given a sequence id result = customProv.getDefaultUrl("seqid"); @@ -91,14 +95,14 @@ public class CustomUrlProviderTest // if there is no default url it sets the default to null assertFalse(customProv.setDefaultUrl("No default")); - result = customProv.getDefaultUrl(); + result = customProv.getDefaultUrl("testid"); assertEquals(null, result); // choosing the default picks the DEFAULT_STRING option customProv.chooseDefaultUrl(); result = customProv.getDefaultUrl("seqid"); assertEquals( - UrlProviderI.DEFAULT_STRING.split("\\|")[1].split("\\$")[0] + UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0] + "seqid", result); } @@ -111,28 +115,21 @@ public class CustomUrlProviderTest { // creation from cached url list works + old links upgraded UrlProviderI customProv = new CustomUrlProvider(cachedList); - assertTrue(displayLinks.containsAll(customProv.getLinksForDisplay())); + assertTrue(displayLinks.containsAll(customProv.getLinksForMenu())); // creation from map works + old links upgraded UrlProviderI customProv2 = new CustomUrlProvider(urlMap); - assertTrue(displayLinks.containsAll(customProv2.getLinksForDisplay())); + assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu())); // writing url links as a string works // because UrlProvider does not guarantee order of links, we can't just // compare the output of writeUrlsAsString to a string, hence the hoops here String result = customProv.writeUrlsAsString(); UrlProviderI up = new CustomUrlProvider(result); - assertTrue(displayLinks.containsAll(up.getLinksForDisplay())); + assertTrue(displayLinks.containsAll(up.getLinksForMenu())); result = customProv2.writeUrlsAsString(); UrlProviderI up2 = new CustomUrlProvider(result); - assertTrue(displayLinks.containsAll(up2.getLinksForDisplay())); - - // resetting urls from a pair of lists works - customProv.setUrlLinks(names, urls); - assertTrue(displayLinks2.containsAll(customProv.getLinksForDisplay())); - - customProv2.setUrlLinks(names, urls); - assertTrue(displayLinks2.containsAll(customProv2.getLinksForDisplay())); + assertTrue(displayLinks.containsAll(up2.getLinksForMenu())); } } diff --git a/test/jalview/urls/IdentifiersUrlProviderTest.java b/test/jalview/urls/IdentifiersUrlProviderTest.java index 843e2d5..8ea47c9 100644 --- a/test/jalview/urls/IdentifiersUrlProviderTest.java +++ b/test/jalview/urls/IdentifiersUrlProviderTest.java @@ -48,9 +48,9 @@ public class IdentifiersUrlProviderTest + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]"; private static final String[] dlinks = { - "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$", - "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$", - "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$"}; + "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$", + "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$", + "ENA|http://identifiers.org/ena.embl/$DB_ACCESSION$" }; private static final String[] dlinks1 = { "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$", @@ -117,13 +117,13 @@ public class IdentifiersUrlProviderTest String idList = "MIR:00000005|MIR:00000011|MIR:00000372"; UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile); - assertTrue(displayLinks.containsAll(idProv.getLinksForDisplay())); + assertTrue(displayLinks.containsAll(idProv.getLinksForMenu())); // because UrlProvider does not guarantee order of links, we can't just // compare the output of writeUrlsAsString to a string, hence the hoops here String result = idProv.writeUrlsAsString(); UrlProviderI up = new IdentifiersUrlProvider(result, testfile); - assertTrue(displayLinks.containsAll(up.getLinksForDisplay())); + assertTrue(displayLinks.containsAll(up.getLinksForMenu())); } @@ -138,51 +138,23 @@ public class IdentifiersUrlProviderTest UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile); // initially no default - assertEquals(null, idProv.getDefaultUrl()); + assertEquals(null, idProv.getDefaultUrl("seqid")); // set and then retrieve default assertTrue(idProv.setDefaultUrl("MIR:00000005")); - assertEquals("MIR:00000005", idProv.getDefaultUrl()); - assertEquals("http://identifiers.org/uniprot/id", - idProv.getDefaultUrl("id")); + assertEquals("http://identifiers.org/uniprot/seqid", + idProv.getDefaultUrl("seqid")); + + // ids less than length 4 return null + assertEquals(null, + idProv.getDefaultUrl("123")); // attempt to set bad default assertFalse(idProv.setDefaultUrl("MIR:00001234")); // default set to null (as default should have been set elsewhere) - assertEquals(null, idProv.getDefaultUrl()); + assertEquals(null, idProv.getDefaultUrl("seqid")); // chooseDefaultUrl not implemented for IdentifiersUrlProvider assertEquals(null, idProv.chooseDefaultUrl()); } - - /* - * Test url setting works - */ - @Test(groups = { "Functional" }) - public void testSetUrlLinks() - { - // creation from cached id list - String idList = "MIR:00000005|MIR:00000011|MIR:00000372"; - UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile); - - // set url links - String[] ids = { "MIR:00000372", "MIR:00000011" }; - Vector names = new Vector(Arrays.asList(ids)); - Vector urls = null; - idProv.setUrlLinks(names, urls); - Vector result = idProv.getLinksForDisplay(); - assertEquals(displayLinks1.size(), result.size()); - assertTrue(displayLinks1.containsAll(result)); - - //set default url then reset url links, default should be unset if not present - String[] moreids = { "MIR:00000005", "MIR:00000011" }; - names = new Vector(Arrays.asList(moreids)); - idProv.setDefaultUrl("MIR:00000372"); - idProv.setUrlLinks(names, urls); - result = idProv.getLinksForDisplay(); - assertEquals(displayLinks2.size(), result.size()); - assertTrue(displayLinks2.containsAll(result)); - assertEquals(null, idProv.getDefaultUrl()); - - } } -- 1.7.10.2