Search in sources :

Example 1 with MultipleFilterDialect

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

the class MultipleFilterDialectTest method testGlobalExpressionParseFailure.

/**
 * Verify that the last error is returned when all dialects fail.
 */
@Test
public void testGlobalExpressionParseFailure() throws Exception {
    JoinFilterDialect dialect1 = mock(JoinFilterDialect.class);
    JoinFilterDialect dialect2 = mock(JoinFilterDialect.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("one"));
    when(dialect2.parseGlobalExpression("/author", queryParams, NO_VERSION)).thenThrow(new ParseException("two"));
    try {
        dialect.parseGlobalExpression("/author", queryParams, NO_VERSION);
    } catch (ParseException e) {
        assertEquals("two\none", e.getMessage());
    }
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) JoinFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.JoinFilterDialect) Test(org.junit.jupiter.api.Test)

Example 2 with MultipleFilterDialect

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

the class MultipleFilterDialectTest method testMissingGlobalDialect.

/**
 * Verify that missing dialects throws a ParseException
 */
@Test
public void testMissingGlobalDialect() throws Exception {
    MultipleFilterDialect dialect = new MultipleFilterDialect(Collections.emptyList(), 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");
    assertThrows(ParseException.class, () -> dialect.parseGlobalExpression("/author", queryParams, NO_VERSION));
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) Test(org.junit.jupiter.api.Test)

Example 3 with MultipleFilterDialect

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

the class MultipleFilterDialectTest method testTypedExpressionParseFailure.

/**
 * Verify that the last error is returned when all dialects fail.
 */
@Test
public void testTypedExpressionParseFailure() throws Exception {
    SubqueryFilterDialect dialect1 = mock(SubqueryFilterDialect.class);
    SubqueryFilterDialect dialect2 = mock(SubqueryFilterDialect.class);
    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("one"));
    when(dialect2.parseTypedExpression("/author", queryParams, NO_VERSION)).thenThrow(new ParseException("two"));
    try {
        dialect.parseTypedExpression("/author", queryParams, NO_VERSION);
    } catch (ParseException e) {
        assertEquals("two\none", e.getMessage());
    }
}
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) Test(org.junit.jupiter.api.Test)

Example 4 with MultipleFilterDialect

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

the class MultipleFilterDialectTest method testMissingTypedDialect.

/**
 * Verify that missing dialects throws a ParseException
 */
@Test
public void testMissingTypedDialect() throws Exception {
    MultipleFilterDialect dialect = new MultipleFilterDialect(Collections.emptyList(), 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");
    assertThrows(ParseException.class, () -> dialect.parseTypedExpression("/author", queryParams, NO_VERSION));
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) Test(org.junit.jupiter.api.Test)

Example 5 with MultipleFilterDialect

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

the class VerboseErrorResponsesTestBinder 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(getDataStore()).withAuditLogger(auditLogger).withJoinFilterDialect(multipleFilterStrategy).withSubqueryFilterDialect(multipleFilterStrategy).withEntityDictionary(dictionary).withVerboseErrors().build());
            elide.doScans();
            return elide;
        }

        @Override
        public void dispose(Elide elide) {
        // do nothing
        }
    }).to(Elide.class).named("elide");
    bind(new BillingService() {

        @Override
        public long purchase(Invoice invoice) {
            return 0;
        }
    }).to(BillingService.class);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Invoice(example.models.triggers.Invoice) 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) BillingService(example.models.triggers.services.BillingService)

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