Search in sources :

Example 46 with QueryParamsBuilder

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

the class RelationshipsTests method shouldDeleteRelationshipWithDeleteStrategy.

@Test
public void shouldDeleteRelationshipWithDeleteStrategy() {
    // arrage
    TrackerApiResponse response = trackerActions.postAndGetJobReport(new File("src/test/resources/tracker/importer/teis/teisAndRelationship.json")).validateSuccessfulImport();
    List<String> teis = response.extractImportedTeis();
    String relationship = response.extractImportedRelationships().get(0);
    JsonObject obj = new JsonObjectBuilder().addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).addProperty("relationshipType", relationshipType).addProperty("relationship", relationship).wrapIntoArray("relationships");
    // act
    response = trackerActions.postAndGetJobReport(obj, new QueryParamsBuilder().add("importStrategy=DELETE"));
    // assert
    response.validate().body("status", equalTo("OK")).body("stats.deleted", equalTo(1));
    trackerActions.get("/relationships/" + relationship).validate().statusCode(404);
    trackerActions.getTrackedEntity(teis.get(0) + "?fields=relationships").validate().body("relationships", Matchers.empty());
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) File(java.io.File) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with QueryParamsBuilder

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

the class TeiUpdateTests method shouldUpdateWithUpdateStrategy.

@Test
public void shouldUpdateWithUpdateStrategy() throws Exception {
    // arrange
    String teiId = importTei();
    JsonObject teiBody = trackerActions.getTrackedEntity(teiId).getBody();
    teiBody = JsonObjectBuilder.jsonObject(teiBody).addProperty("trackedEntity", teiId).wrapIntoArray("trackedEntities");
    // act
    ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add("importStrategy=UPDATE"));
    // assert
    response.validate().statusCode(200).body("status", equalTo("OK")).body("stats.updated", equalTo(1));
}
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) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with QueryParamsBuilder

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

the class TeiUpdateTests method shouldReturnErrorWhenTeiDoesntExist.

@ParameterizedTest
@ValueSource(strings = { "UPDATE", "DELETE" })
public void shouldReturnErrorWhenTeiDoesntExist(String importStrategy) throws Exception {
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/tei.json"));
    ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add(String.format("importStrategy=%s", importStrategy)));
    response.validate().statusCode(200).body("status", equalTo("ERROR")).body("stats.ignored", equalTo(1)).body("validationReport.errorReports", notNullValue()).rootPath("validationReport.errorReports[0]").body("errorCode", equalTo("E1063")).body("message", containsStringIgnoringCase("does not exist"));
}
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) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with QueryParamsBuilder

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

the class DataImportTest method dataValuesCanBeImportedAsync.

@Test
public void dataValuesCanBeImportedAsync() {
    ApiResponse response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_bulk.json"), new QueryParamsBuilder().addAll("reportMode=DEBUG", "async=true")).validateStatus(200);
    String taskId = response.extractString("response.id");
    // Validate that job was successful
    systemActions.waitUntilTaskCompleted("DATAVALUE_IMPORT", taskId).validate().body("message", Matchers.containsInAnyOrder("Process started", "Importing data values", "Import done"));
    // validate task summaries were created
    ApiResponse taskSummariesResponse = systemActions.waitForTaskSummaries("DATAVALUE_IMPORT", taskId);
    taskSummariesResponse.validate().statusCode(200).body("status", equalTo("SUCCESS")).rootPath("importCount").body("deleted", equalTo(0)).body("ignored", equalTo(0));
    ImportSummary importSummary = taskSummariesResponse.getImportSummaries().get(0);
    assertThat(taskSummariesResponse.getAsString(), importSummary.getImportCount().getImported() + importSummary.getImportCount().getUpdated(), greaterThan(0));
}
Also used : ImportSummary(org.hisp.dhis.dto.ImportSummary) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 50 with QueryParamsBuilder

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

the class SharingActions method setupSharingForConfiguredUserGroup.

public void setupSharingForConfiguredUserGroup(String type, String id) {
    JsonObject jsonObject = this.get(new QueryParamsBuilder().add("type=" + type).add("id=" + id).build()).getBody();
    jsonObject.add("object", JsonObjectBuilder.jsonObject().addProperty("publicAccess", "--------").addUserGroupAccess().build());
    this.post(jsonObject, new QueryParamsBuilder().add("type=" + type).add("id=" + id)).validate().statusCode(200);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject)

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