use of de.westnordost.osmapi.changesets.ChangesetsDao 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.changesets.ChangesetsDao in project StreetComplete by westnordost.
the class OsmQuestChangesUploadTest method testHandleChangesetConflictDifferentUser.
/* Simulates the changeset that is about to be used was created by a different user, so a new
* changeset needs to be created. (after that, it runs into the same case above, for simplicity
* sake*/
public void testHandleChangesetConflictDifferentUser() {
final long userId = 10;
final long otherUserId = 15;
final long firstChangesetId = 123;
final long secondChangesetId = 124;
// reports that the changeset is open but does belong to another user
ChangesetsDao changesetsDao = mock(ChangesetsDao.class);
when(changesetsDao.get(firstChangesetId)).thenReturn(createOpenChangesetForUser(otherUserId));
when(changesetsDao.get(secondChangesetId)).thenReturn(createOpenChangesetForUser(userId));
doTestHandleChangesetConflict(changesetsDao, userId, firstChangesetId, secondChangesetId);
}
use of de.westnordost.osmapi.changesets.ChangesetsDao in project StreetComplete by westnordost.
the class UserChangesetsDaoTest method testAmount.
public void testAmount() {
OsmConnection osm = new OsmConnection("https://master.apis.dev.openstreetmap.org/api/0.6/", "StreetComplete test case", null);
long userId = 12;
UserDao userDao = new UserDao(osm);
UserInfo info = userDao.get(userId);
UserChangesetsDao dao = new UserChangesetsDao(new ChangesetsDao(osm));
Counter counter = new Counter();
dao.findAll(counter, userId, new Date(0));
assertEquals(info.changesetsCount, counter.count);
}
use of de.westnordost.osmapi.changesets.ChangesetsDao in project StreetComplete by westnordost.
the class OsmQuestChangesUploadTest method testHandleChangesetConflictAlreadyClosed.
/* Simulates the changeset that is about to be used is already closed, so a new changeset needs
to be created. (after that, it runs into the same case above, for simplicity sake*/
public void testHandleChangesetConflictAlreadyClosed() {
final long userId = 10;
final long firstChangesetId = 123;
final long secondChangesetId = 124;
// reports that the changeset is open but does belong to another user
ChangesetsDao changesetsDao = mock(ChangesetsDao.class);
when(changesetsDao.get(firstChangesetId)).thenReturn(createClosedChangesetForUser(userId));
when(changesetsDao.get(secondChangesetId)).thenReturn(createOpenChangesetForUser(userId));
doTestHandleChangesetConflict(changesetsDao, userId, firstChangesetId, secondChangesetId);
}
Aggregations