@@ -565,7 +565,7 @@ public void attributesWork() {
565565 );
566566
567567 assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ));
568- assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ,
null ));
568+ assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ,
new HashMap <>() ));
569569 assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of ()));
570570 assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of (
"age" ,
10 )));
571571 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of (
"age" ,
9 )));
@@ -599,7 +599,7 @@ public void attributesWork2() {
599599 );
600600
601601 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ));
602- assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
null ));
602+ assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
new HashMap <>() ));
603603 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of ()));
604604
605605 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of (
"age" ,
10 )));
@@ -634,7 +634,7 @@ public void attributesGreaterThanNegativeNumber() {
634634 );
635635
636636 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ));
637- assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
null ));
637+ assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
new HashMap <>() ));
638638 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of ()));
639639 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of (
"age" ,
10 )));
640640 assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of (
"age" , -
20 )));
@@ -671,7 +671,7 @@ public void attributesForSets() {
671671 );
672672
673673 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ));
674- assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
null ));
674+ assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
new HashMap <>() ));
675675
676676 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of ()));
677677 assertEquals (
"off" ,
client .
getTreatment (
"[email protected] " ,
test ,
ImmutableMap .<
String ,
Object >
of (
"products" ,
Lists .
newArrayList ())));
@@ -1894,7 +1894,7 @@ public void testTreatmentsByFlagSet() {
18941894 Map <String , String > getTreatmentResult ;
18951895 for (int i = 0 ; i < numKeys ; i ++) {
18961896 String randomKey = RandomStringUtils .random (10 );
1897- getTreatmentResult = client .getTreatmentsByFlagSet (randomKey , "set1" , null );
1897+ getTreatmentResult = client .getTreatmentsByFlagSet (randomKey , "set1" , new HashMap <>() );
18981898 assertEquals ("on" , getTreatmentResult .get (test ));
18991899 }
19001900 verify (splitCacheConsumer , times (numKeys )).fetchMany (new ArrayList <>(Arrays .asList (test )));
@@ -1927,7 +1927,7 @@ public void testTreatmentsByFlagSetInvalid() {
19271927 new EvaluatorImp (splitCacheConsumer , segmentCacheConsumer ), TELEMETRY_STORAGE , TELEMETRY_STORAGE ,
19281928 flagSetsFilter
19291929 );
1930- assertTrue (client .getTreatmentsByFlagSet (RandomStringUtils .random (10 ), "" , null ).isEmpty ());
1930+ assertTrue (client .getTreatmentsByFlagSet (RandomStringUtils .random (10 ), "" , new HashMap <>() ).isEmpty ());
19311931 }
19321932
19331933 @ Test
@@ -1974,7 +1974,7 @@ public void testTreatmentsByFlagSets() {
19741974 Map <String , String > getTreatmentResult ;
19751975 for (int i = 0 ; i < numKeys ; i ++) {
19761976 String randomKey = RandomStringUtils .random (10 );
1977- getTreatmentResult = client .getTreatmentsByFlagSets (randomKey , Arrays .asList ("set1" , "set3" ), null );
1977+ getTreatmentResult = client .getTreatmentsByFlagSets (randomKey , Arrays .asList ("set1" , "set3" ), new HashMap <>() );
19781978 assertEquals ("on" , getTreatmentResult .get (test ));
19791979 assertEquals ("on" , getTreatmentResult .get (test2 ));
19801980 }
@@ -2081,4 +2081,81 @@ public void treatmentsWorksAndHasConfigFlagSets() {
20812081
20822082 verify (splitCacheConsumer , times (1 )).fetchMany (anyList ());
20832083 }
2084+
2085+ @ Test
2086+ public void impressionPropertiesTest () {
2087+ String test = "test1" ;
2088+
2089+ ParsedCondition age_equal_to_0_should_be_on = new ParsedCondition (ConditionType .ROLLOUT ,
2090+ CombiningMatcher .of ("age" , new EqualToMatcher (-20 , DataType .NUMBER )),
2091+ Lists .newArrayList (partition ("on" , 100 )),
2092+ "foolabel"
2093+ );
2094+
2095+ List <ParsedCondition > conditions = Lists .newArrayList (age_equal_to_0_should_be_on );
2096+ ParsedSplit parsedSplit = ParsedSplit .createParsedSplitForTests (test , 123 , false , Treatments .OFF , conditions , null , 1 , 1 , new HashSet <>(Arrays .asList ("set" )), true );
2097+ Map <String , ParsedSplit > parsedSplits = new HashMap <>();
2098+ parsedSplits .put (test , parsedSplit );
2099+
2100+ SplitCacheConsumer splitCacheConsumer = mock (SplitCacheConsumer .class );
2101+ SegmentCacheConsumer segmentCacheConsumer = mock (SegmentCacheConsumer .class );
2102+ when (splitCacheConsumer .get (test )).thenReturn (parsedSplit );
2103+ when (splitCacheConsumer .fetchMany (Arrays .asList (test ))).thenReturn (parsedSplits );
2104+ Map <String , HashSet <String >> splits = new HashMap <>();
2105+ splits .put ("set" , new HashSet <>(Arrays .asList (test )));
2106+ when (splitCacheConsumer .getNamesByFlagSets (Arrays .asList ("set" ))).thenReturn (splits );
2107+
2108+ SDKReadinessGates gates = mock (SDKReadinessGates .class );
2109+ ImpressionsManager impressionsManager = mock (ImpressionsManager .class );
2110+ SplitClientImpl client = new SplitClientImpl (
2111+ mock (SplitFactory .class ),
2112+ splitCacheConsumer ,
2113+ impressionsManager ,
2114+ NoopEventsStorageImp .create (),
2115+ config ,
2116+ gates ,
2117+ new EvaluatorImp (splitCacheConsumer , segmentCacheConsumer ), TELEMETRY_STORAGE , TELEMETRY_STORAGE ,
2118+ new FlagSetsFilterImpl (new HashSet <>())
2119+ );
2120+ Map <String , Object > attributes = ImmutableMap .<String , Object >of ("age" , -20 , "acv" , "1000000" );
2121+ EvaluationOptions properties = new EvaluationOptions (new HashMap <String , Object >()
2122+ {{
2123+ put ("prop2" , "val2" );
2124+ put ("prop1" , "val1" );
2125+ }});
2126+ Map <String , String > result = new HashMap <>();
2127+ result .put (test , Treatments .ON );
2128+ List <String > split_names = Arrays .asList (test );
2129+
2130+ assertEquals (
"on" ,
client .
getTreatment (
"[email protected] " ,
test ,
attributes ,
properties ));
2131+ assertEquals (
"on" ,
client .
getTreatmentWithConfig (
"[email protected] " ,
test ,
attributes ,
properties ).
treatment ());
2132+ assertEquals (
"on" ,
client .
getTreatments (
"[email protected] " ,
Arrays .
asList (
test ),
attributes ,
properties ).
get (
test ));
2133+ assertEquals (
"on" ,
client .
getTreatmentsWithConfig (
"[email protected] " ,
Arrays .
asList (
test ),
attributes ,
properties ).
get (
test ).
treatment ());
2134+ assertEquals (
"on" ,
client .
getTreatmentsByFlagSet (
"[email protected] " ,
"set" ,
attributes ,
properties ).
get (
test ));
2135+ assertEquals (
"on" ,
client .
getTreatmentsByFlagSets (
"[email protected] " ,
Arrays .
asList (
"set" ),
attributes ,
properties ).
get (
test ));
2136+ assertEquals (
"on" ,
client .
getTreatmentsWithConfigByFlagSet (
"[email protected] " ,
"set" ,
attributes ,
properties ).
get (
test ).
treatment ());
2137+ assertEquals (
"on" ,
client .
getTreatmentsWithConfigByFlagSets (
"[email protected] " ,
Arrays .
asList (
"set" ),
attributes ,
properties ).
get (
test ).
treatment ());
2138+ assertEquals (
"on" ,
client .
getTreatment (
new Key (
"[email protected] " ,
"[email protected] " ),
test ,
attributes ,
properties ));
2139+ assertEquals (
"on" ,
client .
getTreatmentWithConfig (
new Key (
"[email protected] " ,
"[email protected] " ),
test ,
attributes ,
properties ).
treatment ());
2140+ assertEquals (
"on" ,
client .
getTreatments (
new Key (
"[email protected] " ,
"[email protected] " ),
Arrays .
asList (
test ),
attributes ,
properties ).
get (
test ));
2141+ assertEquals (
"on" ,
client .
getTreatmentsWithConfig (
new Key (
"[email protected] " ,
"[email protected] " ),
Arrays .
asList (
test ),
attributes ,
properties ).
get (
test ).
treatment ());
2142+ assertEquals (
"on" ,
client .
getTreatmentsByFlagSet (
new Key (
"[email protected] " ,
"[email protected] " ),
"set" ,
attributes ,
properties ).
get (
test ));
2143+ assertEquals (
"on" ,
client .
getTreatmentsByFlagSets (
new Key (
"[email protected] " ,
"[email protected] " ),
Arrays .
asList (
"set" ),
attributes ,
properties ).
get (
test ));
2144+ assertEquals (
"on" ,
client .
getTreatmentsWithConfigByFlagSet (
new Key (
"[email protected] " ,
"[email protected] " ),
"set" ,
attributes ,
properties ).
get (
test ).
treatment ());
2145+ assertEquals (
"on" ,
client .
getTreatmentsWithConfigByFlagSets (
new Key (
"[email protected] " ,
"[email protected] " ),
Arrays .
asList (
"set" ),
attributes ,
properties ).
get (
test ).
treatment ());
2146+
2147+ ArgumentCaptor <List > impressionCaptor = ArgumentCaptor .forClass (List .class );
2148+ verify (impressionsManager , times (16 )).track (impressionCaptor .capture ());
2149+ assertNotNull (impressionCaptor .getValue ());
2150+
2151+ DecoratedImpression impression = (DecoratedImpression ) impressionCaptor .getAllValues ().get (0 ).get (0 );
2152+ assertEquals (
"[email protected] " ,
impression .
impression ().
key ());
2153+ assertEquals ("{\" prop2\" :\" val2\" ,\" prop1\" :\" val1\" }" , impression .impression ().properties ());
2154+
2155+ for (int i =1 ; i <=15 ; i ++) {
2156+ impression = (DecoratedImpression ) impressionCaptor .getAllValues ().get (i ).get (0 );
2157+ assertEquals ("bilal" + i + "@codigo.com" , impression .impression ().key ());
2158+ assertEquals ("{\" prop2\" :\" val2\" ,\" prop1\" :\" val1\" }" , impression .impression ().properties ());
2159+ }
2160+ }
20842161}
0 commit comments