Search in sources :

Example 36 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class DataValidatorTest method testGetMissingDataElement.

@Test
void testGetMissingDataElement() {
    final String uid = CodeGenerator.generateUid();
    when(idObjectManager.get(DataElement.class, uid)).thenReturn(null);
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> dataValidator.getAndValidateDataElement(uid));
    assertEquals(ErrorCode.E1100, ex.getErrorCode());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test)

Example 37 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class FilterValidatorTest method testCheckNamesAndOperatorsWhenCombinationIsInvalid.

@Test
void testCheckNamesAndOperatorsWhenCombinationIsInvalid() {
    // Given
    final String invalidCombination = "dimensionItemType:ilike:";
    final Set<String> filters = new HashSet<>(singletonList(invalidCombination));
    // When throws
    final IllegalQueryException thrown = assertThrows(IllegalQueryException.class, () -> checkNamesAndOperators(filters));
    // Then
    assertThat(thrown.getMessage(), containsString("Unable to parse filter `dimensionItemType:ilike:`"));
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Test(org.junit.jupiter.api.Test)

Example 38 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapperTest method verifyCriteriaMappingFailOnMissingProgram.

@Test
void verifyCriteriaMappingFailOnMissingProgram() {
    TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
    criteria.setProgram(programA.getUid() + 'A');
    IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
    assertEquals("Program does not exist: " + programA.getUid() + "A", e.getMessage());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Example 39 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapperTest method verifyCriteriaMappingFailOnMissingAttribute.

@Test
void verifyCriteriaMappingFailOnMissingAttribute() {
    TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
    criteria.setAttribute(newHashSet(attrD.getUid(), attrE.getUid(), "missing"));
    IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
    assertEquals("Attribute does not exist: missing", e.getMessage());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Example 40 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapperTest method testGetFromUrlFailOnNonProvidedAndAssignedUsers.

@Test
void testGetFromUrlFailOnNonProvidedAndAssignedUsers() {
    TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
    criteria.setAssignedUser(userIds);
    criteria.setAssignedUserMode(AssignedUserSelectionMode.CURRENT);
    IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
    assertEquals("Assigned User uid(s) cannot be specified if selectionMode is not PROVIDED", e.getMessage());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Aggregations

IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)98 Test (org.junit.jupiter.api.Test)26 ErrorMessage (org.hisp.dhis.feedback.ErrorMessage)22 HashSet (java.util.HashSet)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)17 User (org.hisp.dhis.user.User)14 QueryItem (org.hisp.dhis.common.QueryItem)13 ArrayList (java.util.ArrayList)12 Date (java.util.Date)11 Program (org.hisp.dhis.program.Program)11 QueryFilter (org.hisp.dhis.common.QueryFilter)10 TrackedEntityInstanceCriteria (org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria)10 Transactional (org.springframework.transaction.annotation.Transactional)10 QueryOperator (org.hisp.dhis.common.QueryOperator)9 List (java.util.List)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)7 Map (java.util.Map)6 Set (java.util.Set)6