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