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