use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class MatchesTemplateVisitorTest method conjunctionMatchesTest.
@Test
public void conjunctionMatchesTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;highScore==123", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("lowScore>100;highScore=={{variable}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
Argument expected = Argument.builder().name("variable").value(123L).build();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(1, extractedArgs.size());
assertEquals(extractedArgs.get("variable"), expected);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class MatchesTemplateVisitorTest method mulipleConjunctionOrderTest.
@Test
public void mulipleConjunctionOrderTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;(highScore>=100;highScore<999)", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore>={{low}};highScore<{{high}}", playerStatsType, false, true);
Argument expected1 = Argument.builder().name("low").value(100L).build();
Argument expected2 = Argument.builder().name("high").value(999L).build();
Map<String, Argument> extractedArgs = new HashMap<>();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(2, extractedArgs.size());
assertEquals(extractedArgs.get("low"), expected1);
assertEquals(extractedArgs.get("high"), expected2);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class MatchesTemplateVisitorTest method parameterizedFilterArgumentsDoNotMatch.
@Test
public void parameterizedFilterArgumentsDoNotMatch() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("recordedDate[grain:day]=='2020-01-01'", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("recordedDate[grain:month]=={{day}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(0, extractedArgs.size());
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class MatchesTemplateVisitorTest method predicateWithAliasMatchesTest.
@Test
public void predicateWithAliasMatchesTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
Attribute attribute = Attribute.builder().type(ClassType.of(Long.class)).name("highScore").alias("myScore").build();
FilterExpression templateExpression = dialect.parseFilterExpression("myScore=={{foo}}", playerStatsType, false, true, Set.of(attribute));
Map<String, Argument> extractedArgs = new HashMap<>();
Argument expected = Argument.builder().name("foo").value(123L).build();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(1, extractedArgs.size());
assertEquals(extractedArgs.get("foo"), expected);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class MatchesTemplateVisitorTest method predicateMatchWithoutTemplateTest.
@Test
public void predicateMatchWithoutTemplateTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(0, extractedArgs.size());
}
Aggregations