1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.ByteArrayInputStream;
|
---|
7 | import java.io.InputStream;
|
---|
8 | import java.nio.charset.StandardCharsets;
|
---|
9 | import java.util.Collection;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.notes.Note;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.data.osm.NoteData;
|
---|
17 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
18 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
19 | import org.openstreetmap.josm.tools.Pair;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests of {@link OsmChangeReader}.
|
---|
25 | */
|
---|
26 | public class OsmChangeReaderTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup rule
|
---|
30 | */
|
---|
31 | @Rule
|
---|
32 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
33 | public JOSMTestRules test = new JOSMTestRules();
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Parse osmChange.
|
---|
37 | * @param osm OSM data in osmChange format, without header/footer
|
---|
38 | * @return data set
|
---|
39 | * @throws Exception if any error occurs
|
---|
40 | */
|
---|
41 | private static Pair<DataSet, NoteData> parse(String osm) throws Exception {
|
---|
42 | try (InputStream in = new ByteArrayInputStream((
|
---|
43 | "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n" +
|
---|
44 | "<osmChange generator=\"test\" version=\"0.6\">" + osm + "</osmChange>")
|
---|
45 | .getBytes(StandardCharsets.UTF_8))) {
|
---|
46 | return OsmChangeReader.parseDataSetAndNotes(in, NullProgressMonitor.INSTANCE);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Checks reading of OsmAnd notes.
|
---|
52 | * @throws Exception never
|
---|
53 | */
|
---|
54 | @Test
|
---|
55 | public void testNotes() throws Exception {
|
---|
56 | NoteData nd = parse(
|
---|
57 | "<create>\r\n" +
|
---|
58 | " <note lat=\"50.23887555404037\" lon=\"13.358299552342795\" id=\"-2\">\r\n" +
|
---|
59 | " <comment text=\"something\" />\r\n" +
|
---|
60 | " </note>\r\n" +
|
---|
61 | " </create>\r\n" +
|
---|
62 | " <modify />\r\n" +
|
---|
63 | " <delete />").b;
|
---|
64 | Collection<Note> notes = nd.getNotes();
|
---|
65 | assertEquals(1, notes.size());
|
---|
66 | Note n = notes.iterator().next();
|
---|
67 | assertEquals(new LatLon(50.23887555404037, 13.358299552342795), n.getLatLon());
|
---|
68 | assertEquals("something", n.getFirstComment().getText());
|
---|
69 | }
|
---|
70 | }
|
---|