use of de.westnordost.osmapi.map.data.Element in project StreetComplete by westnordost.
the class TagFilterExpressionTest method createElement.
private Element createElement(Element.Type type) {
Element element = mock(Element.class);
when(element.getType()).thenReturn(type);
return element;
}
use of de.westnordost.osmapi.map.data.Element 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.osmapi.map.data.Element 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));
}
use of de.westnordost.osmapi.map.data.Element 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));
}
use of de.westnordost.osmapi.map.data.Element 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");
}
Aggregations