Skip to content

feat(ATS): pass odp common data and identifiers to java core #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ public OptimizelyManager build(Context context) {
Map<String, Object> commonData = OptimizelyDefaultAttributes.buildODPCommonData(context, logger);

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

ODPApiManager odpApiManager = new DefaultODPApiManager(
context,
Expand All @@ -1058,11 +1058,8 @@ public OptimizelyManager build(Context context) {
.withApiManager(odpApiManager)
.withSegmentCacheSize(odpSegmentCacheSize)
.withSegmentCacheTimeout(odpSegmentCacheTimeoutInSecs)

// TODO: this will be fixed in a separate PR after java-sdk is extended for android-sdk support.
//.withExtraCommonData(commonData)
//.withExtraCommonIdentifiers(commonIdentifiers)

.withUserCommonData(commonData)
.withUserCommonIdentifiers(commonIdentifiers)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.runners.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand All @@ -69,6 +70,7 @@
import static org.powermock.api.mockito.PowerMockito.whenNew;

import java.sql.Time;
import java.util.Map;
import java.util.concurrent.TimeUnit;

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

@Test
public void testBuildWithODP_defaultCommonDataAndIdentifiers() throws Exception {
ODPEventManager mockEventManager = mock(ODPEventManager.class);
whenNew(ODPEventManager.class).withAnyArguments().thenReturn(mockEventManager);
whenNew(ODPSegmentManager.class).withAnyArguments().thenReturn(mock(ODPSegmentManager.class));
whenNew(ODPManager.class).withAnyArguments().thenReturn(mock(ODPManager.class));

OptimizelyManager manager = OptimizelyManager.builder()
.withSDKKey(testSdkKey)
.withVuid("test-vuid")
.build(mockContext);

ArgumentCaptor<Map<String, Object>> captorData = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<Map<String, String>> captorIdentifiers = ArgumentCaptor.forClass(Map.class);

verify(mockEventManager).setUserCommonData(captorData.capture());
verify(mockEventManager).setUserCommonIdentifiers(captorIdentifiers.capture());

Map<String, Object> data = captorData.getValue();
Map<String, String> identifiers = captorIdentifiers.getValue();

// here we just validate if data is passed or not (all values are validated in other tests: OptimizelyDefaultAttributesTest)
assertEquals(data.get("os"), "Android");
assertEquals(data.size(), 4);

assertEquals(identifiers.get("vuid"), "test-vuid");
assertEquals(identifiers.size(), 1);
}

}
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ allprojects {
// SNAPSHOT support
maven {url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

configurations.all {
// no cache for SNAPSHOT dependency
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}

ext {
Expand Down