JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(Constants.EDIT_WORKSPACE,
LanguageCodeConverters.languageCodeToLocale(DEFAULT_LANGUAGE));
FacetField field;
QueryResultWrapper res;
// check facets
res = doQuery(session, "eventsType", "rep:facet(facet.mincount=1)");
checkResultSize(res, 27);
field = res.getFacetField("eventsType");
assertNotNull("Facet field is null",field);
assertNotNull("Facet values are null",field.getValues());
assertEquals("Query did not return correct number of facets", 6, field.getValues().size());
Iterator<FacetField.Count> counts = field.getValues().iterator();
checkFacet(counts.next(), SHOW, 7);
checkFacet(counts.next(), PRESS_CONFERENCE, 6);
checkFacet(counts.next(), CONFERENCE, 5);
checkFacet(counts.next(), ROAD_SHOW, 4);
checkFacet(counts.next(), CONSUMER_SHOW, 3);
checkFacet(counts.next(), MEETING, 2);
for (FacetField.Count count : field.getValues()) {
QueryResultWrapper resCheck = doFilteredQuery(session, "eventsType", count.getName());
checkResultSize(resCheck, (int) count.getCount());
}
for (FacetField.Count count : field.getValues()) {
QueryResultWrapper resCheck = doQuery(session, "rep:filter(eventsType)", count.getAsFilterQuery());
checkResultSize(resCheck, (int) count.getCount());
}
// test facet options : prefix
res = doQuery(session, "eventsType", "rep:facet(facet.mincount=1&prefix=c)");
field = res.getFacetField("eventsType");
assertNotNull("Facet field is null",field);
assertNotNull("Facet values are null",field.getValues());
assertEquals("Query did not return correct number of facet values", 2, field.getValues().size());
counts = field.getValues().iterator();
checkFacet(counts.next(), CONFERENCE, 5);
checkFacet(counts.next(), CONSUMER_SHOW, 3);
for (FacetField.Count count : field.getValues()) {
QueryResultWrapper resCheck = doQuery(session, "rep:filter(eventsType)", count.getAsFilterQuery());
checkResultSize(resCheck, (int) count.getCount());
}
// test facet options : sort=false - lexicographic order
res = doQuery(session, "eventsType", "rep:facet(facet.mincount=1&sort=false)");
field = res.getFacetField("eventsType");
assertNotNull("Facet field is null",field);
assertNotNull("Facet values are null",field.getValues());
assertEquals("Query did not return correct number of facet value", 6, field.getValues().size());
counts = field.getValues().iterator();
checkFacet(counts.next(), CONFERENCE, 5);
checkFacet(counts.next(), CONSUMER_SHOW, 3);
checkFacet(counts.next(), MEETING, 2);
checkFacet(counts.next(), PRESS_CONFERENCE, 6);
checkFacet(counts.next(), ROAD_SHOW, 4);
checkFacet(counts.next(), SHOW, 7);
for (FacetField.Count count : field.getValues()) {
QueryResultWrapper resCheck = doQuery(session, "rep:filter(eventsType)", count.getAsFilterQuery());
checkResultSize(resCheck, (int) count.getCount());
}
}