Search in sources :

Example 1 with MergedElementDao

use of de.westnordost.streetcomplete.data.osm.persist.MergedElementDao 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 MergedElementDao

use of de.westnordost.streetcomplete.data.osm.persist.MergedElementDao 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)

Example 3 with MergedElementDao

use of de.westnordost.streetcomplete.data.osm.persist.MergedElementDao 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));
}
Also used : SharedPreferences(android.content.SharedPreferences) Element(de.westnordost.osmapi.map.data.Element) ChangesetsDao(de.westnordost.osmapi.changesets.ChangesetsDao) OpenChangesetsDao(de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao) 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) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Example 4 with MergedElementDao

use of de.westnordost.streetcomplete.data.osm.persist.MergedElementDao in project StreetComplete by westnordost.

the class OsmQuestChangesUploadTest method testDropChangeWhenUnresolvableElementChange.

public void testDropChangeWhenUnresolvableElementChange() {
    OsmQuest quest = createAnsweredQuestWithNonAppliableChange();
    Element element = createElement();
    OsmQuestDao questDb = mock(OsmQuestDao.class);
    MergedElementDao elementDao = mock(MergedElementDao.class);
    DownloadedTilesDao downloadedTilesDao = mock(DownloadedTilesDao.class);
    OsmQuestChangesUpload u = new OsmQuestChangesUpload(null, questDb, elementDao, null, null, null, null, downloadedTilesDao, null, null);
    assertFalse(u.uploadQuestChange(123, quest, element, false, false));
    verify(questDb).delete(quest.getId());
    verify(downloadedTilesDao).remove(any(Point.class));
}
Also used : Element(de.westnordost.osmapi.map.data.Element) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) Point(android.graphics.Point) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) DownloadedTilesDao(de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Example 5 with MergedElementDao

use of de.westnordost.streetcomplete.data.osm.persist.MergedElementDao in project StreetComplete by westnordost.

the class OsmQuestChangesUploadTest method testUploadNormally.

public void testUploadNormally() {
    OsmQuest quest = createAnsweredQuestWithAppliableChange();
    Element element = createElement();
    OsmQuestDao questDb = mock(OsmQuestDao.class);
    MapDataDao mapDataDao = mock(MapDataDao.class);
    QuestStatisticsDao statisticsDao = mock(QuestStatisticsDao.class);
    MergedElementDao elementDb = mock(MergedElementDao.class);
    OsmQuestUnlocker osmQuestUnlocker = mock(OsmQuestUnlocker.class);
    OsmQuestChangesUpload u = new OsmQuestChangesUpload(mapDataDao, questDb, elementDb, null, statisticsDao, null, null, null, null, osmQuestUnlocker);
    assertTrue(u.uploadQuestChange(1, quest, element, false, false));
    assertEquals(QuestStatus.CLOSED, quest.getStatus());
    verify(statisticsDao).addOne("TestQuestType");
}
Also used : OsmQuestUnlocker(de.westnordost.streetcomplete.data.osm.OsmQuestUnlocker) Element(de.westnordost.osmapi.map.data.Element) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) MapDataDao(de.westnordost.osmapi.map.MapDataDao) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatisticsDao(de.westnordost.streetcomplete.data.statistics.QuestStatisticsDao) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Aggregations

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