Search in sources :

Example 11 with ApiResponse

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

the class MetadataImportTest method shouldImportUniqueMetadataAndReturnObjectReports.

@Test
public void shouldImportUniqueMetadataAndReturnObjectReports() throws Exception {
    // arrange
    JsonObject object = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
    // act
    ApiResponse response = metadataActions.post(object, new QueryParamsBuilder().addAll("async=false", "importReportMode=DEBUG", "importStrategy=CREATE"));
    // assert
    response.validate().statusCode(200).rootPath("response").body("stats", notNullValue()).body("stats.total", greaterThan(0)).body("typeReports", notNullValue()).body("typeReports.stats", notNullValue()).body("typeReports.objectReports", Matchers.notNullValue());
    List<HashMap> stats = response.extractList("response.typeReports.stats");
    stats.forEach(x -> {
        assertEquals(x.get("total"), x.get("created"));
    });
    List<ObjectReport> objectReports = getObjectReports(response.getTypeReports());
    assertNotNull(objectReports);
    validateCreatedEntities(objectReports);
}
Also used : HashMap(java.util.HashMap) FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ObjectReport(org.hisp.dhis.dto.ObjectReport) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Example 12 with ApiResponse

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

the class OrgUnitsTest method shouldAddWithoutLevel.

@Test
public void shouldAddWithoutLevel() {
    OrgUnit orgUnit = orgUnitActions.generateDummy();
    orgUnit.setLevel(null);
    ApiResponse response = orgUnitActions.post(orgUnit);
    ResponseValidationHelper.validateObjectCreation(response);
    String uid = response.extractUid();
    assertNotNull(uid, "Org unit id was not returned.");
    response = orgUnitActions.get(uid);
    // todo create validation helper to check the similarity.
    response.validate().statusCode(200).body("shortName", equalTo(orgUnit.getShortName())).body("name", equalTo(orgUnit.getName())).body("openingDate", equalTo(orgUnit.getOpeningDate()));
}
Also used : OrgUnit(org.hisp.dhis.dto.OrgUnit) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 13 with ApiResponse

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

the class UserDisableTest method shouldEnableUser.

@Test
public void shouldEnableUser() {
    loginActions.loginAsUser(userName, password);
    loginActions.loginAsSuperUser();
    ApiResponse preChangeResponse = userActions.get(userId);
    preChangeResponse.validate().statusCode(200).body("disabled", is(false));
    ApiResponse response = userActions.post(userId + "/disabled", new Object(), null);
    response.validate().statusCode(204);
    ApiResponse getResponse = userActions.get(userId);
    getResponse.validate().statusCode(200).body("disabled", is(true));
    loginActions.addAuthenticationHeader(userName, password);
    loginActions.getLoggedInUserInfo().validate().statusCode(401);
    loginActions.loginAsSuperUser();
    ApiResponse enableResponse = userActions.post(userId + "/enabled", new Object(), null);
    enableResponse.validate().statusCode(204);
    ApiResponse getAfterEnabled = userActions.get(userId);
    getAfterEnabled.validate().statusCode(200).body("disabled", is(false));
    loginActions.addAuthenticationHeader(userName, password);
    loginActions.getLoggedInUserInfo().validate().statusCode(200);
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 14 with ApiResponse

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

the class UserPaginationTest method checkPaginationResultsForcingInMemoryPagination.

@Test
public void checkPaginationResultsForcingInMemoryPagination() {
    // this test forces the metadata query engine to execute an "in memory"
    // sorting and pagination
    // since the sort ("order") value is set to 'displayName' that is a
    // "virtual" field (that is, not a database column)
    // The metadata query engine can not execute a sql query using this
    // field, since it does not exist
    // on the table. Therefore, the engine loads the entire content of the
    // table in memory and
    // executes a sort + pagination "in memory"
    ApiResponse response = paginationActions.getPaginated(startPage, pageSize);
    response.validate().statusCode(200);
    paginationActions.assertPagination(response, total, total / pageSize, pageSize, startPage);
}
Also used : ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 15 with ApiResponse

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

the class UserPaginationTest method checkPaginationResultsForcingDatabaseOnlyPagination.

@Test
public void checkPaginationResultsForcingDatabaseOnlyPagination() {
    // this test forces the metadata query engine to execute the query
    // (including pagination) on the database only.
    // The sort ("order") value is set to 'id' that is mapped to a DB
    // column.
    ApiResponse response = paginationActions.getPaginated(Arrays.asList(DEFAULT_METADATA_FILTER.split(",")), Arrays.asList(DEFAULT_METADATA_FIELDS.split(",")), Collections.singletonList("id:ASC"), startPage, pageSize);
    response.validate().statusCode(200);
    paginationActions.assertPagination(response, total, total / pageSize, pageSize, startPage);
}
Also used : 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