-
Notifications
You must be signed in to change notification settings - Fork 32
fix: add Optimizely builder option for client-engine info #466
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
Changes from all commits
9c5082e
0098c8e
a854b08
2f93f8b
6abfd63
05ed197
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* | ||
* Copyright 2016-2017, 2019, Optimizely and contributors | ||
* Copyright 2016-2017, 2019, 2022, Optimizely and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -30,13 +30,29 @@ | |
/** | ||
* Helper class to retrieve the SDK version information. | ||
*/ | ||
@Immutable | ||
public final class BuildVersionInfo { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(BuildVersionInfo.class); | ||
|
||
@Deprecated | ||
public final static String VERSION = readVersionNumber(); | ||
|
||
// can be overridden by other wrapper client (android-sdk, etc) | ||
|
||
private static String clientVersion = readVersionNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. final? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unlike the old VERSION, this private variable can be changed with Optimizely.Builder. |
||
|
||
public static void setClientVersion(String version) { | ||
if (version == null || version.isEmpty()) { | ||
logger.warn("ClientVersion cannot be empty, defaulting to the core java-sdk version."); | ||
return; | ||
} | ||
clientVersion = version; | ||
} | ||
|
||
public static String getClientVersion() { | ||
return clientVersion; | ||
} | ||
|
||
private static String readVersionNumber() { | ||
BufferedReader bufferedReader = null; | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* | ||
* Copyright 2016-2017, 2019, Optimizely and contributors | ||
* Copyright 2016-2017, 2019, 2022, Optimizely and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -20,12 +20,17 @@ | |
import com.optimizely.ab.config.*; | ||
import com.optimizely.ab.error.ErrorHandler; | ||
import com.optimizely.ab.error.NoOpErrorHandler; | ||
import com.optimizely.ab.event.BatchEventProcessor; | ||
import com.optimizely.ab.event.EventHandler; | ||
import com.optimizely.ab.event.LogEvent; | ||
import com.optimizely.ab.event.internal.BuildVersionInfo; | ||
import com.optimizely.ab.event.internal.payload.EventBatch; | ||
import com.optimizely.ab.optimizelydecision.OptimizelyDecideOption; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
@@ -34,11 +39,14 @@ | |
import java.util.List; | ||
|
||
import static com.optimizely.ab.config.DatafileProjectConfigTestUtils.*; | ||
import static junit.framework.Assert.assertEquals; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
import static org.mockito.Mockito.never; | ||
|
||
/** | ||
* Tests for {@link Optimizely#builder(String, EventHandler)}. | ||
|
@@ -195,4 +203,45 @@ public void withDefaultDecideOptions() throws Exception { | |
assertEquals(optimizelyClient.defaultDecideOptions.get(2), OptimizelyDecideOption.EXCLUDE_VARIABLES); | ||
} | ||
|
||
@Test | ||
public void withClientInfo() throws Exception { | ||
Optimizely optimizely; | ||
EventHandler eventHandler; | ||
ArgumentCaptor<LogEvent> argument = ArgumentCaptor.forClass(LogEvent.class); | ||
|
||
// default client-engine info (java-sdk) | ||
|
||
eventHandler = mock(EventHandler.class); | ||
optimizely = Optimizely.builder(validConfigJsonV4(), eventHandler).build(); | ||
optimizely.track("basic_event", "tester"); | ||
|
||
verify(eventHandler, timeout(5000)).dispatchEvent(argument.capture()); | ||
assertEquals(argument.getValue().getEventBatch().getClientName(), "java-sdk"); | ||
assertEquals(argument.getValue().getEventBatch().getClientVersion(), BuildVersionInfo.getClientVersion()); | ||
|
||
// invalid override with null inputs | ||
|
||
reset(eventHandler); | ||
optimizely = Optimizely.builder(validConfigJsonV4(), eventHandler) | ||
.withClientInfo(null, null) | ||
.build(); | ||
optimizely.track("basic_event", "tester"); | ||
|
||
verify(eventHandler, timeout(5000)).dispatchEvent(argument.capture()); | ||
assertEquals(argument.getValue().getEventBatch().getClientName(), "java-sdk"); | ||
assertEquals(argument.getValue().getEventBatch().getClientVersion(), BuildVersionInfo.getClientVersion()); | ||
|
||
// override client-engine info | ||
|
||
reset(eventHandler); | ||
optimizely = Optimizely.builder(validConfigJsonV4(), eventHandler) | ||
.withClientInfo(EventBatch.ClientEngine.ANDROID_SDK, "1.2.3") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it confusing to check "android-sdk" client engine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify this comment? Not clear to me. |
||
.build(); | ||
optimizely.track("basic_event", "tester"); | ||
|
||
verify(eventHandler, timeout(5000)).dispatchEvent(argument.capture()); | ||
assertEquals(argument.getValue().getEventBatch().getClientName(), "android-sdk"); | ||
assertEquals(argument.getValue().getEventBatch().getClientVersion(), "1.2.3"); | ||
} | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.