Search in sources :

Example 36 with ApiResponse

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

the class MetadataActions method importMetadata.

public MetadataApiResponse importMetadata(File file, String... queryParams) {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll(queryParams);
    queryParamsBuilder.addAll("importReportMode=FULL");
    ApiResponse response = postFile(file, queryParamsBuilder);
    response.validate().statusCode(200);
    return new MetadataApiResponse(response);
}
Also used : MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse)

Example 37 with ApiResponse

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

the class RestApiActions method get.

/**
 * Sends get request with provided path and queryParams appended to URL.
 *
 * @param resourceId         Id of resource
 * @param queryParamsBuilder Query params to append to url
 */
public ApiResponse get(String resourceId, QueryParamsBuilder queryParamsBuilder) {
    String path = queryParamsBuilder == null ? "" : queryParamsBuilder.build();
    Response response = this.given().contentType(ContentType.TEXT).when().get(resourceId + path);
    return new ApiResponse(response);
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) Response(io.restassured.response.Response) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 38 with ApiResponse

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

the class RestApiActions method postFile.

public ApiResponse postFile(File file, QueryParamsBuilder queryParamsBuilder) {
    String url = queryParamsBuilder == null ? "" : queryParamsBuilder.build();
    ApiResponse response = new ApiResponse(this.given().body(file).when().post(url));
    saveCreatedObjects(response);
    return response;
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 39 with ApiResponse

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

the class UserAssignmentTests method shouldBeEnabledOnProgramStage.

@ParameterizedTest
@ValueSource(strings = { "WITHOUT_REGISTRATION", "WITH_REGISTRATION" })
public void shouldBeEnabledOnProgramStage(String programType) {
    // arrange
    String programId = programActions.get("?filter=programStages:ge:1&filter=programType:eq:" + programType).extractString("programs.id[0]");
    String programStageId = programActions.get(programId).extractString("programStages.id[0]");
    // act - enabling user assignment
    ApiResponse response = programActions.programStageActions.enableUserAssignment(programStageId, true);
    // assert
    ResponseValidationHelper.validateObjectUpdate(response, 200);
    response = programActions.programStageActions.get(programStageId);
    response.validate().statusCode(200).body(userAssignmentProperty, equalTo(true));
    // act - disabling user assignment
    response = programActions.programStageActions.enableUserAssignment(programStageId, false);
    // assert
    ResponseValidationHelper.validateObjectUpdate(response, 200);
    response = programActions.programStageActions.get(programStageId);
    response.validate().statusCode(200).body(userAssignmentProperty, equalTo(false));
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with ApiResponse

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

the class ImportStrategyTests method shouldDeleteWithDeleteStrategy.

@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisWithEnrollmentsAndEvents.json", "src/test/resources/tracker/importer/teis/teiAndEnrollment.json", "src/test/resources/tracker/importer/teis/teis.json", "src/test/resources/tracker/importer/events/events.json" })
public void shouldDeleteWithDeleteStrategy(String fileName) throws Exception {
    // arrange
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
    trackerActions.postAndGetJobReport(teiBody).validateSuccessfulImport();
    teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
    // act
    ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add("importStrategy=DELETE"));
    // assert
    response.validate().statusCode(200).body("status", equalTo("OK")).body("stats.deleted", Matchers.greaterThanOrEqualTo(1));
}
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) 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