use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method getRolesTest.
@Test
public void getRolesTest() {
RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
roleEntity.setId(1L);
Mockito.when(roleRepository.findAll()).thenReturn(List.of(roleEntity));
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles();
UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true);
assertEquals(1, userRoleModelsSet.size());
assertTrue(userRoleModelsSet.contains(expectedUserRoleModel));
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method getRolesByRoleIdsTest.
@Test
public void getRolesByRoleIdsTest() {
RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
roleEntity.setId(1L);
Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity));
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles(List.of(1L));
UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true);
assertEquals(1, userRoleModelsSet.size());
assertTrue(userRoleModelsSet.contains(expectedUserRoleModel));
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class DefaultRoleAccessor method createRoleWithPermissions.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserRoleModel createRoleWithPermissions(String roleName, PermissionMatrixModel permissionMatrix) {
RoleEntity roleEntity = createRole(roleName, true);
List<PermissionMatrixRelation> permissions = updateRoleOperations(roleEntity, permissionMatrix);
return new UserRoleModel(roleEntity.getId(), roleEntity.getRoleName(), roleEntity.getCustom(), createModelFromPermission(permissions));
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method updateTest.
@Test
public void updateTest() throws Exception {
String newRoleName = "newRoleName";
Long longId = 1L;
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, newRoleName, Set.of(permissionModel));
UserRoleModel userRoleModel = new UserRoleModel(longId, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
Mockito.when(roleAccessor.getRoles()).thenReturn(Set.of());
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.update(1L, rolePermissionModel);
Mockito.verify(authorizationManager).updateRoleName(Mockito.eq(longId), Mockito.eq(newRoleName));
Mockito.verify(authorizationManager).updatePermissionsForRole(Mockito.anyString(), Mockito.any());
assertTrue(rolePermissionModelActionResponse.isSuccessful());
assertFalse(rolePermissionModelActionResponse.hasContent());
assertEquals(HttpStatus.NO_CONTENT, rolePermissionModelActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method getOneTest.
@Test
public void getOneTest() {
PermissionModel permissionModel = createPermissionModel();
UserRoleModel userRoleModel = new UserRoleModel(1L, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.getOne(1L);
assertTrue(rolePermissionModelActionResponse.isSuccessful());
assertTrue(rolePermissionModelActionResponse.hasContent());
assertEquals(HttpStatus.OK, rolePermissionModelActionResponse.getHttpStatus());
}
Aggregations