source: josm/trunk/test/unit/org/openstreetmap/josm/io/NoteReaderTest.java@ 14219

Last change on this file since 14219 was 10134, checked in by Don-vip, 8 years ago

sonar, javadoc

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.IOException;
7import java.util.List;
8
9import org.junit.Test;
10import org.openstreetmap.josm.data.coor.LatLon;
11import org.openstreetmap.josm.data.notes.Note;
12import org.openstreetmap.josm.data.notes.Note.State;
13import org.openstreetmap.josm.data.notes.NoteComment;
14import org.openstreetmap.josm.data.notes.NoteComment.Action;
15import org.openstreetmap.josm.data.osm.User;
16import org.openstreetmap.josm.tools.date.DateUtils;
17import org.xml.sax.SAXException;
18
19/**
20 * Unit tests of {@link NoteReader} class.
21 */
22public class NoteReaderTest {
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
30 public void testNoteReader() throws SAXException, IOException {
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>&lt;p&gt;test&lt;/p&gt;</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>&lt;p&gt;&lt;/p&gt;</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());
70 assertEquals(State.CLOSED, n.getState());
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());
77 assertEquals(Action.OPENED, c1.getNoteAction());
78 assertEquals("test", c1.getText());
79 assertEquals(User.createOsmUser(1626, "FredB"), c1.getUser());
80
81 NoteComment c2 = comments.get(1);
82 assertEquals(Action.CLOSED, c2.getNoteAction());
83 assertEquals("", c2.getText());
84 }
85
86 /**
87 * Non-regression test for bug #12393.
88 * @throws Exception if an error occurs
89 */
90 @Test
91 public void testTicket12393() throws Exception {
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}
Note: See TracBrowser for help on using the repository browser.