use of com.yahoo.elide.core.filter.dialect.jsonapi.SubqueryFilterDialect 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.SubqueryFilterDialect 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);
}
Aggregations