use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class UserAssignmentTests method shouldImportEventWithUserAssignment.
@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void shouldImportEventWithUserAssignment(String userAssignmentEnabled) throws Exception {
// arrange
String loggedInUser = loginActions.getLoggedInUserId();
programActions.programStageActions.enableUserAssignment(programStageId, Boolean.parseBoolean(userAssignmentEnabled));
// act
String eventId = createEvents(programId, programStageId, loggedInUser).extractImportedEvents().get(0);
ApiResponse response = trackerActions.getEvent(eventId);
if (!Boolean.parseBoolean(userAssignmentEnabled)) {
response.validate().body("assignedUser", nullValue());
return;
}
response.validate().body("assignedUser", equalTo(loggedInUser));
}
use of org.hisp.dhis.dto.ApiResponse 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.dto.ApiResponse 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.dto.ApiResponse in project dhis2-core by dhis2.
the class EventImportDataValueValidationTests method shouldValidateCompletedOnInsert.
@Test
public void shouldValidateCompletedOnInsert() {
programActions.programStageActions.setValidationStrategy(programStageId, "ON_UPDATE_AND_INSERT");
JsonObject event = eventActions.createEventBody(OU_ID, programId, programStageId);
event.addProperty("status", "COMPLETED");
ApiResponse response = eventActions.post(event, new QueryParamsBuilder().add("skipCache=true"));
response.validate().statusCode(409).body("status", equalTo("ERROR")).rootPath("response").body("ignored", equalTo(1)).body("imported", equalTo(0)).body("importSummaries[0].conflicts[0].value", equalTo("value_required_but_not_provided"));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class EventImportDataValueValidationTests method shouldImportEventsWithCompulsoryDataValues.
@Test
public void shouldImportEventsWithCompulsoryDataValues() {
JsonObject events = eventActions.createEventBody(OU_ID, programId, programStageId);
addDataValue(events, mandatoryDataElementId, "TEXT VALUE");
ApiResponse response = eventActions.post(events);
response.validate().statusCode(200).body("status", equalTo("OK")).body("response.imported", equalTo(1));
String eventID = response.extractString("response.importSummaries.reference[0]");
assertNotNull(eventID, "Failed to extract eventId");
eventActions.get(eventID).validate().statusCode(200).body("dataValues", not(Matchers.emptyArray()));
}
Aggregations