1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.ByteArrayInputStream;
|
---|
8 | import java.nio.charset.StandardCharsets;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
14 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests of {@link OsmChangesetParser} class.
|
---|
21 | */
|
---|
22 | class OsmChangesetParserTest {
|
---|
23 |
|
---|
24 | private static final String BEGIN =
|
---|
25 | "<osm version=\"0.6\" generator=\"OpenStreetMap server\" copyright=\"OpenStreetMap and contributors\" " +
|
---|
26 | "attribution=\"http://www.openstreetmap.org/copyright\" license=\"http://opendatacommons.org/licenses/odbl/1-0/\">" +
|
---|
27 | "<changeset id=\"36749147\" user=\"kesler\" uid=\"13908\" created_at=\"2016-01-22T21:55:37Z\" "+
|
---|
28 | "closed_at=\"2016-01-22T21:56:39Z\" open=\"false\" min_lat=\"36.6649211\" min_lon=\"55.377015\" max_lat=\"38.1490357\" " +
|
---|
29 | "max_lon=\"60.3766983\" comments_count=\"2\" changes_count=\"9\">" +
|
---|
30 | "<tag k=\"created_by\" v=\"JOSM/1.5 (9329 en)\"/>" +
|
---|
31 | "<tag k=\"comment\" v=\"Fixing errors in North Khorasan\"/>";
|
---|
32 |
|
---|
33 | private static final String DISCUSSION =
|
---|
34 | "<discussion>" +
|
---|
35 | "<comment date=\"2016-09-13T13:28:20Z\" uid=\"1733149\" user=\"Jean Passepartout\">" +
|
---|
36 | "<text>" +
|
---|
37 | "Hi keeler, Thank you for contributing to OpenStreetMap. " +
|
---|
38 | "I noticed you added this way: http://www.openstreetmap.org/way/363580576, " +
|
---|
39 | "but it is a duplicate of another way, with a different name. "+
|
---|
40 | "Could you review and fix this? Please let me know if you need any help. " +
|
---|
41 | "Thank you and Happy Mapping! Jean Passepartout" +
|
---|
42 | "</text>" +
|
---|
43 | "</comment>" +
|
---|
44 | "<comment date=\"2016-09-17T21:58:57Z\" uid=\"13908\" user=\"kesler\">" +
|
---|
45 | "<text>" +
|
---|
46 | "Hi Jean, Thanks for your attempts to fix Iran map errors and please excuse me for delayed reply. "+
|
---|
47 | "I fixed my mistake and developed Esfarayen town map more in changeset https://www.openstreetmap.org/changeset/42234849. " +
|
---|
48 | "Please feel free and don't hesitate to tell me every big or even minor mis-mapped area in Iran. Thaks." +
|
---|
49 | "</text>" +
|
---|
50 | "</comment>" +
|
---|
51 | "</discussion>";
|
---|
52 |
|
---|
53 | private static final String END =
|
---|
54 | "</changeset>" +
|
---|
55 | "</osm>";
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Setup test.
|
---|
59 | */
|
---|
60 | @RegisterExtension
|
---|
61 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
62 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
63 |
|
---|
64 | private static List<Changeset> parse(String cs) throws IllegalDataException {
|
---|
65 | return OsmChangesetParser.parse(new ByteArrayInputStream(cs.getBytes(StandardCharsets.UTF_8)), NullProgressMonitor.INSTANCE);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Parse single changeset - without discussion
|
---|
70 | * @throws IllegalDataException in case of error
|
---|
71 | */
|
---|
72 | @Test
|
---|
73 | void testParseWithoutDiscussion() throws IllegalDataException {
|
---|
74 | // http://api.openstreetmap.org/api/0.6/changeset/36749147
|
---|
75 | Changeset cs = parse(BEGIN + END).iterator().next();
|
---|
76 | assertEquals(2, cs.getCommentsCount());
|
---|
77 | assertEquals(9, cs.getChangesCount());
|
---|
78 | assertTrue(cs.getDiscussion().isEmpty());
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Parse single changeset - with discussion
|
---|
83 | * @throws IllegalDataException in case of error
|
---|
84 | */
|
---|
85 | @Test
|
---|
86 | void testParseWithDiscussion() throws IllegalDataException {
|
---|
87 | // http://api.openstreetmap.org/api/0.6/changeset/36749147?include_discussion=true
|
---|
88 | Changeset cs = parse(BEGIN + DISCUSSION + END).iterator().next();
|
---|
89 | assertEquals(2, cs.getCommentsCount());
|
---|
90 | assertEquals(9, cs.getChangesCount());
|
---|
91 | assertEquals(2, cs.getDiscussion().size());
|
---|
92 | }
|
---|
93 | }
|
---|