Search in sources :

Example 66 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class MatchesTemplateVisitorTest method conjunctionContainsTest.

@Test
public void conjunctionContainsTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;highScore==123", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("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);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 67 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class MatchesTemplateVisitorTest method disjunctionDoesNotContainTest.

@Test
public void disjunctionDoesNotContainTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100,player.name==Bob*", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("highScore=={{variable}}", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(0, extractedArgs.size());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 68 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class MatchesTemplateVisitorTest method parameterizedFilterArgumentsIgnored.

@Test
public void parameterizedFilterArgumentsIgnored() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("recordedDate[grain:day]=='2020-01-01'", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("recordedDate=={{day}}", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(1, extractedArgs.size());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 69 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class MatchesTemplateVisitorTest method predicateMismatchTest.

@Test
public void predicateMismatchTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("highScore!=123", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("highScore=={{variable}}", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(0, extractedArgs.size());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 70 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class GraphQLEntityProjectMakerTest method testParameterizedAttributeDefaultValue.

@Test
public void testParameterizedAttributeDefaultValue() {
    String graphQLRequest = document(selection(field("parameterizedExample", selections(field("attribute"))))).toQuery();
    GraphQLEntityProjectionMaker projectionMaker = new GraphQLEntityProjectionMaker(settings);
    GraphQLProjectionInfo projectionInfo = projectionMaker.make(graphQLRequest);
    assertEquals(1, projectionInfo.getProjections().size());
    EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
    // Verify Entity Argument
    assertEquals(1, projection.getArguments().size());
    Argument entityArgument = projection.getArguments().iterator().next();
    assertEquals("entityArgument", entityArgument.getName());
    assertEquals(String.class, entityArgument.getType());
    assertEquals("defaultArgValue", entityArgument.getValue());
    // Verify Attribute Argument
    assertEquals(1, projection.getAttributes().size());
    Attribute attribute = projection.getAttributes().iterator().next();
    assertEquals(1, attribute.getArguments().size());
    Argument argument = attribute.getArguments().iterator().next();
    assertEquals("argument", argument.getName());
    assertEquals(String.class, argument.getType());
    assertEquals("defaultValue", argument.getValue());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) PersistentResourceFetcherTest(com.yahoo.elide.graphql.PersistentResourceFetcherTest) Test(org.junit.jupiter.api.Test)

Aggregations

Argument (com.yahoo.elide.core.request.Argument)71 Test (org.junit.jupiter.api.Test)59 HashMap (java.util.HashMap)48 Query (com.yahoo.elide.datastores.aggregation.query.Query)38 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)35 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)25 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)22 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)15 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)14 HashSet (java.util.HashSet)14 Path (com.yahoo.elide.core.Path)12 ToString (lombok.ToString)12 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)11 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)10 Date (java.util.Date)10 SQLDimensionProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection)9 GameRevenue (example.GameRevenue)7 PlayerStats (example.PlayerStats)6 SQLMetricProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection)5 Month (com.yahoo.elide.datastores.aggregation.timegrains.Month)5