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);
}
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"))));
}
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")));
}
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));
}
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()));
}
}
Aggregations