Search in sources :

Example 11 with ValidationResultQuery

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);
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 12 with ValidationResultQuery

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));
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with ValidationResultQuery

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);
}
Also used : Category(org.hisp.dhis.category.Category) ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) Test(org.junit.jupiter.api.Test)

Example 14 with ValidationResultQuery

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");
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) Test(org.junit.jupiter.api.Test)

Example 15 with ValidationResultQuery

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);
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResultQuery (org.hisp.dhis.validation.comparator.ValidationResultQuery)19 Test (org.junit.jupiter.api.Test)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)8 Category (org.hisp.dhis.category.Category)2 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)2 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)1 Period (org.hisp.dhis.period.Period)1 PeriodType (org.hisp.dhis.period.PeriodType)1