use of com.vmware.photon.controller.model.query.QueryUtils.QueryTemplate in project photon-model by vmware.
the class QueryUtilsTest method doTest.
private void doTest(ComputeDescription cd, Set<String> expected, List<String> tenantLinks) {
Query queryForReferrers = QueryUtils.queryForReferrers(cd.documentSelfLink, ComputeState.class, ComputeState.FIELD_NAME_DESCRIPTION_LINK);
// The classes under testing: QueryByPages and QueryTop
List<QueryTemplate<?, ComputeState>> queryStrategies = Arrays.asList(new QueryByPages<>(getHost(), queryForReferrers, ComputeState.class, tenantLinks), new QueryTop<>(getHost(), queryForReferrers, ComputeState.class, tenantLinks));
// Test collectDocuments/queryDocuments/collectLinks/queryLinks per strategy
for (QueryTemplate<?, ComputeState> queryStrategy : queryStrategies) {
for (boolean isDirect : Arrays.asList(true, false)) {
final String msg = queryStrategy.getClass().getSimpleName() + ":" + isDirect;
{
// Test collectDocuments, which internally also tests queryDocuments
DeferredResult<Set<String>> documentLinksDR = queryStrategy.setDirect(isDirect).collectDocuments(mapping(cs -> cs.documentSelfLink, toSet()));
Set<String> actual = waitToComplete(documentLinksDR);
assertThat(msg, actual, equalTo(expected));
}
{
// Test collectLinks, which internally also tests queryLinks
DeferredResult<Set<String>> documentLinksDR = queryStrategy.setDirect(isDirect).collectLinks(toSet());
Set<String> actual = waitToComplete(documentLinksDR);
assertThat(msg, actual, equalTo(expected));
}
}
}
}
Aggregations