Search in sources :

Example 56 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder 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)

Example 57 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class UserAssignmentTests method shouldRemoveUserAssignment.

@Test
public void shouldRemoveUserAssignment() throws Exception {
    // arrange
    String loggedInUser = loginActions.getLoggedInUserId();
    programActions.programStageActions.enableUserAssignment(programStageId, true);
    createEvents(programId, programStageId, loggedInUser);
    JsonObject eventBody = trackerActions.get("/events?program=" + programId + "&assignedUserMode=CURRENT&ouMode=ACCESSIBLE").validateStatus(200).extractJsonObject("instances[0]");
    assertNotNull(eventBody, "no events matching the query.");
    String eventId = eventBody.get("event").getAsString();
    // act
    eventBody.add("assignedUser", null);
    trackerActions.postAndGetJobReport(new JsonObjectBuilder(eventBody).wrapIntoArray("events"), new QueryParamsBuilder().addAll("importStrategy=UPDATE")).validateSuccessfulImport();
    // assert
    trackerActions.getEvent(eventId).validate().body("assignedUser", nullValue());
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class TeiValidationTests method shouldReturnErrorWhenAttributeWithOptionSetInvalid.

@Test
public void shouldReturnErrorWhenAttributeWithOptionSetInvalid() {
    JsonObject trackedEntities = buildTeiWithMandatoryAttribute().addAttribute(attributeWithOptionSet, DataGenerator.randomString()).array();
    trackerActions.postAndGetJobReport(trackedEntities, new QueryParamsBuilder().add("async=false")).validateErrorReport().body("errorCode", hasItem("E1125")).body("trackerType", hasItem("TRACKED_ENTITY"));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 59 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class TeiValidationTests method shouldReturnErrorWhenRemovingMandatoryAttributes.

@Test
public void shouldReturnErrorWhenRemovingMandatoryAttributes() {
    JsonObject object = buildTeiWithEnrollmentAndMandatoryAttributes().array();
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("async=false"));
    String teiId = response.validateSuccessfulImport().extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    JsonObjectBuilder.jsonObject(object).addPropertyByJsonPath("trackedEntities[0].trackedEntity", teiId).addPropertyByJsonPath("trackedEntities[0].attributes[0].value", null).addPropertyByJsonPath("trackedEntities[0].enrollments[0].enrollment", enrollmentId).addPropertyByJsonPath("trackedEntities[0].enrollments[0].attributes[0].value", null);
    trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("async=false")).validateErrorReport().body("", hasSize(2)).body("trackerType", hasItems("TRACKED_ENTITY", "ENROLLMENT")).body("errorCode", hasItems("E1076", "E1076")).body("message", hasItem(allOf(containsStringIgnoringCase("TrackedEntityAttribute"), containsStringIgnoringCase(mandatoryTetAttribute)))).body("message", hasItem(allOf(containsStringIgnoringCase("TrackedEntityAttribute"), containsStringIgnoringCase(mandatoryProgramAttribute))));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 60 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class TeiValidationTests method shouldNotReturnErrorWhenRemovingNotMandatoryAttributes.

@Test
public void shouldNotReturnErrorWhenRemovingNotMandatoryAttributes() {
    JsonObject payload = buildTeiWithMandatoryAndOptionSetAttribute().array();
    String teiId = trackerActions.postAndGetJobReport(payload, new QueryParamsBuilder().add("async=false")).validateSuccessfulImport().extractImportedTeis().get(0);
    JsonObjectBuilder.jsonObject(payload).addPropertyByJsonPath("trackedEntities[0]", "trackedEntity", teiId).addPropertyByJsonPath("trackedEntities[0].attributes[1]", "value", null);
    trackerActions.postAndGetJobReport(payload, new QueryParamsBuilder().add("async=false")).validateSuccessfulImport();
    trackerActions.getTrackedEntity(teiId).validate().body("attributes", hasSize(1));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Aggregations

QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)90 JsonObject (com.google.gson.JsonObject)54 Test (org.junit.jupiter.api.Test)51 ApiResponse (org.hisp.dhis.dto.ApiResponse)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 ApiTest (org.hisp.dhis.ApiTest)27 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)21 File (java.io.File)20 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)20 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)8 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)6 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)5 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)4 JsonArray (com.google.gson.JsonArray)3 HashMap (java.util.HashMap)3 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 ImportSummary (org.hisp.dhis.dto.ImportSummary)3