// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.io; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.List; import org.junit.Test; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.notes.Note; import org.openstreetmap.josm.data.notes.Note.State; import org.openstreetmap.josm.data.notes.NoteComment; import org.openstreetmap.josm.data.notes.NoteComment.Action; import org.openstreetmap.josm.data.osm.User; import org.openstreetmap.josm.tools.date.DateUtils; import org.xml.sax.SAXException; /** * Unit tests of {@link NoteReader} class. */ public class NoteReaderTest { /** * Test to read the first note of OSM database. * @throws SAXException if any SAX parsing error occurs * @throws IOException if any I/O error occurs */ @Test public void testNoteReader() throws SAXException, IOException { List list = new NoteReader( "\n"+ "\n"+ "\n"+ " 4\n"+ " http://api.openstreetmap.org/api/0.6/notes/4\n"+ " http://api.openstreetmap.org/api/0.6/notes/4/reopen\n"+ " 2013-04-24 08:07:02 UTC\n"+ " closed\n"+ " 2013-04-24 08:08:51 UTC\n"+ " \n"+ " \n"+ " 2013-04-24 08:07:02 UTC\n"+ " 1626\n"+ " FredB\n"+ " http://www.openstreetmap.org/user/FredB\n"+ " opened\n"+ " test\n"+ " <p>test</p>\n"+ " \n"+ " \n"+ " 2013-04-24 08:08:51 UTC\n"+ " 1626\n"+ " FredB\n"+ " http://www.openstreetmap.org/user/FredB\n"+ " closed\n"+ " \n"+ " <p></p>\n"+ " \n"+ " \n"+ "\n"+ "").parse(); assertEquals(1, list.size()); Note n = list.get(0); assertEquals(DateUtils.fromString("2013-04-24 08:08:51 UTC"), n.getClosedAt()); assertEquals(DateUtils.fromString("2013-04-24 08:07:02 UTC"), n.getCreatedAt()); assertEquals(4, n.getId()); assertEquals(new LatLon(36.7232991, 68.86415), n.getLatLon()); assertEquals(State.CLOSED, n.getState()); List comments = n.getComments(); assertEquals(2, comments.size()); NoteComment c1 = comments.get(0); assertEquals(c1, n.getFirstComment()); assertEquals(DateUtils.fromString("2013-04-24 08:07:02 UTC"), c1.getCommentTimestamp()); assertEquals(Action.OPENED, c1.getNoteAction()); assertEquals("test", c1.getText()); assertEquals(User.createOsmUser(1626, "FredB"), c1.getUser()); NoteComment c2 = comments.get(1); assertEquals(Action.CLOSED, c2.getNoteAction()); assertEquals("", c2.getText()); } /** * Non-regression test for bug #12393. * @throws Exception if an error occurs */ @Test public void testTicket12393() throws Exception { // CHECKSTYLE.OFF: LineLength new NoteReader( ""+ "Jump Start Espresso | 26930"+ ""+ ""+ "mapped, but inadvertently hid the note"+ "").parse(); // CHECKSTYLE.ON: LineLength } }