Search in sources :

Example 6 with MultipleFilterDialect

use of com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect in project elide by yahoo.

the class MultipleFilterDialectTest method testGlobalExpressionParsing.

/**
 * Verify that all dialects are iterated over.
 */
@Test
public void testGlobalExpressionParsing() throws Exception {
    JoinFilterDialect dialect1 = mock(JoinFilterDialect.class);
    JoinFilterDialect dialect2 = mock(JoinFilterDialect.class);
    FilterExpression filterExpression = mock(FilterExpression.class);
    MultipleFilterDialect dialect = new MultipleFilterDialect(Arrays.asList(dialect1, dialect2), Collections.emptyList());
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("filter[author.books.title][in]", "foo,bar,baz");
    queryParams.add("filter[author.name][infix]", "Hemingway");
    when(dialect1.parseGlobalExpression("/author", queryParams, NO_VERSION)).thenThrow(new ParseException(""));
    when(dialect2.parseGlobalExpression("/author", queryParams, NO_VERSION)).thenReturn(filterExpression);
    FilterExpression returnExpression = dialect.parseGlobalExpression("/author", queryParams, NO_VERSION);
    verify(dialect1, times(1)).parseGlobalExpression("/author", queryParams, NO_VERSION);
    verify(dialect2, times(1)).parseGlobalExpression("/author", queryParams, NO_VERSION);
    assertEquals(returnExpression, filterExpression);
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) JoinFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.JoinFilterDialect) Test(org.junit.jupiter.api.Test)

Example 7 with MultipleFilterDialect

use of com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect in project elide by yahoo.

the class MultipleFilterDialectTest method testTypedExpressionParsing.

/**
 * Verify that all dialects are iterated over.
 */
@Test
public void testTypedExpressionParsing() throws Exception {
    SubqueryFilterDialect dialect1 = mock(SubqueryFilterDialect.class);
    SubqueryFilterDialect dialect2 = mock(SubqueryFilterDialect.class);
    Map<String, FilterExpression> expressionMap = Collections.emptyMap();
    MultipleFilterDialect dialect = new MultipleFilterDialect(Collections.emptyList(), Arrays.asList(dialect1, dialect2));
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.add("filter[author.books.title][in]", "foo,bar,baz");
    queryParams.add("filter[author.name][infix]", "Hemingway");
    when(dialect1.parseTypedExpression("/author", queryParams, NO_VERSION)).thenThrow(new ParseException(""));
    when(dialect2.parseTypedExpression("/author", queryParams, NO_VERSION)).thenReturn(expressionMap);
    Map<String, FilterExpression> returnMap = dialect.parseTypedExpression("/author", queryParams, NO_VERSION);
    verify(dialect1, times(1)).parseTypedExpression("/author", queryParams, NO_VERSION);
    verify(dialect2, times(1)).parseTypedExpression("/author", queryParams, NO_VERSION);
    assertEquals(returnMap, expressionMap);
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) SubqueryFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.SubqueryFilterDialect) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 8 with MultipleFilterDialect

use of com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect in project elide by yahoo.

the class StandardTestBinder method configure.

@Override
protected void configure() {
    EntityDictionary dictionary = EntityDictionary.builder().injector(injector::inject).checks(TestCheckMappings.MAPPINGS).build();
    bind(dictionary).to(EntityDictionary.class);
    // Elide instance
    bindFactory(new Factory<Elide>() {

        @Override
        public Elide provide() {
            DefaultFilterDialect defaultFilterStrategy = new DefaultFilterDialect(dictionary);
            RSQLFilterDialect rsqlFilterStrategy = RSQLFilterDialect.builder().dictionary(dictionary).build();
            MultipleFilterDialect multipleFilterStrategy = new MultipleFilterDialect(Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy), Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy));
            Elide elide = new Elide(new ElideSettingsBuilder(IntegrationTest.getDataStore()).withAuditLogger(auditLogger).withJoinFilterDialect(multipleFilterStrategy).withSubqueryFilterDialect(multipleFilterStrategy).withEntityDictionary(dictionary).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", Calendar.getInstance().getTimeZone()).build());
            elide.doScans();
            return elide;
        }

        @Override
        public void dispose(Elide elide) {
        }
    }).to(Elide.class).named("elide");
    bind(BILLING_SERVICE).to(BillingService.class);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) DefaultFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.DefaultFilterDialect) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)

Aggregations

MultipleFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect)8 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)6 Test (org.junit.jupiter.api.Test)6 Elide (com.yahoo.elide.Elide)2 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)2 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)2 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)2 DefaultFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.DefaultFilterDialect)2 JoinFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.JoinFilterDialect)2 SubqueryFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.SubqueryFilterDialect)2 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)2 Invoice (example.models.triggers.Invoice)1 BillingService (example.models.triggers.services.BillingService)1