Search in sources :

Example 1 with NoteManager

use of io.jawg.osmcontributor.ui.managers.NoteManager in project osm-contributor by jawg.

the class NoteManagerTest method testSaveAndQuery.

@Test
public void testSaveAndQuery() {
    NoteManager noteManager = component.getNoteManager();
    Note note = getNote(1);
    Note saved = noteManager.saveNote(note);
    Note queried = noteManager.queryForId(saved.getId());
    Comment queriedComment = ((ArrayList<Comment>) queried.getComments()).get(0);
    assertThat(queried.getLatitude()).isEqualTo(42.0);
    assertThat(queried.getLongitude()).isEqualTo(73.0);
    assertThat(queried.getUpdated()).isTrue();
    assertThat(queriedComment.getText()).isEqualTo("firstComment1");
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) ArrayList(java.util.ArrayList) NoteManager(io.jawg.osmcontributor.ui.managers.NoteManager) Test(org.junit.Test)

Example 2 with NoteManager

use of io.jawg.osmcontributor.ui.managers.NoteManager in project osm-contributor by jawg.

the class NoteManagerTest method testBulkSaveAndBulkUpdate.

@Test
public void testBulkSaveAndBulkUpdate() {
    NoteManager noteManager = component.getNoteManager();
    // try to save and then update 1000 notes.
    // 1000 because it can happen in real life and pose problems if we try to do an "IN" sql clause
    List<Note> notes = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        notes.add(getNote(i));
    }
    noteManager.saveNotes(notes);
    for (Note note : notes) {
        assertThat(note.getId()).isNotNull();
    }
    for (Note note : notes) {
        Comment newComment = new Comment();
        newComment.setText("secondComment");
        newComment.setAction(Comment.ACTION_OPEN);
        newComment.setNote(note);
        newComment.setUpdated(true);
        newComment.setCreatedDate(new DateTime());
        note.getComments().clear();
        note.getComments().add(newComment);
    }
    List<Note> savedNotes = noteManager.saveNotes(notes);
    for (Note note : savedNotes) {
        assertThat(note.getComments()).hasSize(1);
        Comment com = ((ArrayList<Comment>) note.getComments()).get(0);
        assertThat(com.getText()).isEqualTo("secondComment");
    }
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) ArrayList(java.util.ArrayList) NoteManager(io.jawg.osmcontributor.ui.managers.NoteManager) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Comment (io.jawg.osmcontributor.model.entities.Comment)2 Note (io.jawg.osmcontributor.model.entities.Note)2 NoteManager (io.jawg.osmcontributor.ui.managers.NoteManager)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DateTime (org.joda.time.DateTime)1