Search in sources :

Example 51 with ApiResponse

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

the class UserAssignmentFilterTests method eventsShouldBeFilteredForAssignedUser.

@Test
public void eventsShouldBeFilteredForAssignedUser() {
    // arrange
    loginActions.loginAsUser(userUsername, userPassword);
    // act
    ApiResponse response = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=CURRENT");
    // assert
    response.validate().statusCode(200).body("events", hasSize(4)).body("events.assignedUser", everyItem(equalTo(userId)));
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 52 with ApiResponse

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

the class UserAssignmentFilterTests method changeEventStatus.

private ApiResponse changeEventStatus(String eventId, String eventStatus) {
    JsonObject body = eventActions.get(eventId).getBody();
    body.addProperty("status", eventStatus);
    ApiResponse response = eventActions.update(eventId, body);
    response.validate().statusCode(200);
    return response;
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 53 with ApiResponse

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

the class UserAssignmentFilterTests method createEvents.

private ApiResponse createEvents(Object body) throws Exception {
    ApiResponse eventResponse = eventActions.post(body, new QueryParamsBuilder().add("skipCache=true"));
    eventResponse.validate().statusCode(200);
    return eventResponse;
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 54 with ApiResponse

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

the class SideEffectsTests method shouldSendNotificationIfNotSkipSideEffects.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void shouldSendNotificationIfNotSkipSideEffects(Boolean shouldSkipSideEffects) {
    JsonObject object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, trackerProgramStageId, "COMPLETED");
    ApiResponse response = new RestApiActions("/messageConversations").get("", new QueryParamsBuilder().add("fields=*"));
    int size = response.getBody().getAsJsonArray("messageConversations").size();
    trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("skipSideEffects=" + shouldSkipSideEffects)).validateSuccessfulImport();
    int expectedCount = (shouldSkipSideEffects) ? size : size + 1;
    response = messageConversationsActions.waitForNotification(expectedCount);
    response.validate().statusCode(200).body("messageConversations", hasSize(expectedCount));
    if (shouldSkipSideEffects) {
        return;
    }
    response.validate().body("messageConversations.subject", hasItem("TA program stage completion"));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) RestApiActions(org.hisp.dhis.actions.RestApiActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with ApiResponse

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

the class DataElementsTest method shouldCreate.

@ParameterizedTest
@MethodSource("getDataElementCombinations")
public void shouldCreate(String domainType, String valueType, String aggregationType, boolean withCategoryCombo, String categoryComboDimensionType) {
    // arrange
    JsonObject body = dataElementActions.body(aggregationType, domainType, valueType);
    if (withCategoryCombo) {
        String categoryComboId = createCategoryCombo(categoryComboDimensionType);
        JsonObject categoryCombo = new JsonObject();
        categoryCombo.addProperty("id", categoryComboId);
        body.add("categoryCombo", categoryCombo);
    }
    // act
    ApiResponse response = dataElementActions.post(body);
    // assert
    ResponseValidationHelper.validateObjectCreation(response);
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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