Skip to content

Commit 67a3008

Browse files
authored
feat(ATS): pass odp common data and identifiers to java core (#445)
1 parent 2b0dc02 commit 67a3008

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ public OptimizelyManager build(Context context) {
10431043
Map<String, Object> commonData = OptimizelyDefaultAttributes.buildODPCommonData(context, logger);
10441044

10451045
// Pass common identifiers for android-sdk only to java-core sdk. All ODP events will include these identifiers.
1046-
Map<String, Object> commonIdentifiers = (vuid != null) ? Collections.singletonMap("vuid", vuid) : Collections.emptyMap();
1046+
Map<String, String> commonIdentifiers = (vuid != null) ? Collections.singletonMap("vuid", vuid) : Collections.emptyMap();
10471047

10481048
ODPApiManager odpApiManager = new DefaultODPApiManager(
10491049
context,
@@ -1058,11 +1058,8 @@ public OptimizelyManager build(Context context) {
10581058
.withApiManager(odpApiManager)
10591059
.withSegmentCacheSize(odpSegmentCacheSize)
10601060
.withSegmentCacheTimeout(odpSegmentCacheTimeoutInSecs)
1061-
1062-
// TODO: this will be fixed in a separate PR after java-sdk is extended for android-sdk support.
1063-
//.withExtraCommonData(commonData)
1064-
//.withExtraCommonIdentifiers(commonIdentifiers)
1065-
1061+
.withUserCommonData(commonData)
1062+
.withUserCommonIdentifiers(commonIdentifiers)
10661063
.build();
10671064
}
10681065

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyManagerBuilderTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.junit.Before;
4545
import org.junit.Test;
4646
import org.junit.runner.RunWith;
47+
import org.mockito.ArgumentCaptor;
4748
import org.mockito.runners.MockitoJUnitRunner;
4849
import org.powermock.core.classloader.annotations.PowerMockIgnore;
4950
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -69,6 +70,7 @@
6970
import static org.powermock.api.mockito.PowerMockito.whenNew;
7071

7172
import java.sql.Time;
73+
import java.util.Map;
7274
import java.util.concurrent.TimeUnit;
7375

7476
@RunWith(PowerMockRunner.class)
@@ -369,4 +371,33 @@ public void testBuildWithODP_customSegmentFetchTimeout() throws Exception {
369371
assertEquals(ODPEventClient.Companion.getCONNECTION_TIMEOUT(), 30*1000);
370372
}
371373

374+
@Test
375+
public void testBuildWithODP_defaultCommonDataAndIdentifiers() throws Exception {
376+
ODPEventManager mockEventManager = mock(ODPEventManager.class);
377+
whenNew(ODPEventManager.class).withAnyArguments().thenReturn(mockEventManager);
378+
whenNew(ODPSegmentManager.class).withAnyArguments().thenReturn(mock(ODPSegmentManager.class));
379+
whenNew(ODPManager.class).withAnyArguments().thenReturn(mock(ODPManager.class));
380+
381+
OptimizelyManager manager = OptimizelyManager.builder()
382+
.withSDKKey(testSdkKey)
383+
.withVuid("test-vuid")
384+
.build(mockContext);
385+
386+
ArgumentCaptor<Map<String, Object>> captorData = ArgumentCaptor.forClass(Map.class);
387+
ArgumentCaptor<Map<String, String>> captorIdentifiers = ArgumentCaptor.forClass(Map.class);
388+
389+
verify(mockEventManager).setUserCommonData(captorData.capture());
390+
verify(mockEventManager).setUserCommonIdentifiers(captorIdentifiers.capture());
391+
392+
Map<String, Object> data = captorData.getValue();
393+
Map<String, String> identifiers = captorIdentifiers.getValue();
394+
395+
// here we just validate if data is passed or not (all values are validated in other tests: OptimizelyDefaultAttributesTest)
396+
assertEquals(data.get("os"), "Android");
397+
assertEquals(data.size(), 4);
398+
399+
assertEquals(identifiers.get("vuid"), "test-vuid");
400+
assertEquals(identifiers.size(), 1);
401+
}
402+
372403
}

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ allprojects {
5858
// SNAPSHOT support
5959
maven {url "https://oss.sonatype.org/content/repositories/snapshots/" }
6060
}
61+
62+
configurations.all {
63+
// no cache for SNAPSHOT dependency
64+
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
65+
}
6166
}
6267

6368
ext {

0 commit comments

Comments
 (0)