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());
}
}
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));
}
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());
}
}
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));
}
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);
}
Aggregations