baf9c6381054ef769229afebc7971d58a7dfc8df
[jalview.git] / test / jalview / urls / AppletUrlProviderFactoryTest.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.UrlConstants;
24
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.testng.Assert;
30 import org.testng.annotations.Test;
31
32 public class AppletUrlProviderFactoryTest {
33
34   @Test(groups = { "Functional" })
35   public void testCreateUrlProvider()
36   {
37     final String defaultUrl = UrlConstants.DEFAULT_STRING.substring(
38             UrlConstants.DEFAULT_STRING.indexOf(UrlConstants.SEP) + 1,
39             UrlConstants.DEFAULT_STRING.length());
40     Map<String, String> urlList = new HashMap<String, String>()
41     {
42       {
43         put("Test1", "http://identifiers.org/uniprot/$DB_ACCESSION$");
44         put("Test2", defaultUrl);
45       }
46     };
47
48     UrlProviderFactoryI factory = new AppletUrlProviderFactory("Test2",
49             urlList);
50     UrlProviderI prov = factory.createUrlProvider();
51
52     // default url correctly set
53     Assert.assertEquals(prov.getDefaultUrlId(), "Test2");
54     Assert.assertEquals(prov.getDefaultUrl("FER_CAPAN"),
55             defaultUrl.replace("$SEQUENCE_ID$",
56                     "FER_CAPAN"));
57
58     List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
59
60     // 2 links in provider
61     Assert.assertEquals(allLinks.size(), 2);
62
63     // first link set correctly
64     Assert.assertEquals(allLinks.get(0).getId(), "Test1");
65     Assert.assertEquals(allLinks.get(0).getName(), "Test1");
66     Assert.assertEquals(allLinks.get(0).getUrl(),
67             "http://identifiers.org/uniprot/$DB_ACCESSION$");
68     Assert.assertFalse(allLinks.get(0).getIsDefault());
69     Assert.assertTrue(allLinks.get(0).getIsSelected());
70
71     // second link set correctly
72     Assert.assertEquals(allLinks.get(1).getId(), "Test2");
73     Assert.assertEquals(allLinks.get(1).getName(), "Test2");
74     Assert.assertEquals(allLinks.get(1).getUrl(), defaultUrl);
75     Assert.assertTrue(allLinks.get(1).getIsDefault());
76     Assert.assertTrue(allLinks.get(1).getIsSelected());
77   }
78 }