use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class RestApiActions method create.
/**
* Shortcut used in preconditions only. Sends post request to specified
* endpoint and verifies that request was successful
*
* @param object Body of request
* @return ID of generated entity.
*/
public String create(Object object) {
ApiResponse response = post(object);
response.validate().statusCode(is(oneOf(200, 201)));
return response.extractUid();
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class RestApiActions method post.
public ApiResponse post(String resource, String contentType, Object object, QueryParamsBuilder queryParams) {
String path = queryParams == null ? "" : queryParams.build();
ApiResponse response = new ApiResponse(this.given().body(object).contentType(contentType).when().post(resource + path));
saveCreatedObjects(response);
return response;
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class TrackerActions method waitUntilJobIsCompleted.
public ApiResponse waitUntilJobIsCompleted(String jobId) {
logger.info(String.format("Waiting until tracker job with id %s is completed", jobId));
ApiResponse response = null;
boolean completed = false;
int maxAttempts = 100;
while (!completed && maxAttempts > 0) {
response = getJob(jobId);
response.validate().statusCode(200);
completed = response.extractList("completed").contains(true);
maxAttempts--;
}
if (maxAttempts == 0) {
logger.warning(String.format("Tracker job didn't complete in %d. Message: %s", maxAttempts, response.extract("message")));
}
logger.info("Tracker job is completed. Message: " + response.extract("message"));
return response;
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class EventsTests method shouldImportEvents.
@Test
public void shouldImportEvents() throws Exception {
JsonObject eventBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/events/events.json"));
TrackerApiResponse importResponse = trackerActions.postAndGetJobReport(eventBody);
importResponse.validateSuccessfulImport().validateEvents().body("stats.created", Matchers.equalTo(4)).body("objectReports", notNullValue()).body("objectReports[0].errorReports", empty());
eventBody.getAsJsonArray("events").forEach(event -> {
String eventId = event.getAsJsonObject().get("event").getAsString();
ApiResponse response = trackerActions.get("/events/" + eventId);
response.validate().statusCode(200);
assertThat(response.getBody(), matchesJSON(event));
});
}
use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.
the class EventsDataValueValidationTests method setupData.
private void setupData() {
ApiResponse response = programActions.createEventProgram(OU_ID);
programId = response.extractUid();
assertNotNull(programId, "Failed to create a program");
sharingActions.setupSharingForConfiguredUserGroup("program", programId);
programStageId = programActions.get(programId, new QueryParamsBuilder().add("fields=*")).extractString("programStages.id[0]");
assertNotNull(programStageId, "Failed to create a programStage");
ApiResponse dataelements = dataElementActions.get("?fields=id&filter=domainType:eq:TRACKER&filter=valueType:in:[TEXT,LONG_TEXT]&pageSize=2");
dataelements.validate().body("dataElements", hasSize(2));
mandatoryDataElementId = dataelements.extractString("dataElements.id[0]");
notMandatoryDataElementId = dataelements.extractString("dataElements.id[1]");
programActions.addDataElement(programStageId, mandatoryDataElementId, true).validate().statusCode(200);
programActions.addDataElement(programStageId, notMandatoryDataElementId, false).validate().statusCode(200);
}
Aggregations