Search in sources :

Example 26 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class DataItemQueryTests method testFilterUsingInvalidDimensionTypeUsingDefaultPagination.

@Test
public void testFilterUsingInvalidDimensionTypeUsingDefaultPagination() {
    // Given
    final String anyInvalidDimensionType = "INVALID_TYPE";
    final String theUrlParams = "?filter=dimensionItemType:in:[%s]";
    // When
    final ApiResponse response = dataItemActions.get(format(theUrlParams, anyInvalidDimensionType));
    // Then
    response.validate().statusCode(is(CONFLICT));
    response.validate().body("pager", is(nullValue()));
    response.validate().body("httpStatus", is("Conflict"));
    response.validate().body("httpStatusCode", is(CONFLICT));
    response.validate().body("status", is("ERROR"));
    response.validate().body("errorCode", is("E2016"));
    response.validate().body("message", containsString("Unable to parse element `" + anyInvalidDimensionType + "` on filter `dimensionItemType`. The values available are:"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 27 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class DataItemQueryTests method testGetAllDataItemsUsingDefaultPaginationOrderedByCode.

@Test
public void testGetAllDataItemsUsingDefaultPaginationOrderedByCode() {
    // When
    final ApiResponse response = dataItemActions.get("?order=name:asc");
    // Then
    response.validate().statusCode(is(OK));
    response.validate().body("pager", isA(Object.class));
    response.validate().body("dataItems", is(not(empty())));
    response.validate().body("dataItems.code", hasItem("AAAAAAA-1234"));
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 28 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class DataItemQueryTests method testFilterByProgramUsingNonexistentAttributeAndDefaultPagination.

@Test
public void testFilterByProgramUsingNonexistentAttributeAndDefaultPagination() {
    // Given
    final String theDimensionType = "PROGRAM_INDICATOR";
    final String theProgramId = Constants.EVENT_PROGRAM_ID;
    final String aNonExistingAttr = "nonExistingAttr";
    final String theUrlParams = "?filter=dimensionItemType:in:[%s]&filter=" + aNonExistingAttr + ":eq:%s&order=code:asc";
    // When
    final ApiResponse response = dataItemActions.get(format(theUrlParams, theDimensionType, theProgramId));
    // Then
    response.validate().statusCode(is(CONFLICT));
    response.validate().body("pager", is(nullValue()));
    response.validate().body("httpStatus", is("Conflict"));
    response.validate().body("httpStatusCode", is(CONFLICT));
    response.validate().body("status", is("ERROR"));
    response.validate().body("errorCode", is("E2034"));
    response.validate().body("message", containsString("Filter not supported: `" + aNonExistingAttr + "`"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 29 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class TestCleanUp method deleteEntity.

public boolean deleteEntity(String resource, String id) {
    ApiResponse response = new RestApiActions(resource).delete(id + "?force=true");
    if (response.statusCode() == 200 || response.statusCode() == 404) {
        logger.info(String.format("Entity from resource %s with id %s deleted", resource, id));
        if (response.containsImportSummaries()) {
            return response.extract("response.importCount.deleted").equals(1);
        }
        return true;
    }
    logger.warning(String.format("Entity from resource %s with id %s was not deleted. Status code: %s", resource, id, response.statusCode()));
    return false;
}
Also used : RestApiActions(org.hisp.dhis.actions.RestApiActions) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 30 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class TrackerActions method getJobReport.

public TrackerApiResponse getJobReport(String jobId, String reportMode) {
    ApiResponse response = this.get(String.format("/jobs/%s/report?reportMode=%s", jobId, reportMode));
    // add created entities
    saveCreatedData(response);
    return new TrackerApiResponse(response);
}
Also used : TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse)

Aggregations

ApiResponse (org.hisp.dhis.dto.ApiResponse)145 Test (org.junit.jupiter.api.Test)75 JsonObject (com.google.gson.JsonObject)63 ApiTest (org.hisp.dhis.ApiTest)63 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)48 File (java.io.File)25 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)18 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)18 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)14 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)11 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)11 RestApiActions (org.hisp.dhis.actions.RestApiActions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 JsonArray (com.google.gson.JsonArray)5 ImportSummary (org.hisp.dhis.dto.ImportSummary)5 LoginActions (org.hisp.dhis.actions.LoginActions)4 MetadataApiResponse (org.hisp.dhis.dto.MetadataApiResponse)4 ArrayList (java.util.ArrayList)3