QueryParser { public ParsedQuery<T> parse(Multimap<String, String> uriParams) { return parse(uriParamParser.multimapToMultivaluedMap(uriParams)); } protected  QueryParser(final Class<T> spec, boolean strictMode, MetaQuerySpec<T> meta, UriParamParser uriParamParser); static Builder<T> newBuilder(Class<T> spec); ParsedQuery<T> parse(Multimap<String, String> uriParams); ParsedQuery<T> createEmptyQuery(); ParsedQuery<T> parse(Map<String, List<String>> uriParams); SelectBuilder<T> newSelectBuilder(Multimap<String, String> query); SelectBuilder<T> newSelectBuilder(Map<String, List<String>> query); Class<T> getQueryType(); MetaQuerySpec<T> getMeta(); Collection<String> getOrderableFields();  }
@Test public void itBindsSingleValues() { query.put("id__eq", "1"); query.put("count__gt", "100"); Spec spec = parser.parse(query).getBoundQuery(); assertThat(spec.getId()).isEqualTo(1); assertThat(spec.getCount()).isEqualTo(100L); }
@Test public void itBindsMultipleValues() { query.putAll("id__in", ImmutableList.of("1", "2", "3")); ParsedQuery<Spec> parsedQuery = parser.parse(query); assertThat(StringUtils.normalizeSpace(SelectBuilder.forParsedQuery(parsedQuery).build().getRawSelect().toString())) .isEqualTo("select * from where `id` in ( 1, 2, 3 ) limit 10"); }
@Test public void itBindsCommaDelimitedMultipleValues() { query.put("id__in", "1,2,3"); ParsedQuery<Spec> parsedQuery = parser.parse(query); assertThat(StringUtils.normalizeSpace(SelectBuilder.forParsedQuery(parsedQuery).build().getRawSelect().toString())) .isEqualTo("select * from where `id` in ( 1, 2, 3 ) limit 10"); }
@Test public void itChecksCamelCaseStrategy() { query.put("fullName", "example"); query.put("middle_name", "middle"); Spec spec = parser.parse(query).getBoundQuery(); assertThat(spec.getFullName()).isEqualTo("example"); assertThat(spec.getMiddleName()).isEqualTo("middle"); }
@Test public void itUsesNamingStrategy() { query.put("full_name", "example"); Spec spec = parser.parse(query).getBoundQuery(); assertThat(spec.getFullName()).isEqualTo("example"); }
@Test(expected = FilterViolation.class) public void itDisallowsUnknownFilters() { query.put("secret__eq", "true"); parser.parse(query); }
@Test(expected = FilterViolation.class) public void itDisallowsMissingFilters() { query.put("count__eq", "1"); parser.parse(query); }
@Test(expected = FilterViolation.class) public void itDisallowsInvalidFilters() { query.put("count__something", "1"); parser.parse(query); }
@Test(expected = FilterViolation.class) public void itDisallowsInvalidFilterValues() { query.put("count__gt", "blah"); parser.parse(query); }
@Test(expected = ConstraintViolation.class) public void itRespectsMinLimit() { query.put("limit", "-1"); parser.parse(query); }
@Test(expected = ConstraintViolation.class) public void itRespectsMinOffset() { query.put("offset", "-1"); parser.parse(query); }