use of de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao in project StreetComplete by westnordost.
the class OsmQuestUnlockerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ElementGeometryDao elementGeometryDao = mock(ElementGeometryDao.class);
when(elementGeometryDao.get(Element.Type.NODE, 1)).thenReturn(new ElementGeometry(POS));
osmNoteQuestDao = mock(OsmNoteQuestDao.class);
when(osmNoteQuestDao.getAllPositions(any(BoundingBox.class))).thenReturn(Collections.emptyList());
osmQuestDao = mock(OsmQuestDao.class);
when(osmQuestDao.getAll(null, null, null, Element.Type.NODE, 1L)).thenReturn(Collections.emptyList());
questType = mock(OsmElementQuestType.class);
final List<QuestType> questTypes = Collections.singletonList(questType);
osmQuestUnlocker = new OsmQuestUnlocker(osmNoteQuestDao, osmQuestDao, elementGeometryDao, () -> questTypes);
}
use of de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao in project StreetComplete by westnordost.
the class OsmQuestChangesUploadTest method testDropChangeWhenElementDeleted.
public void testDropChangeWhenElementDeleted() {
OsmQuest quest = createAnsweredQuest(null);
OsmQuestDao questDb = mock(OsmQuestDao.class);
DownloadedTilesDao downloadedTilesDao = mock(DownloadedTilesDao.class);
OsmQuestChangesUpload u = new OsmQuestChangesUpload(null, questDb, null, null, null, null, null, downloadedTilesDao, null, null);
assertFalse(u.uploadQuestChange(-1, quest, null, false, false));
verify(downloadedTilesDao).remove(any(Point.class));
verify(questDb).delete(quest.getId());
}
use of de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao in project StreetComplete by westnordost.
the class OsmQuestChangesUploadTest method doTestHandleChangesetConflict.
private void doTestHandleChangesetConflict(ChangesetsDao changesetsDao, long userId, long firstChangesetId, long secondChangesetId) {
OsmQuest quest = createAnsweredQuestWithAppliableChange();
Element element = createElement();
MergedElementDao elementDb = mock(MergedElementDao.class);
OsmQuestDao questDb = mock(OsmQuestDao.class);
DownloadedTilesDao downloadedTilesDao = mock(DownloadedTilesDao.class);
OpenChangesetsDao manageChangesetsDb = mock(OpenChangesetsDao.class);
MapDataDao mapDataDao = createMapDataDaoThatReportsConflictOnUploadAndNodeDeleted();
when(mapDataDao.openChangeset(any(Map.class))).thenReturn(secondChangesetId);
SharedPreferences prefs = createPreferencesForUser(userId);
OsmQuestChangesUpload u = new OsmQuestChangesUpload(mapDataDao, questDb, elementDb, null, null, manageChangesetsDb, changesetsDao, downloadedTilesDao, prefs, null);
assertFalse(u.uploadQuestChange(firstChangesetId, quest, element, false, false));
verify(manageChangesetsDb).replace(new OpenChangesetKey("TestQuestType", "test case"), secondChangesetId);
verify(questDb).delete(quest.getId());
verify(elementDb).delete(Element.Type.NODE, A_NODE_ID);
verify(downloadedTilesDao).remove(any(Point.class));
}
use of de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao in project StreetComplete by westnordost.
the class OsmQuestChangesUploadTest method testCancel.
public void testCancel() throws InterruptedException {
OsmQuestDao questDb = mock(OsmQuestDao.class);
ElementGeometryDao elementGeometryDao = mock(ElementGeometryDao.class);
MergedElementDao elementDB = mock(MergedElementDao.class);
OpenChangesetsDao openChangesetsDb = mock(OpenChangesetsDao.class);
when(questDb.getAll(null, QuestStatus.ANSWERED)).thenAnswer(invocation -> {
// take your time...
Thread.sleep(1000);
ArrayList<OsmQuest> result = new ArrayList<>();
result.add(null);
return result;
});
final OsmQuestChangesUpload u = new OsmQuestChangesUpload(null, questDb, elementDB, elementGeometryDao, null, openChangesetsDb, null, null, null, null);
final AtomicBoolean cancel = new AtomicBoolean(false);
Thread t = new Thread(() -> u.upload(cancel));
t.start();
cancel.set(true);
// cancelling the thread works if we come out here without exceptions. If the upload
// would actually try to start anything, there would be a nullpointer exception since we
// feeded it only with nulls to work with
t.join();
// this is not called anymore immediately since quests are kept in DB for some time before deletion (#373)
// verify(elementGeometryDao).deleteUnreferenced();
// verify(elementDB).deleteUnreferenced();
}
use of de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao in project StreetComplete by westnordost.
the class OsmQuestChangesUploadTest method testHandleElementConflictAndThenDeleted.
/* Simulates an element conflict while uploading the element, when updating the element from
mock server, it turns out that it has been deleted */
public void testHandleElementConflictAndThenDeleted() {
final long changesetId = 123;
final long userId = 10;
OsmQuest quest = createAnsweredQuestWithAppliableChange();
Element element = createElement();
MergedElementDao elementDb = mock(MergedElementDao.class);
OsmQuestDao questDb = mock(OsmQuestDao.class);
DownloadedTilesDao downloadedTilesDao = mock(DownloadedTilesDao.class);
MapDataDao mapDataDao = createMapDataDaoThatReportsConflictOnUploadAndNodeDeleted();
// a changeset dao+prefs that report that the changeset is open and the changeset is owned by the user
ChangesetsDao changesetsDao = mock(ChangesetsDao.class);
when(changesetsDao.get(changesetId)).thenReturn(createOpenChangesetForUser(userId));
SharedPreferences prefs = mock(SharedPreferences.class);
when(prefs.getLong(Prefs.OSM_USER_ID, -1)).thenReturn(userId);
OsmQuestChangesUpload u = new OsmQuestChangesUpload(mapDataDao, questDb, elementDb, null, null, null, changesetsDao, downloadedTilesDao, prefs, null);
assertFalse(u.uploadQuestChange(changesetId, quest, element, false, false));
verify(questDb).delete(quest.getId());
verify(elementDb).delete(Element.Type.NODE, A_NODE_ID);
verify(downloadedTilesDao).remove(any(Point.class));
}
Aggregations