use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldValidateUniqueness.
@Test
public void shouldValidateUniqueness() throws Exception {
String tei = importTei();
String value = DataGenerator.randomString();
JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(uniqueAttributeId, value).array(programId, Constants.ORG_UNIT_IDS[1]);
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(importTei()).addAttribute(uniqueAttributeId, value).array(programId, Constants.ORG_UNIT_IDS[1]);
trackerActions.postAndGetJobReport(payload).validateErrorReport();
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotUpdateRelationship.
@Test
public void shouldNotUpdateRelationship() {
// arrange
String relationshipId = new IdGenerator().generateUniqueId();
JsonObject relationship = JsonObjectBuilder.jsonObject().addProperty("relationship", relationshipId).addProperty("relationshipType", relationshipType).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).wrapIntoArray("relationships");
trackerActions.postAndGetJobReport(relationship).validate().statusCode(200);
JsonObject relationshipBody = trackerActions.get("/relationships/" + relationshipId).getBody();
JsonObjectBuilder.jsonObject(relationship).addObjectByJsonPath("relationships[0]", "from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1)).build()).addObjectByJsonPath("relationships[0]", "to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0)).build()).build();
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(relationship, new QueryParamsBuilder().add("importStrategy=UPDATE"));
// assert
response.validateErrorReport();
assertThat(trackerActions.get("/relationships/" + relationshipId).getBody(), matchesJSON(relationshipBody));
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldRejectTetAttributes.
@Test
public void shouldRejectTetAttributes() throws Exception {
String tetAttribute = "dIVt4l5vIOa";
String tei = importTei();
JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(tetAttribute, "NOT_A_VALUE").array(programId, Constants.ORG_UNIT_IDS[1]);
trackerActions.postAndGetJobReport(payload).validateErrorReport().body("", hasSize(1)).body("errorCode", hasItem("E1019")).body("message", hasItem(containsStringIgnoringCase("Only program attributes")));
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldUpdateAttributeValue.
@Test
public void shouldUpdateAttributeValue() throws Exception {
String tei = importTei();
JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(numberAttributeId, "5").array(programId, Constants.ORG_UNIT_IDS[1]);
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
payload = new JsonObjectBuilder(payload).addPropertyByJsonPath("enrollments[0].attributes[0].value", "9").build();
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
trackerActions.getTrackedEntity(tei + "?program=" + programId).validateStatus(200).validate().statusCode(200).body("attributes", hasSize(greaterThanOrEqualTo(1))).body("attributes.attribute", hasItem(numberAttributeId)).body("attributes.value", hasItem("9"));
}
use of org.hisp.dhis.actions.IdGenerator 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