Search in sources :

Example 16 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class LoginTests method addOAuthClient.

private void addOAuthClient() {
    JsonObject client = new JsonObject();
    client.addProperty("name", "OAuth2 client" + DataGenerator.randomString());
    client.addProperty("cid", oauthClientId);
    client.addProperty("secret", secret);
    JsonArray grantTypes = new JsonArray();
    grantTypes.add("password");
    grantTypes.add("refresh_token");
    grantTypes.add("authorization_code");
    client.add("grantTypes", grantTypes);
    ApiResponse response = oauth2Clients.post(client);
    ResponseValidationHelper.validateObjectCreation(response);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 17 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class LoginTests method shouldBeAbleToGetRefreshToken.

@Test
public void shouldBeAbleToGetRefreshToken() {
    loginActions.addAuthenticationHeader(oauthClientId, secret);
    JsonObject object = new JsonObject();
    object.addProperty("password", password);
    object.addProperty("grant_type", "password");
    object.addProperty("username", userName);
    ApiResponse passwordGrantTypeResponse = uaaActions.post("oauth/token", new JsonObject(), new QueryParamsBuilder().addAll("password=" + password, "username=" + userName, "grant_type=password"));
    passwordGrantTypeResponse.validate().statusCode(200);
    loginActions.addAuthenticationHeader(oauthClientId, secret);
    ApiResponse refreshTokenResponse = uaaActions.post("oauth/token", new JsonObject(), new QueryParamsBuilder().addAll("grant_type=refresh_token", "refresh_token=" + passwordGrantTypeResponse.extractString("refresh_token")));
    refreshTokenResponse.validate().statusCode(200).body("access_token", notNullValue()).body("token_type", notNullValue()).body("refresh_token", notNullValue()).body("expires_in", notNullValue()).body("scope", notNullValue()).body("access_token", not(equalTo(passwordGrantTypeResponse.extractString("access_token"))));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test)

Example 18 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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 19 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse 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 20 with ApiResponse

use of org.hisp.dhis.dto.ApiResponse in project dhis2-core by dhis2.

the class DataImportTest method dataValuesCanBeImportedForSingleDataSet.

@Test
public void dataValuesCanBeImportedForSingleDataSet() throws IOException {
    String orgUnit = "O6uvpzGd5pu";
    String period = "201911";
    String dataSet = "VEM58nY22sO";
    JsonObject importedPayload = new JsonFileReader(new File("src/test/resources/aggregate/dataValues_single_dataset.json")).get();
    ApiResponse response = dataValueSetActions.post(importedPayload);
    response.validate().statusCode(200).rootPath("response").body("status", equalTo("SUCCESS")).body("conflicts", empty()).body("importCount", notNullValue()).rootPath("response.importCount").body("ignored", not(greaterThan(0))).body("deleted", not(greaterThan(0)));
    ImportSummary importSummary = response.getImportSummaries().get(0);
    assertThat(importSummary, notNullValue());
    assertThat(response.getAsString(), importSummary.getImportCount().getImported() + importSummary.getImportCount().getUpdated(), greaterThanOrEqualTo(2));
    response = dataValueSetActions.get(String.format("?orgUnit=%s&period=%s&dataSet=%s", orgUnit, period, dataSet));
    response.validate().body("dataSet", equalTo(dataSet)).body("period", equalTo(period)).body("orgUnit", equalTo(orgUnit)).body("dataValues", hasSize(greaterThanOrEqualTo(2)));
    JsonArray dataValues = response.getBody().get("dataValues").getAsJsonArray();
    for (JsonElement j : dataValues) {
        JsonObject object = j.getAsJsonObject();
        response = dataValueActions.get(String.format("?ou=%s&pe=%s&de=%s&co=%s", orgUnit, period, object.get("dataElement").getAsString(), object.get("categoryOptionCombo").getAsString()));
        response.validate().statusCode(200).body(containsString(object.get("value").getAsString()));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ImportSummary(org.hisp.dhis.dto.ImportSummary) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) JsonFileReader(org.hisp.dhis.helpers.file.JsonFileReader) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Aggregations

ApiResponse (org.hisp.dhis.dto.ApiResponse)145 Test (org.junit.jupiter.api.Test)75 JsonObject (com.google.gson.JsonObject)63 ApiTest (org.hisp.dhis.ApiTest)63 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)49 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)48 File (java.io.File)25 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)18 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)18 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)14 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)11 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)11 RestApiActions (org.hisp.dhis.actions.RestApiActions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 JsonArray (com.google.gson.JsonArray)5 ImportSummary (org.hisp.dhis.dto.ImportSummary)5 LoginActions (org.hisp.dhis.actions.LoginActions)4 MetadataApiResponse (org.hisp.dhis.dto.MetadataApiResponse)4 ArrayList (java.util.ArrayList)3