6868public class APISamplesInJava {
6969
7070 static public void samplesAll (Context context ) {
71- samplesForCmab__local_datafile (context );
72- samplesForCmab__cdn_datafile (context );
73-
71+ samplesForCmab (context );
7472 samplesForDecide (context );
7573 samplesForInitialization (context );
7674 samplesForOptimizelyConfig (context );
@@ -99,99 +97,39 @@ static public void samplesAll(Context context) {
9997 }
10098
10199
102- static public void samplesForCmab__local_datafile (Context context ) {
100+ static public void samplesForCmab (Context context ) {
103101 List <OptimizelyDecideOption > defaultDecideOptions = Arrays .asList (
104102 OptimizelyDecideOption .INCLUDE_REASONS ,
105103 OptimizelyDecideOption .IGNORE_USER_PROFILE_SERVICE
106104 );
107105
108- OptimizelyManager optimizelyManager = OptimizelyManager .builder ()
109- .withSDKKey ("invalid-sdk-key-for-cmab-testing" )
110- .withDefaultDecideOptions (defaultDecideOptions )
111- .build (context );
112- // we use raw datafile for this testing
113- OptimizelyClient optimizelyClient = optimizelyManager .initialize (context , R .raw .datafile_full );
114-
115- String userId = "user_123" ;
116- Map <String , Object > attributes = new HashMap <>();
117- attributes .put ("is_logged_in" , false );
118- attributes .put ("app_version" , "1.3.2" );
119- OptimizelyUserContext user = optimizelyClient .createUserContext (userId , attributes );
120-
121- // decide (decideSync)
122-
123- String flagKey = "cmab-1" ;
124-
125- List <OptimizelyDecideOption > options = Arrays .asList (OptimizelyDecideOption .INCLUDE_REASONS );
126- Log .d ("Samples" ,"=================================================================" );
127- Log .d ("Samples" ,"[CMAB Local Datafile] calling sync decision for cmab..." );
128- Log .d ("Samples" ,"=================================================================" );
129- OptimizelyDecision decision = user .decide (flagKey , options );
106+ // we use cmab test project=4552646833471488 datafile for this testing
130107
131- Log .d ("Samples" ,"=================================================================" );
132- Log .d ("Samples" ,"[CMAB Local Datafile] sync decision for cmab: " + decision .toString ());
133- if (decision .getEnabled ()) {
134- Log .e ("Samples" ,"[ERROR] " + flagKey + " is expected to be NOT enabled for this user!" );
135- }
136- Log .d ("Samples" ,"=================================================================" );
137-
138- // decideAsync
139-
140- Log .d ("Samples" ,"=================================================================" );
141- Log .d ("Samples" ,"[CMAB Local Datafile] calling async decision for cmab..." );
142- Log .d ("Samples" ,"=================================================================" );
143- final CountDownLatch latch = new CountDownLatch (1 );
144- user .decideAsync (flagKey , options , (OptimizelyDecision optDecision ) -> {
145- Log .d ("Samples" ,"=================================================================" );
146- Log .d ("Samples" ,"[CMAB Local Datafile] async decision for cmab: " + optDecision .toString ());
147- if (!optDecision .getEnabled ()) {
148- Log .e ("Samples" ,"[ERROR] " + flagKey + " is expected to be enabled for this user!" );
149- }
150- Log .d ("Samples" ,"=================================================================" );
151- latch .countDown ();
152- });
153-
154- try {
155- latch .await (5 , TimeUnit .SECONDS );
156- Log .d ("Samples" , "[CMAB Local Datafile] Latch released. Async operation completed." );
157- } catch (InterruptedException e ) {
158- e .printStackTrace ();
159- Thread .currentThread ().interrupt ();
160- }
161- }
162-
163-
164- static public void samplesForCmab__cdn_datafile (Context context ) {
165- List <OptimizelyDecideOption > defaultDecideOptions = Arrays .asList (
166- OptimizelyDecideOption .INCLUDE_REASONS ,
167- OptimizelyDecideOption .IGNORE_USER_PROFILE_SERVICE
168- );
169-
170- // we use project=4552646833471488 for CMAB testing
171108 OptimizelyManager optimizelyManager = OptimizelyManager .builder ()
172109 .withSDKKey ("4ft9p1vSXYM5hLATwWdRc" )
173110 .withDefaultDecideOptions (defaultDecideOptions )
174111 .build (context );
175112 // we use raw datafile for this testing
176- OptimizelyClient optimizelyClient = optimizelyManager .initialize (context , R .raw .datafile_full );
113+ OptimizelyClient optimizelyClient = optimizelyManager .initialize (context , R .raw .datafile_full , false , false );
177114
178- String userId = "user_20 " ;
115+ String userId = "user_123 " ;
179116 Map <String , Object > attributes = new HashMap <>();
180117 attributes .put ("country" , "us" );
118+ attributes .put ("extra-1" , 100 );
181119 OptimizelyUserContext user = optimizelyClient .createUserContext (userId , attributes );
182120
183- // decide (decideSync)
184-
185121 String flagKey = "cmab-flag" ;
186122
123+ // decide (decideSync)
124+
187125 List <OptimizelyDecideOption > options = Arrays .asList (OptimizelyDecideOption .INCLUDE_REASONS );
188126 Log .d ("Samples" ,"=================================================================" );
189- Log .d ("Samples" ,"[CMAB CDN Datafile ] calling sync decision for cmab..." );
127+ Log .d ("Samples" ,"[CMAB] calling sync decision for cmab..." );
190128 Log .d ("Samples" ,"=================================================================" );
191129 OptimizelyDecision decision = user .decide (flagKey , options );
192130
193131 Log .d ("Samples" ,"=================================================================" );
194- Log .d ("Samples" ,"[CMAB CDN Datafile ] sync decision for cmab: " + decision .toString ());
132+ Log .d ("Samples" ,"[CMAB] sync decision for cmab: " + decision .toString ());
195133 if (decision .getEnabled ()) {
196134 Log .e ("Samples" ,"[ERROR] " + flagKey + " is expected to be NOT enabled for this user!" );
197135 }
@@ -200,12 +138,12 @@ static public void samplesForCmab__cdn_datafile(Context context) {
200138 // decideAsync
201139
202140 Log .d ("Samples" ,"=================================================================" );
203- Log .d ("Samples" ,"[CMAB CDN Datafile ] calling async decision for cmab..." );
141+ Log .d ("Samples" ,"[CMAB] calling async decision for cmab..." );
204142 Log .d ("Samples" ,"=================================================================" );
205143 final CountDownLatch latch = new CountDownLatch (1 );
206144 user .decideAsync (flagKey , options , (OptimizelyDecision optDecision ) -> {
207145 Log .d ("Samples" ,"=================================================================" );
208- Log .d ("Samples" ,"[CMAB CDN Datafile ] async decision for cmab: " + optDecision .toString ());
146+ Log .d ("Samples" ,"[CMAB] async decision for cmab: " + optDecision .toString ());
209147 if (!optDecision .getEnabled ()) {
210148 Log .e ("Samples" ,"[ERROR] " + flagKey + " is expected to be enabled for this user!" );
211149 }
@@ -215,11 +153,12 @@ static public void samplesForCmab__cdn_datafile(Context context) {
215153
216154 try {
217155 latch .await (5 , TimeUnit .SECONDS );
218- Log .d ("Samples" , "[CMAB CDN Datafile ] Latch released. Async operation completed." );
156+ Log .d ("Samples" , "[CMAB] Latch released. Async operation completed." );
219157 } catch (InterruptedException e ) {
220158 e .printStackTrace ();
221159 Thread .currentThread ().interrupt ();
222160 }
161+
223162 }
224163
225164 static public void samplesForDecide (Context context ) {
0 commit comments