use of de.westnordost.osmapi.map.data.OsmNode in project StreetComplete by westnordost.
the class OsmQuestDownloadTest method testIgnoreBlacklistedPositionsAndInvalidGeometry.
public void testIgnoreBlacklistedPositionsAndInvalidGeometry() {
LatLon blacklistPos = new OsmLatLon(3.0, 4.0);
ElementWithGeometry blacklistElement = new ElementWithGeometry();
blacklistElement.element = new OsmNode(0, 0, blacklistPos, null);
blacklistElement.geometry = new ElementGeometry(blacklistPos);
ElementWithGeometry invalidGeometryElement = new ElementWithGeometry();
invalidGeometryElement.element = new OsmNode(0, 0, new OsmLatLon(1.0, 1.0), null);
invalidGeometryElement.geometry = null;
OsmElementQuestType questType = new ListBackedQuestType(Arrays.asList(blacklistElement, invalidGeometryElement));
setUpOsmQuestDaoMockWithNoPreviousElements();
OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
VisibleQuestListener listener = mock(VisibleQuestListener.class);
dl.setQuestListener(listener);
dl.download(questType, new BoundingBox(0, 0, 1, 1), Collections.singleton(blacklistPos));
verify(listener, times(0)).onQuestsCreated(any(Collection.class), any(QuestGroup.class));
}
use of de.westnordost.osmapi.map.data.OsmNode in project StreetComplete by westnordost.
the class OsmQuestDownloadTest method testDeleteObsoleteQuests.
public void testDeleteObsoleteQuests() {
LatLon pos = new OsmLatLon(3.0, 4.0);
ElementWithGeometry node4 = new ElementWithGeometry();
node4.element = new OsmNode(4, 0, pos, null);
node4.geometry = new ElementGeometry(pos);
// questType mock will only "find" the Node #4
OsmElementQuestType questType = new ListBackedQuestType(Collections.singletonList(node4));
// in the quest database mock, there are quests for node 4 and node 5
List<OsmQuest> quests = new ArrayList<>();
quests.add(new OsmQuest(12L, questType, Element.Type.NODE, 4, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
quests.add(new OsmQuest(13L, questType, Element.Type.NODE, 5, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
when(osmQuestDao.getAll(any(BoundingBox.class), any(QuestStatus.class), anyString(), any(Element.Type.class), anyLong())).thenReturn(quests);
doAnswer(invocation -> {
Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
assertEquals(1, deletedQuests.size());
assertEquals(13L, (long) deletedQuests.iterator().next());
return 1;
}).when(osmQuestDao).deleteAll(any(Collection.class));
OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
VisibleQuestListener listener = mock(VisibleQuestListener.class);
dl.setQuestListener(listener);
// -> we expect that quest with node #5 is removed
dl.download(questType, new BoundingBox(0, 0, 1, 1), null);
verify(osmQuestDao).deleteAll(any(Collection.class));
verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
use of de.westnordost.osmapi.map.data.OsmNode in project StreetComplete by westnordost.
the class NodeDao method createObjectFrom.
@Override
protected Node createObjectFrom(Cursor cursor) {
int colId = cursor.getColumnIndexOrThrow(NodeTable.Columns.ID), colLat = cursor.getColumnIndexOrThrow(NodeTable.Columns.LATITUDE), colLon = cursor.getColumnIndexOrThrow(NodeTable.Columns.LONGITUDE), colVersion = cursor.getColumnIndexOrThrow(NodeTable.Columns.VERSION), colTags = cursor.getColumnIndexOrThrow(NodeTable.Columns.TAGS);
long id = cursor.getLong(colId);
int version = cursor.getInt(colVersion);
LatLon latLon = new OsmLatLon(cursor.getDouble(colLat), cursor.getDouble(colLon));
Map<String, String> tags = null;
if (!cursor.isNull(colTags)) {
tags = serializer.toObject(cursor.getBlob(colTags), HashMap.class);
}
return new OsmNode(id, version, latLon, tags);
}
use of de.westnordost.osmapi.map.data.OsmNode in project StreetComplete by westnordost.
the class NodeDaoTest method testPutGetWithTags.
public void testPutGetWithTags() {
Map<String, String> tags = new HashMap<>();
tags.put("a key", "a value");
LatLon pos = new OsmLatLon(2, 2);
Node node = new OsmNode(5, 1, pos, tags);
dao.put(node);
Node dbNode = dao.get(5);
checkEqual(node, dbNode);
}
use of de.westnordost.osmapi.map.data.OsmNode in project StreetComplete by westnordost.
the class NodeDaoTest method testPutGetNoTags.
public void testPutGetNoTags() {
LatLon pos = new OsmLatLon(2, 2);
Node node = new OsmNode(5, 1, pos, null);
dao.put(node);
Node dbNode = dao.get(5);
checkEqual(node, dbNode);
}
Aggregations