Search in sources :

Example 1 with OpenChangesetsDao

use of de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao 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));
}
Also used : OpenChangesetsDao(de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao) SharedPreferences(android.content.SharedPreferences) OpenChangesetKey(de.westnordost.streetcomplete.data.changesets.OpenChangesetKey) Element(de.westnordost.osmapi.map.data.Element) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) MapDataDao(de.westnordost.osmapi.map.MapDataDao) Point(android.graphics.Point) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) DownloadedTilesDao(de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao) HashMap(java.util.HashMap) Map(java.util.Map) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Example 2 with OpenChangesetsDao

use of de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao 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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OpenChangesetsDao(de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao) ArrayList(java.util.ArrayList) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) ElementGeometryDao(de.westnordost.streetcomplete.data.osm.persist.ElementGeometryDao) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Aggregations

OpenChangesetsDao (de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)2 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)2 MergedElementDao (de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)2 OsmQuestDao (de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao)2 SharedPreferences (android.content.SharedPreferences)1 Point (android.graphics.Point)1 MapDataDao (de.westnordost.osmapi.map.MapDataDao)1 Element (de.westnordost.osmapi.map.data.Element)1 OpenChangesetKey (de.westnordost.streetcomplete.data.changesets.OpenChangesetKey)1 ElementGeometryDao (de.westnordost.streetcomplete.data.osm.persist.ElementGeometryDao)1 DownloadedTilesDao (de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1