1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.Collections;
|
---|
8 | import java.util.HashSet;
|
---|
9 | import java.util.Map;
|
---|
10 | import java.util.Set;
|
---|
11 |
|
---|
12 | import org.junit.Rule;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.data.Preferences;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 | import org.openstreetmap.josm.tools.MultiMap;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | *
|
---|
22 | * Unit tests for class {@link ImageryInfo}.
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public class ImageryInfoTest {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Setup tests
|
---|
29 | */
|
---|
30 | @Rule
|
---|
31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
32 | public JOSMTestRules test = new JOSMTestRules();
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Test if extended URL is returned properly
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | public void testGetExtendedUrl() {
|
---|
39 | ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
|
---|
40 | testImageryTMS.setDefaultMinZoom(16);
|
---|
41 | testImageryTMS.setDefaultMaxZoom(23);
|
---|
42 | assertEquals("tms[16,23]:http://localhost", testImageryTMS.getExtendedUrl());
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/13264">Bug #13264</a>.
|
---|
47 | */
|
---|
48 | @Test
|
---|
49 | public void testConstruct13264() {
|
---|
50 | final ImageryInfo info = new ImageryInfo("test imagery", "tms[16-23]:http://localhost");
|
---|
51 | assertEquals(ImageryInfo.ImageryType.TMS, info.getImageryType());
|
---|
52 | assertEquals(16, info.getMinZoom());
|
---|
53 | assertEquals(23, info.getMaxZoom());
|
---|
54 | assertEquals("http://localhost", info.getUrl());
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Tests the {@linkplain Preferences#serializeStruct(Object, Class) serialization} of {@link ImageryInfo.ImageryPreferenceEntry}
|
---|
59 | */
|
---|
60 | @Test
|
---|
61 | public void testSerializeStruct() {
|
---|
62 | final ImageryInfo.ImageryPreferenceEntry info = new ImageryInfo.ImageryPreferenceEntry();
|
---|
63 | info.noTileHeaders = new MultiMap<>();
|
---|
64 | info.noTileHeaders.put("ETag", "foo");
|
---|
65 | info.noTileHeaders.put("ETag", "bar");
|
---|
66 | final Map<String, String> map = Preferences.serializeStruct(info, ImageryInfo.ImageryPreferenceEntry.class);
|
---|
67 | assertEquals("{noTileHeaders={\"ETag\":[\"foo\",\"bar\"]}}", map.toString());
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Tests the {@linkplain Preferences#deserializeStruct(Map, Class)} deserialization} of {@link ImageryInfo.ImageryPreferenceEntry}
|
---|
72 | */
|
---|
73 | @Test
|
---|
74 | public void testDeserializeStruct() {
|
---|
75 | final ImageryInfo.ImageryPreferenceEntry info = Preferences.deserializeStruct(
|
---|
76 | Collections.singletonMap("noTileHeaders", "{\"ETag\":[\"foo\",\"bar\"]}"), ImageryInfo.ImageryPreferenceEntry.class);
|
---|
77 | MultiMap<String, String> expect = new MultiMap<>();
|
---|
78 | expect.put("ETag", "foo");
|
---|
79 | expect.put("ETag", "bar");
|
---|
80 | assertEquals(info.noTileHeaders, expect);
|
---|
81 | final Set<String> eTag = info.noTileHeaders.get("ETag");
|
---|
82 | assertEquals(eTag, new HashSet<>(Arrays.asList("foo", "bar")));
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Tests the {@linkplain Preferences#deserializeStruct(Map, Class)} deserialization} of legacy {@link ImageryInfo.ImageryPreferenceEntry}
|
---|
87 | */
|
---|
88 | @Test
|
---|
89 | public void testDeserializeStructTicket12474() {
|
---|
90 | final ImageryInfo.ImageryPreferenceEntry info = Preferences.deserializeStruct(
|
---|
91 | Collections.singletonMap("noTileHeaders", "{\"ETag\":\"foo-and-bar\"}"), ImageryInfo.ImageryPreferenceEntry.class);
|
---|
92 | final Set<String> eTag = info.noTileHeaders.get("ETag");
|
---|
93 | assertEquals(eTag, Collections.singleton("foo-and-bar"));
|
---|
94 | }
|
---|
95 | }
|
---|