Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions splitio/example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
plugins {
id 'com.android.application'
id 'dev.flutter.flutter-gradle-plugin'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {

compileSdk flutter.compileSdkVersion
Expand All @@ -37,8 +16,6 @@ android {
applicationId "io.split.splitio_example"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

buildTypes {
Expand Down
11 changes: 0 additions & 11 deletions splitio/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.4.0'
}
}

allprojects {
repositories {
google()
Expand Down
29 changes: 21 additions & 8 deletions splitio/example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0" // apply true
id "com.android.application" version "8.4.0" apply false
}

include ":app"
12 changes: 7 additions & 5 deletions splitio_android/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
group 'io.split.splitio'
version '0.0.1'

buildscript {
repositories {
google()
Expand All @@ -12,14 +9,19 @@ buildscript {
}
}

plugins {
id 'com.android.library'
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
group 'io.split.splitio'
version '0.0.1'

android {
compileSdk 31
Expand All @@ -36,7 +38,7 @@ android {
}

dependencies {
implementation 'io.split.client:android-client:5.1.0-rc1'
implementation 'io.split.client:android-client:5.3.1'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.12.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void log(Impression impression) {
public void close() {

}

private static Map<String, Object> impressionToMap(final Impression impression) {
final Map<String, Object> impressionMap = new HashMap<>();

Expand All @@ -45,6 +44,7 @@ private static Map<String, Object> impressionToMap(final Impression impression)
impressionMap.put("appliedRule", impression.appliedRule());
impressionMap.put("changeNumber", impression.changeNumber());
impressionMap.put("attributes", impression.attributes());
impressionMap.put("properties", impression.properties());

return impressionMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public void setUp() {

@Test
public void loggingInvokesMethodOnMethodChannel() {
Impression impression = new Impression("key", null, "my_split", "on", 20021002, "on treatment", 1002L, Collections.emptyMap());
Impression impression = new Impression("key", null, "my_split", "on", 20021002, "on treatment", 1002L, Collections.emptyMap(), "[{\"prop1\", \"value1\"}, {\"prop2\", \"value2\"}]");
mImpressionListener.log(impression);

verify(mMethodChannel).invokeMethod(eq("impressionLog"), any());
}

@Test
public void loggingInvokesMethodOnMethodChannelWithCorrectArgument() {
Impression impression = new Impression("key", null, "my_split", "on", 20021002, "on treatment", 1002L, Collections.singletonMap("age", 25));
Impression impression = new Impression("key", null, "my_split", "on", 20021002, "on treatment", 1002L, Collections.singletonMap("age", 25), "[{\"prop1\", \"value1\"}, {\"prop2\", \"value2\"}]");
Map<String, Object> expectedImpressionMap = new HashMap<>();
expectedImpressionMap.put("key", "key");
expectedImpressionMap.put("bucketingKey", null);
Expand All @@ -49,6 +49,7 @@ public void loggingInvokesMethodOnMethodChannelWithCorrectArgument() {
expectedImpressionMap.put("appliedRule", "on treatment");
expectedImpressionMap.put("changeNumber", 1002L);
expectedImpressionMap.put("attributes", Collections.singletonMap("age", 25));
expectedImpressionMap.put("properties", "[{\"prop1\", \"value1\"}, {\"prop2\", \"value2\"}]");
mImpressionListener.log(impression);

verify(mMethodChannel).invokeMethod("impressionLog", expectedImpressionMap);
Expand Down
49 changes: 49 additions & 0 deletions splitio_platform_interface/lib/split_prerequisite.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Prerequisite {
final String _name;

final Set<String> _treatments;

String get name => _name;

Set<String> get treatments => _treatments;

Prerequisite(this._name, this._treatments);

static Prerequisite fromEntry(el) {
final String name = (el['n'] ?? el['n:'] ?? '').toString();
final List<dynamic> rawTreatments = (el['t'] as List<dynamic>?) ?? [];
final Set<String> treatments =
rawTreatments.map((e) => e.toString()).toSet();

return Prerequisite(name, treatments);
}

@override
String toString() {
return '''Prerequisite = {
name: $name,
treatments: $treatments
}''';
}

equals(Prerequisite other) {
return name == other.name && treatments == other.treatments;
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Prerequisite &&
name == other.name &&
other.treatments.containsAll(treatments);
}

@override
int get hashCode {
int treatmentsHash = 0;
for (final t in _treatments) {
treatmentsHash ^= t.hashCode;
}
return name.hashCode ^ treatmentsHash;
}
}
22 changes: 18 additions & 4 deletions splitio_platform_interface/lib/split_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'dart:core';

class SplitView {
import 'package:splitio_platform_interface/split_prerequisite.dart';

class SplitView {
static const String _keyName = 'name';
static const String _keyTrafficType = 'trafficType';
static const String _keyKilled = 'killed';
Expand All @@ -11,6 +12,7 @@ class SplitView {
static const String _keyDefaultTreatment = 'defaultTreatment';
static const String _keySets = 'sets';
static const String _keyImpressionsDisabled = 'impressionsDisabled';
static const String _keyPrerequisites = 'prerequisites';

String name;
String trafficType;
Expand All @@ -21,10 +23,14 @@ class SplitView {
String defaultTreatment;
List<String> sets = [];
bool impressionsDisabled = false;
Set<Prerequisite> prerequisites = <Prerequisite>{};

SplitView(this.name, this.trafficType, this.killed, this.treatments,
this.changeNumber, this.configs,
[this.defaultTreatment = '', this.sets = const [], this.impressionsDisabled = false]);
[this.defaultTreatment = '',
this.sets = const [],
this.impressionsDisabled = false,
this.prerequisites = const <Prerequisite>{}]);

static SplitView? fromEntry(Map<dynamic, dynamic>? entry) {
if (entry == null || entry.isEmpty) {
Expand All @@ -48,6 +54,14 @@ class SplitView {
entry[_keyImpressionsDisabled] = false;
}

if (entry[_keyPrerequisites] == null) {
entry[_keyPrerequisites] = [];
}

final List<dynamic> prereqRaw = (entry[_keyPrerequisites] as List?) ?? [];
final Set<Prerequisite> prerequisites =
prereqRaw.map((el) => Prerequisite.fromEntry(el)).toSet();

return SplitView(
entry[_keyName],
entry[_keyTrafficType],
Expand All @@ -57,8 +71,8 @@ class SplitView {
mappedConfig,
entry[_keyDefaultTreatment] ?? '',
(entry[_keySets] as List).map((el) => el as String).toList(),
entry[_keyImpressionsDisabled] ?? false
);
entry[_keyImpressionsDisabled] ?? false,
prerequisites);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion splitio_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: splitio_platform_interface
description: A common platform interface for the splitio plugin.
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.5.0
version: 1.6.0-rc.1
repository: https://github.com/splitio/flutter-sdk-plugin/tree/main/splitio_platform_interface

environment:
Expand Down
32 changes: 32 additions & 0 deletions splitio_platform_interface/test/prerequisites_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:splitio_platform_interface/split_prerequisite.dart';

void main() {
group('Prerequisite', () {
test('fromEntry creates correct instance', () {
final entry = {
'n': 'feature1',
't': ['on', 'off']
};
final prereq = Prerequisite.fromEntry(entry);
expect(prereq.name, 'feature1');
expect(prereq.treatments, {'on', 'off'});
});

test('equality and hashCode', () {
final a = Prerequisite('feat', {'a', 'b'});
final b = Prerequisite('feat', {'b', 'a'});
final c = Prerequisite('feat2', {'a', 'b'});
expect(a, equals(b));
expect(a.hashCode, equals(b.hashCode));
expect(a, isNot(equals(c)));
});

test('toString contains name and treatments', () {
final prereq = Prerequisite('myFeature', {'t1'});
final str = prereq.toString();
expect(str, contains('myFeature'));
expect(str, contains('t1'));
});
});
}
15 changes: 15 additions & 0 deletions splitio_platform_interface/test/split_view_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:splitio_platform_interface/split_prerequisite.dart';
import 'package:splitio_platform_interface/split_view.dart';

void main() {
Expand All @@ -25,6 +26,16 @@ void main() {
'defaultTreatment': 'on',
'sets': ['set1', 'set2'],
'impressionsDisabled': true,
'prerequisites': [
{
'n:': 'pre1',
't': ['on', 'off']
},
{
'n': 'pre2',
't': ['off']
}
],
});

expect(splitView?.name, 'my_split');
Expand All @@ -36,5 +47,9 @@ void main() {
expect(splitView?.defaultTreatment, 'on');
expect(splitView?.sets, ['set1', 'set2']);
expect(splitView?.impressionsDisabled, true);
expect(splitView?.prerequisites, {
Prerequisite('pre1', {'on', 'off'}),
Prerequisite('pre2', {'off'})
});
});
}
Loading