Search in sources :

Example 76 with ApiResponse

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

the class DataImportTest method dataValuesCanBeImportedAsync.

@Test
public void dataValuesCanBeImportedAsync() {
    ApiResponse response = dataValueSetActions.postFile(new File("src/test/resources/aggregate/dataValues_bulk.json"), new QueryParamsBuilder().addAll("reportMode=DEBUG", "async=true")).validateStatus(200);
    String taskId = response.extractString("response.id");
    // Validate that job was successful
    systemActions.waitUntilTaskCompleted("DATAVALUE_IMPORT", taskId).validate().body("message", Matchers.containsInAnyOrder("Process started", "Importing data values", "Import done"));
    // validate task summaries were created
    ApiResponse taskSummariesResponse = systemActions.waitForTaskSummaries("DATAVALUE_IMPORT", taskId);
    taskSummariesResponse.validate().statusCode(200).body("status", equalTo("SUCCESS")).rootPath("importCount").body("deleted", equalTo(0)).body("ignored", equalTo(0));
    ImportSummary importSummary = taskSummariesResponse.getImportSummaries().get(0);
    assertThat(taskSummariesResponse.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 77 with ApiResponse

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

the class DataItemQueryTests method testFilterByDimensionTypeUsingDefaultPagination.

@Test
public void testFilterByDimensionTypeUsingDefaultPagination() {
    // Given
    final String theDimensionType = "PROGRAM_INDICATOR";
    final String theUrlParams = "?filter=dimensionItemType:in:[%s]";
    // When
    final ApiResponse response = dataItemActions.get(format(theUrlParams, theDimensionType));
    // Then
    response.validate().statusCode(is(OK));
    response.validate().body("pager", isA(Object.class));
    response.validate().body("dataItems", is(not(empty())));
    response.validate().body("dataItems.dimensionItemType", everyItem(is(theDimensionType)));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 78 with ApiResponse

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

the class UserActions method addRoleToUser.

public void addRoleToUser(String userId, String userRoleId) {
    ApiResponse response = this.get(userId);
    if (response.extractList("userRoles.id").contains(userRoleId)) {
        return;
    }
    JsonObject object = response.getBody();
    JsonObject userRole = new JsonObject();
    userRole.addProperty("id", userRoleId);
    object.get("userRoles").getAsJsonArray().add(userRole);
    this.update(userId, object).validate().statusCode(200);
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 79 with ApiResponse

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

the class UserActions method addUser.

public String addUser(final String firstName, final String surname, final String username, final String password) {
    String id = idGenerator.generateUniqueId();
    JsonObject user = new JsonObjectBuilder().addProperty("id", id).addProperty("firstName", firstName).addProperty("surname", surname).addProperty("username", username).addProperty("password", password).build();
    ApiResponse response = this.post(user);
    response.validate().statusCode(201);
    TestRunStorage.addCreatedEntity(endpoint, id);
    return id;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 80 with ApiResponse

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

the class UserActions method grantUserDataViewAccessToOrgUnit.

public void grantUserDataViewAccessToOrgUnit(String userId, String orgUnitId) {
    JsonObject object = this.get(userId).getBodyAsJsonBuilder().addOrAppendToArray("dataViewOrganisationUnits", new JsonObjectBuilder().addProperty("id", orgUnitId).build()).build();
    ApiResponse response = this.update(userId, object);
    response.validate().statusCode(200).body("status", equalTo("OK"));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse)

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