use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class MetadataActions method importMetadata.
public MetadataApiResponse importMetadata(File file, String... queryParams) {
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
queryParamsBuilder.addAll(queryParams);
queryParamsBuilder.addAll("importReportMode=FULL");
ApiResponse response = postFile(file, queryParamsBuilder);
response.validate().statusCode(200);
return new MetadataApiResponse(response);
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class ImportStrategyTests method shouldDeleteReferencingDataWhenTeiIsDeleted.
@Test
public void shouldDeleteReferencingDataWhenTeiIsDeleted() throws Exception {
// arrange
JsonObject body = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teiAndEnrollment.json"));
TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
String teiId = response.extractImportedTeis().get(0);
String enrollmentId = response.extractImportedEnrollments().get(0);
body.remove("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).validate().statusCode(404);
trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class ImportStrategyTests method shouldDeleteWithDeleteStrategy.
@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisWithEnrollmentsAndEvents.json", "src/test/resources/tracker/importer/teis/teiAndEnrollment.json", "src/test/resources/tracker/importer/teis/teis.json", "src/test/resources/tracker/importer/events/events.json" })
public void shouldDeleteWithDeleteStrategy(String fileName) throws Exception {
// arrange
JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
trackerActions.postAndGetJobReport(teiBody).validateSuccessfulImport();
teiBody = new FileReaderUtils().readJsonAndGenerateData(new File(fileName));
// act
ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add("importStrategy=DELETE"));
// assert
response.validate().statusCode(200).body("status", equalTo("OK")).body("stats.deleted", Matchers.greaterThanOrEqualTo(1));
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class RuleEngineTests method shouldSendProgramRuleNotification.
@Test
public void shouldSendProgramRuleNotification() {
JsonObject payload = new EventDataBuilder().addDataValue("ILRgzHhzFkg", "true").addDataValue("z3Z4TD3oBCP", "true").addDataValue("BuZ5LGNfGEU", "40").array(Constants.ORG_UNIT_IDS[0], eventProgramId, "Mt6Ac5brjoK");
loginActions.loginAsAdmin();
ApiResponse response = new RestApiActions("/messageConversations").get("", new QueryParamsBuilder().add("fields=*"));
int size = response.getBody().getAsJsonArray("messageConversations").size();
loginActions.loginAsSuperUser();
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
loginActions.loginAsAdmin();
messageConversationsActions.waitForNotification(size + 1);
messageConversationsActions.get("", new QueryParamsBuilder().add("fields=*")).validate().statusCode(200).body("messageConversations", hasSize(size + 1)).body("messageConversations.subject", hasItem("Program rule triggered"));
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class RuleEngineTests method shouldShowErrorsBasedOnValidationStrategy.
@ParameterizedTest
@CsvSource({ "ON_COMPLETE,COMPLETED,true", "ON_COMPLETE,ACTIVE,false", "ON_UPDATE_AND_INSERT,ACTIVE,true" })
public void shouldShowErrorsBasedOnValidationStrategy(String validationStrategy, String eventStatus, boolean shouldFail) {
String programStage = new ProgramStageActions().get("", new QueryParamsBuilder().addAll("filter=program.id:eq:" + trackerProgramId, "filter=validationStrategy:eq:" + validationStrategy)).extractString("programStages.id[0]");
JsonObject payload = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, programStage);
// program rule is triggered for events with date earlier than today
new JsonObjectBuilder(payload).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].occurredAt", Instant.now().minus(1, ChronoUnit.DAYS).toString()).addPropertyByJsonPath("trackedEntities[0].enrollments[0].events[0].status", eventStatus);
TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
if (shouldFail) {
response.validateErrorReport();
return;
}
response.validateSuccessfulImport();
}
Aggregations