[9666] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.io;
|
---|
| 3 |
|
---|
[17275] | 4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
[9666] | 5 |
|
---|
| 6 | import java.io.IOException;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
[17275] | 9 | import org.junit.jupiter.api.Test;
|
---|
[9666] | 10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
| 11 | import org.openstreetmap.josm.data.notes.Note;
|
---|
| 12 | import org.openstreetmap.josm.data.notes.Note.State;
|
---|
| 13 | import org.openstreetmap.josm.data.notes.NoteComment;
|
---|
| 14 | import org.openstreetmap.josm.data.notes.NoteComment.Action;
|
---|
| 15 | import org.openstreetmap.josm.data.osm.User;
|
---|
| 16 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
| 17 | import org.xml.sax.SAXException;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Unit tests of {@link NoteReader} class.
|
---|
| 21 | */
|
---|
[17275] | 22 | class NoteReaderTest {
|
---|
[9666] | 23 |
|
---|
| 24 | /**
|
---|
| 25 | * Test to read the first note of OSM database.
|
---|
| 26 | * @throws SAXException if any SAX parsing error occurs
|
---|
| 27 | * @throws IOException if any I/O error occurs
|
---|
| 28 | */
|
---|
| 29 | @Test
|
---|
[17275] | 30 | void testNoteReader() throws SAXException, IOException {
|
---|
[9666] | 31 | List<Note> list = new NoteReader(
|
---|
| 32 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
---|
| 33 | "<osm version=\"0.6\" generator=\"OpenStreetMap server\">\n"+
|
---|
| 34 | "<note lon=\"68.86415\" lat=\"36.7232991\">\n"+
|
---|
| 35 | " <id>4</id>\n"+
|
---|
| 36 | " <url>http://api.openstreetmap.org/api/0.6/notes/4</url>\n"+
|
---|
| 37 | " <reopen_url>http://api.openstreetmap.org/api/0.6/notes/4/reopen</reopen_url>\n"+
|
---|
| 38 | " <date_created>2013-04-24 08:07:02 UTC</date_created>\n"+
|
---|
| 39 | " <status>closed</status>\n"+
|
---|
| 40 | " <date_closed>2013-04-24 08:08:51 UTC</date_closed>\n"+
|
---|
| 41 | " <comments>\n"+
|
---|
| 42 | " <comment>\n"+
|
---|
| 43 | " <date>2013-04-24 08:07:02 UTC</date>\n"+
|
---|
| 44 | " <uid>1626</uid>\n"+
|
---|
| 45 | " <user>FredB</user>\n"+
|
---|
| 46 | " <user_url>http://www.openstreetmap.org/user/FredB</user_url>\n"+
|
---|
| 47 | " <action>opened</action>\n"+
|
---|
| 48 | " <text>test</text>\n"+
|
---|
| 49 | " <html><p>test</p></html>\n"+
|
---|
| 50 | " </comment>\n"+
|
---|
| 51 | " <comment>\n"+
|
---|
| 52 | " <date>2013-04-24 08:08:51 UTC</date>\n"+
|
---|
| 53 | " <uid>1626</uid>\n"+
|
---|
| 54 | " <user>FredB</user>\n"+
|
---|
| 55 | " <user_url>http://www.openstreetmap.org/user/FredB</user_url>\n"+
|
---|
| 56 | " <action>closed</action>\n"+
|
---|
| 57 | " <text></text>\n"+
|
---|
| 58 | " <html><p></p></html>\n"+
|
---|
| 59 | " </comment>\n"+
|
---|
| 60 | " </comments>\n"+
|
---|
| 61 | "</note>\n"+
|
---|
| 62 | "</osm>").parse();
|
---|
| 63 |
|
---|
| 64 | assertEquals(1, list.size());
|
---|
| 65 | Note n = list.get(0);
|
---|
| 66 | assertEquals(DateUtils.fromString("2013-04-24 08:08:51 UTC"), n.getClosedAt());
|
---|
| 67 | assertEquals(DateUtils.fromString("2013-04-24 08:07:02 UTC"), n.getCreatedAt());
|
---|
| 68 | assertEquals(4, n.getId());
|
---|
| 69 | assertEquals(new LatLon(36.7232991, 68.86415), n.getLatLon());
|
---|
[10134] | 70 | assertEquals(State.CLOSED, n.getState());
|
---|
[9666] | 71 | List<NoteComment> comments = n.getComments();
|
---|
| 72 | assertEquals(2, comments.size());
|
---|
| 73 |
|
---|
| 74 | NoteComment c1 = comments.get(0);
|
---|
| 75 | assertEquals(c1, n.getFirstComment());
|
---|
| 76 | assertEquals(DateUtils.fromString("2013-04-24 08:07:02 UTC"), c1.getCommentTimestamp());
|
---|
[10134] | 77 | assertEquals(Action.OPENED, c1.getNoteAction());
|
---|
[9666] | 78 | assertEquals("test", c1.getText());
|
---|
| 79 | assertEquals(User.createOsmUser(1626, "FredB"), c1.getUser());
|
---|
| 80 |
|
---|
| 81 | NoteComment c2 = comments.get(1);
|
---|
[10134] | 82 | assertEquals(Action.CLOSED, c2.getNoteAction());
|
---|
[9666] | 83 | assertEquals("", c2.getText());
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * Non-regression test for bug #12393.
|
---|
| 88 | * @throws Exception if an error occurs
|
---|
| 89 | */
|
---|
| 90 | @Test
|
---|
[17275] | 91 | void testTicket12393() throws Exception {
|
---|
[9666] | 92 | // CHECKSTYLE.OFF: LineLength
|
---|
| 93 | new NoteReader(
|
---|
| 94 | "<note id=\"233775\" lat=\"48.2411985\" lon=\"-122.3744820\" created_at=\"2014-08-31T17:13:29Z\" closed_at=\"2015-09-06T23:35:14Z\">"+
|
---|
| 95 | "<comment action=\"opened\" timestamp=\"2014-08-31T17:13:29Z\" uid=\"7247\" user=\"goldfndr\">Jump Start Espresso | 26930</comment>"+
|
---|
| 96 | "<comment action=\"hidden\" timestamp=\"2015-09-06T23:34:26Z\" uid=\"355617\" user=\"pnorman\"></comment>"+
|
---|
| 97 | "<comment action=\"reopened\" timestamp=\"2015-09-06T23:34:38Z\" uid=\"355617\" user=\"pnorman\"></comment>"+
|
---|
| 98 | "<comment action=\"closed\" timestamp=\"2015-09-06T23:35:14Z\" uid=\"355617\" user=\"pnorman\">mapped, but inadvertently hid the note</comment>"+
|
---|
| 99 | "</note>").parse();
|
---|
| 100 | // CHECKSTYLE.ON: LineLength
|
---|
| 101 | }
|
---|
| 102 | }
|
---|