use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class OptionSetTests method shouldRemoveOptions.
@Test
public void shouldRemoveOptions() {
// arrange
createOption(createdOptionSet);
ApiResponse response = optionActions.optionSetActions.get(createdOptionSet);
JsonObject object = response.getBody();
object.remove("options");
// act
response = optionActions.optionSetActions.update(createdOptionSet, object);
response.validate().statusCode(200);
// assert
response = optionActions.optionSetActions.get(createdOptionSet);
response.validate().statusCode(200).body("options", hasSize(0));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class MetadataImportBasedOnSchemasTest method postBasedOnSchema.
@ParameterizedTest
@MethodSource("getSchemaEndpoints")
public void postBasedOnSchema(String endpoint, String schema) {
RestApiActions apiActions = new RestApiActions(endpoint);
List<String> blacklistedEndpoints = Arrays.asList("jobConfigurations", "relationshipTypes", "messageConversations", "users", "organisationUnitLevels", "programRuleActions", "programRuleVariables", "eventCharts", // blacklisted because contains
"programStages");
// conditionally required properties, which
// are not marked as required
List<SchemaProperty> schemaProperties = schemasActions.getRequiredProperties(schema);
Assumptions.assumeFalse(blacklistedEndpoints.contains(endpoint), "N/A test case - blacklisted endpoint.");
Assumptions.assumeFalse(schemaProperties.stream().anyMatch(schemaProperty -> schemaProperty.getPropertyType() == PropertyType.COMPLEX), "N/A test case - body would require COMPLEX objects.");
// post
JsonObject object = DataGenerator.generateObjectMatchingSchema(schemaProperties);
ApiResponse response = apiActions.post(object);
// validate response;
ResponseValidationHelper.validateObjectCreation(response);
// validate removal;
response = apiActions.delete(response.extractUid());
ResponseValidationHelper.validateObjectRemoval(response, endpoint + " was not deleted");
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class MetadataImportBasedOnSchemasTest method getMatchesSchema.
@ParameterizedTest
@MethodSource("getSchemaEndpoints")
public // todo add better schema validation when spec is ready
void getMatchesSchema(String endpoint, String schema) {
RestApiActions apiActions = new RestApiActions(endpoint);
ApiResponse response = apiActions.get("?fields=*");
response.validate().statusCode(200).body(endpoint, Matchers.notNullValue());
Object firstObject = response.extract(endpoint + "[0]");
if (firstObject == null) {
return;
}
schemasActions.validateObjectAgainstSchema(schema, firstObject).validate().statusCode(200);
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class MetadataImportTest method shouldSkipSharing.
@Test
public void shouldSkipSharing() {
JsonObject metadata = generateMetadataObjectWithInvalidSharing();
ApiResponse response = metadataActions.post(metadata, new QueryParamsBuilder().add("skipSharing=true"));
response.validate().statusCode(200).rootPath("response").body("status", is(oneOf("SUCCESS", "OK"))).body("stats.created", equalTo(1));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class MetadataImportTest method shouldReturnImportSummariesWhenImportingInvalidMetadataAsync.
@Test
public void shouldReturnImportSummariesWhenImportingInvalidMetadataAsync() throws Exception {
// arrange
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
queryParamsBuilder.addAll("async=true", "importReportMode=DEBUG", "importStrategy=CREATE_AND_UPDATE", "atomicMode=NONE");
JsonObject metadata = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
metadata.getAsJsonArray("organisationUnits").get(0).getAsJsonObject().addProperty("shortName", RandomStringUtils.random(51));
// act
ApiResponse response = metadataActions.post(metadata, queryParamsBuilder);
response.validate().statusCode(200).body(notNullValue()).body("response.name", equalTo("metadataImport")).body("response.jobType", equalTo("METADATA_IMPORT"));
String taskId = response.extractString("response.id");
// Validate that job was successful
systemActions.waitUntilTaskCompleted("METADATA_IMPORT", taskId).validate().body("message", hasItem(containsString("Import:Start"))).body("message", hasItem(containsString("Import:Done")));
// validate task summaries were created
systemActions.waitForTaskSummaries("METADATA_IMPORT", taskId).validate().body(notNullValue()).body("status", equalTo("WARNING")).body("typeReports", notNullValue()).rootPath("typeReports").body("stats.total", everyItem(greaterThan(0))).body("stats.ignored", hasSize(greaterThanOrEqualTo(1))).body("objectReports", notNullValue()).body("objectReports", hasSize(greaterThanOrEqualTo(1))).body("objectReports.errorReports", notNullValue());
}
Aggregations