Search in sources :

Example 1 with SubqueryFilterDialect

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());
    }
}
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 2 with SubqueryFilterDialect

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

Aggregations

MultipleFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect)2 SubqueryFilterDialect (com.yahoo.elide.core.filter.dialect.jsonapi.SubqueryFilterDialect)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 Test (org.junit.jupiter.api.Test)2 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)1