Search in sources :

Example 1 with ValidationResultQuery

use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.

the class ValidationResultServiceTest method assertLegalQuery.

private void assertLegalQuery(BiConsumer<ValidationResultQuery, List<String>> operation, String... values) {
    ValidationResultQuery query = new ValidationResultQuery();
    operation.accept(query, asList(values));
    assertEquals(emptyList(), service.getValidationResults(query));
    assertEquals(0, service.countValidationResults(query));
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery)

Example 2 with ValidationResultQuery

use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.

the class ValidationResultStoreTest method testQuery.

@Test
void testQuery() throws Exception {
    List<ValidationResult> expected = asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC);
    save(expected);
    ValidationResultQuery query = new ValidationResultQuery();
    setMockUserService(superUserService);
    assertEqualSets(expected, validationResultStore.query(query));
    setMockUserService(userAService);
    assertEqualSets(expected, validationResultStore.query(query));
    setMockUserService(userBService);
    assertEqualSets(asList(validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    setMockUserService(userCService);
    assertEqualSets(singletonList(validationResultBA), validationResultStore.query(query));
    setMockUserService(userDService);
    assertEqualSets(singletonList(validationResultBB), validationResultStore.query(query));
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with ValidationResultQuery

use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.

the class ValidationResultStoreTest method testQueryWithValidationRuleFilter.

@Test
void testQueryWithValidationRuleFilter() {
    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.setVr(singletonList(validationRuleA.getUid()));
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC), validationResultStore.query(query));
    // filter on B gives results for B
    query.setVr(singletonList(validationRuleB.getUid()));
    assertEqualSets(asList(validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    // case with multiple units
    query.setVr(asList(validationRuleA.getUid(), validationRuleB.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.setVr(singletonList(validationRuleA.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 4 with ValidationResultQuery

use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.

the class ValidationResultStoreTest method testQueryWithCreatedDateFilter.

@Test
void testQueryWithCreatedDateFilter() {
    Date beforeA = new Date();
    wait1ms();
    save(asList(validationResultAA, validationResultAB, validationResultAC));
    wait1ms();
    Date beforeB = new Date();
    wait1ms();
    save(asList(validationResultBA, validationResultBB, validationResultBC));
    // B and onwards gives Bs
    ValidationResultQuery query = new ValidationResultQuery();
    query.setCreatedDate(beforeB);
    assertEqualSets(asList(validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    // A and onwards gives As and Bs
    query.setCreatedDate(beforeA);
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    // after A and B onwards => none
    wait1ms();
    query.setCreatedDate(new Date());
    assertEqualSets(emptyList(), validationResultStore.query(query));
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) Date(java.util.Date) LocalDate(java.time.LocalDate) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with ValidationResultQuery

use of org.hisp.dhis.validation.comparator.ValidationResultQuery in project dhis2-core by dhis2.

the class ValidationResultStoreTest method testQueryWithIsoPeriodFilter.

@Test
void testQueryWithIsoPeriodFilter() {
    save(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC));
    // test with superuser so user adds no extra restrictions
    setMockUserService(superUserService);
    ValidationResultQuery query = new ValidationResultQuery();
    // periodA is Jan 2017, periodB is Feb 2017
    // monthly ISO pattern: YYYY-MM
    query.setPe(singletonList("2017-01"));
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC), validationResultStore.query(query));
    query.setPe(asList("2017-01", "2017-02"));
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    // QUARTERLY
    query.setPe(singletonList("2017Q1"));
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    // YEARLY
    query.setPe(singletonList("2017"));
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC, validationResultBA, validationResultBB, validationResultBC), validationResultStore.query(query));
    // WEEKLY
    query.setPe(singletonList("2017W3"));
    assertEqualSets(asList(validationResultAA, validationResultAB, validationResultAC), validationResultStore.query(query));
}
Also used : ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) 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