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