Skip to content

Commit a9982a9

Browse files
committed
Added unit test for RBS matcher
1 parent 380bcc3 commit a9982a9

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package io.split.engine.matchers;
2+
3+
import com.google.common.collect.Lists;
4+
import com.google.common.collect.Sets;
5+
import io.split.client.dtos.ConditionType;
6+
import io.split.client.dtos.MatcherCombiner;
7+
import io.split.engine.evaluator.EvaluationContext;
8+
import io.split.engine.evaluator.Evaluator;
9+
import io.split.engine.experiments.ParsedCondition;
10+
import io.split.engine.experiments.ParsedRuleBasedSegment;
11+
import io.split.engine.matchers.strings.WhitelistMatcher;
12+
import io.split.storages.RuleBasedSegmentCache;
13+
import io.split.storages.RuleBasedSegmentCacheConsumer;
14+
import io.split.storages.SegmentCache;
15+
import io.split.storages.memory.RuleBasedSegmentCacheInMemoryImp;
16+
import io.split.storages.memory.SegmentCacheInMemoryImpl;
17+
import org.junit.Test;
18+
import org.mockito.Mockito;
19+
20+
import java.util.Set;
21+
22+
import static org.hamcrest.Matchers.is;
23+
import static org.junit.Assert.assertThat;
24+
25+
public class RuleBasedSegmentMatcherTest {
26+
@Test
27+
public void works() {
28+
Evaluator evaluator = Mockito.mock(Evaluator.class);
29+
SegmentCache segmentCache = new SegmentCacheInMemoryImpl();
30+
RuleBasedSegmentCache ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp();
31+
EvaluationContext evaluationContext = new EvaluationContext(evaluator, segmentCache, ruleBasedSegmentCache);
32+
AttributeMatcher whiteListMatcher = AttributeMatcher.vanilla(new WhitelistMatcher(Lists.newArrayList("test_1", "admin")));
33+
CombiningMatcher whitelistCombiningMatcher = new CombiningMatcher(MatcherCombiner.AND, Lists.newArrayList(whiteListMatcher));
34+
35+
AttributeMatcher ruleBasedSegmentMatcher = AttributeMatcher.vanilla(new RuleBasedSegmentMatcher("sample_rule_based_segment"));
36+
CombiningMatcher ruleBasedSegmentCombinerMatcher = new CombiningMatcher(MatcherCombiner.AND, Lists.newArrayList(ruleBasedSegmentMatcher));
37+
ParsedCondition ruleBasedSegmentCondition = new ParsedCondition(ConditionType.ROLLOUT, ruleBasedSegmentCombinerMatcher, null, "test rbs rule");
38+
ParsedRuleBasedSegment parsedRuleBasedSegment = new ParsedRuleBasedSegment("sample_rule_based_segment",
39+
Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, whitelistCombiningMatcher, null, "whitelist label")),"user",
40+
123, Lists.newArrayList("[email protected]","[email protected]"), Lists.newArrayList());
41+
ruleBasedSegmentCache.update(Lists.newArrayList(parsedRuleBasedSegment), null, 123);
42+
43+
RuleBasedSegmentMatcher matcher = new RuleBasedSegmentMatcher("sample_rule_based_segment");
44+
45+
assertThat(matcher.match("[email protected]", null, null, evaluationContext), is(false));
46+
assertThat(matcher.match("admin", null, null, evaluationContext), is(true));
47+
48+
assertThat(matcher.match("foo", null, null, evaluationContext), is(false));
49+
assertThat(matcher.match(null, null, null, evaluationContext), is(false));
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)