Search in sources :

Example 71 with QueryParamsBuilder

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);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 72 with QueryParamsBuilder

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));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 73 with QueryParamsBuilder

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));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 74 with QueryParamsBuilder

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);
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 75 with QueryParamsBuilder

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)));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Aggregations

QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)90 JsonObject (com.google.gson.JsonObject)54 Test (org.junit.jupiter.api.Test)51 ApiResponse (org.hisp.dhis.dto.ApiResponse)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 ApiTest (org.hisp.dhis.ApiTest)27 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)21 File (java.io.File)20 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)20 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)8 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)6 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)5 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)4 JsonArray (com.google.gson.JsonArray)3 HashMap (java.util.HashMap)3 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)3 ImportSummary (org.hisp.dhis.dto.ImportSummary)3