Search in sources :

Example 36 with QueryParamsBuilder

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

the class EventImportDataValueValidationTests method shouldValidateDataValuesOnUpdate.

@Test
public void shouldValidateDataValuesOnUpdate() {
    programActions.programStageActions.setValidationStrategy(programStageId, "ON_UPDATE_AND_INSERT");
    JsonObject events = eventActions.createEventBody(OU_ID, programId, programStageId);
    ApiResponse response = eventActions.post(events, 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 37 with QueryParamsBuilder

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

the class EnrollmentsTests method shouldAllowFutureEnrollments.

@ParameterizedTest
@ValueSource(strings = { "true", "false " })
public void shouldAllowFutureEnrollments(String shouldAddFutureDays) throws Exception {
    // arrange
    JsonObject object = programActions.get(multipleEnrollmentsProgram).getBodyAsJsonBuilder().addProperty("selectEnrollmentDatesInFuture", shouldAddFutureDays).build();
    programActions.update(multipleEnrollmentsProgram, object).validateStatus(200);
    String teiId = importTei();
    // act
    JsonObject enrollment = new EnrollmentDataBuilder().setTei(teiId).setEnrollmentDate(Instant.now().plus(2, ChronoUnit.DAYS).toString()).addEvent(new EventDataBuilder().setProgram(multipleEnrollmentsProgram).setOu(Constants.ORG_UNIT_IDS[0]).setProgramStage(multipleEnrollmentsProgramStage)).array(multipleEnrollmentsProgram, Constants.ORG_UNIT_IDS[0]);
    // assert
    TrackerApiResponse response = trackerActions.postAndGetJobReport(enrollment, new QueryParamsBuilder().add("async", "false"));
    if (Boolean.parseBoolean(shouldAddFutureDays)) {
        response.validateSuccessfulImport();
        return;
    }
    response.validateErrorReport().body("errorCode", hasSize(1)).body("errorCode", hasItems("E1020"));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with QueryParamsBuilder

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

the class EventIdSchemeTests method eventsShouldBeImportedWithProgramScheme.

@ParameterizedTest
@MethodSource("provideIdSchemeArguments")
public void eventsShouldBeImportedWithProgramScheme(String scheme, String property) throws Exception {
    // arrange
    String programPropertyValue = programActions.get(PROGRAM_ID).extractString(property);
    assertNotNull(programPropertyValue, String.format("Program property %s was not present.", property));
    JsonObject object = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/event.json")).replacePropertyValuesWithIds("event").replacePropertyValuesWith("orgUnit", orgUnitId).replacePropertyValuesWith("program", programPropertyValue).replacePropertyValuesWith("programStage", PROGRAM_STAGE_ID).get(JsonObject.class);
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("programIdScheme=" + scheme));
    // assert
    String eventId = response.validateSuccessfulImport().extractImportedEvents().get(0);
    assertNotNull("Event was not created", eventId);
    trackerActions.get("/events/" + eventId).validate().statusCode(200).body("program", equalTo(PROGRAM_ID));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 39 with QueryParamsBuilder

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

the class EventIdSchemeTests method eventsShouldBeImportedWithOrgUnitScheme.

@ParameterizedTest
@MethodSource("provideIdSchemeArguments")
public void eventsShouldBeImportedWithOrgUnitScheme(String ouScheme, String ouProperty) throws Exception {
    String ouPropertyValue = orgUnitActions.get(orgUnitId).extractString(ouProperty);
    assertNotNull(ouPropertyValue, String.format("Org unit property %s was not present.", ouProperty));
    JsonObject object = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/event.json")).replacePropertyValuesWith("orgUnit", ouPropertyValue).replacePropertyValuesWithIds("event").get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("orgUnitIdScheme=" + ouScheme));
    String eventId = response.validateSuccessfulImport().extractImportedEvents().get(0);
    trackerActions.get("/events/" + eventId).validate().statusCode(200).body("orgUnit", equalTo(orgUnitId));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 40 with QueryParamsBuilder

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

the class EventExportTests method shouldUseCorrectScopeWhenNoOu.

@ParameterizedTest(name = "{0}")
@MethodSource
public void shouldUseCorrectScopeWhenNoOu(String description, String program, List<String> expectedOrgUnits) {
    loginActions.loginAsUser(userName, password);
    QueryParamsBuilder builder = new QueryParamsBuilder();
    if (program != null) {
        builder.add("program", program);
    }
    eventActions.get(builder.build()).validate().statusCode(200).body("events.orgUnit", everyItem(in(expectedOrgUnits)));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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