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);
}
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);
}
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);
}
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));
}
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;
}
Aggregations