Search in sources :

Example 6 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class AnalyticsDimensionsTest method shouldReturnAssociatedCategoriesWhenProgramHasCatCombo.

@Test
public void shouldReturnAssociatedCategoriesWhenProgramHasCatCombo() {
    String programWithCatCombo = programActions.get("?filter=categoryCombo.code:!eq:default&filter=programType:eq:WITH_REGISTRATION").extractString("programs.id[0]");
    String programStage = programActions.get(programWithCatCombo + "/programStages").extractString("programStages[0].id");
    assertNotNull(programStage);
    Consumer<ApiResponse> validate = response -> {
        response.validate().body("dimensions", hasSize(greaterThanOrEqualTo(1))).body("dimensions.dimensionType", everyItem(startsWith("CATEGORY"))).body("dimensions.dimensionType", hasItems("CATEGORY", "CATEGORY_OPTION_GROUP_SET"));
    };
    validate.accept(analyticsEventActions.aggregate().getDimensions(programStage, new QueryParamsBuilder().add("filter", "dimensionType:like:CATEGORY")));
    validate.accept(analyticsEventActions.query().getDimensions(programStage, new QueryParamsBuilder().add("filter", "dimensionType:like:CATEGORY")));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Constants(org.hisp.dhis.Constants) Arrays(java.util.Arrays) AnalyticsEventActions(org.hisp.dhis.actions.analytics.AnalyticsEventActions) AnalyticsEnrollmentsActions(org.hisp.dhis.actions.analytics.AnalyticsEnrollmentsActions) BeforeAll(org.junit.jupiter.api.BeforeAll) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ProgramActions(org.hisp.dhis.actions.metadata.ProgramActions) Matchers(org.hamcrest.Matchers) ProgramStageActions(org.hisp.dhis.actions.metadata.ProgramStageActions) CustomMatchers(org.hisp.dhis.helpers.matchers.CustomMatchers) Arguments(org.junit.jupiter.params.provider.Arguments) ApiResponse(org.hisp.dhis.dto.ApiResponse) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Program(org.hisp.dhis.dto.Program) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Ordering(com.google.common.collect.Ordering) ApiTest(org.hisp.dhis.ApiTest) Sorted(org.hisp.dhis.helpers.matchers.Sorted) TrackedEntityAttributeActions(org.hisp.dhis.actions.metadata.TrackedEntityAttributeActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiTest(org.hisp.dhis.ApiTest)

Example 7 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class DataImportTest method dataValuesCanBeImportedInBulk.

@Test
public void dataValuesCanBeImportedInBulk() {
    ApiResponse response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_bulk.json"), new QueryParamsBuilder().add("importReportMode=FULL"));
    response.validate().statusCode(200).rootPath("response").body("status", equalTo("SUCCESS")).body("conflicts", empty()).body("importCount", notNullValue()).rootPath("importCount").body("ignored", not(greaterThan(0))).body("deleted", not(greaterThan(0)));
    ImportSummary importSummary = response.getImportSummaries().get(0);
    assertThat(response.getAsString(), importSummary.getImportCount().getImported() + importSummary.getImportCount().getUpdated(), greaterThan(0));
}
Also used : ImportSummary(org.hisp.dhis.dto.ImportSummary) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 8 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class DataImportTest method cleanUp.

@AfterAll
public void cleanUp() {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll("importReportMode=FULL", "importStrategy=DELETE");
    ApiResponse response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_bulk.json"), queryParamsBuilder);
    response.validate().statusCode(200);
    response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_single_dataset.json"), queryParamsBuilder);
    response.validate().statusCode(200);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) AfterAll(org.junit.jupiter.api.AfterAll)

Example 9 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class ProgramActions method addDataElement.

public ApiResponse addDataElement(String programStageId, String dataElementId, boolean isMandatory) {
    JsonObject object = programStageActions.get(programStageId, new QueryParamsBuilder().add("fields=*")).getBody();
    JsonObjectBuilder.jsonObject(object).addOrAppendToArray("programStageDataElements", new JsonObjectBuilder().addProperty("compulsory", String.valueOf(isMandatory)).addObject("dataElement", new JsonObjectBuilder().addProperty("id", dataElementId)).build());
    return programStageActions.update(programStageId, object);
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder)

Example 10 with QueryParamsBuilder

use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.

the class MetadataActions method importMetadata.

public MetadataApiResponse importMetadata(JsonObject object, String... queryParams) {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll(queryParams);
    queryParamsBuilder.addAll("atomicMode=OBJECT", "importReportMode=FULL");
    ApiResponse response = post(object, queryParamsBuilder);
    response.validate().statusCode(200);
    return new MetadataApiResponse(response);
}
Also used : MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) MetadataApiResponse(org.hisp.dhis.dto.MetadataApiResponse)

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