From 96b8ecca446eca75f8fddea49387436a25b536eb Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 12 Dec 2016 08:47:48 +0000 Subject: [PATCH] JAL-2316 Unit tests --- src/jalview/urls/UrlLinkDisplay.java | 6 +- test/jalview/urls/UrlLinkDisplayTest.java | 122 +++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 test/jalview/urls/UrlLinkDisplayTest.java diff --git a/src/jalview/urls/UrlLinkDisplay.java b/src/jalview/urls/UrlLinkDisplay.java index f8584e4..2582f90 100644 --- a/src/jalview/urls/UrlLinkDisplay.java +++ b/src/jalview/urls/UrlLinkDisplay.java @@ -111,7 +111,7 @@ public class UrlLinkDisplay public void setUrl(String rowUrl) { - link = new UrlLink(rowUrl); + link = new UrlLink(getName(), rowUrl); } public void setIsDefault(boolean rowDefault) @@ -178,8 +178,8 @@ public class UrlLinkDisplay { if (index == DEFAULT) { - // default link must be a $SEQUENCE_ID$ link - // so only allow editing if it is + // default link must not be a $DB_ACCESSION$ link + // so only allow editing if it is not return (!link.usesDBAccession()); } else if (index == SELECTED) diff --git a/test/jalview/urls/UrlLinkDisplayTest.java b/test/jalview/urls/UrlLinkDisplayTest.java new file mode 100644 index 0000000..5172304 --- /dev/null +++ b/test/jalview/urls/UrlLinkDisplayTest.java @@ -0,0 +1,122 @@ +package jalview.urls; + +import jalview.util.UrlLink; + +import java.util.List; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class UrlLinkDisplayTest { + + @Test(groups = { "Functional" }) + public void testDisplayColumnNames() + { + // 4 column names returned although 5 names internal to UrlLinkDisplay + List names = UrlLinkDisplay.getDisplayColumnNames(); + Assert.assertEquals(names.size(), 4); + } + + @Test(groups = { "Functional" }) + public void getValue() + { + UrlLink link = new UrlLink("Test Url", + "http://identifiers.org/$DB_ACCESSION$"); + UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); + + Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.DEFAULT)); + Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Url"); + Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED)); + Assert.assertEquals(u.getValue(UrlLinkDisplay.URL), + "http://identifiers.org/$DB_ACCESSION$"); + } + + @Test(groups = { "Functional" }) + public void testIsEditable() + { + // only default and selected columns are editable ever + // default only editable if link contains $SEQUENCE_ID$ + + UrlLink link = new UrlLink("Test Url", + "http://identifiers.org/$DB_ACCESSION$"); + UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); + + Assert.assertFalse(u.isEditable(UrlLinkDisplay.DEFAULT)); + Assert.assertTrue(u.isEditable(UrlLinkDisplay.SELECTED)); + Assert.assertFalse(u.isEditable(UrlLinkDisplay.ID)); + Assert.assertFalse(u.isEditable(UrlLinkDisplay.URL)); + Assert.assertFalse(u.isEditable(UrlLinkDisplay.NAME)); + + UrlLink vlink = new UrlLink("Test Sequence ID Url", + "http://myurl/$SEQUENCE_ID$"); + UrlLinkDisplay v = new UrlLinkDisplay("Test", vlink, false, false); + + Assert.assertTrue(v.isEditable(UrlLinkDisplay.DEFAULT)); + Assert.assertTrue(v.isEditable(UrlLinkDisplay.SELECTED)); + Assert.assertFalse(v.isEditable(UrlLinkDisplay.ID)); + Assert.assertFalse(v.isEditable(UrlLinkDisplay.URL)); + Assert.assertFalse(v.isEditable(UrlLinkDisplay.NAME)); + } + + @Test(groups = { "Functional" }) + public void testName() + { + UrlLink link = new UrlLink("Test Url", + "http://identifiers.org/$DB_ACCESSION$"); + UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); + + // Name initially as input in link + Assert.assertEquals(u.getName(), "Test Url"); + + // Setting updates name + u.setName("New Name"); + Assert.assertEquals(u.getName(), "New Name"); + } + + @Test(groups = { "Functional" }) + public void testUrl() + { + UrlLink link = new UrlLink("Test Url", + "http://identifiers.org/$DB_ACCESSION$"); + UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); + + // Url initially as input in link + Assert.assertEquals(u.getUrl(), "http://identifiers.org/$DB_ACCESSION$"); + + // Setting updates url + u.setUrl("http://something.new/$SEQUENCE_ID$"); + Assert.assertEquals(u.getUrl(), "http://something.new/$SEQUENCE_ID$"); + } + + @Test(groups = { "Functional" }) + public void testGetSetValue() + { + UrlLink link = new UrlLink("Test Url", + "http://identifiers.org/$DB_ACCESSION$"); + UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); + + Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.DEFAULT)); + Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED)); + Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Url"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.URL), + "http://identifiers.org/$DB_ACCESSION$"); + + u.setValue(UrlLinkDisplay.DEFAULT, true); + Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.DEFAULT)); + + u.setValue(UrlLinkDisplay.SELECTED, true); + Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.SELECTED)); + + u.setValue(UrlLinkDisplay.NAME, "New Name"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "New Name"); + + u.setValue(UrlLinkDisplay.ID, "New ID"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "New ID"); + + u.setValue(UrlLinkDisplay.URL, "http://something.new/$SEQUENCE_ID$"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.URL), + "http://something.new/$SEQUENCE_ID$"); + } +} -- 1.7.10.2