use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class EventDataBuilder method addNote.
public EventDataBuilder addNote(String value) {
JsonObject note = new JsonObjectBuilder().addProperty("value", value).build();
this.builder.addOrAppendToArray("notes", note);
return this;
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldValidateUniquenessWithinThePayload.
@Test
public void shouldValidateUniquenessWithinThePayload() throws Exception {
String tei = importTei();
String teiB = importTei();
String value = DataGenerator.randomString();
Function<String, JsonObject> singleEnrollment = (teiId) -> {
return new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(teiId).addAttribute(uniqueAttributeId, value).setProgram(programId).setOu(Constants.ORG_UNIT_IDS[1]).single();
};
JsonObject payload = new JsonObjectBuilder().addOrAppendToArray("enrollments", singleEnrollment.apply(tei), singleEnrollment.apply(teiB)).build();
trackerActions.postAndGetJobReport(payload).validateErrorReport();
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldRemoveAttributeValue.
@Test
public void shouldRemoveAttributeValue() throws Exception {
String tei = importTei();
JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(optionSetAttributeId, "TA_YES").array(programId, Constants.ORG_UNIT_IDS[1]);
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
payload = new JsonObjectBuilder(payload).addPropertyByJsonPath("enrollments[0].attributes[0].value", null).build();
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
trackerActions.getTrackedEntity(tei + "?program=" + programId).validateStatus(200).validate().statusCode(200).body("attributes", hasSize(greaterThanOrEqualTo(1))).body("attributes.attribute", not(hasItem(optionSetAttributeId))).body("attributes.value", not(hasItem("TA_YES")));
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class RelationshipsTests method shouldDeleteRelationshipWithDeleteStrategy.
@Test
public void shouldDeleteRelationshipWithDeleteStrategy() {
// arrage
TrackerApiResponse response = trackerActions.postAndGetJobReport(new File("src/test/resources/tracker/importer/teis/teisAndRelationship.json")).validateSuccessfulImport();
List<String> teis = response.extractImportedTeis();
String relationship = response.extractImportedRelationships().get(0);
JsonObject obj = new JsonObjectBuilder().addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).addProperty("relationshipType", relationshipType).addProperty("relationship", relationship).wrapIntoArray("relationships");
// act
response = trackerActions.postAndGetJobReport(obj, new QueryParamsBuilder().add("importStrategy=DELETE"));
// assert
response.validate().body("status", equalTo("OK")).body("stats.deleted", equalTo(1));
trackerActions.get("/relationships/" + relationship).validate().statusCode(404);
trackerActions.getTrackedEntity(teis.get(0) + "?fields=relationships").validate().body("relationships", Matchers.empty());
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class UserActions method addUser.
public String addUser(final String firstName, final String surname, final String username, final String password) {
String id = idGenerator.generateUniqueId();
JsonObject user = new JsonObjectBuilder().addProperty("id", id).addProperty("firstName", firstName).addProperty("surname", surname).addProperty("username", username).addProperty("password", password).build();
ApiResponse response = this.post(user);
response.validate().statusCode(201);
TestRunStorage.addCreatedEntity(endpoint, id);
return id;
}
Aggregations