use of org.hisp.dhis.dto.schemas.SchemaProperty 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.schemas.SchemaProperty in project dhis2-core by dhis2.
the class DataGenerator method generateObjectMatchingSchema.
public static JsonObject generateObjectMatchingSchema(List<SchemaProperty> schemaProperties) {
JsonObject objectBody = new JsonObject();
for (SchemaProperty prop : schemaProperties) {
JsonElement element;
if (prop.getPropertyType() == PropertyType.REFERENCE) {
List<SchemaProperty> referenceProperties = new SchemasActions().getRequiredProperties(prop.getName());
JsonObject referenceObject = generateObjectMatchingSchema(referenceProperties);
String uid = new RestApiActions(prop.getRelativeApiEndpoint()).post(referenceObject).extractUid();
referenceObject.addProperty("id", uid);
element = referenceObject;
} else if (prop.getPropertyType() == PropertyType.IDENTIFIER) {
if (!StringUtils.containsAny(prop.getName(), "id", "uid", "code")) {
Schema schema = new SchemasActions().getSchema(prop.getName());
JsonObject referenceObject = generateObjectMatchingSchema(schema.getRequiredProperties());
String uid = new RestApiActions(schema.getPlural()).post(referenceObject).extractUid();
element = new JsonPrimitive(uid);
} else {
element = new JsonPrimitive(new IdGenerator().generateUniqueId());
}
} else {
element = generateRandomValueMatchingSchema(prop);
}
objectBody.add(prop.getName(), element);
}
return objectBody;
}
Aggregations