[android] - add binding integration for cache management API

This commit is contained in:
tobrun
2019-06-19 14:01:45 +02:00
committed by Tobrun
parent e611e57271
commit 21f7522967
16 changed files with 722 additions and 38 deletions

View File

@@ -0,0 +1,89 @@
package com.mapbox.mapboxsdk.testapp.offline
import android.content.Context
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.offline.OfflineManager
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class)
class CacheTest {
@Rule
@JvmField
var rule = ActivityTestRule(FeatureOverviewActivity::class.java)
private val context: Context by lazy { rule.activity }
private val countDownLatch = CountDownLatch(1)
@Test
fun testSetMaximumAmbientCacheSize() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).setMaximumAmbientCacheSize(10000000, object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
countDownLatch.await()
}
@Test
fun testSetClearAmbientCache() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).clearAmbientCache(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
countDownLatch.await()
}
@Test
fun testSetInvalidateAmbientCache() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).invalidateAmbientCache(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
countDownLatch.await()
}
@Test
fun testSetResetDatabase() {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).resetDatabase(object : OfflineManager.FileSourceCallback {
override fun onSuccess() {
countDownLatch.countDown()
}
override fun onError(message: String) {
Assert.assertNull("onError should not be called", message)
}
})
}
countDownLatch.await()
}
}

View File

@@ -35,7 +35,7 @@ class OfflineManagerTest : AppCenter() {
@Test(timeout = 30_000)
fun a_copyFileFromAssets() {
val latch = CountDownLatch(1)
rule.runOnUiThread {
rule.activity.runOnUiThread {
FileUtils.CopyFileFromAssetsTask(rule.activity, object : FileUtils.OnFileCopiedFromAssetsListener {
override fun onFileCopiedFromAssets() {
latch.countDown()
@@ -52,7 +52,7 @@ class OfflineManagerTest : AppCenter() {
@Test(timeout = 30_000)
fun b_mergeRegion() {
val latch = CountDownLatch(1)
rule.runOnUiThread {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).mergeOfflineRegions(
FileSource.getResourcesCachePath(rule.activity) + "/" + TEST_DB_FILE_NAME,
object : OfflineManager.MergeOfflineRegionsCallback {
@@ -72,7 +72,7 @@ class OfflineManagerTest : AppCenter() {
@Test(timeout = 30_000)
fun c_listRegion() {
val latch = CountDownLatch(1)
rule.runOnUiThread {
rule.activity.runOnUiThread {
OfflineManager.getInstance(context).listOfflineRegions(object : OfflineManager.ListOfflineRegionsCallback {
override fun onList(offlineRegions: Array<out OfflineRegion>?) {
assert(offlineRegions?.size == 1)
@@ -89,9 +89,26 @@ class OfflineManagerTest : AppCenter() {
}
@Test(timeout = 30_000)
fun d_deleteRegion() {
fun d_invalidateRegion() {
val latch = CountDownLatch(1)
rule.runOnUiThread {
rule.activity.runOnUiThread {
mergedRegion.invalidate(object : OfflineRegion.OfflineRegionInvalidateCallback {
override fun onInvalidate() {
latch.countDown()
}
override fun onError(error: String?) {
throw RuntimeException("Unable to delete region")
}
})
}
latch.await()
}
@Test(timeout = 30_000)
fun e_deleteRegion() {
val latch = CountDownLatch(1)
rule.activity.runOnUiThread {
mergedRegion.delete(object : OfflineRegion.OfflineRegionDeleteCallback {
override fun onDelete() {
latch.countDown()