Search in sources :

Example 61 with ApiResponse

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

the class EventImportDataValueValidationTests method shouldNotValidateDataValuesOnUpdateWithOnCompleteStrategy.

@Test
public void shouldNotValidateDataValuesOnUpdateWithOnCompleteStrategy() {
    programActions.programStageActions.setValidationStrategy(programStageId, "ON_COMPLETE");
    JsonObject events = eventActions.createEventBody(OU_ID, programId, programStageId);
    ApiResponse response = eventActions.post(events, new QueryParamsBuilder().add("skipCache=true"));
    response.validate().statusCode(200).body("status", equalTo("OK")).body("response.ignored", equalTo(0)).body("response.imported", 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) ApiTest(org.hisp.dhis.ApiTest)

Example 62 with ApiResponse

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

the class EventImportDataValueValidationTests method shouldValidateDataValuesOnCompleteWhenEventIsCompleted.

@Test
public void shouldValidateDataValuesOnCompleteWhenEventIsCompleted() {
    programActions.programStageActions.setValidationStrategy(programStageId, "ON_COMPLETE");
    JsonObject event = eventActions.createEventBody(OU_ID, programId, programStageId);
    event.addProperty("status", "COMPLETED");
    ApiResponse response = eventActions.post(event, new QueryParamsBuilder().add("skipCache=true"));
    response.validate().statusCode(409).body("status", equalTo("ERROR")).rootPath("response").body("ignored", equalTo(1)).body("imported", equalTo(0)).body("importSummaries[0].conflicts[0].value", equalTo("value_required_but_not_provided"));
}
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) ApiTest(org.hisp.dhis.ApiTest)

Example 63 with ApiResponse

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

the class EventImportDataValueValidationTests method shouldValidateDataValuesOnUpdate.

@Test
public void shouldValidateDataValuesOnUpdate() {
    programActions.programStageActions.setValidationStrategy(programStageId, "ON_UPDATE_AND_INSERT");
    JsonObject events = eventActions.createEventBody(OU_ID, programId, programStageId);
    ApiResponse response = eventActions.post(events, new QueryParamsBuilder().add("skipCache=true"));
    response.validate().statusCode(409).body("status", equalTo("ERROR")).rootPath("response").body("ignored", equalTo(1)).body("imported", equalTo(0)).body("importSummaries[0].conflicts[0].value", equalTo("value_required_but_not_provided"));
}
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) ApiTest(org.hisp.dhis.ApiTest)

Example 64 with ApiResponse

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

the class AbstractOrgUnitAssociationTestSupport method validateResponseHasKey.

private ApiResponse validateResponseHasKey(Function<String, ApiResponse> apiResponseProvider, String key) {
    ApiResponse apiResponse = apiResponseProvider.apply(key);
    apiResponse.validate().body("$", hasKey(key));
    return apiResponse;
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 65 with ApiResponse

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

the class UserLookupTests method shouldLookupSpecificUser.

@ParameterizedTest
@CsvSource({ "PQD6wXJ2r5j,id", "taadmin,username" })
public void shouldLookupSpecificUser(String resource, String propertyToValidate) {
    ApiResponse response = lookupActions.get(resource);
    response.validate().statusCode(200).body(propertyToValidate, equalTo(resource)).body("id", notNullValue()).body("username", notNullValue()).body("firstName", notNullValue()).body("surname", notNullValue()).body("displayName", notNullValue());
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) CsvSource(org.junit.jupiter.params.provider.CsvSource) 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