Search in sources :

Example 1 with User

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

the class TrackedEntityInstanceAclReadTests method before.

@BeforeAll
public void before() throws Exception {
    teiActions = new TEIActions();
    metadataActions = new MetadataActions();
    userActions = new UserActions();
    // Setup as SuperUser
    new LoginActions().loginAsDefaultUser();
    // Set up metadata (Import twice to connect all references)
    metadataActions.importAndValidateMetadata(new File("src/test/resources/tracker/acl/metadata.json"));
    metadataActions.importAndValidateMetadata(new File("src/test/resources/tracker/acl/metadata.json"));
    // Import test data
    teiActions.postFile(new File("src/test/resources/tracker/acl/data.json"));
    // Set up all users for testing
    users.add(new User("User A", "O2PajOxjJSa", "UserA!123"));
    users.add(new User("User B", "aDy67f9ijOe", "UserB!123"));
    users.add(new User("User C", "CKrrGm5Be8O", "UserC!123"));
    users.add(new User("User D", "Lpa5INiC3Qf", "UserD!123"));
    users.add(new User("User ALL", "GTqb3WOZMop", "UserALL!123"));
    // Update passwords, so we can log in as them
    // Set AllAuth if user has it and ou scopes.
    // Map metadata and data sharing
    users.forEach(this::setupUser);
}
Also used : User(org.hisp.dhis.helpers.models.User) UserActions(org.hisp.dhis.actions.UserActions) MetadataActions(org.hisp.dhis.actions.metadata.MetadataActions) LoginActions(org.hisp.dhis.actions.LoginActions) TEIActions(org.hisp.dhis.actions.tracker.TEIActions) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with User

use of org.hisp.dhis.helpers.models.User 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)

Aggregations

LoginActions (org.hisp.dhis.actions.LoginActions)2 User (org.hisp.dhis.helpers.models.User)2 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 UserActions (org.hisp.dhis.actions.UserActions)1 MetadataActions (org.hisp.dhis.actions.metadata.MetadataActions)1 TEIActions (org.hisp.dhis.actions.tracker.TEIActions)1 ApiResponse (org.hisp.dhis.dto.ApiResponse)1 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1