Skip to content

Commit 86cd0e5

Browse files
mnoman09thomaszurkan-optimizely
authored andcommitted
- Updated Java sdk version from 1.8 to 2.0.0-beta2 and removed Live variables (#168)
* - Updated Java sdk version from 1.8 to 2.0.0-beta2 (#9) * - Updated Java sdk version from 1.8 to 2.0.0-beta2 - Removed getVariableString getVariableBoolean getVariableInteger getVariableDouble -Remove track with revenue as a parameter. Pass the revenue value as an event tag instead track(String, String, long) track(String, String, Map<String, String>, long) * added multidex enabled support * make common Constant of $multidex_ver to use in all gradle * Upgraded Java sdk (#13) * Excluded group: 'com.google.code.findbugs' from dependency of com.optimizely.ab:core-api removed Multidex enabling from sdk and test app * Updated Test unit tests * included Collection library which was removed due to merging of master * undo comment space
1 parent ea767fc commit 86cd0e5

File tree

7 files changed

+17
-302
lines changed

7 files changed

+17
-302
lines changed

android-sdk/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ android {
3232
versionName version_name
3333
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3434
buildConfigField "String", "CLIENT_VERSION", "\"$version_name\""
35-
consumerProguardFiles '../proguard-rules.txt'
35+
consumerProguardFiles '../proguard-rules.txt'
3636
}
3737
testOptions {
3838
unitTests.returnDefaultValues = true
@@ -62,7 +62,9 @@ dependencies {
6262
compile project(':datafile-handler')
6363
compile project(':event-handler')
6464
compile project(':user-profile')
65-
compile "com.optimizely.ab:core-api:$java_core_ver"
65+
compile ("com.optimizely.ab:core-api:$java_core_ver") {
66+
exclude group: 'com.google.code.findbugs'
67+
}
6668
provided "com.android.support:support-annotations:$support_annotations_ver"
6769

6870
testCompile "junit:junit:$junit_ver"

android-sdk/src/androidTest/java/com/optimizely/ab/android/sdk/OptimizelyClientTest.java

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -774,74 +774,6 @@ public void testIsInvalid() {
774774
assertFalse(optimizelyClient.isValid());
775775
}
776776

777-
@Test
778-
public void testGoodGetVariableString() {
779-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
780-
String v = optimizelyClient.getVariableString("test_variable", "userId",
781-
Collections.<String, String>emptyMap(), true);
782-
assertEquals(v, "true");
783-
}
784-
785-
@Test
786-
public void testBadGetVariableString() {
787-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
788-
optimizelyClient.getVariableString("test_key", "userId",
789-
Collections.<String, String>emptyMap(), true);
790-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
791-
"for user {}", "test_key", "userId");
792-
}
793-
794-
@Test
795-
public void testGoodGetVariableBoolean() {
796-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
797-
Boolean b = optimizelyClient.getVariableBoolean("test_variable", "userId",
798-
Collections.<String, String>emptyMap(), true);
799-
assertNotNull(b);
800-
}
801-
802-
@Test
803-
public void testBadGetVariableBoolean() {
804-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
805-
optimizelyClient.getVariableBoolean("test_key", "userId",
806-
Collections.<String, String>emptyMap(), true);
807-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
808-
"for user {}", "test_key", "userId");
809-
}
810-
811-
@Test
812-
public void testGoodGetVariableInteger() {
813-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
814-
Integer i = optimizelyClient.getVariableInteger("test_variable", "userId",
815-
Collections.<String, String>emptyMap(), true);
816-
assertNull(i);
817-
}
818-
819-
@Test
820-
public void testBadGetVariableInteger() {
821-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
822-
optimizelyClient.getVariableInteger("test_key", "userId",
823-
Collections.<String, String>emptyMap(), true);
824-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
825-
"for user {}", "test_key", "userId");
826-
}
827-
828-
@Test
829-
public void testGoodGetVariableDouble() {
830-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
831-
Double v = optimizelyClient.getVariableDouble("test_variable", "userId",
832-
Collections.<String, String>emptyMap(), true);
833-
assertNull(v);
834-
}
835-
836-
@Test
837-
public void testBadGetVariableDouble() {
838-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
839-
optimizelyClient.getVariableDouble("test_key", "userId",
840-
Collections.<String, String>emptyMap(), true);
841-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
842-
"for user {}", "test_key", "userId");
843-
}
844-
845777
@Test
846778
public void testDefaultAttributes() {
847779
Context context = mock(Context.class);

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

Lines changed: 5 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import com.optimizely.ab.config.Experiment;
2626
import com.optimizely.ab.config.ProjectConfig;
2727
import com.optimizely.ab.config.Variation;
28+
import com.optimizely.ab.internal.ReservedEventKey;
2829
import com.optimizely.ab.notification.NotificationListener;
2930

3031
import org.slf4j.Logger;
3132

33+
import java.util.Collections;
3234
import java.util.HashMap;
3335
import java.util.Map;
3436

@@ -219,7 +221,7 @@ public void track(@NonNull String eventName,
219221
@NonNull String userId,
220222
long eventValue) throws UnknownEventTypeException {
221223
if (isValid()) {
222-
optimizely.track(eventName, userId, getDefaultAttributes(), eventValue);
224+
optimizely.track(eventName, userId, getDefaultAttributes(), Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
223225
} else {
224226
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
225227
" with value {}", eventName, userId, eventValue);
@@ -228,7 +230,7 @@ public void track(@NonNull String eventName,
228230

229231
/**
230232
* Track an event for a user with attributes and a value
231-
* @see Optimizely#track(String, String, Map, long)
233+
* @see Optimizely#track(String, String, Map, Map)
232234
* @deprecated see {@link Optimizely#track(String, String, Map, Map)} and pass in revenue values as event tags instead.
233235
* @param eventName the String name of the event
234236
* @param userId the String user id
@@ -240,157 +242,13 @@ public void track(@NonNull String eventName,
240242
@NonNull Map<String, String> attributes,
241243
long eventValue) {
242244
if (isValid()) {
243-
optimizely.track(eventName, userId, getAllAttributes(attributes), eventValue);
245+
optimizely.track(eventName, userId, getAllAttributes(attributes), Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
244246
} else {
245247
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
246248
" with value {} and attributes", eventName, userId, eventValue);
247249
}
248250
}
249251

250-
/**
251-
* Get the value of a String live variable
252-
* @param variableKey the String key for the variable
253-
* @param userId the user ID
254-
* @param activateExperiment the flag denoting whether to activate an experiment or not
255-
* @return String value of the live variable
256-
*/
257-
public @Nullable String getVariableString(@NonNull String variableKey,
258-
@NonNull String userId,
259-
boolean activateExperiment) {
260-
return getVariableString(variableKey, userId, getDefaultAttributes(),
261-
activateExperiment);
262-
}
263-
264-
/**
265-
* Get the value of a String live variable
266-
* @param variableKey the String key for the variable
267-
* @param userId the user ID
268-
* @param attributes a map of attributes about the user
269-
* @param activateExperiment the flag denoting whether to activate an experiment or not
270-
* @return String value of the live variable
271-
*/
272-
public @Nullable String getVariableString(@NonNull String variableKey,
273-
@NonNull String userId,
274-
@NonNull Map<String, String> attributes,
275-
boolean activateExperiment) {
276-
if (isValid()) {
277-
return optimizely.getVariableString(variableKey, userId, getAllAttributes(attributes),
278-
activateExperiment);
279-
} else {
280-
logger.warn("Optimizely is not initialized, could not get live variable {} " +
281-
"for user {}", variableKey, userId);
282-
return null;
283-
}
284-
}
285-
286-
/**
287-
* Get the value of a Boolean live variable
288-
* @param variableKey the String key for the variable
289-
* @param userId the user ID
290-
* @param activateExperiment the flag denoting whether to activate an experiment or not
291-
* @return Boolean value of the live variable
292-
*/
293-
public @Nullable Boolean getVariableBoolean(@NonNull String variableKey,
294-
@NonNull String userId,
295-
boolean activateExperiment) {
296-
return getVariableBoolean(variableKey, userId, getDefaultAttributes(),
297-
activateExperiment);
298-
}
299-
300-
/**
301-
* Get the value of a Boolean live variable
302-
* @param variableKey the String key for the variable
303-
* @param userId the user ID
304-
* @param attributes a map of attributes about the user
305-
* @param activateExperiment the flag denoting whether to activate an experiment or not
306-
* @return Boolean value of the live variable
307-
*/
308-
public @Nullable Boolean getVariableBoolean(@NonNull String variableKey,
309-
@NonNull String userId,
310-
@NonNull Map<String, String> attributes,
311-
boolean activateExperiment) {
312-
if (isValid()) {
313-
return optimizely.getVariableBoolean(variableKey, userId, getAllAttributes(attributes),
314-
activateExperiment);
315-
} else {
316-
logger.warn("Optimizely is not initialized, could not get live variable {} " +
317-
"for user {}", variableKey, userId);
318-
return null;
319-
}
320-
}
321-
322-
/**
323-
* Get the value of a Integer live variable
324-
* @param variableKey the String key for the variable
325-
* @param userId the user ID
326-
* @param activateExperiment the flag denoting whether to activate an experiment or not
327-
* @return Integer value of the live variable
328-
*/
329-
public @Nullable Integer getVariableInteger(@NonNull String variableKey,
330-
@NonNull String userId,
331-
boolean activateExperiment) {
332-
return getVariableInteger(variableKey, userId, getDefaultAttributes(),
333-
activateExperiment);
334-
}
335-
336-
/**
337-
* Get the value of a Integer live variable
338-
* @param variableKey the String key for the variable
339-
* @param userId the user ID
340-
* @param attributes a map of attributes about the user
341-
* @param activateExperiment the flag denoting whether to activate an experiment or not
342-
* @return Integer value of the live variable
343-
*/
344-
public @Nullable Integer getVariableInteger(@NonNull String variableKey,
345-
@NonNull String userId,
346-
@NonNull Map<String, String> attributes,
347-
boolean activateExperiment) {
348-
if (isValid()) {
349-
return optimizely.getVariableInteger(variableKey, userId, getAllAttributes(attributes),
350-
activateExperiment);
351-
} else {
352-
logger.warn("Optimizely is not initialized, could not get live variable {} " +
353-
"for user {}", variableKey, userId);
354-
return null;
355-
}
356-
}
357-
358-
/**
359-
* Get the value of a Double live variable
360-
* @param variableKey the String key for the variable
361-
* @param userId the user ID
362-
* @param activateExperiment the flag denoting whether to activate an experiment or not
363-
* @return Double value of the live variable
364-
*/
365-
public @Nullable Double getVariableDouble(@NonNull String variableKey,
366-
@NonNull String userId,
367-
boolean activateExperiment) {
368-
return getVariableDouble(variableKey, userId, getDefaultAttributes(),
369-
activateExperiment);
370-
}
371-
372-
/**
373-
* Get the value of a Double live variable
374-
* @param variableKey the String key for the variable
375-
* @param userId the user ID
376-
* @param attributes a map of attributes about the user
377-
* @param activateExperiment the flag denoting whether to activate an experiment or not
378-
* @return Double value of the live variable
379-
*/
380-
public @Nullable Double getVariableDouble(@NonNull String variableKey,
381-
@NonNull String userId,
382-
@NonNull Map<String, String> attributes,
383-
boolean activateExperiment) {
384-
if (isValid()) {
385-
return optimizely.getVariableDouble(variableKey, userId, getAllAttributes(attributes),
386-
activateExperiment);
387-
} else {
388-
logger.warn("Optimizely is not initialized, could not get live variable {} " +
389-
"for user {}", variableKey, userId);
390-
return null;
391-
}
392-
}
393-
394252
/**
395253
* Get the variation the user is bucketed into
396254
* @see Optimizely#getVariation(Experiment, String)

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

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.optimizely.ab.Optimizely;
2020
import com.optimizely.ab.config.Experiment;
2121
import com.optimizely.ab.config.Variation;
22+
import com.optimizely.ab.internal.ReservedEventKey;
2223
import com.optimizely.ab.notification.NotificationListener;
2324

2425
import org.junit.Test;
@@ -108,13 +109,6 @@ public void testBadTrack2() {
108109
"with attributes", "event1", "1");
109110
}
110111

111-
@Test(expected=ArgumentsAreDifferent.class)
112-
public void testGoodTrack3() {
113-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
114-
optimizelyClient.track("event1", "1", 1L);
115-
verify(optimizely).track("event1", "1", 1L);
116-
}
117-
118112
@Test
119113
public void testBadTrack3() {
120114
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
@@ -128,8 +122,8 @@ public void testGoodTrack4() {
128122
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
129123
final HashMap<String, String> attributes = new HashMap<>();
130124
optimizelyClient.track("event1", "1", attributes, 1L);
131-
verify(optimizely).track("event1", "1", attributes, 1L);
132-
}
125+
Map<String, String> defaultAttributes = new HashMap<>();
126+
verify(optimizely).track("event1", "1", defaultAttributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L)); }
133127

134128
@Test
135129
public void testBadTrack4() {
@@ -209,78 +203,6 @@ public void testIsInvalid() {
209203
assertFalse(optimizelyClient.isValid());
210204
}
211205

212-
@Test
213-
public void testGoodGetVariableString() {
214-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
215-
optimizelyClient.getVariableString("test_key", "userId",
216-
Collections.<String, String>emptyMap(), true);
217-
verify(optimizely).getVariableString("test_key", "userId",
218-
Collections.<String, String>emptyMap(), true);
219-
}
220-
221-
@Test
222-
public void testBadGetVariableString() {
223-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
224-
optimizelyClient.getVariableString("test_key", "userId",
225-
Collections.<String, String>emptyMap(), true);
226-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
227-
"for user {}", "test_key", "userId");
228-
}
229-
230-
@Test
231-
public void testGoodGetVariableBoolean() {
232-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
233-
optimizelyClient.getVariableBoolean("test_key", "userId",
234-
Collections.<String, String>emptyMap(), true);
235-
verify(optimizely).getVariableBoolean("test_key", "userId",
236-
Collections.<String, String>emptyMap(), true);
237-
}
238-
239-
@Test
240-
public void testBadGetVariableBoolean() {
241-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
242-
optimizelyClient.getVariableBoolean("test_key", "userId",
243-
Collections.<String, String>emptyMap(), true);
244-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
245-
"for user {}", "test_key", "userId");
246-
}
247-
248-
@Test
249-
public void testGoodGetVariableInteger() {
250-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
251-
optimizelyClient.getVariableInteger("test_key", "userId",
252-
Collections.<String, String>emptyMap(), true);
253-
verify(optimizely).getVariableInteger("test_key", "userId",
254-
Collections.<String, String>emptyMap(), true);
255-
}
256-
257-
@Test
258-
public void testBadGetVariableInteger() {
259-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
260-
optimizelyClient.getVariableInteger("test_key", "userId",
261-
Collections.<String, String>emptyMap(), true);
262-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
263-
"for user {}", "test_key", "userId");
264-
}
265-
266-
@Test
267-
public void testGoodGetVariableDouble() {
268-
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
269-
optimizelyClient.getVariableDouble("test_key", "userId",
270-
Collections.<String, String>emptyMap(), true);
271-
verify(optimizely).getVariableDouble("test_key", "userId",
272-
Collections.<String, String>emptyMap(), true);
273-
}
274-
275-
@Test
276-
public void testBadGetVariableDouble() {
277-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
278-
optimizelyClient.getVariableDouble("test_key", "userId",
279-
Collections.<String, String>emptyMap(), true);
280-
verify(logger).warn("Optimizely is not initialized, could not get live variable {} " +
281-
"for user {}", "test_key", "userId");
282-
}
283-
284206
//======== Notification listeners ========//
285207

286208
@Test

0 commit comments

Comments
 (0)