source: josm/trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java@ 16836

Last change on this file since 16836 was 16836, checked in by simon04, 4 years ago

fix #18555 - Tag2Link: make search engine configurable

Advanced preference key tag2link.search

File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.util.ArrayList;
5import java.util.Arrays;
6import java.util.List;
7
8import org.junit.Assert;
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.testutils.JOSMTestRules;
12
13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14
15/**
16 * Test {@link Tag2Link}
17 */
18public class Tag2LinkTest {
19
20 List<String> links = new ArrayList<>();
21
22 void addLink(String name, String url) {
23 links.add(name + " // " + url);
24 }
25
26 void checkLinks(String... expected) {
27 Assert.assertEquals(Arrays.asList(expected), links);
28 }
29
30 /**
31 * Setup test.
32 */
33 @Rule
34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35 public JOSMTestRules test = new JOSMTestRules().preferences();
36
37 /**
38 * Unit test of function {@link Tag2Link#initialize()}.
39 */
40 @Test
41 public void testInitialize() {
42 Tag2Link.initialize();
43 Assert.assertTrue("obtains at least 40 rules", Tag2Link.wikidataRules.size() > 40);
44 }
45
46 /**
47 * Unit test of function {@link Tag2Link#getLinksForTag}.
48 */
49 @Test
50 public void testName() {
51 Tag2Link.getLinksForTag("name", "foobar", this::addLink);
52 checkLinks("Search on duckduckgo.com // https://duckduckgo.com/?q=foobar",
53 "Search on google.com // https://www.google.com/search?q=foobar");
54 }
55
56 /**
57 * Unit test of function {@link Tag2Link#getLinksForTag}.
58 */
59 @Test
60 public void testWebsite() {
61 Tag2Link.getLinksForTag("website", "http://www.openstreetmap.org/", this::addLink);
62 checkLinks("Open openstreetmap.org // http://www.openstreetmap.org/");
63 links.clear();
64 Tag2Link.getLinksForTag("website", "https://www.openstreetmap.org/", this::addLink);
65 checkLinks("Open openstreetmap.org // https://www.openstreetmap.org/");
66 links.clear();
67 Tag2Link.getLinksForTag("website", "www.openstreetmap.org", this::addLink);
68 checkLinks("Open openstreetmap.org // http://www.openstreetmap.org");
69 }
70
71 /**
72 * Unit test of function {@link Tag2Link#getLinksForTag}.
73 */
74 @Test
75 public void testWikipedia() {
76 Tag2Link.getLinksForTag("wikipedia", "de:Wohnhausgruppe Herderstraße", this::addLink);
77 checkLinks("View Wikipedia article // https://de.wikipedia.org/wiki/Wohnhausgruppe_Herderstraße");
78 links.clear();
79 Tag2Link.getLinksForTag("wikipedia", "de:Stadtbahn Köln#Innenstadttunnel", this::addLink);
80 checkLinks("View Wikipedia article // https://de.wikipedia.org/wiki/Stadtbahn_Köln#Innenstadttunnel");
81 }
82
83 /**
84 * Unit test of function {@link Tag2Link#getLinksForTag}.
85 */
86 @Test
87 public void testImageCommonsImage() {
88 Tag2Link.getLinksForTag("image", "File:Witten Brücke Gasstraße.jpg", this::addLink);
89 checkLinks("View image on Wikimedia Commons // https://commons.wikimedia.org/wiki/File:Witten Brücke Gasstraße.jpg");
90 }
91
92 /**
93 * Unit test of function {@link Tag2Link#getLinksForTag}.
94 */
95 @Test
96 public void testImageCommonsCategory() {
97 Tag2Link.getLinksForTag("image", "category:JOSM", this::addLink);
98 checkLinks("View category on Wikimedia Commons // https://commons.wikimedia.org/wiki/category:JOSM");
99 }
100
101 /**
102 * Unit test of function {@link Tag2Link#getLinksForTag}.
103 */
104 @Test
105 public void testBrandWikidata() {
106 Tag2Link.getLinksForTag("brand:wikidata", "Q259340", this::addLink);
107 checkLinks("View Wikidata item // https://www.wikidata.org/wiki/Q259340");
108 }
109
110 /**
111 * Unit test of function {@link Tag2Link#getLinksForTag}.
112 */
113 @Test
114 public void testArchipelagoWikidata() {
115 Tag2Link.getLinksForTag("archipelago:wikidata", "Q756987;Q756988", this::addLink);
116 checkLinks("View Wikidata item // https://www.wikidata.org/wiki/Q756987",
117 "View Wikidata item // https://www.wikidata.org/wiki/Q756988");
118 }
119
120}
Note: See TracBrowser for help on using the repository browser.