Search in sources :

Example 56 with ApiResponse

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

the class MetadataImportImportStrategyTests method shouldUpdateMetadataByIdentifier.

@ValueSource(strings = { "CODE", "UID" })
@ParameterizedTest
public void shouldUpdateMetadataByIdentifier(String identifier) throws IOException {
    JsonObject ob = new JsonFileReader(new File("src/test/resources/setup/metadata.json")).get(JsonObject.class);
    ApiResponse response = metadataActions.importMetadata(ob, "identifier=" + identifier);
    response.validate().statusCode(200).body("stats.updated", equalTo(response.extract("stats.total")));
}
Also used : JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) JsonFileReader(org.hisp.dhis.helpers.file.JsonFileReader) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with ApiResponse

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

the class TeiImportTests method shouldImportTeiWithAttributes.

@Test
public void shouldImportTeiWithAttributes() throws Exception {
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/tei.json"));
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(teiBody);
    // assert
    response.validateSuccessfulImport().validateTeis().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
    // assert that the TEI was imported
    String teiId = response.extractImportedTeis().get(0);
    ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
    teiResponse.validate().statusCode(200);
    assertThat(teiResponse.getBody(), matchesJSON(teiBody.get("trackedEntities").getAsJsonArray().get(0)));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 58 with ApiResponse

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

the class TeiImportTests method shouldImportTeisWithEnrollmentsEventsAndRelationship.

@Test
public void shouldImportTeisWithEnrollmentsEventsAndRelationship() throws Exception {
    // the file contains 2 teis with 1 enrollment and 1 event each
    JsonObject teiPayload = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teisWithEnrollmentsAndEvents.json"));
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(teiPayload);
    response.validateSuccessfulImport().validate().body("stats.created", equalTo(7)).rootPath("bundleReport.typeReportMap").body("TRACKED_ENTITY.objectReports", hasSize(2)).body("ENROLLMENT.objectReports", hasSize(2)).body("EVENT.objectReports", hasSize(2)).body("RELATIONSHIP.objectReports", hasSize(1));
    JsonObject teiBody = teiPayload.get("trackedEntities").getAsJsonArray().get(0).getAsJsonObject();
    ApiResponse trackedEntityResponse = trackerActions.getTrackedEntity(teiBody.get("trackedEntity").getAsString() + "?fields=*").validateStatus(200);
    assertThat(trackedEntityResponse.getBody(), matchesJSON(teiBody));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 59 with ApiResponse

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

the class TeiImportTests method shouldImportTeiAndEnrollmentWithAttributes.

@Test
public void shouldImportTeiAndEnrollmentWithAttributes() throws Exception {
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teiWithEnrollmentAndAttributes.json"));
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(teiBody);
    // assert
    response.validateSuccessfulImport().validate().body("stats.created", equalTo(2)).rootPath("bundleReport.typeReportMap").body("TRACKED_ENTITY.objectReports", hasSize(1)).body("ENROLLMENT.objectReports", hasSize(1));
    // assert that the TEI was imported
    String teiId = response.extractImportedTeis().get(0);
    ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
    teiResponse.validate().statusCode(200);
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 60 with ApiResponse

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

the class PotentialDuplicatesTests method shouldFilterByStatus.

@ParameterizedTest
@ValueSource(strings = { "OPEN", "INVALID", "MERGED" })
public void shouldFilterByStatus(String status) {
    String teiA = createTei();
    String teiB = createTei();
    potentialDuplicatesActions.createPotentialDuplicate(teiA, teiB, status).validate().statusCode(200);
    ApiResponse response = potentialDuplicatesActions.get("", new QueryParamsBuilder().add("status=" + status));
    response.validate().body("identifiableObjects", hasSize(greaterThanOrEqualTo(1))).body("identifiableObjects.status", everyItem(equalTo(status)));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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