Search in sources :

Example 1 with QueryTemplate

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));
            }
        }
    }
}
Also used : QueryTemplate(com.vmware.photon.controller.model.query.QueryUtils.QueryTemplate) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Set(java.util.Set) HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Query(com.vmware.xenon.services.common.QueryTask.Query) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

QueryTemplate (com.vmware.photon.controller.model.query.QueryUtils.QueryTemplate)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 Query (com.vmware.xenon.services.common.QueryTask.Query)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1