-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathParsedRuleBasedSegmentTest.java
More file actions
50 lines (42 loc) · 2.71 KB
/
ParsedRuleBasedSegmentTest.java
File metadata and controls
50 lines (42 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package io.split.engine.experiments;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.split.client.dtos.ConditionType;
import io.split.client.dtos.MatcherCombiner;
import io.split.client.dtos.SplitChange;
import io.split.client.utils.Json;
import io.split.client.utils.RuleBasedSegmentsToUpdate;
import io.split.engine.matchers.AttributeMatcher;
import io.split.engine.matchers.CombiningMatcher;
import io.split.engine.matchers.UserDefinedSegmentMatcher;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import static io.split.client.utils.RuleBasedSegmentProcessor.processRuleBasedSegmentChanges;
public class ParsedRuleBasedSegmentTest {
@Test
public void works() {
AttributeMatcher segmentMatcher = AttributeMatcher.vanilla(new UserDefinedSegmentMatcher("employees"));
CombiningMatcher segmentCombiningMatcher = new CombiningMatcher(MatcherCombiner.AND, Lists.newArrayList(segmentMatcher));
ParsedRuleBasedSegment parsedRuleBasedSegment = new ParsedRuleBasedSegment("another_rule_based_segment",
Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, segmentCombiningMatcher, null, "label")),"user",
123, Lists.newArrayList("mauro@test.io","gaston@test.io"), Lists.newArrayList("segment1", "segment2"));
Assert.assertEquals(Sets.newHashSet("employees"), parsedRuleBasedSegment.getSegmentsNames());
Assert.assertEquals("another_rule_based_segment", parsedRuleBasedSegment.ruleBasedSegment());
Assert.assertEquals(Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, segmentCombiningMatcher, null, "label")),
parsedRuleBasedSegment.parsedConditions());
Assert.assertEquals(123, parsedRuleBasedSegment.changeNumber());
}
@Test
public void worksWithoutExcluded() {
RuleBasedSegmentParser parser = new RuleBasedSegmentParser();
String load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
+ "\"status\": \"ACTIVE\",\"conditions\": [{\"contitionType\": \"ROLLOUT\","
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}],"
+ "\"combiner\": \"AND\"}}]}]}}";
SplitChange change = Json.fromJson(load, SplitChange.class);
RuleBasedSegmentsToUpdate toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedKeys().isEmpty());
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedSegments().isEmpty());
}
}