JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / urls / UrlLinkDisplayTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.urls;
22
23 import jalview.util.UrlLink;
24
25 import java.util.List;
26
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
29
30 public class UrlLinkDisplayTest
31 {
32
33   @Test(groups = { "Functional" })
34   public void testDisplayColumnNames()
35   {
36     // 5 column names returned although 6 names internal to UrlLinkDisplay
37     List<String> names = UrlLinkDisplay.getDisplayColumnNames();
38     Assert.assertEquals(names.size(), 5);
39   }
40
41   @Test(groups = { "Functional" })
42   public void getValue()
43   {
44     UrlLink link = new UrlLink("Test Name",
45             "http://identifiers.org/$DB_ACCESSION$", "TestDB");
46     UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
47
48     Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.PRIMARY));
49     Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test");
50     Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "TestDB");
51     Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Name");
52     Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED));
53     Assert.assertEquals(u.getValue(UrlLinkDisplay.URL),
54             "http://identifiers.org/$DB_ACCESSION$");
55   }
56
57   @Test(groups = { "Functional" })
58   public void testIsEditable()
59   {
60     // only default and selected columns are editable ever
61     // default only editable if link contains $SEQUENCE_ID$
62
63     UrlLink link = new UrlLink("Test Url",
64             "http://identifiers.org/$DB_ACCESSION$", "TestName");
65     UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
66
67     Assert.assertFalse(u.isEditable(UrlLinkDisplay.PRIMARY));
68     Assert.assertTrue(u.isEditable(UrlLinkDisplay.SELECTED));
69     Assert.assertFalse(u.isEditable(UrlLinkDisplay.ID));
70     Assert.assertFalse(u.isEditable(UrlLinkDisplay.URL));
71     Assert.assertFalse(u.isEditable(UrlLinkDisplay.NAME));
72     Assert.assertFalse(u.isEditable(UrlLinkDisplay.DATABASE));
73
74     UrlLink vlink = new UrlLink("Test Sequence ID Url",
75             "http://myurl/$SEQUENCE_ID$", "TestName");
76     UrlLinkDisplay v = new UrlLinkDisplay("Test", vlink, false, false);
77
78     Assert.assertTrue(v.isEditable(UrlLinkDisplay.PRIMARY));
79     Assert.assertTrue(v.isEditable(UrlLinkDisplay.SELECTED));
80     Assert.assertFalse(v.isEditable(UrlLinkDisplay.ID));
81     Assert.assertFalse(v.isEditable(UrlLinkDisplay.URL));
82     Assert.assertFalse(v.isEditable(UrlLinkDisplay.NAME));
83     Assert.assertFalse(v.isEditable(UrlLinkDisplay.DATABASE));
84   }
85
86   @Test(groups = { "Functional" })
87   public void testName()
88   {
89     UrlLink link = new UrlLink("Test Url",
90             "http://identifiers.org/$DB_ACCESSION$", "TestName");
91     UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
92
93     // Name initially as input in link
94     Assert.assertEquals(u.getDBName(), "TestName");
95
96     // Setting updates name
97     u.setDBName("NewName");
98     Assert.assertEquals(u.getDBName(), "NewName");
99   }
100
101   @Test(groups = { "Functional" })
102   public void testDescription()
103   {
104     UrlLink link = new UrlLink("Test Name",
105             "http://identifiers.org/$DB_ACCESSION$", "TestDB");
106     UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
107
108     // Desc initially as input in link
109     Assert.assertEquals(u.getDescription(), "Test Name");
110
111     // Setting updates name
112     u.setDescription("New Desc");
113     Assert.assertEquals(u.getDescription(), "New Desc");
114   }
115
116   @Test(groups = { "Functional" })
117   public void testUrl()
118   {
119     UrlLink link = new UrlLink("Test Name",
120             "http://identifiers.org/$DB_ACCESSION$", "TestDB");
121     UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
122
123     // Url initially as input in link
124     Assert.assertEquals(u.getUrl(),
125             "http://identifiers.org/$DB_ACCESSION$");
126
127     // Setting updates url
128     u.setUrl("http://something.new/$SEQUENCE_ID$");
129     Assert.assertEquals(u.getUrl(), "http://something.new/$SEQUENCE_ID$");
130   }
131
132   @Test(groups = { "Functional" })
133   public void testGetSetValue()
134   {
135     UrlLink link = new UrlLink("Test Name",
136             "http://identifiers.org/$DB_ACCESSION$", "TestDB");
137     UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
138
139     Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.PRIMARY));
140     Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED));
141     Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "TestDB");
142     Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Name");
143     Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test");
144     Assert.assertEquals(u.getValue(UrlLinkDisplay.URL),
145             "http://identifiers.org/$DB_ACCESSION$");
146
147     u.setValue(UrlLinkDisplay.PRIMARY, true);
148     Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.PRIMARY));
149
150     u.setValue(UrlLinkDisplay.SELECTED, true);
151     Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.SELECTED));
152
153     u.setValue(UrlLinkDisplay.NAME, "New Desc");
154     Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "New Desc");
155     Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "New Desc");
156
157     u.setValue(UrlLinkDisplay.DATABASE, "NewName");
158     Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "NewName");
159
160     u.setValue(UrlLinkDisplay.ID, "New ID");
161     Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "New ID");
162
163     u.setValue(UrlLinkDisplay.URL, "http://something.new/$SEQUENCE_ID$");
164     Assert.assertEquals(u.getValue(UrlLinkDisplay.URL),
165             "http://something.new/$SEQUENCE_ID$");
166   }
167 }