Replacing hardcoded configuration with configurable API and removing Mapbox assets (#90)

* Refactoring online file source so that tile server configuration is not hardcoded - part 1

* Added default templates

* Update from master

* Renaming MGLAccountManager to MGLSettings. Passing ResourceOptions and TileServerOptions to relevant classes and method in order to remove mapbox hardocded configuration

* Fixing build

* Addedm missing theme

* Unit tests fixes

* Fixing unit tests, adding factory methods for creating predefined configuration.

* Fixing mapbox unit tests

* Additional unit test fixes

* Making MapboxConfiguration default

* Making get/set resource options available in all classes that inherits from FileSource

* Making get/set resource options available in all classes that inherits from FileSource - part 2

* Fixes for Android

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Removing hardcoded configuration in iOS project - part 1

* Fixing wrong file extension, making use of tile server options.

* Use apiKey and MGL_API_KEY everywhere

* Just a rename

* Re-enabling tests and improving MGLSettings init

* Removing mapbox hardcoded configuration, using api key everywhere, implementing JNI conversion for TileServerOptions

* Lint issues.

* Integrating configurable tile server properties into Android SDK - part 2

* Removing mabox accounts

* Exposing multiple configurations to Android SDK - bug fixes

* Removing TileServerOptions from public interface - native methods dont work before mapbox-gl library is loaded

* Adding support for configurable predefined styles

* Migrating predefined styles in test app + cleanup

* Parameter fix

* Bug fixes

* Fixing render test build

* Fixing offline tester

* Fixing benchmark tool

* Fix: typo in method name

* Adding code for public access to TileServerOptions

* Bug fixes and debug code removal

* Fixes for macOS, adding unit tests from MapLibre, removing redundant members from OnlineFileSource

* Unit test fixes

* MacOS test app - migrating to configurable tile server options, part 1

* Fixing offline maps

* Migrating macOS test app to MapTiler

* Minor improvements

* Putting back apiKey test

* Added unit tests for MapTiler configuration

* Migrating test resources to MapTiler

* minor fix

* A few fixes

* Fixing macOS tests, removing feedback functionality

* Migrating ios test app to MapTiler

* Migrating ui tests

* UI tests fix

* Benchmarking app fix

* Cleanup and strings updates

* Migrating benchmark app to maptiler

* API key injection in benchmark app

* Putting back release configuration

* Additional tests and fixing issues identified by thread sanitizer.

* Removing test filters

* Fixes and addressing lint issues

* More Maptiler tests + minro fix

* Android instrumentation test migration to MapTiler. Exposing missing TileServerOptions in Android SDK. Minor fixes.

* No requirements on API key format.

* Fixing offline cache test tool

* Adding configurable domain name for sources, adding source domain int MapTiler configuration, cleanup

* Migrating tests to MapTiler, adding code for canonicalizing URLs, removing mapbox stuff from comments, cleanup

* More tests

* Updated database size

* Lint issues

* Fixed test

* Updating developer config API key

* Fixes for Android, propagaing updated tileServerOptions to native file sources, more tests

* Just a few more fixes

* Propagating updated settings to file sources + additional unit test

* Lint issues

* Removing test filter and fixing incorrect uri

* Release preparation

* macos release notes
This commit is contained in:
Petr Pokorny
2021-06-29 12:44:51 +02:00
committed by GitHub
parent 9a49fa16c9
commit d62ff400c6
398 changed files with 107907 additions and 184517 deletions

View File

@@ -190,7 +190,7 @@ class LocationComponentTest : EspressoTest() {
uiController: UiController,
context: Context
) {
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
component.activateLocationComponent(
LocationComponentActivationOptions
@@ -675,7 +675,7 @@ class LocationComponentTest : EspressoTest() {
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
component.isLocationComponentEnabled = false
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
component.isLocationComponentEnabled = true
TestingAsyncUtils.waitForLayer(uiController, mapView)
@@ -796,7 +796,7 @@ class LocationComponentTest : EspressoTest() {
component.onStop()
component.onStart()
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
TestingAsyncUtils.waitForLayer(uiController, mapView)
}
}
@@ -821,7 +821,7 @@ class LocationComponentTest : EspressoTest() {
.build()
)
component.isLocationComponentEnabled = true
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
component.onStop()
component.onStart()
TestingAsyncUtils.waitForLayer(uiController, mapView)
@@ -908,7 +908,7 @@ class LocationComponentTest : EspressoTest() {
)
component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
component.onStop()
TestingAsyncUtils.waitForLayer(uiController, mapView)
component.onStart()

View File

@@ -154,7 +154,7 @@ class LocationLayerControllerTest : EspressoTest() {
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
styleChangeIdlingResource.waitForStyle(mapboxMap, Style.LIGHT)
styleChangeIdlingResource.waitForStyle(mapboxMap, Style.getPredefinedStyle("Bright"))
TestingAsyncUtils.waitForLayer(uiController, mapView)
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
@@ -456,7 +456,7 @@ class LocationLayerControllerTest : EspressoTest() {
component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
styleChangeIdlingResource.waitForStyle(mapboxMap, Style.LIGHT)
styleChangeIdlingResource.waitForStyle(mapboxMap, Style.getPredefinedStyle("Bright"))
TestingAsyncUtils.waitForLayer(uiController, mapView)
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
@@ -503,7 +503,7 @@ class LocationLayerControllerTest : EspressoTest() {
`is`(true)
)
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
TestingAsyncUtils.waitForLayer(uiController, mapView)
assertThat(

View File

@@ -0,0 +1,96 @@
package com.mapbox.mapboxsdk.maps
import androidx.test.annotation.UiThreadTest
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.mapbox.mapboxsdk.AppCenter
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.WellKnownTileServer
import com.mapbox.mapboxsdk.storage.FileSource
import com.mapbox.mapboxsdk.testapp.MapboxApplication
import com.mapbox.mapboxsdk.util.TileServerOptions
import org.junit.*
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class BootstrapTest : AppCenter() {
var apiKeyBackup: String? = null
@Before
@UiThreadTest
fun before() {
apiKeyBackup = Mapbox.getApiKey()
}
@After
@UiThreadTest
fun after() {
val context = InstrumentationRegistry.getInstrumentation().context
Mapbox.getInstance(context, apiKeyBackup, MapboxApplication.TILE_SERVER)
}
@Test
@UiThreadTest
fun defaultBootstrap() {
val context = InstrumentationRegistry.getInstrumentation().context
Mapbox.getInstance(context)
val tileServerOptions = TileServerOptions.get(WellKnownTileServer.MapLibre)
Assert.assertTrue(
Style.getPredefinedStyles().count() == tileServerOptions.defaultStyles.count()
)
Assert.assertTrue(
Style.getPredefinedStyles().first().url == tileServerOptions.defaultStyles.first().url
)
val fileSource = FileSource.getInstance(context)
Assert.assertEquals(fileSource.apiBaseUrl, tileServerOptions.baseURL)
}
@Test
@UiThreadTest
fun maptilerBootstrap() {
val context = InstrumentationRegistry.getInstrumentation().context
val key = "abcdef"
Mapbox.getInstance(context, key, WellKnownTileServer.MapTiler)
val tileServerOptions = TileServerOptions.get(WellKnownTileServer.MapTiler)
Assert.assertTrue(
Style.getPredefinedStyles().count() == tileServerOptions.defaultStyles.count()
)
Assert.assertTrue(
Style.getPredefinedStyles().first().url == tileServerOptions.defaultStyles.first().url
)
val fileSource = FileSource.getInstance(context)
Assert.assertEquals(fileSource.apiBaseUrl, tileServerOptions.baseURL)
Assert.assertEquals(fileSource.apiKey, key)
}
@Test
@UiThreadTest
fun duplicateBootstrap() {
val context = InstrumentationRegistry.getInstrumentation().context
val key = "pk.abcdef"
Mapbox.getInstance(context, key, WellKnownTileServer.MapTiler)
Mapbox.getInstance(context)
Mapbox.getInstance(context, key, WellKnownTileServer.Mapbox)
val tileServerOptions = TileServerOptions.get(WellKnownTileServer.Mapbox)
Assert.assertTrue(
Style.getPredefinedStyles().count() == tileServerOptions.defaultStyles.count()
)
Assert.assertTrue(
Style.getPredefinedStyles().first().url == tileServerOptions.defaultStyles.first().url
)
val fileSource = FileSource.getInstance(context)
Assert.assertEquals(fileSource.apiBaseUrl, tileServerOptions.baseURL)
Assert.assertEquals(fileSource.apiKey, key)
}
}

View File

@@ -21,8 +21,8 @@ import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
public class MapboxTest extends AppCenter {
private static final String ACCESS_TOKEN = "pk.0000000001";
private static final String ACCESS_TOKEN_2 = "pk.0000000002";
private static final String API_KEY = "pk.0000000001";
private static final String API_KEY_2 = "pk.0000000002";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -31,7 +31,7 @@ public class MapboxTest extends AppCenter {
@Before
public void setup() {
realToken = Mapbox.getAccessToken();
realToken = Mapbox.getApiKey();
}
@Test
@@ -52,44 +52,26 @@ public class MapboxTest extends AppCenter {
@Test
@UiThreadTest
public void setAccessToken() {
Mapbox.setAccessToken(ACCESS_TOKEN);
assertSame(ACCESS_TOKEN, Mapbox.getAccessToken());
Mapbox.setAccessToken(ACCESS_TOKEN_2);
assertSame(ACCESS_TOKEN_2, Mapbox.getAccessToken());
public void setApiKey() {
Mapbox.setApiKey(API_KEY);
assertSame(API_KEY, Mapbox.getApiKey());
Mapbox.setApiKey(API_KEY_2);
assertSame(API_KEY_2, Mapbox.getApiKey());
}
@Test
@UiThreadTest
public void setInvalidAccessToken() {
final String invalidAccessToken = "xyz";
public void setNullApiKey() {
expectedException.expect(MapboxConfigurationException.class);
expectedException.expectMessage(
"A valid access token parameter is required when using a Mapbox service."
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens."
+ "Currently provided token is: " + invalidAccessToken
"A valid API key is required, currently provided key is: " + null
);
Mapbox.setAccessToken(invalidAccessToken);
}
@Test
@UiThreadTest
public void setNullAccessToken() {
expectedException.expect(MapboxConfigurationException.class);
expectedException.expectMessage(
"A valid access token parameter is required when using a Mapbox service."
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens."
+ "Currently provided token is: " + null
);
Mapbox.setAccessToken(null);
Mapbox.setApiKey(null);
}
@After
public void tearDown() {
Mapbox.setAccessToken(realToken);
Mapbox.setApiKey(realToken);
}
}

View File

@@ -6,12 +6,15 @@ import androidx.test.annotation.UiThreadTest
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.mapbox.mapboxsdk.AppCenter
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.WellKnownTileServer
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.geometry.LatLngBounds
import com.mapbox.mapboxsdk.geometry.ProjectedMeters
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
import com.mapbox.mapboxsdk.testapp.MapboxApplication
import com.mapbox.mapboxsdk.testapp.utils.TestConstants
import junit.framework.Assert.*
import org.junit.After
@@ -41,6 +44,8 @@ class NativeMapViewTest : AppCenter() {
@UiThreadTest
fun before() {
val context = InstrumentationRegistry.getInstrumentation().context
val apiKey = Mapbox.getApiKey()
Mapbox.getInstance(context, apiKey, WellKnownTileServer.MapTiler)
nativeMapView = NativeMapView(context, 2.0f, false, null, null, DummyRenderer(context))
nativeMapView.resizeView(WIDTH, HEIGHT)
}
@@ -48,13 +53,16 @@ class NativeMapViewTest : AppCenter() {
@After
@UiThreadTest
fun after() {
val context = InstrumentationRegistry.getInstrumentation().context
val apiKey = Mapbox.getApiKey()
Mapbox.getInstance(context, apiKey, MapboxApplication.TILE_SERVER)
nativeMapView.destroy()
}
@Test
@UiThreadTest
fun testSetStyleUrl() {
val expected = Style.DARK
val expected = Style.getPredefinedStyle("Pastel")
nativeMapView.styleUri = expected
val actual = nativeMapView.styleUri
assertEquals("Style URL should match", expected, actual)

View File

@@ -69,7 +69,7 @@ class OfflineDownloadTest : OfflineRegion.OfflineRegionObserver {
private fun createTestRegionDefinition(): OfflineRegionDefinition {
return OfflineGeometryRegionDefinition(
Style.MAPBOX_STREETS,
Style.getPredefinedStyle("Streets"),
Point.fromLngLat(50.847857, 4.360137),
17.0,
17.0,

View File

@@ -38,7 +38,7 @@ class MapSnapshotterTest {
val options = MapSnapshotter.Options(512, 512)
.withPixelRatio(1.0f)
.withStyleBuilder(
Style.Builder().fromUri(Style.SATELLITE_STREETS)
Style.Builder().fromUri(Style.getPredefinedStyle("Satellite Hybrid"))
.withLayerAbove(bg, "country-label")
)
.withCameraPosition(

View File

@@ -70,9 +70,9 @@ class ImageMissingTest : AppCenter() {
"""
{
"version": 8,
"name": "Mapbox Streets",
"sprite": "mapbox://sprites/mapbox/streets-v8",
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
"name": "Streets",
"sprite": "maptiler://sprites/streets/sprite",
"glyphs": "maptiler://fonts/{fontstack}/{range}.pbf",
"sources": {
"point": {
"type": "geojson",
@@ -114,9 +114,9 @@ class ImageMissingTest : AppCenter() {
"""
{
"version": 8,
"name": "Mapbox Streets",
"sprite": "asset://sprites/mapbox/invalid",
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
"name": "Streets",
"sprite": "maptiler://sprites/streets/sprite",
"glyphs": "maptiler://fonts/{fontstack}/{range}.pbf",
"sources": {
"point": {
"type": "geojson",

View File

@@ -23,7 +23,7 @@ class StyleLoadTest : EspressoTest() {
val layer = SymbolLayer("id", "id")
mapboxMap.setStyle(Style.Builder().withSource(source).withLayer(layer))
TestingAsyncUtils.waitForLayer(uiController, mapView)
mapboxMap.setStyle(Style.Builder().fromUrl(Style.MAPBOX_STREETS))
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Streets")))
TestingAsyncUtils.waitForLayer(uiController, mapView)
source.setGeoJson("{}")
}

View File

@@ -184,11 +184,11 @@ public class RuntimeStyleTests extends EspressoTest {
public void testAddRemoveSource() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
mapboxMap.getStyle().addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
mapboxMap.getStyle().addSource(new VectorSource("my-source", "maptiler://sources/hillshades"));
mapboxMap.getStyle().removeSource("my-source");
// Add initial source
mapboxMap.getStyle().addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
mapboxMap.getStyle().addSource(new VectorSource("my-source", "maptiler://sources/hillshades"));
// Remove
boolean removeOk = mapboxMap.getStyle().removeSource("my-source");
@@ -196,7 +196,7 @@ public class RuntimeStyleTests extends EspressoTest {
assertNull(mapboxMap.getStyle().getLayer("my-source"));
// Add
Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
Source source = new VectorSource("my-source", "maptiler://sources/hillshades");
mapboxMap.getStyle().addSource(source);
// Remove, preserving the reference
@@ -210,7 +210,7 @@ public class RuntimeStyleTests extends EspressoTest {
// Test adding a duplicate source
try {
Source source2 = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
Source source2 = new VectorSource("my-source", "maptiler://sources/hillshades");
mapboxMap.getStyle().addSource(source2);
fail("Should not have been allowed to add a source with a duplicate id");
} catch (CannotAddSourceException cannotAddSourceException) {
@@ -224,9 +224,9 @@ public class RuntimeStyleTests extends EspressoTest {
public void testVectorSourceUrlGetter() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
VectorSource source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
VectorSource source = new VectorSource("my-source", "maptiler://sources/hillshades");
mapboxMap.getStyle().addSource(source);
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUri());
assertEquals("maptiler://sources/hillshades", source.getUri());
});
}
@@ -234,9 +234,9 @@ public class RuntimeStyleTests extends EspressoTest {
public void testRasterSourceUrlGetter() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
RasterSource source = new RasterSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
RasterSource source = new RasterSource("my-source", "maptiler://sources/hillshades");
mapboxMap.getStyle().addSource(source);
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUri());
assertEquals("maptiler://sources/hillshades", source.getUri());
});
}
@@ -260,7 +260,7 @@ public class RuntimeStyleTests extends EspressoTest {
@Override
public void perform(UiController uiController, View view) {
mapboxMap.getStyle().addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
mapboxMap.getStyle().addSource(new VectorSource("my-source", "maptiler://sources/hillshades"));
mapboxMap.getStyle().addLayer(new LineLayer("my-layer", "my-source"));
mapboxMap.getStyle().removeSource("my-source");
assertNotNull(mapboxMap.getStyle().getSource("my-source"));