Search in sources :

Example 1 with ChangesetsDao

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));
}
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 2 with ChangesetsDao

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);
}
Also used : ChangesetsDao(de.westnordost.osmapi.changesets.ChangesetsDao) OpenChangesetsDao(de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)

Example 3 with ChangesetsDao

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);
}
Also used : UserDao(de.westnordost.osmapi.user.UserDao) OsmConnection(de.westnordost.osmapi.OsmConnection) ChangesetsDao(de.westnordost.osmapi.changesets.ChangesetsDao) UserInfo(de.westnordost.osmapi.user.UserInfo) Date(java.util.Date)

Example 4 with ChangesetsDao

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);
}
Also used : ChangesetsDao(de.westnordost.osmapi.changesets.ChangesetsDao) OpenChangesetsDao(de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)

Aggregations

ChangesetsDao (de.westnordost.osmapi.changesets.ChangesetsDao)4 OpenChangesetsDao (de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)3 SharedPreferences (android.content.SharedPreferences)1 Point (android.graphics.Point)1 OsmConnection (de.westnordost.osmapi.OsmConnection)1 MapDataDao (de.westnordost.osmapi.map.MapDataDao)1 Element (de.westnordost.osmapi.map.data.Element)1 UserDao (de.westnordost.osmapi.user.UserDao)1 UserInfo (de.westnordost.osmapi.user.UserInfo)1 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)1 MergedElementDao (de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)1 OsmQuestDao (de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao)1 DownloadedTilesDao (de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao)1 Date (java.util.Date)1