Search in sources :

Example 71 with ApiResponse

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

the class EventsTests method eventsImportNewEventsFromFile.

@ParameterizedTest
@MethodSource("provideEventFilesTestArguments")
public void eventsImportNewEventsFromFile(String fileName, String contentType) throws Exception {
    Object obj = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/" + fileName)).replacePropertyValuesWithIds("event").get();
    ApiResponse response = trackerActions.post("", contentType, obj, new QueryParamsBuilder().addAll("dryRun=false", "eventIdScheme=UID", "orgUnitIdScheme=UID"));
    response.validate().statusCode(200);
    String jobId = response.extractString("response.id");
    trackerActions.waitUntilJobIsCompleted(jobId);
    response = trackerActions.getJobReport(jobId, "FULL");
    response.validate().statusCode(200).body("status", equalTo("OK"));
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 72 with ApiResponse

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

the class RelationshipsTests method shouldImportRelationshipsToExistingEntities.

@MethodSource("provideRelationshipData")
@ParameterizedTest(name = "{index} {1} to {3}")
public void shouldImportRelationshipsToExistingEntities(String relType, String fromInstance, String fromInstanceId, String toInstance, String toInstanceId) {
    // arrange
    JsonObject relationship = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relType).addObject("from", JsonObjectBuilder.jsonObject().addProperty(fromInstance, fromInstanceId)).addObject("to", JsonObjectBuilder.jsonObject().addProperty(toInstance, toInstanceId)).wrapIntoArray("relationships");
    createdRelationships = trackerActions.postAndGetJobReport(relationship).validateSuccessfulImport().extractImportedRelationships();
    ApiResponse response = trackerActions.get("/relationships/" + createdRelationships.get(0));
    validateRelationship(response, relType, fromInstance, fromInstanceId, toInstance, toInstanceId, createdRelationships.get(0));
    ApiResponse entityResponse = getEntityInRelationship(toInstance, toInstanceId);
    validateRelationship(entityResponse, relType, fromInstance, fromInstanceId, toInstance, toInstanceId, createdRelationships.get(0));
    entityResponse = getEntityInRelationship(fromInstance, fromInstanceId);
    validateRelationship(entityResponse, relType, fromInstance, fromInstanceId, toInstance, toInstanceId, createdRelationships.get(0));
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 73 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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 74 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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 75 with ApiResponse

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

the class RelationshipsTest method before.

@BeforeAll
public void before() throws Exception {
    relationshipActions = new RelationshipActions();
    trackedEntityInstanceActions = new RestApiActions("/trackedEntityInstances");
    metadataActions = new MetadataActions();
    eventActions = new EventActions();
    new LoginActions().loginAsSuperUser();
    metadataActions.importAndValidateMetadata(new File("src/test/resources/tracker/relationshipTypes.json"));
    JsonObject teiObject = new FileReaderUtils().read(new File("src/test/resources/tracker/teis/teis.json")).replacePropertyValuesWithIds("trackedEntityInstance").get(JsonObject.class);
    teis = trackedEntityInstanceActions.post(teiObject).extractUids();
    JsonObject eventObject = new FileReaderUtils().read(new File("src/test/resources/tracker/events/events.json")).replacePropertyValuesWithIds("event").get(JsonObject.class);
    ApiResponse response = eventActions.post(eventObject).validateStatus(200);
    events = response.extractUids();
}
Also used : RestApiActions(org.hisp.dhis.actions.RestApiActions) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) MetadataActions(org.hisp.dhis.actions.metadata.MetadataActions) LoginActions(org.hisp.dhis.actions.LoginActions) RelationshipActions(org.hisp.dhis.actions.tracker.RelationshipActions) EventActions(org.hisp.dhis.actions.tracker.EventActions) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) BeforeAll(org.junit.jupiter.api.BeforeAll)

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