Skip to content

Commit

Permalink
support configurable sdk name and version
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeopt committed Jun 16, 2023
1 parent 657079e commit ac73d9a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public void setup() throws Exception {
notificationCenter,
null,
odpManager,
"test-vuid");
"test-vuid",
null,
null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void eventClientWithCustomNameAndVersion() throws Exception {

ArgumentCaptor<LogEvent> argument = ArgumentCaptor.forClass(LogEvent.class);
verify(mockEventHandler, timeout(5000)).dispatchEvent(argument.capture());
assertEquals(argument.getValue().getEventBatch().getClientName(), "android-sdk");
assertEquals(argument.getValue().getEventBatch().getClientVersion(), BuildConfig.CLIENT_VERSION);
assertEquals(argument.getValue().getEventBatch().getClientName(), "test-sdk");
assertEquals(argument.getValue().getEventBatch().getClientVersion(), "test-version");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void initializeSyncWithEnvironment() {
EventHandler eventHandler = mock(DefaultEventHandler.class);
EventProcessor eventProcessor = mock(EventProcessor.class);
OptimizelyManager optimizelyManager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, 3600L, datafileHandler, null, 3600L,
eventHandler, eventProcessor, null, null, null, null, null);
eventHandler, eventProcessor, null, null, null, null, null, null, null);
/*
* Scenario#1: when datafile is not Empty
* Scenario#2: when datafile is Empty
Expand Down Expand Up @@ -222,7 +222,7 @@ public void initializeAsyncWithEnvironment() {
EventHandler eventHandler = mock(DefaultEventHandler.class);
EventProcessor eventProcessor = mock(EventProcessor.class);
final OptimizelyManager optimizelyManager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, 3600L, datafileHandler, null, 3600L,
eventHandler, eventProcessor, null, null, null, null, null);
eventHandler, eventProcessor, null, null, null, null, null, null, null);

/*
* Scenario#1: when datafile is not Empty
Expand Down Expand Up @@ -494,7 +494,7 @@ public void initializeSyncWithUpdateOnNewDatafileDisabled() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
new Answer<Object>() {
Expand Down Expand Up @@ -527,7 +527,7 @@ public void initializeSyncWithUpdateOnNewDatafileEnabled() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
new Answer<Object>() {
Expand Down Expand Up @@ -560,7 +560,7 @@ public void initializeSyncWithDownloadToCacheDisabled() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
new Answer<Object>() {
Expand Down Expand Up @@ -593,7 +593,7 @@ public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingEnab
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
(Answer<Object>) invocation -> {
Expand Down Expand Up @@ -625,7 +625,7 @@ public void initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingEnabl
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
new Answer<Object>() {
Expand Down Expand Up @@ -658,7 +658,7 @@ public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingDisa
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
new Answer<Object>() {
Expand Down Expand Up @@ -692,7 +692,7 @@ public void initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingDisab
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null);

doAnswer(
new Answer<Object>() {
Expand Down Expand Up @@ -725,7 +725,7 @@ public void initializeSyncWithResourceDatafileNoCache() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = spy(new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null));
null, null, null, null, null, null, null, null, null));

datafileHandler.removeSavedDatafile(context, manager.getDatafileConfig());
OptimizelyClient client = manager.initialize(context, R.raw.datafile, downloadToCache, updateConfigOnNewDatafile);
Expand All @@ -742,7 +742,7 @@ public void initializeSyncWithResourceDatafileNoCacheWithDefaultParams() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

OptimizelyManager manager = spy(new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0,
null, null, null, null, null, null, null));
null, null, null, null, null, null, null, null, null));

datafileHandler.removeSavedDatafile(context, manager.getDatafileConfig());
OptimizelyClient client = manager.initialize(context, R.raw.datafile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public String getSdkName(Context context) {
if (sdkName == null) {
sdkName = OptimizelyClientEngine.getClientEngineNameFromContext(context);
}
return sdkName
return sdkName;
}

@NonNull
Expand All @@ -533,7 +533,7 @@ public String getSdkVersion() {
sdkVersion = "UNKNOWN";
}
}
return sdkVersion
return sdkVersion;
}

private boolean datafileDownloadEnabled() {
Expand Down Expand Up @@ -599,7 +599,7 @@ public void onStartComplete(UserProfileService userProfileService) {
private OptimizelyClient buildOptimizely(@NonNull Context context, @NonNull String datafile) throws ConfigParseException {
EventHandler eventHandler = getEventHandler(context);

String sdkName = getSdkName();
String sdkName = getSdkName(context);
String sdkVersion = getSdkVersion();

Optimizely.Builder builder = Optimizely.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public void testBuildWithCustomSdkNameAndVersion() throws Exception {
OptimizelyManager manager = OptimizelyManager.builder()
.withSDKKey(testSdkKey)
.withClientInfo("test-sdk", "test-version")
.withVuid("any-to-avoid-generate")
.build(mockContext);
assertEquals(manager.getSdkName(mockContext), "test-sdk");
assertEquals(manager.getSdkVersion(), "test-version");
Expand Down Expand Up @@ -249,7 +250,9 @@ public void testBuildWithDefaultODP_defaultEnabled() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
any(ODPManager.class),
eq("test-vuid"));
eq("test-vuid"),
any(),
any());
}

@Test
Expand Down Expand Up @@ -277,7 +280,9 @@ public void testBuildWithDefaultODP_disabled() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
isNull(),
eq("test-vuid"));
eq("test-vuid"),
any(),
any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public void testBuildWithDatafileDownloadInterval() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
any(ODPManager.class),
anyString());
anyString(),
any(),
any());
}

@Test
Expand All @@ -131,7 +133,9 @@ public void testBuildWithDatafileDownloadIntervalDeprecated() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
any(ODPManager.class),
anyString());
anyString(),
any(),
any());
}

@Test
Expand Down Expand Up @@ -170,7 +174,9 @@ public void testBuildWithEventDispatchInterval() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
any(ODPManager.class),
anyString());
anyString(),
any(),
any());
}

@Test
Expand Down Expand Up @@ -212,7 +218,9 @@ public void testBuildWithEventDispatchRetryInterval() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
any(ODPManager.class),
anyString());
anyString(),
any(),
any());
}

@Test
Expand Down Expand Up @@ -250,7 +258,9 @@ public void testBuildWithEventDispatchIntervalDeprecated() throws Exception {
any(NotificationCenter.class),
any(), // nullable (DefaultDecideOptions)
any(ODPManager.class),
anyString());
anyString(),
any(),
any());
}

}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ allprojects {
mavenCentral()
// SNAPSHOT support
maven {url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
}

configurations.all {
Expand Down
1 change: 1 addition & 0 deletions shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
api ("com.optimizely.ab:core-api:$java_core_ver") {
exclude group: 'com.google.code.findbugs'
}

implementation "androidx.annotation:annotation:$annotations_ver"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.work:work-runtime:$work_runtime"
Expand Down

0 comments on commit ac73d9a

Please sign in to comment.