Search in sources :

Example 1 with UserRoleEntity

use of io.gravitee.rest.api.model.UserRoleEntity in project gravitee-management-rest-api by gravitee-io.

the class UserMapperTest method testConvertUserEntityWithPermissions.

@Test
public void testConvertUserEntityWithPermissions() throws Exception {
    Instant now = Instant.now();
    Date nowDate = Date.from(now);
    // init
    UserEntity userEntity = new UserEntity();
    UserRoleEntity userRoleEntityOrganization = new UserRoleEntity();
    userRoleEntityOrganization.setId("org-id");
    userRoleEntityOrganization.setScope(RoleScope.ORGANIZATION);
    HashMap<String, char[]> organizationPermissions = new HashMap<>();
    organizationPermissions.put("USER", new char[] { 'C', 'R', 'U', 'D' });
    organizationPermissions.put("ENVIRONMENT", new char[] { 'C', 'R', 'U', 'D' });
    userRoleEntityOrganization.setPermissions(organizationPermissions);
    UserRoleEntity userRoleEntityEnvironment = new UserRoleEntity();
    userRoleEntityEnvironment.setScope(RoleScope.ENVIRONMENT);
    userRoleEntityEnvironment.setId("env-id");
    HashMap<String, char[]> environmentPermissions = new HashMap<>();
    environmentPermissions.put("APPLICATION", new char[] { 'C' });
    userRoleEntityEnvironment.setPermissions(environmentPermissions);
    userEntity.setCreatedAt(nowDate);
    userEntity.setEmail(USER_EMAIL);
    userEntity.setFirstname(USER_FIRSTNAME);
    userEntity.setId(USER_ID);
    userEntity.setLastConnectionAt(nowDate);
    userEntity.setLastname(USER_LASTNAME);
    userEntity.setPassword(USER_PASSWORD);
    userEntity.setPicture(USER_PICTURE);
    userEntity.setRoles(new HashSet<>(Arrays.asList(userRoleEntityOrganization, userRoleEntityEnvironment)));
    userEntity.setSource(USER_SOURCE);
    userEntity.setSourceId(USER_SOURCE_ID);
    userEntity.setStatus(USER_STATUS);
    userEntity.setUpdatedAt(nowDate);
    // Test
    User responseUser = userMapper.convert(userEntity);
    assertNotNull(responseUser);
    assertEquals(USER_ID, responseUser.getId());
    assertEquals(USER_EMAIL, responseUser.getEmail());
    assertEquals(USER_FIRSTNAME, responseUser.getFirstName());
    assertEquals(USER_LASTNAME, responseUser.getLastName());
    assertEquals(USER_FIRSTNAME + ' ' + USER_LASTNAME, responseUser.getDisplayName());
    assertTrue(responseUser.getPermissions().getAPPLICATION().containsAll(Arrays.asList("C")));
}
Also used : UserRoleEntity(io.gravitee.rest.api.model.UserRoleEntity) SearchableUser(io.gravitee.rest.api.idp.api.identity.SearchableUser) User(io.gravitee.rest.api.portal.rest.model.User) HashMap(java.util.HashMap) Instant(java.time.Instant) Date(java.util.Date) RegisterUserEntity(io.gravitee.rest.api.model.RegisterUserEntity) NewExternalUserEntity(io.gravitee.rest.api.model.NewExternalUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Aggregations

SearchableUser (io.gravitee.rest.api.idp.api.identity.SearchableUser)1 NewExternalUserEntity (io.gravitee.rest.api.model.NewExternalUserEntity)1 RegisterUserEntity (io.gravitee.rest.api.model.RegisterUserEntity)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 UserRoleEntity (io.gravitee.rest.api.model.UserRoleEntity)1 User (io.gravitee.rest.api.portal.rest.model.User)1 Instant (java.time.Instant)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1