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