Search in sources :

Example 91 with ApiResponse

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

the class RestApiActions method create.

/**
 * Shortcut used in preconditions only. Sends post request to specified
 * endpoint and verifies that request was successful
 *
 * @param object Body of request
 * @return ID of generated entity.
 */
public String create(Object object) {
    ApiResponse response = post(object);
    response.validate().statusCode(is(oneOf(200, 201)));
    return response.extractUid();
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 92 with ApiResponse

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

the class RestApiActions method post.

public ApiResponse post(String resource, String contentType, Object object, QueryParamsBuilder queryParams) {
    String path = queryParams == null ? "" : queryParams.build();
    ApiResponse response = new ApiResponse(this.given().body(object).contentType(contentType).when().post(resource + path));
    saveCreatedObjects(response);
    return response;
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 93 with ApiResponse

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

the class TrackerActions method waitUntilJobIsCompleted.

public ApiResponse waitUntilJobIsCompleted(String jobId) {
    logger.info(String.format("Waiting until tracker job with id %s is completed", jobId));
    ApiResponse response = null;
    boolean completed = false;
    int maxAttempts = 100;
    while (!completed && maxAttempts > 0) {
        response = getJob(jobId);
        response.validate().statusCode(200);
        completed = response.extractList("completed").contains(true);
        maxAttempts--;
    }
    if (maxAttempts == 0) {
        logger.warning(String.format("Tracker job didn't complete in %d. Message: %s", maxAttempts, response.extract("message")));
    }
    logger.info("Tracker job is completed. Message: " + response.extract("message"));
    return response;
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse)

Example 94 with ApiResponse

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

the class EventsTests method shouldImportEvents.

@Test
public void shouldImportEvents() throws Exception {
    JsonObject eventBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/events/events.json"));
    TrackerApiResponse importResponse = trackerActions.postAndGetJobReport(eventBody);
    importResponse.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(4)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    eventBody.getAsJsonArray("events").forEach(event -> {
        String eventId = event.getAsJsonObject().get("event").getAsString();
        ApiResponse response = trackerActions.get("/events/" + eventId);
        response.validate().statusCode(200);
        assertThat(response.getBody(), matchesJSON(event));
    });
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 95 with ApiResponse

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

the class EventsDataValueValidationTests method setupData.

private void setupData() {
    ApiResponse response = programActions.createEventProgram(OU_ID);
    programId = response.extractUid();
    assertNotNull(programId, "Failed to create a program");
    sharingActions.setupSharingForConfiguredUserGroup("program", programId);
    programStageId = programActions.get(programId, new QueryParamsBuilder().add("fields=*")).extractString("programStages.id[0]");
    assertNotNull(programStageId, "Failed to create a programStage");
    ApiResponse dataelements = dataElementActions.get("?fields=id&filter=domainType:eq:TRACKER&filter=valueType:in:[TEXT,LONG_TEXT]&pageSize=2");
    dataelements.validate().body("dataElements", hasSize(2));
    mandatoryDataElementId = dataelements.extractString("dataElements.id[0]");
    notMandatoryDataElementId = dataelements.extractString("dataElements.id[1]");
    programActions.addDataElement(programStageId, mandatoryDataElementId, true).validate().statusCode(200);
    programActions.addDataElement(programStageId, notMandatoryDataElementId, false).validate().statusCode(200);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) 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