source: osm/applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/io/WikosmDownloadReaderTest.java@ 33631

Last change on this file since 33631 was 33631, checked in by nyuriks, 7 years ago

Fix broken Wikosm unit test

File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.wikipedia.io;
3
4import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5import org.junit.Rule;
6import org.junit.Test;
7import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
8import org.openstreetmap.josm.data.osm.PrimitiveId;
9import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
10import org.openstreetmap.josm.testutils.JOSMTestRules;
11
12import java.io.ByteArrayInputStream;
13import java.io.InputStream;
14import java.io.UnsupportedEncodingException;
15import java.nio.charset.StandardCharsets;
16import java.util.Arrays;
17import java.util.List;
18
19import static org.hamcrest.CoreMatchers.is;
20import static org.junit.Assert.assertThat;
21
22/**
23 * Unit tests of {@link WikosmDownloadReader} class.
24 */
25public class WikosmDownloadReaderTest {
26
27 /**
28 * Base test environment is enough
29 */
30 @Rule
31 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
32 public JOSMTestRules test = new JOSMTestRules().preferences();
33
34 /**
35 * Tests point generation
36 */
37 @Test
38 public void testPoint() throws UnsupportedEncodingException {
39 assertThat(WikosmDownloadReader.point(9.5, 47.16),
40 is("\"Point(9.5 47.16)\"^^geo:wktLiteral"));
41 assertThat(WikosmDownloadReader.boxParams(1.1, 2.2, 3.3, 4.4),
42 is("\nbd:serviceParam wikibase:cornerWest \"Point(1.1 2.2)\"^^geo:wktLiteral." +
43 "\nbd:serviceParam wikibase:cornerEast \"Point(3.3 4.4)\"^^geo:wktLiteral.\n"));
44 }
45
46 /**
47 * Tests server response parsing
48 */
49 @Test
50 public void testIdParsing() throws UnsupportedEncodingException {
51 String json = String.join("\n",
52 "{\"results\":{\"bindings\":[",
53 "{\"a\":{\"type\": \"uri\", \"value\": \"https://www.openstreetmap.org/node/12345\"}},",
54 "{\"a\":{\"type\": \"uri\", \"value\": \"https://www.openstreetmap.org/way/1234512345\"}},",
55 "{\"a\":{\"type\": \"uri\", \"value\": \"https://www.openstreetmap.org/relation/98765\"}}",
56 "]}}"
57 );
58
59 InputStream stream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8.name()));
60 List<PrimitiveId> actual = WikosmDownloadReader.getPrimitiveIds(stream);
61
62 List<PrimitiveId> expected = Arrays.asList(new PrimitiveId[]{
63 new SimplePrimitiveId(12345, OsmPrimitiveType.NODE),
64 new SimplePrimitiveId(1234512345, OsmPrimitiveType.WAY),
65 new SimplePrimitiveId(98765, OsmPrimitiveType.RELATION),
66 });
67
68 assertThat(actual, is(expected));
69 }
70}
Note: See TracBrowser for help on using the repository browser.