3030import org .junit .Test ;
3131import org .mockito .Mockito ;
3232
33+ import java .io .IOException ;
34+ import java .nio .charset .StandardCharsets ;
35+ import java .nio .file .Files ;
36+ import java .nio .file .Paths ;
3337import java .util .ArrayList ;
3438import java .util .HashMap ;
3539import java .util .HashSet ;
@@ -533,7 +537,7 @@ public void contains_string() {
533537 }
534538
535539 @ Test
536- public void unsupportedMatcher () {
540+ public void UnsupportedMatcher () {
537541 SplitParser parser = new SplitParser ();
538542 String splitWithUndefinedMatcher = "{\" since\" :-1,\" till\" : 1457726098069,\" splits\" : [{ \" changeNumber\" : 123, \" trafficTypeName\" : \" user\" , \" name\" : \" some_name\" ,"
539543 + "\" trafficAllocation\" : 100, \" trafficAllocationSeed\" : 123456, \" seed\" : 321654, \" status\" : \" ACTIVE\" ,"
@@ -555,6 +559,116 @@ public void unsupportedMatcher() {
555559 }
556560 }
557561
562+ @ Test
563+ public void EqualToSemverMatcher () throws IOException {
564+ SplitParser parser = new SplitParser ();
565+ String splits = new String (Files .readAllBytes (Paths .get ("src/test/resources/semver/semver-splits.json" )), StandardCharsets .UTF_8 );
566+ SplitChange change = Json .fromJson (splits , SplitChange .class );
567+ for (Split split : change .splits ) {
568+ // should not cause exception
569+ ParsedSplit parsedSplit = parser .parse (split );
570+ if (split .name .equals ("semver_equalto" )) {
571+ for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
572+ assertTrue (parsedCondition .label ().equals ("equal to semver" ));
573+ for (AttributeMatcher matcher : parsedCondition .matcher ().attributeMatchers ()) {
574+ // Check the matcher is ALL_KEYS
575+ assertTrue (matcher .matcher ().toString ().equals (" == semver 1\\ .22\\ .9" ));
576+ return ;
577+ }
578+ }
579+ }
580+ }
581+ assertTrue (false );
582+ }
583+
584+ @ Test
585+ public void GreaterThanOrEqualSemverMatcher () throws IOException {
586+ SplitParser parser = new SplitParser ();
587+ String splits = new String (Files .readAllBytes (Paths .get ("src/test/resources/semver/semver-splits.json" )), StandardCharsets .UTF_8 );
588+ SplitChange change = Json .fromJson (splits , SplitChange .class );
589+ for (Split split : change .splits ) {
590+ // should not cause exception
591+ ParsedSplit parsedSplit = parser .parse (split );
592+ if (split .name .equals ("semver_greater_or_equalto" )) {
593+ for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
594+ assertTrue (parsedCondition .label ().equals ("greater than or equal to semver" ));
595+ for (AttributeMatcher matcher : parsedCondition .matcher ().attributeMatchers ()) {
596+ // Check the matcher is ALL_KEYS
597+ assertTrue (matcher .matcher ().toString ().equals (" >= semver 1\\ .22\\ .9" ));
598+ return ;
599+ }
600+ }
601+ }
602+ }
603+ assertTrue (false );
604+ }
605+
606+ @ Test
607+ public void LessThanOrEqualSemverMatcher () throws IOException {
608+ SplitParser parser = new SplitParser ();
609+ String splits = new String (Files .readAllBytes (Paths .get ("src/test/resources/semver/semver-splits.json" )), StandardCharsets .UTF_8 );
610+ SplitChange change = Json .fromJson (splits , SplitChange .class );
611+ for (Split split : change .splits ) {
612+ // should not cause exception
613+ ParsedSplit parsedSplit = parser .parse (split );
614+ if (split .name .equals ("semver_less_or_equalto" )) {
615+ for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
616+ assertTrue (parsedCondition .label ().equals ("less than or equal to semver" ));
617+ for (AttributeMatcher matcher : parsedCondition .matcher ().attributeMatchers ()) {
618+ // Check the matcher is ALL_KEYS
619+ assertTrue (matcher .matcher ().toString ().equals (" <= semver 1\\ .22\\ .9" ));
620+ return ;
621+ }
622+ }
623+ }
624+ }
625+ assertTrue (false );
626+ }
627+
628+ @ Test
629+ public void BetweenSemverMatcher () throws IOException {
630+ SplitParser parser = new SplitParser ();
631+ String splits = new String (Files .readAllBytes (Paths .get ("src/test/resources/semver/semver-splits.json" )), StandardCharsets .UTF_8 );
632+ SplitChange change = Json .fromJson (splits , SplitChange .class );
633+ for (Split split : change .splits ) {
634+ // should not cause exception
635+ ParsedSplit parsedSplit = parser .parse (split );
636+ if (split .name .equals ("semver_between" )) {
637+ for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
638+ assertTrue (parsedCondition .label ().equals ("between semver" ));
639+ for (AttributeMatcher matcher : parsedCondition .matcher ().attributeMatchers ()) {
640+ // Check the matcher is ALL_KEYS
641+ assertTrue (matcher .matcher ().toString ().equals (" between semver 1\\ .22\\ .9 and 2\\ .1\\ .0" ));
642+ return ;
643+ }
644+ }
645+ }
646+ }
647+ assertTrue (false );
648+ }
649+
650+ @ Test
651+ public void InListSemverMatcher () throws IOException {
652+ SplitParser parser = new SplitParser ();
653+ String splits = new String (Files .readAllBytes (Paths .get ("src/test/resources/semver/semver-splits.json" )), StandardCharsets .UTF_8 );
654+ SplitChange change = Json .fromJson (splits , SplitChange .class );
655+ for (Split split : change .splits ) {
656+ // should not cause exception
657+ ParsedSplit parsedSplit = parser .parse (split );
658+ if (split .name .equals ("semver_inlist" )) {
659+ for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
660+ assertTrue (parsedCondition .label ().equals ("in list semver" ));
661+ for (AttributeMatcher matcher : parsedCondition .matcher ().attributeMatchers ()) {
662+ // Check the matcher is ALL_KEYS
663+ assertTrue (matcher .matcher ().toString ().startsWith (" in semver list" ));
664+ return ;
665+ }
666+ }
667+ }
668+ }
669+ assertTrue (false );
670+ }
671+
558672 public void set_matcher_test (Condition c , io .split .engine .matchers .Matcher m ) {
559673
560674// SegmentSynchronizationTask segmentFetcher = new SegmentSynchronizationTaskImp(fetcherMap);
0 commit comments