use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class UserAssignmentTests method shouldRemoveUserAssignment.
@Test
public void shouldRemoveUserAssignment() throws Exception {
// arrange
String loggedInUser = loginActions.getLoggedInUserId();
programActions.programStageActions.enableUserAssignment(programStageId, true);
createEvents(programId, programStageId, loggedInUser);
JsonObject eventBody = trackerActions.get("/events?program=" + programId + "&assignedUserMode=CURRENT&ouMode=ACCESSIBLE").validateStatus(200).extractJsonObject("instances[0]");
assertNotNull(eventBody, "no events matching the query.");
String eventId = eventBody.get("event").getAsString();
// act
eventBody.add("assignedUser", null);
trackerActions.postAndGetJobReport(new JsonObjectBuilder(eventBody).wrapIntoArray("events"), new QueryParamsBuilder().addAll("importStrategy=UPDATE")).validateSuccessfulImport();
// assert
trackerActions.getEvent(eventId).validate().body("assignedUser", nullValue());
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class TeiImportTests method shouldImportTei.
@Test
public void shouldImportTei() {
// arrange
JsonObject trackedEntities = new JsonObjectBuilder().addProperty("trackedEntityType", "Q9GufDoplCL").addProperty("orgUnit", Constants.ORG_UNIT_IDS[0]).wrapIntoArray("trackedEntities");
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
response.validateSuccessfulImport().validateTeis().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
// assert that the tei was imported
String teiId = response.extractImportedTeis().get(0);
ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
teiResponse.validate().statusCode(200);
assertThat(teiResponse.getBody(), matchesJSON(trackedEntities.get("trackedEntities").getAsJsonArray().get(0)));
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class PotentialDuplicatesTests method shouldUpdateStatus.
@CsvSource({ "MERGED,INVALID,false", "OPEN,INVALID,true", "OPEN,MERGED,false", "INVALID,OPEN,true", "MERGED,OPEN,false" })
@ParameterizedTest
public void shouldUpdateStatus(String status, String newStatus, boolean shouldUpdate) {
String duplicateId = potentialDuplicatesActions.createAndValidatePotentialDuplicate(createTei(), createTei(), status);
ApiResponse response = potentialDuplicatesActions.update(duplicateId + "?status=" + newStatus, new JsonObjectBuilder().build());
if (shouldUpdate) {
response.validate().statusCode(200);
potentialDuplicatesActions.get(duplicateId).validate().statusCode(200).body("status", equalTo(newStatus));
return;
}
response.validate().statusCode(400).body("status", equalTo("ERROR"));
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class PotentialDuplicatesRelationshipTests method shouldNotMergeManuallyWhenThereAreDuplicateRelationships.
@Test
public void shouldNotMergeManuallyWhenThereAreDuplicateRelationships() {
String teiA = createTei();
String teiB = createTei();
String relationship = createRelationship(teiA, teiB).extractImportedRelationships().get(0);
String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("relationships", Arrays.asList(relationship)).build()).validate().statusCode(409).body("message", containsString("A similar relationship already exists on original"));
}
use of org.hisp.dhis.helpers.JsonObjectBuilder in project dhis2-core by dhis2.
the class EventDataBuilder method addDataValue.
public EventDataBuilder addDataValue(String dataElementId, String value) {
JsonObject dataValue = new JsonObjectBuilder().addProperty("dataElement", dataElementId).addProperty("value", value).build();
this.builder.addOrAppendToArray("dataValues", dataValue);
return this;
}
Aggregations