Search in sources :

Example 66 with ApiResponse

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

the class UserLookupTests method shouldLookupUserByEmail.

@ParameterizedTest
@ValueSource(strings = { "taadmin@", "@dhis2.org", "tasuperuser@dhis2.org" })
public void shouldLookupUserByEmail(String query) {
    ApiResponse response = lookupActions.get("?query=" + query);
    response.validate().statusCode(200).body("users", hasSize(greaterThan(0)));
    List<String> users = response.extractList("users.id");
    users.forEach(user -> {
        userActions.get(user).validate().statusCode(200).body("email", containsStringIgnoringCase(query));
    });
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with ApiResponse

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

the class EnrollmentsTests method shouldImportEnrollmentToExistingTei.

@Test
public void shouldImportEnrollmentToExistingTei() throws Exception {
    String teiId = importTei();
    JsonObject enrollmentPayload = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/enrollments/enrollment.json")).replacePropertyValuesWith("trackedEntity", teiId).get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(enrollmentPayload);
    response.validateSuccessfulImport().validateEnrollments().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports.uid", notNullValue());
    String enrollmentId = response.extractImportedEnrollments().get(0);
    ApiResponse enrollmentResponse = trackerActions.get("/enrollments/" + enrollmentId);
    assertThat(enrollmentResponse.getBody(), matchesJSON(enrollmentPayload.get("enrollments").getAsJsonArray().get(0).getAsJsonObject()));
}
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) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 68 with ApiResponse

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

the class EventExportTests method shouldReturnSingleEvent.

@ParameterizedTest(name = "[{0}]")
@MethodSource
public void shouldReturnSingleEvent(String description, String eventId, Boolean shouldGet) {
    loginActions.loginAsUser(userName, password);
    ApiResponse response = eventActions.get(eventId);
    if (shouldGet) {
        response.validate().statusCode(200);
        return;
    }
    response.validate().statusCode(409);
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 69 with ApiResponse

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

the class EventExportTests method shouldSkipRelationshipsForEventId.

@ValueSource(strings = { "?event=eventId", "?event=eventId&fields=*,!relationships", "?program=programId&fields=*,!relationships" })
@ParameterizedTest
public void shouldSkipRelationshipsForEventId(String queryParams) {
    ApiResponse response = eventActions.get(queryParams.replace("eventId", events.get(captureOu)).replace("programId", withoutRegistrationProgram));
    String body = "relationships";
    if (response.extractList("events") != null) {
        body = "events[0].relationships";
    }
    response.validate().body(body, anyOf(nullValue(), hasSize(0)));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 70 with ApiResponse

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

the class TEIimportTest method teisShouldBeUpdatedAndDeletedInBulk.

@Test
public void teisShouldBeUpdatedAndDeletedInBulk() {
    // arrange
    JsonArray teis = object.getAsJsonArray("trackedEntityInstances");
    JsonObject tei1event = teis.get(0).getAsJsonObject().getAsJsonArray("enrollments").get(0).getAsJsonObject().getAsJsonArray("events").get(0).getAsJsonObject();
    JsonObject tei2enrollment = teis.get(1).getAsJsonObject().getAsJsonArray("enrollments").get(0).getAsJsonObject();
    tei1event.addProperty("deleted", true);
    tei2enrollment.addProperty("status", "COMPLETED");
    // act
    ApiResponse response = teiActions.post(object, new QueryParamsBuilder().addAll("strategy=SYNC"));
    // assert
    String eventId = response.validate().statusCode(200).body("response", notNullValue()).rootPath("response").body("updated", Matchers.greaterThanOrEqualTo(2)).appendRootPath("importSummaries[0]").body("importCount.updated", greaterThanOrEqualTo(1)).appendRootPath("enrollments.importSummaries[0].events.importSummaries[0]").body("status", Matchers.equalTo("SUCCESS"), "reference", notNullValue(), "importCount.deleted", Matchers.equalTo(1), "description", Matchers.stringContainsInOrder("Deletion of event", "was successful")).extract().path("response.importSummaries[0].enrollments.importSummaries[0].events.importSummaries[0].reference");
    String enrollmentId = response.validate().rootPath("response.importSummaries[1].enrollments.importSummaries[0]").body("status", Matchers.equalTo("SUCCESS"), "reference", notNullValue(), "importCount.updated", Matchers.equalTo(1)).extract().path("response.importSummaries[1].enrollments.importSummaries[0].reference");
    // check if updates on event and enrollment were done.
    response = enrollmentActions.get(enrollmentId);
    response.validate().statusCode(200).body("status", Matchers.equalTo("COMPLETED"));
    response = eventActions.get(eventId);
    response.validate().statusCode(404);
}
Also used : JsonArray(com.google.gson.JsonArray) 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)

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