33import com .google .common .collect .Lists ;
44import com .google .common .collect .Sets ;
55import io .split .client .dtos .ConditionType ;
6+ import io .split .client .dtos .ExcludedSegments ;
67import io .split .client .dtos .MatcherCombiner ;
78import io .split .client .dtos .SplitChange ;
89import io .split .client .utils .Json ;
1516import org .junit .Test ;
1617
1718import java .util .ArrayList ;
19+ import java .util .List ;
1820
1921import static io .split .client .utils .RuleBasedSegmentProcessor .processRuleBasedSegmentChanges ;
2022
2123public class ParsedRuleBasedSegmentTest {
2224
2325 @ Test
2426 public void works () {
27+ List <ExcludedSegments > excludedSegments = new ArrayList <>();
28+ excludedSegments .add (new ExcludedSegments ("standard" ,"segment1" ));
29+ excludedSegments .add (new ExcludedSegments ("standard" ,"segment2" ));
30+
2531 AttributeMatcher segmentMatcher = AttributeMatcher .vanilla (new UserDefinedSegmentMatcher ("employees" ));
2632 CombiningMatcher segmentCombiningMatcher = new CombiningMatcher (MatcherCombiner .AND , Lists .newArrayList (segmentMatcher ));
2733 ParsedRuleBasedSegment parsedRuleBasedSegment = new ParsedRuleBasedSegment ("another_rule_based_segment" ,
28- Lists .newArrayList (new ParsedCondition (ConditionType .WHITELIST , segmentCombiningMatcher , null , "label" )),"user" ,
29- 123 , Lists .newArrayList ("mauro@test.io" ,"gaston@test.io" ), Lists . newArrayList ( "segment1" , "segment2" ) );
34+ Lists .newArrayList (new ParsedCondition (ConditionType .WHITELIST , segmentCombiningMatcher , null , "label" )), "user" ,
35+ 123 , Lists .newArrayList ("mauro@test.io" , "gaston@test.io" ), excludedSegments );
3036
3137 Assert .assertEquals (Sets .newHashSet ("employees" ), parsedRuleBasedSegment .getSegmentsNames ());
3238 Assert .assertEquals ("another_rule_based_segment" , parsedRuleBasedSegment .ruleBasedSegment ());
@@ -48,15 +54,15 @@ public void worksWithoutExcluded() {
4854 Assert .assertTrue (toUpdate .getToAdd ().get (0 ).excludedSegments ().isEmpty ());
4955
5056 load = "{\" ff\" :{\" s\" :-1,\" t\" :-1,\" d\" :[]},\" rbs\" :{\" s\" :-1,\" t\" :1457726098069,\" d\" :[{ \" changeNumber\" : 123, \" trafficTypeName\" : \" user\" , \" name\" : \" some_name\" ,"
51- + "\" status\" : \" ACTIVE\" ,\" excluded\" :{\" segments\" :[\" segment1\" ]},\" conditions\" : [{\" contitionType\" : \" ROLLOUT\" ,"
57+ + "\" status\" : \" ACTIVE\" ,\" excluded\" :{\" segments\" :[{ \" type \" : \" standard \" , \" name \" : \" segment1\" } ]},\" conditions\" : [{\" contitionType\" : \" ROLLOUT\" ,"
5258 + "\" label\" : \" some_label\" , \" matcherGroup\" : { \" matchers\" : [{ \" matcherType\" : \" ALL_KEYS\" , \" negate\" : false}],"
5359 + "\" combiner\" : \" AND\" }}]}]}}" ;
5460 change = Json .fromJson (load , SplitChange .class );
5561 toUpdate = processRuleBasedSegmentChanges (parser , change .ruleBasedSegments .d );
5662 Assert .assertTrue (toUpdate .getToAdd ().get (0 ).excludedKeys ().isEmpty ());
5763
5864 load = "{\" ff\" :{\" s\" :-1,\" t\" :-1,\" d\" :[]},\" rbs\" :{\" s\" :-1,\" t\" :1457726098069,\" d\" :[{ \" changeNumber\" : 123, \" trafficTypeName\" : \" user\" , \" name\" : \" some_name\" ,"
59- + "\" status\" : \" ACTIVE\" ,\" excluded\" :{\" segments\" :[\" segment1\" ], \" keys\" :null},\" conditions\" : [{\" contitionType\" : \" ROLLOUT\" ,"
65+ + "\" status\" : \" ACTIVE\" ,\" excluded\" :{\" segments\" :[{ \" type \" : \" standard \" , \" name \" : \" segment1\" } ], \" keys\" :null},\" conditions\" : [{\" contitionType\" : \" ROLLOUT\" ,"
6066 + "\" label\" : \" some_label\" , \" matcherGroup\" : { \" matchers\" : [{ \" matcherType\" : \" ALL_KEYS\" , \" negate\" : false}],"
6167 + "\" combiner\" : \" AND\" }}]}]}}" ;
6268 change = Json .fromJson (load , SplitChange .class );
0 commit comments