use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class EventsTests method eventsImportNewEventsFromFile.
@ParameterizedTest
@MethodSource("provideEventFilesTestArguments")
public void eventsImportNewEventsFromFile(String fileName, String contentType) throws Exception {
Object obj = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/" + fileName)).replacePropertyValuesWithIds("event").get();
ApiResponse response = trackerActions.post("", contentType, obj, new QueryParamsBuilder().addAll("dryRun=false", "eventIdScheme=UID", "orgUnitIdScheme=UID"));
response.validate().statusCode(200);
String jobId = response.extractString("response.id");
trackerActions.waitUntilJobIsCompleted(jobId);
response = trackerActions.getJobReport(jobId, "FULL");
response.validate().statusCode(200).body("status", equalTo("OK"));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class RelationshipsTests method shouldImportRelationshipsToExistingEntities.
@MethodSource("provideRelationshipData")
@ParameterizedTest(name = "{index} {1} to {3}")
public void shouldImportRelationshipsToExistingEntities(String relType, String fromInstance, String fromInstanceId, String toInstance, String toInstanceId) {
// arrange
JsonObject relationship = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relType).addObject("from", JsonObjectBuilder.jsonObject().addProperty(fromInstance, fromInstanceId)).addObject("to", JsonObjectBuilder.jsonObject().addProperty(toInstance, toInstanceId)).wrapIntoArray("relationships");
createdRelationships = trackerActions.postAndGetJobReport(relationship).validateSuccessfulImport().extractImportedRelationships();
ApiResponse response = trackerActions.get("/relationships/" + createdRelationships.get(0));
validateRelationship(response, relType, fromInstance, fromInstanceId, toInstance, toInstanceId, createdRelationships.get(0));
ApiResponse entityResponse = getEntityInRelationship(toInstance, toInstanceId);
validateRelationship(entityResponse, relType, fromInstance, fromInstanceId, toInstance, toInstanceId, createdRelationships.get(0));
entityResponse = getEntityInRelationship(fromInstance, fromInstanceId);
validateRelationship(entityResponse, relType, fromInstance, fromInstanceId, toInstance, toInstanceId, createdRelationships.get(0));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class TeiUpdateTests method shouldUpdateWithUpdateStrategy.
@Test
public void shouldUpdateWithUpdateStrategy() throws Exception {
// arrange
String teiId = importTei();
JsonObject teiBody = trackerActions.getTrackedEntity(teiId).getBody();
teiBody = JsonObjectBuilder.jsonObject(teiBody).addProperty("trackedEntity", teiId).wrapIntoArray("trackedEntities");
// act
ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add("importStrategy=UPDATE"));
// assert
response.validate().statusCode(200).body("status", equalTo("OK")).body("stats.updated", equalTo(1));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class TeiUpdateTests method shouldReturnErrorWhenTeiDoesntExist.
@ParameterizedTest
@ValueSource(strings = { "UPDATE", "DELETE" })
public void shouldReturnErrorWhenTeiDoesntExist(String importStrategy) throws Exception {
JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/tei.json"));
ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add(String.format("importStrategy=%s", importStrategy)));
response.validate().statusCode(200).body("status", equalTo("ERROR")).body("stats.ignored", equalTo(1)).body("validationReport.errorReports", notNullValue()).rootPath("validationReport.errorReports[0]").body("errorCode", equalTo("E1063")).body("message", containsStringIgnoringCase("does not exist"));
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class RelationshipsTest method before.
@BeforeAll
public void before() throws Exception {
relationshipActions = new RelationshipActions();
trackedEntityInstanceActions = new RestApiActions("/trackedEntityInstances");
metadataActions = new MetadataActions();
eventActions = new EventActions();
new LoginActions().loginAsSuperUser();
metadataActions.importAndValidateMetadata(new File("src/test/resources/tracker/relationshipTypes.json"));
JsonObject teiObject = new FileReaderUtils().read(new File("src/test/resources/tracker/teis/teis.json")).replacePropertyValuesWithIds("trackedEntityInstance").get(JsonObject.class);
teis = trackedEntityInstanceActions.post(teiObject).extractUids();
JsonObject eventObject = new FileReaderUtils().read(new File("src/test/resources/tracker/events/events.json")).replacePropertyValuesWithIds("event").get(JsonObject.class);
ApiResponse response = eventActions.post(eventObject).validateStatus(200);
events = response.extractUids();
}
Aggregations