source: josm/trunk/test/unit/org/openstreetmap/josm/io/OsmChangesetParserTest.java @ 11020

Last change on this file since 11020 was 11020, checked in by Don-vip, 2 years ago

add more unit tests

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.ByteArrayInputStream;
8import java.nio.charset.StandardCharsets;
9import java.util.List;
10
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.data.osm.Changeset;
14import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19/**
20 * Unit tests of {@link OsmChangesetParser} class.
21 */
22public 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\">" +
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    @Rule
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    public 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        assertTrue(cs.getDiscussion().isEmpty());
78    }
79
80    /**
81     * Parse single changeset - with discussion
82     * @throws IllegalDataException in case of error
83     */
84    @Test
85    public void testParseWithDiscussion() throws IllegalDataException {
86        // http://api.openstreetmap.org/api/0.6/changeset/36749147?include_discussion=true
87        Changeset cs = parse(BEGIN + DISCUSSION + END).iterator().next();
88        assertEquals(2, cs.getCommentsCount());
89        assertEquals(2, cs.getDiscussion().size());
90    }
91}
Note: See TracBrowser for help on using the repository browser.