use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.
the class ValidationResultServiceTest method assertIllegalQuery.
private void assertIllegalQuery(ErrorCode expected, BiConsumer<ValidationResultQuery, List<String>> operation, String... values) {
ValidationResultQuery query = new ValidationResultQuery();
operation.accept(query, asList(values));
IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> service.getValidationResults(query));
String errorValue = values[values.length - 1];
assertError(ex, expected, errorValue);
ex = assertThrows(IllegalQueryException.class, () -> service.countValidationResults(query));
assertError(ex, expected, errorValue);
}
use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.
the class ValidationResultStoreTest method testQueryWithOrgUnitFilter.
@Test
void testQueryWithOrgUnitFilter() {
save(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC));
// test with superuser so user adds no extra restrictions
setMockUserService(superUserService);
ValidationResultQuery query = new ValidationResultQuery();
// filter on A gives results for A
query.setOu(singletonList(sourceA.getUid()));
assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC), validationResultStore.query(query));
// filter on B gives results for B
query.setOu(singletonList(sourceB.getUid()));
assertEqualSets(asList(validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
// no match case
query.setOu(singletonList(sourceC.getUid()));
assertEqualSets(emptyList(), validationResultStore.query(query));
// case with multiple units
query.setOu(asList(sourceB.getUid(), sourceA.getUid()));
assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
// now we restrict user to only be able to see Bs
setMockUserService(userBService);
// so filtering on As should not give any result
query.setOu(singletonList(sourceA.getUid()));
assertEqualSets(emptyList(), validationResultStore.query(query));
}
use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.
the class ValidationResultStoreHqlTest method queryWithUserWithCategoryAndCategoryOptionGroupSet.
@Test
void queryWithUserWithCategoryAndCategoryOptionGroupSet() {
Category category = new Category();
category.setId(42L);
CategoryOptionGroupSet groupSet = new CategoryOptionGroupSet();
groupSet.setId(42L);
setUpUser("orgUid", category, groupSet);
store.query(new ValidationResultQuery());
assertHQLMatches("from ValidationResult vr where (locate('orgUid',vr.organisationUnit.path) <> 0) and 1 = ...", 988);
}
use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.
the class ValidationResultStoreHqlTest method queryDefaultQuery.
@Test
void queryDefaultQuery() {
store.query(new ValidationResultQuery());
assertHQLMatches("from ValidationResult vr");
}
use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.
the class ValidationResultStoreHqlTest method queryWithOrgUnitAndValidationRuleFilter.
@Test
void queryWithOrgUnitAndValidationRuleFilter() {
ValidationResultQuery query = new ValidationResultQuery();
query.setOu(asList("uid1", "uid2"));
query.setVr(asList("uid3", "uid4"));
store.query(query);
assertHQLMatches("from ValidationResult vr where vr.organisationUnit.uid in :orgUnitsUids and vr.validationRule.uid in :validationRulesUids ");
assertHQLParameter("orgUnitsUids", asList("uid1", "uid2"));
assertHQLParameter("validationRulesUids", asList("uid3", "uid4"));
assertHQLParameterCount(2);
}
Aggregations