use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class EventValidationTests method eventImportShouldValidateReferences.
@ParameterizedTest
@MethodSource("provideValidationArguments")
public void eventImportShouldValidateReferences(String ouId, String programId, String programStageId, String errorCode) {
JsonObject jsonObject = new EventDataBuilder().array(ouId, programId, programStageId);
TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject);
response.validateErrorReport().body("errorCode", hasItem(equalTo(errorCode)));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class EventValidationTests method shouldNotImportDeletedEvents.
@Test
public void shouldNotImportDeletedEvents() throws Exception {
JsonObject eventBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/events/event.json"));
String eventId = trackerActions.postAndGetJobReport(eventBody).validateSuccessfulImport().extractImportedEvents().get(0);
eventActions.softDelete(eventId);
TrackerApiResponse response = trackerActions.postAndGetJobReport(eventBody);
response.validateErrorReport().body("errorCode", hasItem("E1082"));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class EventsTests method shouldAddEventsToExistingTei.
@Test
public void shouldAddEventsToExistingTei() throws Exception {
String programId = Constants.TRACKER_PROGRAM_ID;
String programStageId = "nlXNK4b7LVr";
TrackerApiResponse response = importTeiWithEnrollment(programId);
String enrollmentId = response.extractImportedEnrollments().get(0);
JsonObject event = new EventDataBuilder().setEnrollment(enrollmentId).array(Constants.ORG_UNIT_IDS[1], programId, programStageId);
response = trackerActions.postAndGetJobReport(event).validateSuccessfulImport();
String eventId = response.extractImportedEvents().get(0);
trackerActions.get("/events/" + eventId + "?fields=*").validate().statusCode(200).body("enrollment", equalTo(enrollmentId));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotImportDuplicateRelationships.
@MethodSource("provideDuplicateRelationshipData")
@ParameterizedTest(name = "{index} {6}")
public void shouldNotImportDuplicateRelationships(String fromTei1, String toTei1, String fromTei2, String toTei2, boolean bidirectional, int expectedCount, String representation) {
// arrange
String relationshipTypeId = relationshipTypeActions.get("", new QueryParamsBuilder().addAll("filter=fromConstraint.relationshipEntity:eq:TRACKED_ENTITY_INSTANCE", "filter=toConstraint.relationshipEntity:eq:TRACKED_ENTITY_INSTANCE", "filter=bidirectional:eq:" + bidirectional, "filter=name:like:TA")).extractString("relationshipTypes.id[0]");
JsonObject relationship1 = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relationshipTypeId).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", fromTei1)).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", toTei1)).build();
JsonObject relationship2 = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relationshipTypeId).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", fromTei2)).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", toTei2)).build();
JsonObject payload = JsonObjectBuilder.jsonObject().addArray("relationships", relationship1, relationship2).build();
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
// assert
response.validateSuccessfulImport().validate().body("stats.created", equalTo(expectedCount));
createdRelationships = response.extractImportedRelationships();
}
use of org.hisp.dhis.dto.TrackerApiResponse 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));
}
Aggregations