Search in sources :

Example 6 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class CreateNoteUploadTest method testCreateNoteWithAssociatedElementAndNoNoteYet.

public void testCreateNoteWithAssociatedElementAndNoNoteYet() {
    CreateNote createNote = createACreateNote();
    createNote.elementType = Element.Type.WAY;
    createNote.elementId = 5L;
    createNote.questTitle = "What?";
    when(mapDataDao.getWay(createNote.elementId)).thenReturn(mock(Way.class));
    Note note = createNote(createNote);
    when(notesDao.create(any(LatLon.class), anyString())).thenReturn(note);
    assertNotNull(createNoteUpload.uploadCreateNote(createNote));
    verify(notesDao).create(createNote.position, "Unable to answer \"What?\" for https://www.openstreetmap.org/way/5 via " + ApplicationConstants.USER_AGENT + ":\n\njo ho");
    verifyNoteInsertedIntoDb(createNote.id, note);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Note(de.westnordost.osmapi.notes.Note) Way(de.westnordost.osmapi.map.data.Way)

Example 7 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class CreateNoteUploadTest method testCreateNoteOnExistingClosedNoteWillCancel.

public void testCreateNoteOnExistingClosedNoteWillCancel() {
    CreateNote createNote = createACreateNote();
    createNote.elementType = Element.Type.WAY;
    createNote.elementId = 5L;
    Note note = createNote(createNote);
    note.status = Note.Status.CLOSED;
    setUpThereIsANoteFor(createNote, note);
    assertNull(createNoteUpload.uploadCreateNote(createNote));
    verify(notesDao).getAll(any(BoundingBox.class), any(Handler.class), anyInt(), anyInt());
    verifyNoMoreInteractions(notesDao);
    verifyNoteNotInsertedIntoDb(createNote.id);
}
Also used : Note(de.westnordost.osmapi.notes.Note) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Handler(de.westnordost.osmapi.common.Handler)

Example 8 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class OsmNoteQuestChangesUploadTest method testUploadComment.

public void testUploadComment() {
    OsmNoteQuest quest = createQuest();
    when(osmDao.comment(anyLong(), anyString())).thenReturn(mock(Note.class));
    Note n = osmNoteQuestChangesUpload.uploadNoteChanges(quest);
    assertNotNull(n);
    assertEquals(n, quest.getNote());
    assertEquals(QuestStatus.CLOSED, quest.getStatus());
    verify(questDb).update(quest);
    verify(noteDb).put(n);
}
Also used : Note(de.westnordost.osmapi.notes.Note)

Example 9 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class OsmNotesDownloadTest method testDeleteObsoleteQuests.

public void testDeleteObsoleteQuests() {
    when(preferences.getBoolean(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS, false)).thenReturn(true);
    // in the quest database mock, there are quests for note 4 and note 5
    List<OsmNoteQuest> quests = new ArrayList<>();
    Note note1 = createANote();
    note1.id = 4L;
    quests.add(new OsmNoteQuest(12L, note1, QuestStatus.NEW, null, new Date(), new OsmNoteQuestType(), null));
    Note note2 = createANote();
    note2.id = 5L;
    quests.add(new OsmNoteQuest(13L, note2, QuestStatus.NEW, null, new Date(), new OsmNoteQuestType(), null));
    when(noteQuestDB.getAll(any(BoundingBox.class), any(QuestStatus.class))).thenReturn(quests);
    doAnswer(invocation -> {
        Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
        assertEquals(1, deletedQuests.size());
        assertEquals(13L, (long) deletedQuests.iterator().next());
        return 1;
    }).when(noteQuestDB).deleteAll(any(Collection.class));
    // note dao mock will only "find" the note #4
    List<Note> notes = new ArrayList<>();
    notes.add(note1);
    NotesDao noteServer = new TestListBasedNotesDao(notes);
    OsmNotesDownload dl = new OsmNotesDownload(noteServer, noteDB, noteQuestDB, createNoteDB, preferences, new OsmNoteQuestType());
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    dl.download(new BoundingBox(0, 0, 1, 1), null, 1000);
    verify(noteQuestDB).deleteAll(any(Collection.class));
    verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Also used : ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) Note(de.westnordost.osmapi.notes.Note) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) NotesDao(de.westnordost.osmapi.notes.NotesDao) Collection(java.util.Collection)

Example 10 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class NoteDao method createObjectFrom.

static Note createObjectFrom(Serializer serializer, Cursor cursor) {
    int colNoteId = cursor.getColumnIndexOrThrow(NoteTable.Columns.ID), colLat = cursor.getColumnIndexOrThrow(NoteTable.Columns.LATITUDE), colLon = cursor.getColumnIndexOrThrow(NoteTable.Columns.LONGITUDE), colStatus = cursor.getColumnIndexOrThrow(NoteTable.Columns.STATUS), colCreated = cursor.getColumnIndexOrThrow(NoteTable.Columns.CREATED), colClosed = cursor.getColumnIndexOrThrow(NoteTable.Columns.CLOSED), colComments = cursor.getColumnIndexOrThrow(NoteTable.Columns.COMMENTS);
    Note note = new Note();
    note.id = cursor.getLong(colNoteId);
    note.position = new OsmLatLon(cursor.getDouble(colLat), cursor.getDouble(colLon));
    note.dateCreated = new Date(cursor.getLong(colCreated));
    if (!cursor.isNull(colClosed)) {
        note.dateClosed = new Date(cursor.getLong(colClosed));
    }
    note.status = Note.Status.valueOf(cursor.getString(colStatus));
    note.comments = serializer.toObject(cursor.getBlob(colComments), ArrayList.class);
    return note;
}
Also used : Note(de.westnordost.osmapi.notes.Note) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Date(java.util.Date)

Aggregations

Note (de.westnordost.osmapi.notes.Note)32 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)10 Date (java.util.Date)8 LatLon (de.westnordost.osmapi.map.data.LatLon)5 ArrayList (java.util.ArrayList)5 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)4 NoteComment (de.westnordost.osmapi.notes.NoteComment)3 Way (de.westnordost.osmapi.map.data.Way)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 Handler (de.westnordost.osmapi.common.Handler)1 SingleElementHandler (de.westnordost.osmapi.common.SingleElementHandler)1 OsmConflictException (de.westnordost.osmapi.common.errors.OsmConflictException)1 NotesDao (de.westnordost.osmapi.notes.NotesDao)1 User (de.westnordost.osmapi.user.User)1 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)1 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)1