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);
}
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()));
}
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);
}
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);
}
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);
}
Aggregations