Search in sources :

Example 11 with QueryParamsBuilder

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

the class MetadataActions method importMetadata.

public MetadataApiResponse importMetadata(File file, String... queryParams) {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll(queryParams);
    queryParamsBuilder.addAll("importReportMode=FULL");
    ApiResponse response = postFile(file, queryParamsBuilder);
    response.validate().statusCode(200);
    return new MetadataApiResponse(response);
}
Also used : MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse)

Example 12 with QueryParamsBuilder

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

the class ImportStrategyTests method shouldDeleteReferencingDataWhenTeiIsDeleted.

@Test
public void shouldDeleteReferencingDataWhenTeiIsDeleted() throws Exception {
    // arrange
    JsonObject body = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teiAndEnrollment.json"));
    TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
    String teiId = response.extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    body.remove("enrollments");
    // act
    response = trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=DELETE")).validateSuccessfulImport();
    // assert
    response.validateSuccessfulImport().validate().body("stats.deleted", Matchers.equalTo(1));
    trackerActions.getTrackedEntity(teiId).validate().statusCode(404);
    trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
}
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) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with QueryParamsBuilder

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

the class ImportStrategyTests method shouldDeleteWithDeleteStrategy.

@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisWithEnrollmentsAndEvents.json", "src/test/resources/tracker/importer/teis/teiAndEnrollment.json", "src/test/resources/tracker/importer/teis/teis.json", "src/test/resources/tracker/importer/events/events.json" })
public void shouldDeleteWithDeleteStrategy(String fileName) throws Exception {
    // arrange
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
    trackerActions.postAndGetJobReport(teiBody).validateSuccessfulImport();
    teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
    // act
    ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add("importStrategy=DELETE"));
    // assert
    response.validate().statusCode(200).body("status", equalTo("OK")).body("stats.deleted", Matchers.greaterThanOrEqualTo(1));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) 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 14 with QueryParamsBuilder

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

the class RuleEngineTests method shouldSendProgramRuleNotification.

@Test
public void shouldSendProgramRuleNotification() {
    JsonObject payload = new EventDataBuilder().addDataValue("ILRgzHhzFkg", "true").addDataValue("z3Z4TD3oBCP", "true").addDataValue("BuZ5LGNfGEU", "40").array(Constants.ORG_UNIT_IDS[0], eventProgramId, "Mt6Ac5brjoK");
    loginActions.loginAsAdmin();
    ApiResponse response = new RestApiActions("/messageConversations").get("", new QueryParamsBuilder().add("fields=*"));
    int size = response.getBody().getAsJsonArray("messageConversations").size();
    loginActions.loginAsSuperUser();
    trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
    loginActions.loginAsAdmin();
    messageConversationsActions.waitForNotification(size + 1);
    messageConversationsActions.get("", new QueryParamsBuilder().add("fields=*")).validate().statusCode(200).body("messageConversations", hasSize(size + 1)).body("messageConversations.subject", hasItem("Program rule triggered"));
}
Also used : RestApiActions(org.hisp.dhis.actions.RestApiActions) EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with QueryParamsBuilder

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

the class RuleEngineTests method shouldShowErrorsBasedOnValidationStrategy.

@ParameterizedTest
@CsvSource({ "ON_COMPLETE,COMPLETED,true", "ON_COMPLETE,ACTIVE,false", "ON_UPDATE_AND_INSERT,ACTIVE,true" })
public void shouldShowErrorsBasedOnValidationStrategy(String validationStrategy, String eventStatus, boolean shouldFail) {
    String programStage = new ProgramStageActions().get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + trackerProgramId, "filter=validationStrategy:eq:" + validationStrategy)).extractString("programStages.id[0]");
    JsonObject payload = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, programStage);
    // program rule is triggered for events with date earlier than today
    new JsonObjectBuilder(payload).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].occurredAt", Instant.now().minus(1, ChronoUnit.DAYS).toString()).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].status", eventStatus);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
    if (shouldFail) {
        response.validateErrorReport();
        return;
    }
    response.validateSuccessfulImport();
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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