Search in sources :

Example 96 with ApiResponse

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

the class UserAssignmentTests method shouldImportEventWithUserAssignment.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void shouldImportEventWithUserAssignment(String userAssignmentEnabled) throws Exception {
    // arrange
    String loggedInUser = loginActions.getLoggedInUserId();
    programActions.programStageActions.enableUserAssignment(programStageId, Boolean.parseBoolean(userAssignmentEnabled));
    // act
    String eventId = createEvents(programId, programStageId, loggedInUser).extractImportedEvents().get(0);
    ApiResponse response = trackerActions.getEvent(eventId);
    if (!Boolean.parseBoolean(userAssignmentEnabled)) {
        response.validate().body("assignedUser", nullValue());
        return;
    }
    response.validate().body("assignedUser", equalTo(loggedInUser));
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 97 with ApiResponse

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

the class TeiImportTests method shouldImportTei.

@Test
public void shouldImportTei() {
    // arrange
    JsonObject trackedEntities = new JsonObjectBuilder().addProperty("trackedEntityType", "Q9GufDoplCL").addProperty("orgUnit", Constants.ORG_UNIT_IDS[0]).wrapIntoArray("trackedEntities");
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
    response.validateSuccessfulImport().validateTeis().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    // assert that the tei was imported
    String teiId = response.extractImportedTeis().get(0);
    ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
    teiResponse.validate().statusCode(200);
    assertThat(teiResponse.getBody(), matchesJSON(trackedEntities.get("trackedEntities").getAsJsonArray().get(0)));
}
Also used : JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 98 with ApiResponse

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

the class PotentialDuplicatesTests method shouldUpdateStatus.

@CsvSource({ "MERGED,INVALID,false", "OPEN,INVALID,true", "OPEN,MERGED,false", "INVALID,OPEN,true", "MERGED,OPEN,false" })
@ParameterizedTest
public void shouldUpdateStatus(String status, String newStatus, boolean shouldUpdate) {
    String duplicateId = potentialDuplicatesActions.createAndValidatePotentialDuplicate(createTei(), createTei(), status);
    ApiResponse response = potentialDuplicatesActions.update(duplicateId + "?status=" + newStatus, new JsonObjectBuilder().build());
    if (shouldUpdate) {
        response.validate().statusCode(200);
        potentialDuplicatesActions.get(duplicateId).validate().statusCode(200).body("status", equalTo(newStatus));
        return;
    }
    response.validate().statusCode(400).body("status", equalTo("ERROR"));
}
Also used : JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 99 with ApiResponse

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

the class EventImportDataValueValidationTests method shouldValidateCompletedOnInsert.

@Test
public void shouldValidateCompletedOnInsert() {
    programActions.programStageActions.setValidationStrategy(programStageId, "ON_UPDATE_AND_INSERT");
    JsonObject event = eventActions.createEventBody(OU_ID, programId, programStageId);
    event.addProperty("status", "COMPLETED");
    ApiResponse response = eventActions.post(event, new QueryParamsBuilder().add("skipCache=true"));
    response.validate().statusCode(409).body("status", equalTo("ERROR")).rootPath("response").body("ignored", equalTo(1)).body("imported", equalTo(0)).body("importSummaries[0].conflicts[0].value", equalTo("value_required_but_not_provided"));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 100 with ApiResponse

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

the class EventImportDataValueValidationTests method shouldImportEventsWithCompulsoryDataValues.

@Test
public void shouldImportEventsWithCompulsoryDataValues() {
    JsonObject events = eventActions.createEventBody(OU_ID, programId, programStageId);
    addDataValue(events, mandatoryDataElementId, "TEXT VALUE");
    ApiResponse response = eventActions.post(events);
    response.validate().statusCode(200).body("status", equalTo("OK")).body("response.imported", equalTo(1));
    String eventID = response.extractString("response.importSummaries.reference[0]");
    assertNotNull(eventID, "Failed to extract eventId");
    eventActions.get(eventID).validate().statusCode(200).body("dataValues", not(Matchers.emptyArray()));
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

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