use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class TeiValidationTests method shouldReturnErrorWhenRemovingMandatoryAttributes.
@Test
public void shouldReturnErrorWhenRemovingMandatoryAttributes() {
JsonObject object = buildTeiWithEnrollmentAndMandatoryAttributes().array();
TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("async=false"));
String teiId = response.validateSuccessfulImport().extractImportedTeis().get(0);
String enrollmentId = response.extractImportedEnrollments().get(0);
JsonObjectBuilder.jsonObject(object).addPropertyByJsonPath("trackedEntities[0].trackedEntity", teiId).addPropertyByJsonPath("trackedEntities[0].attributes[0].value", null).addPropertyByJsonPath("trackedEntities[0].enrollments[0].enrollment", enrollmentId).addPropertyByJsonPath("trackedEntities[0].enrollments[0].attributes[0].value", null);
trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("async=false")).validateErrorReport().body("", hasSize(2)).body("trackerType", hasItems("TRACKED_ENTITY", "ENROLLMENT")).body("errorCode", hasItems("E1076", "E1076")).body("message", hasItem(allOf(containsStringIgnoringCase("TrackedEntityAttribute"), containsStringIgnoringCase(mandatoryTetAttribute)))).body("message", hasItem(allOf(containsStringIgnoringCase("TrackedEntityAttribute"), containsStringIgnoringCase(mandatoryProgramAttribute))));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class TeiValidationTests method shouldReturnErrorWhenMandatoryProgramAttributeMissing.
@Test
public void shouldReturnErrorWhenMandatoryProgramAttributeMissing() {
// arrange
JsonObject trackedEntities = new TeiDataBuilder().buildWithEnrollment(trackedEntityType, Constants.ORG_UNIT_IDS[0], program);
// assert
TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
response.validateErrorReport().body("trackerType", hasItem("ENROLLMENT")).body("errorCode", hasItem("E1018"));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class RelationshipsTests method shouldImportObjectsWithRelationship.
@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisAndRelationship.json", "src/test/resources/tracker/importer/teis/teisWithRelationship.json" })
public void shouldImportObjectsWithRelationship(String file) throws Exception {
JsonObject jsonObject = new FileReaderUtils().read(new File(file)).get(JsonObject.class);
TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport();
response.validate().body("stats.total", equalTo(3));
createdRelationships = response.extractImportedRelationships();
ApiResponse relationshipResponse = trackerActions.get("/relationships/" + createdRelationships.get(0));
relationshipResponse.validate().statusCode(200).body("from.trackedEntity", notNullValue()).body("to.trackedEntity", notNullValue());
response.extractImportedTeis().forEach(tei -> {
teiActions.get(tei, new QueryParamsBuilder().add("fields=relationships")).validate().statusCode(200).body("relationships.relationship", contains(createdRelationships.get(0)));
});
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotDuplicateBidirectionalRelationship.
@Test
public void shouldNotDuplicateBidirectionalRelationship() throws Exception {
// Given 2 existing tracked entities and a bidirectional relationship
// between them
String trackedEntity_1 = importTei();
String trackedEntity_2 = importTei();
JsonObject jsonObject = new RelationshipDataBuilder().buildBidirectionalRelationship(trackedEntity_1, trackedEntity_2).array();
JsonObject invertedRelationship = new RelationshipDataBuilder().buildBidirectionalRelationship(trackedEntity_2, trackedEntity_1).array();
TrackerApiResponse trackerApiResponse = trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport();
trackerApiResponse.validateRelationships().body("stats.created", equalTo(1));
String createdRelationshipUid = trackerApiResponse.extractImportedRelationships().get(0);
// when posting the same payload, then relationship is ignored both ways
Stream.of(jsonObject, invertedRelationship).map(trackerActions::postAndGetJobReport).map(tar -> tar.validateSuccessfulImportWithIgnored(1)).map(TrackerApiResponse::validateRelationships).forEach(validatableResponse -> validatableResponse.body("stats.ignored", equalTo(1)));
// and relationship is not duplicated
ApiResponse relationshipResponse = trackerActions.get("/relationships?tei=" + trackedEntity_1);
relationshipResponse.validate().statusCode(200).body("instances[0].relationship", is(createdRelationshipUid)).body("instances.size()", is(1));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class ImportStrategyTests method shouldDeleteReferencingEventsWhenEnrollmentIsDeleted.
@Test
public void shouldDeleteReferencingEventsWhenEnrollmentIsDeleted() {
// arrange
JsonObject body = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], Constants.TRACKER_PROGRAM_ID, "PaOOjwLVW23");
TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
String teiId = response.extractImportedTeis().get(0);
String enrollmentId = response.extractImportedEnrollments().get(0);
String eventId1 = response.extractImportedEvents().get(0);
body = trackerActions.getEnrollment(enrollmentId).validateStatus(200).getBodyAsJsonBuilder().wrapIntoArray("enrollments");
// act
response = trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=DELETE")).validateSuccessfulImport();
// assert
response.validateSuccessfulImport().validate().body("stats.deleted", Matchers.equalTo(1));
trackerActions.getTrackedEntity(teiId + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(0));
trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
trackerActions.get("/events/" + eventId1).validate().statusCode(404);
}
Aggregations