Search in sources :

Example 1 with JoinFilterDialect

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

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);
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) JoinFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.JoinFilterDialect) Test(org.junit.jupiter.api.Test)

Aggregations

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