use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class EventExportTests method shouldUseCorrectScopeWhenOuIsProvided.
@ParameterizedTest(name = "{0}")
@MethodSource
public void shouldUseCorrectScopeWhenOuIsProvided(String description, String mode, String orgUnitId, Boolean shouldReturn, List<String> orgUnit) {
loginActions.loginAsUser(userName, password);
QueryParamsBuilder builder = new QueryParamsBuilder().add("ouMode", mode).add("orgUnit", orgUnitId);
ApiResponse response = eventActions.get(builder.build());
if (shouldReturn) {
response.validate().statusCode(200).body("events", hasSize(greaterThanOrEqualTo(1))).body("events.orgUnit", everyItem(in(orgUnit)));
return;
}
response.validateStatus(409);
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class EventImportIdSchemeTests method eventsShouldBeImportedWithProgramScheme.
@ParameterizedTest
@MethodSource("provideIdSchemeArguments")
public void eventsShouldBeImportedWithProgramScheme(String scheme, String property) throws Exception {
String programPropertyValue = programActions.get(PROGRAM_ID).extractString(property);
assertNotNull(programPropertyValue, String.format("Program property %s was not present.", property));
JsonObject object = new FileReaderUtils().read(new File("src/test/resources/tracker/events/events.json")).replacePropertyValuesWithIds("event").replacePropertyValuesWith("orgUnit", orgUnitId).replacePropertyValuesWith("program", programPropertyValue).get(JsonObject.class);
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder().add("skipCache=true").add("programIdScheme=" + scheme);
ApiResponse response = eventActions.post(object, queryParamsBuilder);
response.validate().statusCode(200).rootPath("response").body("status", equalTo("SUCCESS")).body("ignored", equalTo(0)).body("importSummaries.reference", everyItem(notNullValue()));
String eventId = response.extractString("response.importSummaries.reference[0]");
assertNotNull(eventId);
eventActions.get(eventId).validate().statusCode(200).body("program", equalTo(PROGRAM_ID));
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class EventImportIdSchemeTests method eventsShouldBeImportedWithOrgUnitScheme.
@ParameterizedTest
@MethodSource("provideIdSchemeArguments")
public void eventsShouldBeImportedWithOrgUnitScheme(String ouScheme, String ouProperty) throws Exception {
String ouPropertyValue = orgUnitActions.get(orgUnitId).extractString(ouProperty);
assertNotNull(ouPropertyValue, String.format("Org unit property %s was not present.", ouProperty));
JsonObject object = new FileReaderUtils().read(new File("src/test/resources/tracker/events/events.json")).replacePropertyValuesWith("orgUnit", ouPropertyValue).replacePropertyValuesWithIds("event").get(JsonObject.class);
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder().add("skipCache=true").add("orgUnitIdScheme=" + ouScheme);
ApiResponse response = eventActions.post(object, queryParamsBuilder);
response.validate().statusCode(200).rootPath("response").body("status", equalTo("SUCCESS")).body("ignored", equalTo(0)).body("imported", greaterThan(1)).body("importSummaries.reference", everyItem(notNullValue()));
String eventId = response.extractString("response.importSummaries.reference[0]");
assertNotNull(eventId);
eventActions.get(eventId).validate().statusCode(200).body("orgUnit", equalTo(orgUnitId));
}
use of org.hisp.dhis.helpers.QueryParamsBuilder 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);
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class MetadataImportTest method shouldImportMetadataAsync.
@Test
public void shouldImportMetadataAsync() throws Exception {
JsonObject object = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
// arrange
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
queryParamsBuilder.addAll("async=false", "importReportMode=DEBUG", "importStrategy=CREATE_AND_UPDATE", "atomicMode=NONE");
// import metadata so that we have references and can clean up
// act
ApiResponse response = metadataActions.post(object, queryParamsBuilder);
// send async request
queryParamsBuilder.add("async=true");
response = metadataActions.post(object, queryParamsBuilder);
response.validate().statusCode(200).body("response", notNullValue()).body("response.name", equalTo("metadataImport")).body("response.jobType", equalTo("METADATA_IMPORT"));
String taskId = response.extractString("response.id");
assertNotNull(taskId, "Task id was not returned");
// Validate that job was successful
systemActions.waitUntilTaskCompleted("METADATA_IMPORT", taskId).validate().body("message", notNullValue()).body("message", hasItem(containsString("Import:Start"))).body("message", hasItem(containsString("Import:Done")));
// validate task summaries were created
systemActions.waitForTaskSummaries("METADATA_IMPORT", taskId).validate().body(notNullValue()).body("status", equalTo("OK")).body("typeReports", notNullValue()).rootPath("typeReports").body("stats", notNullValue()).body("stats.total", everyItem(greaterThan(0))).body("objectReports", hasSize(greaterThan(0)));
}
Aggregations