summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkevin <kevin.li@mapbox.com>2019-04-18 17:40:04 +0800
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-04-18 16:00:12 +0200
commit8bbd38093ce8ec703c26fbeac4c7fb7c8d208934 (patch)
tree84e92f8d11f4a6489c313c9db58278521fe93fa0
parenta66cc608a964e2e309c23149735b9145255182c1 (diff)
downloadqtlocation-mapboxgl-8bbd38093ce8ec703c26fbeac4c7fb7c8d208934.tar.gz
add schema test
-rw-r--r--platform/android/MapboxGLAndroidSDK/.gitignore1
-rw-r--r--platform/android/MapboxGLAndroidSDK/build.gradle1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java14
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java41
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java13
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java13
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java13
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java13
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/SchemaTest.java261
-rw-r--r--platform/android/build.gradle1
-rw-r--r--platform/android/gradle/dependencies.gradle2
-rw-r--r--platform/android/gradle/download-schema.gradle8
13 files changed, 305 insertions, 80 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/.gitignore b/platform/android/MapboxGLAndroidSDK/.gitignore
index c24bd2563a..e443847420 100644
--- a/platform/android/MapboxGLAndroidSDK/.gitignore
+++ b/platform/android/MapboxGLAndroidSDK/.gitignore
@@ -1 +1,2 @@
dependency-graph-mapbox-libraries.png
+src/test/resources/mobile-event*
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 74c7c4c465..108f6315d8 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -17,6 +17,7 @@ dependencies {
testImplementation dependenciesList.mockk
testImplementation dependenciesList.robolectric
testImplementation dependenciesList.kotlinLib
+ testImplementation dependenciesList.commonsIO
}
android {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java
index d19b74ebc0..1324e04d87 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java
@@ -10,16 +10,24 @@ import com.mapbox.android.telemetry.Event;
*/
@SuppressLint("ParcelCreator")
public abstract class MapBaseEvent extends Event {
- final String event;
- final String created;
+ private final String event;
+ private final String created;
MapBaseEvent(PhoneState phoneState) {
- event = getEventName();
+ this.event = getEventName();
this.created = phoneState.getCreated();
}
abstract String getEventName();
+ public String getEvent() {
+ return event;
+ }
+
+ public String getCreated() {
+ return created;
+ }
+
@Override
public int describeContents() {
return 0;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java
index 51e38d0430..c9f7f42ed2 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java
@@ -13,8 +13,8 @@ class MapClickEvent extends MapBaseEvent {
private final String cellularNetworkType;
private final String carrier;
private final String orientation;
- private final double latitude;
- private final double longitude;
+ private final double lat;
+ private final double lng;
private final double zoom;
private final int batteryLevel;
private final boolean pluggedIn;
@@ -23,8 +23,8 @@ class MapClickEvent extends MapBaseEvent {
MapClickEvent(PhoneState phoneState, MapState mapState) {
super(phoneState);
this.gesture = mapState.getGesture();
- this.latitude = mapState.getLatitude();
- this.longitude = mapState.getLongitude();
+ this.lat = mapState.getLatitude();
+ this.lng = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.batteryLevel = phoneState.getBatteryLevel();
this.pluggedIn = phoneState.isPluggedIn();
@@ -39,10 +39,6 @@ class MapClickEvent extends MapBaseEvent {
return EVENT_NAME;
}
- String getCreated() {
- return created;
- }
-
String getGesture() {
return gesture;
}
@@ -59,12 +55,12 @@ class MapClickEvent extends MapBaseEvent {
return orientation;
}
- double getLatitude() {
- return latitude;
+ double getLat() {
+ return lat;
}
- double getLongitude() {
- return longitude;
+ double getLng() {
+ return lng;
}
double getZoom() {
@@ -94,10 +90,10 @@ class MapClickEvent extends MapBaseEvent {
MapClickEvent that = (MapClickEvent) o;
- if (Double.compare(that.latitude, latitude) != 0) {
+ if (Double.compare(that.lat, lat) != 0) {
return false;
}
- if (Double.compare(that.longitude, longitude) != 0) {
+ if (Double.compare(that.lng, lng) != 0) {
return false;
}
if (Double.compare(that.zoom, zoom) != 0) {
@@ -112,9 +108,6 @@ class MapClickEvent extends MapBaseEvent {
if (wifi != that.wifi) {
return false;
}
- if (created != null ? !created.equals(that.created) : that.created != null) {
- return false;
- }
if (gesture != null ? !gesture.equals(that.gesture) : that.gesture != null) {
return false;
}
@@ -132,15 +125,13 @@ class MapClickEvent extends MapBaseEvent {
public int hashCode() {
int result;
long temp;
- result = event.hashCode();
- result = 31 * result + (created != null ? created.hashCode() : 0);
- result = 31 * result + (gesture != null ? gesture.hashCode() : 0);
+ result = gesture != null ? gesture.hashCode() : 0;
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (orientation != null ? orientation.hashCode() : 0);
- temp = Double.doubleToLongBits(latitude);
+ temp = Double.doubleToLongBits(lat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(longitude);
+ temp = Double.doubleToLongBits(lng);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
@@ -153,14 +144,12 @@ class MapClickEvent extends MapBaseEvent {
@Override
public String toString() {
return "MapClickEvent{"
- + "event='" + event + '\''
- + ", created='" + created + '\''
+ ", gesture='" + gesture + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
+ ", carrier='" + carrier + '\''
+ ", orientation='" + orientation + '\''
- + ", latitude=" + latitude
- + ", longitude=" + longitude
+ + ", lat=" + lat
+ + ", lng=" + lng
+ ", zoom=" + zoom
+ ", batteryLevel=" + batteryLevel
+ ", pluggedIn=" + pluggedIn
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java
index 64bf70f786..9556a9a524 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java
@@ -36,10 +36,6 @@ class MapDragendEvent extends MapBaseEvent {
return EVENT_NAME;
}
- String getCreated() {
- return created;
- }
-
String getOrientation() {
return orientation;
}
@@ -105,9 +101,6 @@ class MapDragendEvent extends MapBaseEvent {
if (wifi != that.wifi) {
return false;
}
- if (created != null ? !created.equals(that.created) : that.created != null) {
- return false;
- }
if (orientation != null ? !orientation.equals(that.orientation) : that.orientation != null) {
return false;
}
@@ -122,9 +115,7 @@ class MapDragendEvent extends MapBaseEvent {
public int hashCode() {
int result;
long temp;
- result = event.hashCode();
- result = 31 * result + (created != null ? created.hashCode() : 0);
- result = 31 * result + (orientation != null ? orientation.hashCode() : 0);
+ result = orientation != null ? orientation.hashCode() : 0;
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
result = 31 * result + batteryLevel;
@@ -142,8 +133,6 @@ class MapDragendEvent extends MapBaseEvent {
@Override
public String toString() {
return "MapDragendEvent{"
- + "event='" + event + '\''
- + ", created='" + created + '\''
+ ", orientation='" + orientation + '\''
+ ", carrier='" + carrier + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
index 61156b7f18..b12a10b8c4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
@@ -59,10 +59,6 @@ class MapLoadEvent extends MapBaseEvent {
return model;
}
- String getCreated() {
- return created;
- }
-
String getUserId() {
return userId;
}
@@ -131,9 +127,6 @@ class MapLoadEvent extends MapBaseEvent {
if (model != null ? !model.equals(that.model) : that.model != null) {
return false;
}
- if (created != null ? !created.equals(that.created) : that.created != null) {
- return false;
- }
if (userId != null ? !userId.equals(that.userId) : that.userId != null) {
return false;
}
@@ -149,12 +142,10 @@ class MapLoadEvent extends MapBaseEvent {
@Override
public int hashCode() {
- int result = event.hashCode();
- result = 31 * result + operatingSystem.hashCode();
+ int result = operatingSystem != null ? operatingSystem.hashCode() : 0;
result = 31 * result + sdkIdentifier.hashCode();
result = 31 * result + sdkVersion.hashCode();
result = 31 * result + (model != null ? model.hashCode() : 0);
- result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (userId != null ? userId.hashCode() : 0);
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
@@ -170,12 +161,10 @@ class MapLoadEvent extends MapBaseEvent {
@Override
public String toString() {
return "MapLoadEvent{"
- + "event='" + event + '\''
+ ", operatingSystem='" + operatingSystem + '\''
+ ", sdkIdentifier='" + sdkIdentifier + '\''
+ ", sdkVersion='" + sdkVersion + '\''
+ ", model='" + model + '\''
- + ", created='" + created + '\''
+ ", userId='" + userId + '\''
+ ", carrier='" + carrier + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java
index 6a779aacef..cc96052e94 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java
@@ -36,10 +36,6 @@ public class OfflineDownloadEndEvent extends MapBaseEvent {
return EVENT_NAME;
}
- String getCreated() {
- return created;
- }
-
Double getMinZoom() {
return minZoom;
}
@@ -104,9 +100,6 @@ public class OfflineDownloadEndEvent extends MapBaseEvent {
if (state != that.state) {
return false;
}
- if (created != null ? !created.equals(that.created) : that.created != null) {
- return false;
- }
if (minZoom != null ? !minZoom.equals(that.minZoom) : that.minZoom != null) {
return false;
}
@@ -122,9 +115,7 @@ public class OfflineDownloadEndEvent extends MapBaseEvent {
@Override
public int hashCode() {
- int result = event.hashCode();
- result = 31 * result + (created != null ? created.hashCode() : 0);
- result = 31 * result + (minZoom != null ? minZoom.hashCode() : 0);
+ int result = minZoom != null ? minZoom.hashCode() : 0;
result = 31 * result + (maxZoom != null ? maxZoom.hashCode() : 0);
result = 31 * result + (shapeForOfflineRegion != null ? shapeForOfflineRegion.hashCode() : 0);
result = 31 * result + (styleURL != null ? styleURL.hashCode() : 0);
@@ -137,8 +128,6 @@ public class OfflineDownloadEndEvent extends MapBaseEvent {
@Override
public String toString() {
return "OfflineDownloadEndEvent{"
- + "event='" + event + '\''
- + ", created='" + created + '\''
+ ", minZoom=" + minZoom
+ ", maxZoom=" + maxZoom
+ ", shapeForOfflineRegion='" + shapeForOfflineRegion + '\''
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java
index 775e453a4f..497c7e6588 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java
@@ -32,10 +32,6 @@ public class OfflineDownloadStartEvent extends MapBaseEvent {
return EVENT_NAME;
}
- String getCreated() {
- return created;
- }
-
Double getMinZoom() {
return minZoom;
}
@@ -67,9 +63,6 @@ public class OfflineDownloadStartEvent extends MapBaseEvent {
OfflineDownloadStartEvent that = (OfflineDownloadStartEvent) o;
- if (created != null ? !created.equals(that.created) : that.created != null) {
- return false;
- }
if (minZoom != null ? !minZoom.equals(that.minZoom) : that.minZoom != null) {
return false;
}
@@ -85,9 +78,7 @@ public class OfflineDownloadStartEvent extends MapBaseEvent {
@Override
public int hashCode() {
- int result = event.hashCode();
- result = 31 * result + (created != null ? created.hashCode() : 0);
- result = 31 * result + (minZoom != null ? minZoom.hashCode() : 0);
+ int result = minZoom != null ? minZoom.hashCode() : 0;
result = 31 * result + (maxZoom != null ? maxZoom.hashCode() : 0);
result = 31 * result + (shapeForOfflineRegion != null ? shapeForOfflineRegion.hashCode() : 0);
result = 31 * result + (styleURL != null ? styleURL.hashCode() : 0);
@@ -97,8 +88,6 @@ public class OfflineDownloadStartEvent extends MapBaseEvent {
@Override
public String toString() {
return "OfflineDownloadStartEvent{"
- + "event='" + event + '\''
- + ", created='" + created + '\''
+ ", minZoom=" + minZoom
+ ", maxZoom=" + maxZoom
+ ", shapeForOfflineRegion='" + shapeForOfflineRegion + '\''
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java
index 76efa97a31..f5c9493e21 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java
@@ -56,8 +56,8 @@ public class MapEventFactoryTest {
public void testClickEvent() {
mapState.setGesture(TelemetryConstants.DOUBLE_TAP);
MapClickEvent mapClickEvent = MapEventFactory.buildMapClickEvent(phoneState, mapState);
- assertEquals(LATITUDE, mapClickEvent.getLatitude(), 0);
- assertEquals(LONGITUDE, mapClickEvent.getLongitude(), 0);
+ assertEquals(LATITUDE, mapClickEvent.getLat(), 0);
+ assertEquals(LONGITUDE, mapClickEvent.getLng(), 0);
assertEquals(ZOOM, mapClickEvent.getZoom(), 0);
assertEquals(BATTERY_LEVEL, mapClickEvent.getBatteryLevel());
assertEquals(CARRIER, mapClickEvent.getCarrier());
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/SchemaTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/SchemaTest.java
new file mode 100644
index 0000000000..8c4cb09aa3
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/SchemaTest.java
@@ -0,0 +1,261 @@
+package com.mapbox.mapboxsdk.module.telemetry;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class SchemaTest {
+ private static final String MAP_CLICK = "map.click";
+ private static final String MAP_DRAG = "map.dragend";
+ private static final String MAP_LOAD = "map.load";
+ private static ArrayList<JsonObject> schemaArray;
+
+ @BeforeClass
+ public static void downloadSchema() throws Exception {
+ unpackSchemas();
+ }
+
+ @Test
+ public void checkMapClickEventSize() throws Exception {
+ JsonObject schema = grabSchema(MAP_CLICK);
+ List<Field> fields = grabClassFields(MapClickEvent.class);
+
+ assertEquals(schema.size(), fields.size());
+ }
+
+ @Test
+ public void checkMapClickEventFields() throws Exception {
+ JsonObject schema = grabSchema(MAP_CLICK);
+ List<Field> fields = grabClassFields(MapClickEvent.class);
+
+ schemaContainsFields(schema, fields);
+ }
+
+ @Test
+ public void checkMapDragEndEventSize() throws Exception {
+ JsonObject schema = grabSchema(MAP_DRAG);
+ List<Field> fields = grabClassFields(MapDragendEvent.class);
+
+ assertEquals(schema.size(), fields.size());
+ }
+
+ @Test
+ public void checkMapDragEndEventFields() throws Exception {
+ JsonObject schema = grabSchema(MAP_DRAG);
+ List<Field> fields = grabClassFields(MapDragendEvent.class);
+
+ schemaContainsFields(schema, fields);
+ }
+
+ @Test
+ public void checkMapLoadEventSize() throws Exception {
+ JsonObject schema = grabSchema(MAP_LOAD);
+ List<Field> fields = grabClassFields(MapLoadEvent.class);
+
+ //FIXME: this assertion is invalid: we should introduce a concept of mandatory/optional field to schema validation
+ //assertEquals(schema.size(), fields.size());
+ }
+
+ @Test
+ public void checkMapLoadEventFields() throws Exception {
+ JsonObject schema = grabSchema(MAP_LOAD);
+ List<Field> fields = grabClassFields(MapLoadEvent.class);
+
+ schemaContainsFields(schema, fields);
+ }
+
+ private void schemaContainsFields(JsonObject schema, List<Field> fields) {
+ int distanceRemainingCount = 0;
+ int durationRemainingCount = 0;
+
+ for (int i = 0; i < fields.size(); i++) {
+ String thisField = String.valueOf(fields.get(i));
+ String[] fieldArray = thisField.split(" ");
+ String[] typeArray = fieldArray[fieldArray.length - 2].split("\\.");
+ String type = typeArray[typeArray.length - 1];
+
+ String[] nameArray = fieldArray[fieldArray.length - 1].split("\\.");
+ String field = nameArray[nameArray.length - 1];
+
+ SerializedName serializedName = fields.get(i).getAnnotation(SerializedName.class);
+
+ if (serializedName != null) {
+ field = serializedName.value();
+ }
+
+ if (field.equalsIgnoreCase("durationRemaining")) {
+ durationRemainingCount++;
+
+ if (durationRemainingCount > 1) {
+ field = "step" + field;
+ }
+ }
+
+ if (field.equalsIgnoreCase("distanceRemaining")) {
+ distanceRemainingCount++;
+
+ if (distanceRemainingCount > 1) {
+ field = "step" + field;
+ }
+ }
+
+ JsonObject thisSchema = findSchema(schema, field);
+ assertNotNull(thisSchema);
+
+ if (thisSchema.has("type")) {
+ typesMatch(thisSchema, type);
+ }
+ }
+ }
+
+ private JsonObject findSchema(JsonObject schema, String field) {
+ JsonObject thisSchema = schema.getAsJsonObject(field);
+
+ return thisSchema;
+ }
+
+ private void typesMatch(JsonObject schema, String type) {
+ if (type.equalsIgnoreCase("int") || type.equalsIgnoreCase("integer")
+ || type.equalsIgnoreCase("double") || type.equalsIgnoreCase("float")) {
+ type = "number";
+ }
+
+ if (type.contains("[]")) {
+ type = "array";
+ }
+
+ Class<? extends JsonElement> typeClass = schema.get("type").getClass();
+ JsonElement jsonElement = new JsonParser().parse(type.toLowerCase());
+
+ if (typeClass == JsonPrimitive.class) {
+ JsonElement typePrimitive = schema.get("type");
+ assertTrue(typePrimitive.equals(jsonElement));
+ } else {
+ JsonArray arrayOfTypes = schema.getAsJsonArray("type");
+ assertTrue(arrayOfTypes.contains(jsonElement));
+ }
+ }
+
+ private static ByteArrayInputStream getFileBytes() throws IOException {
+ InputStream inputStream = SchemaTest.class.getClassLoader().getResourceAsStream("mobile-event-schemas.jsonl.gz");
+ byte[] byteOut = IOUtils.toByteArray(inputStream);
+
+ return new ByteArrayInputStream(byteOut);
+ }
+
+ private static void unpackSchemas() throws IOException {
+ ByteArrayInputStream bais = getFileBytes();
+ GZIPInputStream gzis = new GZIPInputStream(bais);
+ InputStreamReader reader = new InputStreamReader(gzis);
+ BufferedReader in = new BufferedReader(reader);
+
+ schemaArray = new ArrayList<>();
+
+ Gson gson = new Gson();
+ String readed;
+ while ((readed = in.readLine()) != null) {
+ JsonObject schema = gson.fromJson(readed, JsonObject.class);
+ schemaArray.add(schema);
+ }
+ }
+
+ private JsonObject grabSchema(String eventName) {
+ for (JsonObject thisSchema : schemaArray) {
+ String name = thisSchema.get("name").getAsString();
+
+ if (name.equalsIgnoreCase(eventName)) {
+ Gson gson = new Gson();
+ String schemaString = gson.toJson(thisSchema.get("properties"));
+ JsonObject schema = gson.fromJson(thisSchema.get("properties"), JsonObject.class);
+
+ if (schema.has("step")) {
+ JsonObject stepJson = schema.get("step").getAsJsonObject();
+ JsonObject stepProperties = stepJson.get("properties").getAsJsonObject();
+
+ String stepPropertiesJson = gson.toJson(stepProperties);
+ schemaString = generateStepSchemaString(stepPropertiesJson, schemaString);
+
+ schema = gson.fromJson(schemaString, JsonObject.class);
+ schema.remove("step");
+ }
+
+ schema.remove("userAgent");
+ schema.remove("received");
+ schema.remove("token");
+ schema.remove("authorization");
+ schema.remove("owner");
+ schema.remove("locationAuthorization");
+ schema.remove("locationEnabled");
+ //temporary need to work out a solution to include this data
+ schema.remove("platform");
+
+ return schema;
+ }
+ }
+
+ return null;
+ }
+
+ private List<Field> grabClassFields(Class aClass) {
+ List<Field> fields = new ArrayList<>();
+ Field[] allFields = aClass.getDeclaredFields();
+ for (Field field : allFields) {
+ if (Modifier.isPrivate(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
+ fields.add(field);
+ }
+ }
+ Field[] superFields = aClass.getSuperclass().getDeclaredFields();
+ for (Field field : superFields) {
+ if (Modifier.isPrivate(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
+ fields.add(field);
+ }
+ }
+ return fields;
+ }
+
+ private List<Field> removeField(List<Field> fields, String fieldName) {
+ for (Field field : new ArrayList<>(fields)) {
+ String thisField = String.valueOf(field);
+ String[] fieldArray = thisField.split("\\.");
+ String simpleField = fieldArray[fieldArray.length - 1];
+ if (simpleField.equalsIgnoreCase(fieldName)) {
+ fields.remove(field);
+ }
+ }
+
+ return fields;
+ }
+
+ private String generateStepSchemaString(String stepJson, String schemaString) {
+ stepJson = stepJson.replace("\"distanceRemaining\"", "\"stepdistanceRemaining\"");
+ stepJson = stepJson.replace("durationRemaining", "stepdurationRemaining");
+ stepJson = stepJson.replaceFirst("\\{", ",");
+ schemaString = schemaString.replaceAll("}$", "");
+ schemaString = schemaString + stepJson;
+
+ return schemaString;
+ }
+}
diff --git a/platform/android/build.gradle b/platform/android/build.gradle
index b91be625ee..0be1d73a5c 100644
--- a/platform/android/build.gradle
+++ b/platform/android/build.gradle
@@ -35,3 +35,4 @@ subprojects {
// Load build system information. If this file does not exist, run
// `make platform/android/gradle/configuration.gradle`
apply from: "${rootDir}/gradle/configuration.gradle"
+apply from: "${rootDir}/gradle/download-schema.gradle" \ No newline at end of file
diff --git a/platform/android/gradle/dependencies.gradle b/platform/android/gradle/dependencies.gradle
index 0cd3a2e7fe..f9c6f2ac1b 100644
--- a/platform/android/gradle/dependencies.gradle
+++ b/platform/android/gradle/dependencies.gradle
@@ -52,7 +52,7 @@ ext {
testEspressoIntents : "com.android.support.test.espresso:espresso-intents:${versions.espresso}",
testEspressoContrib : "com.android.support.test.espresso:espresso-contrib:${versions.espresso}",
testUiAutomator : "com.android.support.test.uiautomator:uiautomator-v18:${versions.uiAutomator}",
-
+ commonsIO : 'commons-io:commons-io:2.5',
supportAnnotations : "com.android.support:support-annotations:${versions.supportLib}",
supportAppcompatV7 : "com.android.support:appcompat-v7:${versions.supportLib}",
supportFragmentV4 : "com.android.support:support-fragment:${versions.supportLib}",
diff --git a/platform/android/gradle/download-schema.gradle b/platform/android/gradle/download-schema.gradle
new file mode 100644
index 0000000000..3d3beac651
--- /dev/null
+++ b/platform/android/gradle/download-schema.gradle
@@ -0,0 +1,8 @@
+task downloadSchema(type: Copy) {
+ def address='https://mapbox.s3.amazonaws.com/mapbox-gl-native/event-schema/mobile-event-schemas.jsonl.gz'
+ def target='MapboxGLAndroidSDK/src/test/resources/'
+
+ new File(target + "${address.tokenize('/')[-1]}").withOutputStream { out ->
+ new URL(address).withInputStream { from -> out << from }
+ }
+} \ No newline at end of file