Search in sources :

Example 46 with ApiResponse

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

the class TrackedEntityInstanceAclReadTests method testUserDataAndOrgUnitScopeReadAccess.

@ParameterizedTest
@ValueSource(strings = { "O2PajOxjJSa", "aDy67f9ijOe", "CKrrGm5Be8O", "Lpa5INiC3Qf", "GTqb3WOZMop" })
public void testUserDataAndOrgUnitScopeReadAccess(String userUid) {
    User user = users.stream().filter(_user -> _user.getUid().equals(userUid)).findFirst().orElseThrow(() -> new RuntimeException("User UID not found for test"));
    new LoginActions().loginAsUser(user.getUsername(), user.getPassword());
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll("filter=pyNnf3UaOOg:NE:zz", "trackedEntityType=YDzXLdCvV4h", "ouMode=ACCESSIBLE", "fields=*");
    ApiResponse response = teiActions.get("/", queryParamsBuilder);
    response.validate().statusCode(200);
    response.validate().body("trackedEntityInstances", Matchers.not(Matchers.emptyArray()));
    JsonObject json = response.getBody();
    json.getAsJsonArray("trackedEntityInstances").iterator().forEachRemaining((teiJson) -> assertTrackedEntityInstance(user, teiJson.getAsJsonObject()));
}
Also used : User(org.hisp.dhis.helpers.models.User) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) LoginActions(org.hisp.dhis.actions.LoginActions) ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with ApiResponse

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

the class EventImportTests method post.

private ApiResponse post(String fileName, boolean async) {
    QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
    queryParamsBuilder.addAll("dryRun=false", "eventIdScheme=UID", "orgUnitIdScheme=UID", "async=" + String.valueOf(async));
    ApiResponse response = eventActions.postFile(new File("src/test/resources/tracker/events/" + fileName), queryParamsBuilder);
    return response;
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 48 with ApiResponse

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

the class UserAssignmentFilterTests method eventsShouldBeFilteredByUnassigned.

@Test
public void eventsShouldBeFilteredByUnassigned() {
    // arrange
    loginActions.loginAsUser(userUsername, userPassword);
    String eventId = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=CURRENT").extractString("events.event[0]");
    assertNotNull(eventId, "Event was not found");
    unassignEvent(eventId);
    // act
    ApiResponse currentUserEvents = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=CURRENT");
    ApiResponse unassignedEvents = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=NONE");
    // assert
    currentUserEvents.validate().statusCode(200).body("events", notNullValue()).body("events.event", not(hasItem(eventId)));
    unassignedEvents.validate().statusCode(200).body("events", notNullValue()).body("events.event", hasItem(eventId)).body("events.assignedUser", everyItem(is(emptyOrNullString())));
}
Also used : Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) ApiResponse(org.hisp.dhis.dto.ApiResponse) Test(org.junit.jupiter.api.Test) ApiTest(org.hisp.dhis.ApiTest)

Example 49 with ApiResponse

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

the class UserAssignmentFilterTests method unassignEvent.

private ApiResponse unassignEvent(String eventId) {
    JsonObject body = eventActions.get(eventId).getBody();
    body.addProperty("assignedUser", "");
    ApiResponse response = eventActions.update(eventId, body);
    response.validate().statusCode(200);
    return response;
}
Also used : JsonObject(com.google.gson.JsonObject) ApiResponse(org.hisp.dhis.dto.ApiResponse)

Example 50 with ApiResponse

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

the class UserAssignmentFilterTests method eventsShouldBeFilteredForAssignedUserByStatus.

@Test
public void eventsShouldBeFilteredForAssignedUserByStatus() {
    // arrange
    loginActions.loginAsUser(userUsername, userPassword);
    String eventId = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=CURRENT").extractString("events.event[0]");
    assertNotNull(eventId, "Event was not found");
    String status = "SCHEDULE";
    changeEventStatus(eventId, status);
    // act
    ApiResponse filteredEvents = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=CURRENT&status=" + status);
    ApiResponse activeEvents = eventActions.get("?orgUnit=" + orgUnit + "&assignedUserMode=CURRENT&status=ACTIVE");
    // assert
    filteredEvents.validate().statusCode(200).body("events", hasSize(1)).body("events.assignedUser", everyItem(equalTo(userId))).body("events.status", everyItem(equalTo(status)));
    activeEvents.validate().statusCode(200).body("events", hasSize(3)).body("events.assignedUser", everyItem(equalTo(userId))).body("events.status", everyItem(equalTo("ACTIVE")));
}
Also used : Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) ApiResponse(org.hisp.dhis.dto.ApiResponse) 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