2626import java .nio .charset .StandardCharsets ;
2727import java .nio .file .Files ;
2828import java .nio .file .Paths ;
29+ import java .util .ArrayList ;
30+ import java .util .Arrays ;
2931import java .util .HashMap ;
3032import java .util .Set ;
3133
@@ -61,7 +63,7 @@ public void works() {
6163 }
6264
6365 @ Test
64- public void usingRbsWithinExcludedTest () throws IOException {
66+ public void usingRbsInConditionTest () throws IOException {
6567 String load = new String (Files .readAllBytes (Paths .get ("src/test/resources/rule_base_segments.json" )), StandardCharsets .UTF_8 );
6668 Evaluator evaluator = Mockito .mock (Evaluator .class );
6769 SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
@@ -83,4 +85,57 @@ public void usingRbsWithinExcludedTest() throws IOException {
8385 assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib1 ,
evaluationContext ),
is (
false ));
8486 assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib2 ,
evaluationContext ),
is (
true ));
8587 }
88+
89+ @ Test
90+ public void usingSegmentInExcludedTest () throws IOException {
91+ String load = new String (Files .readAllBytes (Paths .get ("src/test/resources/rule_base_segments3.json" )), StandardCharsets .UTF_8 );
92+ Evaluator evaluator = Mockito .mock (Evaluator .class );
93+ SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
94+ segmentCache .
updateSegment (
"segment1" ,
Arrays .
asList (
"[email protected] " ),
new ArrayList <>(),
123 );
95+ RuleBasedSegmentCache ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp ();
96+ EvaluationContext evaluationContext = new EvaluationContext (evaluator , segmentCache , ruleBasedSegmentCache );
97+
98+ SplitChange change = Json .fromJson (load , SplitChange .class );
99+ RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser ();
100+ RuleBasedSegmentsToUpdate ruleBasedSegmentsToUpdate = processRuleBasedSegmentChanges (ruleBasedSegmentParser ,
101+ change .ruleBasedSegments .d );
102+ ruleBasedSegmentCache .update (ruleBasedSegmentsToUpdate .getToAdd (), null , 123 );
103+ RuleBasedSegmentMatcher matcher = new RuleBasedSegmentMatcher ("sample_rule_based_segment" );
104+ HashMap <String , Object > attrib1 = new HashMap <String , Object >() {{
105+ put (
"email" ,
"[email protected] " );
106+ }};
107+ HashMap <String , Object > attrib2 = new HashMap <String , Object >() {{
108+ put (
"email" ,
"[email protected] " );
109+ }};
110+ HashMap <String , Object > attrib3 = new HashMap <String , Object >() {{
111+ put (
"email" ,
"[email protected] " );
112+ }};
113+ assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib1 ,
evaluationContext ),
is (
false ));
114+ assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib2 ,
evaluationContext ),
is (
false ));
115+ assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib3 ,
evaluationContext ),
is (
true ));
116+ }
117+
118+ @ Test
119+ public void usingRbsInExcludedTest () throws IOException {
120+ String load = new String (Files .readAllBytes (Paths .get ("src/test/resources/rule_base_segments2.json" )), StandardCharsets .UTF_8 );
121+ Evaluator evaluator = Mockito .mock (Evaluator .class );
122+ SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
123+ RuleBasedSegmentCache ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp ();
124+ EvaluationContext evaluationContext = new EvaluationContext (evaluator , segmentCache , ruleBasedSegmentCache );
125+
126+ SplitChange change = Json .fromJson (load , SplitChange .class );
127+ RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser ();
128+ RuleBasedSegmentsToUpdate ruleBasedSegmentsToUpdate = processRuleBasedSegmentChanges (ruleBasedSegmentParser ,
129+ change .ruleBasedSegments .d );
130+ ruleBasedSegmentCache .update (ruleBasedSegmentsToUpdate .getToAdd (), null , 123 );
131+ RuleBasedSegmentMatcher matcher = new RuleBasedSegmentMatcher ("no_excludes" );
132+ HashMap <String , Object > attrib1 = new HashMap <String , Object >() {{
133+ put (
"email" ,
"[email protected] " );
134+ }};
135+ HashMap <String , Object > attrib2 = new HashMap <String , Object >() {{
136+ put (
"email" ,
"[email protected] " );
137+ }};
138+ assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib1 ,
evaluationContext ),
is (
true ));
139+ assertThat (
matcher .
match (
"[email protected] " ,
null ,
attrib2 ,
evaluationContext ),
is (
true ));
140+ }
86141}
0 commit comments