diff --git a/app/src/main/java/de/westnordost/streetcomplete/StreetCompleteApplication.kt b/app/src/main/java/de/westnordost/streetcomplete/StreetCompleteApplication.kt index a695ffbb6c..8ba47fa701 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/StreetCompleteApplication.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/StreetCompleteApplication.kt @@ -44,7 +44,6 @@ import de.westnordost.streetcomplete.data.user.statistics.statisticsModule import de.westnordost.streetcomplete.data.user.userModule import de.westnordost.streetcomplete.data.visiblequests.questPresetsModule import de.westnordost.streetcomplete.overlays.overlaysModule -import de.westnordost.streetcomplete.quests.oneway_suspects.data.trafficFlowSegmentsModule import de.westnordost.streetcomplete.quests.questsModule import de.westnordost.streetcomplete.screens.about.aboutScreenModule import de.westnordost.streetcomplete.screens.main.mainModule @@ -128,7 +127,6 @@ class StreetCompleteApplication : Application() { questsModule, settingsModule, statisticsModule, - trafficFlowSegmentsModule, uploadModule, userModule, arModule, diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/DatabaseInitializer.kt b/app/src/main/java/de/westnordost/streetcomplete/data/DatabaseInitializer.kt index d3b85c43c1..1e9c9d7d7f 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/DatabaseInitializer.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/data/DatabaseInitializer.kt @@ -25,11 +25,10 @@ import de.westnordost.streetcomplete.data.user.statistics.EditTypeStatisticsTabl import de.westnordost.streetcomplete.data.visiblequests.QuestPresetsTable import de.westnordost.streetcomplete.data.visiblequests.QuestTypeOrderTable import de.westnordost.streetcomplete.data.visiblequests.VisibleQuestTypeTable -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowTable /** Creates the database and upgrades it */ object DatabaseInitializer { - const val DB_VERSION = 17 + const val DB_VERSION = 18 fun onCreate(db: Database) { // OSM notes @@ -96,9 +95,6 @@ object DatabaseInitializer { db.exec(UserLinksTable.CREATE) db.exec(ActiveDaysTable.CREATE) - // quest specific tables - db.exec(WayTrafficFlowTable.CREATE) - // logs db.exec(LogsTable.CREATE) db.exec(LogsTable.INDEX_CREATE) @@ -248,6 +244,9 @@ object DatabaseInitializer { if (oldVersion <= 16 && newVersion > 16) { db.renameQuest("AddProhibitedForMoped", "AddMopedAccess") } + if (oldVersion <= 17 && newVersion > 17) { + db.exec("DROP TABLE direction_of_flow;") + } } } diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt b/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt index 8921eac9ca..99ac6ae225 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt @@ -18,7 +18,6 @@ import de.westnordost.streetcomplete.data.quest.QuestTypeRegistry import de.westnordost.streetcomplete.quests.address.AddHousenumber import de.westnordost.streetcomplete.quests.cycleway.AddCycleway import de.westnordost.streetcomplete.quests.existence.CheckExistence -import de.westnordost.streetcomplete.quests.oneway_suspects.AddSuspectedOneway import de.westnordost.streetcomplete.quests.opening_hours.AddOpeningHours import de.westnordost.streetcomplete.quests.place_name.AddPlaceName import de.westnordost.streetcomplete.util.Listeners @@ -422,7 +421,6 @@ class OsmQuestController internal constructor( * all have to wait for that one thread. So, better enqueue the expensive work at the beginning. */ private val OsmElementQuestType<*>.chonkerIndex: Int get() = when (this) { is AddOpeningHours -> 0 // OpeningHoursParser, extensive filter - is AddSuspectedOneway -> 0 // Download, IO is CheckExistence -> 1 // FeatureDictionary, extensive filter is AddHousenumber -> 1 // complex filter is AddCycleway -> 2 // complex filter diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt index 0fe6701e7d..ec82803b88 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt @@ -106,9 +106,6 @@ import de.westnordost.streetcomplete.quests.moped.AddMopedAccess import de.westnordost.streetcomplete.quests.motorcycle_parking_capacity.AddMotorcycleParkingCapacity import de.westnordost.streetcomplete.quests.motorcycle_parking_cover.AddMotorcycleParkingCover import de.westnordost.streetcomplete.quests.oneway.AddOneway -import de.westnordost.streetcomplete.quests.oneway_suspects.AddSuspectedOneway -import de.westnordost.streetcomplete.quests.oneway_suspects.data.TrafficFlowSegmentsApi -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowDao import de.westnordost.streetcomplete.quests.opening_hours.AddOpeningHours import de.westnordost.streetcomplete.quests.opening_hours_signed.CheckOpeningHoursSigned import de.westnordost.streetcomplete.quests.orchard_produce.AddOrchardProduce @@ -187,12 +184,9 @@ import org.koin.dsl.module val questsModule = module { factory { RoadNameSuggestionsSource(get()) } - factory { WayTrafficFlowDao(get()) } single { questTypeRegistry( - get(), - get(), get(), { location -> val countryInfos = get() @@ -207,8 +201,6 @@ val questsModule = module { } fun questTypeRegistry( - trafficFlowSegmentsApi: TrafficFlowSegmentsApi, - trafficFlowDao: WayTrafficFlowDao, arSupportChecker: ArSupportChecker, getCountryInfoByLocation: (LatLon) -> CountryInfo, getFeature: (Element) -> Feature?, @@ -427,7 +419,6 @@ fun questTypeRegistry( 95 to AddMaxPhysicalHeight(arSupportChecker), // same as above, best if it appears right after (if enabled) 96 to AddRoadName(), 97 to AddOneway(), - 98 to AddSuspectedOneway(trafficFlowSegmentsApi, trafficFlowDao), 99 to AddEntrance(), 100 to AddEntranceReference(), diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/AddSuspectedOneway.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/AddSuspectedOneway.kt deleted file mode 100644 index 42f90a6e8f..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/AddSuspectedOneway.kt +++ /dev/null @@ -1,152 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects - -import de.westnordost.streetcomplete.R -import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression -import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry -import de.westnordost.streetcomplete.data.osm.geometry.ElementPolylinesGeometry -import de.westnordost.streetcomplete.data.osm.mapdata.Element -import de.westnordost.streetcomplete.data.osm.mapdata.LatLon -import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry -import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType -import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CAR -import de.westnordost.streetcomplete.osm.Tags -import de.westnordost.streetcomplete.quests.oneway_suspects.data.TrafficFlowSegment -import de.westnordost.streetcomplete.quests.oneway_suspects.data.TrafficFlowSegmentsApi -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowDao -import de.westnordost.streetcomplete.util.logs.Log -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.runBlocking -import kotlin.math.hypot - -class AddSuspectedOneway( - private val trafficFlowSegmentsApi: TrafficFlowSegmentsApi, - private val db: WayTrafficFlowDao -) : OsmElementQuestType { - - private val filter by lazy { """ - ways with - highway ~ trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|residential|living_street|pedestrian|track|road - and !oneway - and junction != roundabout - and area != yes - and ( - access !~ private|no - or (foot and foot !~ private|no) - ) - """.toElementFilterExpression() } - - override val changesetComment = - "Add whether roads are one-way roads as they were marked as likely oneway by improveosm.org" - override val wikiLink = "Key:oneway" - override val icon = R.drawable.ic_quest_oneway - override val hasMarkersAtEnds = true - override val achievements = listOf(CAR) - - override val hint = R.string.quest_arrow_tutorial - - override fun getTitle(tags: Map) = R.string.quest_oneway_title - - override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable { - val bbox = mapData.boundingBox ?: return emptyList() - - val trafficDirectionMap = try { - runBlocking(Dispatchers.IO) { trafficFlowSegmentsApi.get(bbox) } - } catch (e: Exception) { - Log.e("AddSuspectedOneway", "Unable to download traffic metadata", e) - return emptyList() - } - - val suspectedOnewayWayIds = trafficDirectionMap.keys - - val onewayCandidates = mapData.ways.filter { - // so, only the ways suspected by improveOSM to be oneways - it.id in suspectedOnewayWayIds - // but also filter the data as ImproveOSM data may be outdated or catching too much - && filter.matches(it) - /* also exclude rings because the driving direction can then not be determined reliably - from the improveosm data and the quest should stay simple, i.e not require the - user to input it in those cases. Additionally, whether a ring-road is a oneway or - not is less valuable information (for routing) and many times such a ring will - actually be a roundabout. Oneway information on roundabouts is superfluous. - See #1320 */ - && it.nodeIds.first() != it.nodeIds.last() - } - - // rehash traffic direction data into simple "way id -> forward/backward" data and persist - val onewayDirectionMap = onewayCandidates.associate { way -> - val segments = trafficDirectionMap[way.id] - val geometry = mapData.getWayGeometry(way.id) as? ElementPolylinesGeometry - val isForward = - if (segments != null && geometry != null) isForward(geometry.polylines.first(), segments) else null - - way.id to isForward - } - - for ((wayId, isForward) in onewayDirectionMap) { - if (isForward != null) db.put(wayId, isForward) - } - - /* only create quest if direction could be clearly determined (isForward != null) and is the - same direction for all segments belonging to one OSM way */ - return onewayCandidates.filter { onewayDirectionMap[it.id] != null } - } - - override fun isApplicableTo(element: Element): Boolean = - filter.matches(element) && db.isForward(element.id) != null - - /** returns true if all given [trafficFlowSegments] point forward in relation to the - * direction of the OSM [way] and false if they all point backward. - * - * If the segments point into different directions or their direction cannot be - * determined. returns null. - */ - private fun isForward(way: List, trafficFlowSegments: List): Boolean? { - var result: Boolean? = null - for (segment in trafficFlowSegments) { - val fromPositionIndex = findClosestPositionIndexOf(way, segment.fromPosition) - val toPositionIndex = findClosestPositionIndexOf(way, segment.toPosition) - - if (fromPositionIndex == -1 || toPositionIndex == -1) return null - if (fromPositionIndex == toPositionIndex) return null - - val forward = fromPositionIndex < toPositionIndex - if (result == null) { - result = forward - } else if (result != forward) { - return null - } - } - return result - } - - private fun findClosestPositionIndexOf(positions: List, latlon: LatLon): Int { - var shortestDistance = 1.0 - var result = -1 - for ((index, pos) in positions.withIndex()) { - val distance = hypot( - pos.longitude - latlon.longitude, - pos.latitude - latlon.latitude - ) - if (distance < 0.00005 && distance < shortestDistance) { - shortestDistance = distance - result = index - } - } - - return result - } - - override fun createForm() = AddSuspectedOnewayForm() - - override fun applyAnswerTo(answer: SuspectedOnewayAnswer, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { - if (!answer.isOneway) { - tags["oneway"] = "no" - } else { - tags["oneway"] = if (db.isForward(answer.wayId)!!) "yes" else "-1" - } - } - - override fun deleteMetadataOlderThan(timestamp: Long) { - db.deleteUnreferenced() - } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/AddSuspectedOnewayForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/AddSuspectedOnewayForm.kt deleted file mode 100644 index 0e893ca707..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/AddSuspectedOnewayForm.kt +++ /dev/null @@ -1,59 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects - -import android.os.Bundle -import android.view.View -import de.westnordost.streetcomplete.R -import de.westnordost.streetcomplete.data.osm.geometry.ElementPolylinesGeometry -import de.westnordost.streetcomplete.databinding.QuestSuspectedOnewayBinding -import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm -import de.westnordost.streetcomplete.quests.AnswerItem -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowDao -import de.westnordost.streetcomplete.util.ktx.viewLifecycleScope -import de.westnordost.streetcomplete.util.math.getOrientationAtCenterLineInDegrees -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.koin.android.ext.android.inject -import kotlin.math.PI - -class AddSuspectedOnewayForm : AbstractOsmQuestForm() { - - override val contentLayoutResId = R.layout.quest_suspected_oneway - private val binding by contentViewBinding(QuestSuspectedOnewayBinding::bind) - - private val db: WayTrafficFlowDao by inject() - - override val buttonPanelAnswers = listOf( - AnswerItem(R.string.quest_generic_hasFeature_no) { applyAnswer(false) }, - AnswerItem(R.string.quest_generic_hasFeature_yes) { applyAnswer(true) } - ) - - private var mapRotation: Float = 0f - private var wayRotation: Float = 0f - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - wayRotation = (geometry as ElementPolylinesGeometry).getOrientationAtCenterLineInDegrees() - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - viewLifecycleScope.launch { - val isForward = withContext(Dispatchers.IO) { db.isForward(element.id) == true } - binding.onewayIcon.setImageResource( - if (isForward) R.drawable.ic_oneway_yes else R.drawable.ic_oneway_yes_reverse - ) - binding.onewayIcon.rotation = wayRotation + mapRotation - } - } - - override fun onMapOrientation(rotation: Float, tilt: Float) { - mapRotation = (rotation * 180 / PI).toFloat() - binding.onewayIcon.rotation = wayRotation + mapRotation - } - - private fun applyAnswer(answer: Boolean) { - // the quest needs the way ID of the element to find out the direction of the oneway - applyAnswer(SuspectedOnewayAnswer(answer, element.id)) - } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/SuspectedOnewayAnswer.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/SuspectedOnewayAnswer.kt deleted file mode 100644 index 55cc4d6cca..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/SuspectedOnewayAnswer.kt +++ /dev/null @@ -1,3 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects - -data class SuspectedOnewayAnswer(val isOneway: Boolean, val wayId: Long) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegment.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegment.kt deleted file mode 100644 index 26a0768af6..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegment.kt +++ /dev/null @@ -1,11 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects.data - -import de.westnordost.streetcomplete.data.osm.mapdata.LatLon -import kotlinx.serialization.Serializable - -@Serializable -data class TrafficFlowSegment( - val wayId: Long, - val fromPosition: LatLon, - val toPosition: LatLon, -) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegmentsApi.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegmentsApi.kt deleted file mode 100644 index 2ab37ab63c..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegmentsApi.kt +++ /dev/null @@ -1,34 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects.data - -import de.westnordost.streetcomplete.data.osm.mapdata.BoundingBox -import de.westnordost.streetcomplete.util.ktx.format -import io.ktor.client.HttpClient -import io.ktor.client.call.body -import io.ktor.client.plugins.expectSuccess -import io.ktor.client.request.get -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.Json - -/** Dao for using this API: https://github.com/streetcomplete/oneway-data-api */ -class TrafficFlowSegmentsApi( - private val httpClient: HttpClient, - private val apiUrl: String -) { - - suspend fun get(bbox: BoundingBox): Map> { - val bboxString = listOf( - bbox.min.longitude, - bbox.min.latitude, - bbox.max.longitude, - bbox.max.latitude - ).joinToString(",") { it.format(7) } - - val response = httpClient.get("$apiUrl?bbox=$bboxString") { expectSuccess = true } - val json = Json { ignoreUnknownKeys = true } - val segmentsList = json.decodeFromString(response.body()) - return segmentsList.segments.groupBy { it.wayId } - } -} - -@Serializable -private data class TrafficFlowSegmentList(val segments: List) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegmentsModule.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegmentsModule.kt deleted file mode 100644 index c94536acdb..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/TrafficFlowSegmentsModule.kt +++ /dev/null @@ -1,8 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects.data - -import org.koin.dsl.module - -const val ONEWAY_API_URL = "https://www.westnordost.de/streetcomplete/oneway-data-api/" -val trafficFlowSegmentsModule = module { - factory { TrafficFlowSegmentsApi(get(), ONEWAY_API_URL) } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/WayTrafficFlowDao.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/WayTrafficFlowDao.kt deleted file mode 100644 index 85a6b95a44..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/WayTrafficFlowDao.kt +++ /dev/null @@ -1,32 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects.data - -import de.westnordost.streetcomplete.data.Database -import de.westnordost.streetcomplete.data.osm.mapdata.WayTables -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowTable.Columns.IS_FORWARD -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowTable.Columns.WAY_ID -import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowTable.NAME - -class WayTrafficFlowDao(private val db: Database) { - - fun put(wayId: Long, isForward: Boolean) { - db.replace(NAME, listOf( - WAY_ID to wayId, - IS_FORWARD to if (isForward) 1 else 0 - )) - } - - /** returns whether the direction of road user flow is forward or null if unknown */ - fun isForward(wayId: Long): Boolean? = - db.queryOne(NAME, - columns = arrayOf(IS_FORWARD), - where = "$WAY_ID = $wayId" - ) { it.getInt(IS_FORWARD) != 0 } - - fun delete(wayId: Long) { - db.delete(NAME, "$WAY_ID = $wayId") - } - - fun deleteUnreferenced() { - db.delete(NAME, "$WAY_ID NOT IN (SELECT ${WayTables.Columns.ID} AS $WAY_ID FROM ${WayTables.NAME});") - } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/WayTrafficFlowTable.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/WayTrafficFlowTable.kt deleted file mode 100644 index 6a41f96c23..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/oneway_suspects/data/WayTrafficFlowTable.kt +++ /dev/null @@ -1,17 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects.data - -object WayTrafficFlowTable { - const val NAME = "direction_of_flow" - - object Columns { - const val WAY_ID = "way_id" - const val IS_FORWARD = "is_forward" - } - - const val CREATE = """ - CREATE TABLE $NAME ( - ${Columns.WAY_ID} int PRIMARY KEY, - ${Columns.IS_FORWARD} int NOT NULL - ); - """ -} diff --git a/app/src/main/res/layout/quest_suspected_oneway.xml b/app/src/main/res/layout/quest_suspected_oneway.xml deleted file mode 100644 index 56a5632078..0000000000 --- a/app/src/main/res/layout/quest_suspected_oneway.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - diff --git a/app/src/main/res/raw/credits_projects.yml b/app/src/main/res/raw/credits_projects.yml index 84d9f6a237..35861376fd 100644 --- a/app/src/main/res/raw/credits_projects.yml +++ b/app/src/main/res/raw/credits_projects.yml @@ -1,5 +1,4 @@ - Jannik Vieten (exploide) created the photo upload service for StreetComplete -- ENT8R created an API to query oneway data from improveOSM - ENT8R created the map stylesheets for StreetComplete - Nils Rokita maintained the map tileserver used till v20, map-data.de - Ruben Kelevra maintains an unofficial Mastodon account for news and support diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1b76ca47be..a24b04d71c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1186,7 +1186,6 @@ If there are no signs along the whole street which apply for the highlighted sec "Hidden by %1$s, %2$s" "Anonymous" - "Is this a one-way street?" "Is this a one-way street? In which direction?" "Oneway in this direction" "Not a oneway" diff --git a/app/src/test/java/de/westnordost/streetcomplete/QuestsOverpassPrinter.kt b/app/src/test/java/de/westnordost/streetcomplete/QuestsOverpassPrinter.kt index 2b9613ca40..e09bd62283 100644 --- a/app/src/test/java/de/westnordost/streetcomplete/QuestsOverpassPrinter.kt +++ b/app/src/test/java/de/westnordost/streetcomplete/QuestsOverpassPrinter.kt @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.quests.questTypeRegistry import de.westnordost.streetcomplete.testutils.mock fun main() { - val registry = questTypeRegistry(mock(), mock(), mock(), mock(), mock()) + val registry = questTypeRegistry(mock(), mock(), mock()) for (questType in registry) { if (questType is OsmElementQuestType<*>) { diff --git a/app/src/test/java/de/westnordost/streetcomplete/quests/oneway_suspects/TrafficFlowSegmentsApiTest.kt b/app/src/test/java/de/westnordost/streetcomplete/quests/oneway_suspects/TrafficFlowSegmentsApiTest.kt deleted file mode 100644 index 980d647bc9..0000000000 --- a/app/src/test/java/de/westnordost/streetcomplete/quests/oneway_suspects/TrafficFlowSegmentsApiTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -package de.westnordost.streetcomplete.quests.oneway_suspects - -import de.westnordost.streetcomplete.data.osm.mapdata.BoundingBox -import de.westnordost.streetcomplete.data.osm.mapdata.LatLon -import de.westnordost.streetcomplete.quests.oneway_suspects.data.ONEWAY_API_URL -import de.westnordost.streetcomplete.quests.oneway_suspects.data.TrafficFlowSegment -import de.westnordost.streetcomplete.quests.oneway_suspects.data.TrafficFlowSegmentsApi -import io.ktor.client.HttpClient -import io.ktor.client.engine.mock.MockEngine -import io.ktor.client.engine.mock.respondBadRequest -import io.ktor.client.engine.mock.respondError -import io.ktor.client.engine.mock.respondOk -import io.ktor.client.plugins.ClientRequestException -import io.ktor.client.plugins.ServerResponseException -import io.ktor.http.HttpStatusCode -import kotlinx.coroutines.runBlocking -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith - -class TrafficFlowSegmentsApiTest { - private val boundingBox = BoundingBox( - -34.0, - 18.0, - -33.0, - 19.0 - ) - - @Test fun `get with empty response does not result in error`(): Unit = runBlocking { - val mockEngine = MockEngine { request -> respondOk("""{"segments": []}""") } - - assertEquals(mapOf(), TrafficFlowSegmentsApi(HttpClient(mockEngine), ONEWAY_API_URL).get(boundingBox)) - } - - @Test fun `get with two different ways`() = runBlocking { - val mockEngine = MockEngine { request -> respondOk(""" - {"segments":[ - {"wayId":1,"fromPosition":{"lon":1, "lat":2},"toPosition":{"lon":5, "lat":6}}, - {"wayId":2,"fromPosition":{"lon":3, "lat":4},"toPosition":{"lon":7, "lat":8}} - ]} - """) } - - assertEquals( - mapOf( - 1L to listOf(TrafficFlowSegment(1L, LatLon(2.0, 1.0), LatLon(6.0, 5.0))), - 2L to listOf(TrafficFlowSegment(2L, LatLon(4.0, 3.0), LatLon(8.0, 7.0))) - ), - TrafficFlowSegmentsApi(HttpClient(mockEngine), ONEWAY_API_URL).get(boundingBox) - ) - } - - @Test fun `get with two of same way`() = runBlocking { - val mockEngine = MockEngine { request -> respondOk(""" - {"segments":[ - {"wayId":1,"fromPosition":{"lon":1, "lat":2},"toPosition":{"lon":5, "lat":6}}, - {"wayId":1,"fromPosition":{"lon":3, "lat":4},"toPosition":{"lon":7, "lat":8}} - ]} - """) } - - assertEquals( - mapOf(1L to listOf( - TrafficFlowSegment(1L, LatLon(2.0, 1.0), LatLon(6.0, 5.0)), - TrafficFlowSegment(1L, LatLon(4.0, 3.0), LatLon(8.0, 7.0)) - )), - TrafficFlowSegmentsApi(HttpClient(mockEngine), ONEWAY_API_URL).get(boundingBox) - ) - } - - @Test fun `get throws an ClientRequestException on a 400 response`(): Unit = runBlocking { - val mockEngine = MockEngine { request -> respondBadRequest() } - assertFailsWith { TrafficFlowSegmentsApi(HttpClient(mockEngine), ONEWAY_API_URL).get(boundingBox) } - } - - @Test fun `get throws an ServerResponseException on a 500 response`(): Unit = runBlocking { - val mockEngine = MockEngine { request -> respondError(HttpStatusCode.InternalServerError) } - assertFailsWith { TrafficFlowSegmentsApi(HttpClient(mockEngine), ONEWAY_API_URL).get(boundingBox) } - } - - @Test fun `get makes request to correct URL`(): Unit = runBlocking { - val mockEngine = MockEngine { request -> respondOk("""{"segments": []}""") } - - TrafficFlowSegmentsApi(HttpClient(mockEngine), ONEWAY_API_URL).get(boundingBox) - - assertEquals( - ONEWAY_API_URL + "?bbox=18.0000000,-34.0000000,19.0000000,-33.0000000", - mockEngine.requestHistory[0].url.toString() - ) - } -}