@Test public void createRoleShouldThrowExceptionWhenRoleIdAlreadyExists() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Cannot create a role that already exists"); RoleModel originalRole = aRole(RoleType.SCHOOL); originalRole.setId(123L); given(mockRoleDao.find(123L)).willReturn(originalRole); RoleModel toCreate = aRole(RoleType.SCHOOL); toCreate.setId(123L); underTest.createRole(toCreate); }
public RoleModel createRole(RoleModel role) { if (roleExists(role.getId())) { throw new IllegalStateException("Cannot create a role that already exists"); } if (RoleUtils.isReservedRoleName(role.getName())) { throw new IllegalStateException("Cannot create a role with reserved role name: " + role.getName()); } validateRolePermissions(role); roleDao.store(role); return role; }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleModel createRole(RoleModel role) { if (roleExists(role.getId())) { throw new IllegalStateException("Cannot create a role that already exists"); } if (RoleUtils.isReservedRoleName(role.getName())) { throw new IllegalStateException("Cannot create a role with reserved role name: " + role.getName()); } validateRolePermissions(role); roleDao.store(role); return role; } }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleModel createRole(RoleModel role) { if (roleExists(role.getId())) { throw new IllegalStateException("Cannot create a role that already exists"); } if (RoleUtils.isReservedRoleName(role.getName())) { throw new IllegalStateException("Cannot create a role with reserved role name: " + role.getName()); } validateRolePermissions(role); roleDao.store(role); return role; }  }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleModel createRole(RoleModel role) { if (roleExists(role.getId())) { throw new IllegalStateException("Cannot create a role that already exists"); } if (RoleUtils.isReservedRoleName(role.getName())) { throw new IllegalStateException("Cannot create a role with reserved role name: " + role.getName()); } validateRolePermissions(role); roleDao.store(role); return role; }  void setRoleDao(RoleDAO roleDao); void setPermissionDao(PermissionDAO permissionDao); void setUsersService(UsersService usersService); void setRoleAssignmentDao(RoleAssignmentDAO roleAssignmentDao); @Override void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent); RoleModel createRole(RoleModel role); RoleAssignment createRoleAssignment(RoleAssignment roleAssignment); List<PermissionModel> getSchoolPermissions(); List<PermissionModel> getVaultPermissions(); RoleModel getRole(long id); RoleModel getIsAdmin(); RoleModel getDataOwner(); List<RoleModel> getEditableRoles(); List<RoleModel> getViewableRoles(); List<RoleModel> getSchoolRoles(); List<RoleModel> getVaultRoles(); RoleAssignment getRoleAssignment(long id); List<RoleAssignment> getRoleAssignmentsForSchool(String schoolId); List<RoleAssignment> getRoleAssignmentsForVault(String vaultId); User getVaultOwner(String vaultId); List<RoleAssignment> getRoleAssignmentsForUser(String userId); List<RoleAssignment> getRoleAssignmentsForRole(Long roleId); boolean hasAdminDashboardPermissions(String userId); Set<Permission> getUserPermissions(String userId); boolean hasPermission(String userId, Permission permission); boolean isAdminUser(String userId); RoleModel updateRole(RoleModel role); RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment); void deleteRole(Long roleId); void deleteRoleAssignment(Long roleAssignmentId); }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleModel createRole(RoleModel role) { if (roleExists(role.getId())) { throw new IllegalStateException("Cannot create a role that already exists"); } if (RoleUtils.isReservedRoleName(role.getName())) { throw new IllegalStateException("Cannot create a role with reserved role name: " + role.getName()); } validateRolePermissions(role); roleDao.store(role); return role; }  void setRoleDao(RoleDAO roleDao); void setPermissionDao(PermissionDAO permissionDao); void setUsersService(UsersService usersService); void setRoleAssignmentDao(RoleAssignmentDAO roleAssignmentDao); @Override void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent); RoleModel createRole(RoleModel role); RoleAssignment createRoleAssignment(RoleAssignment roleAssignment); List<PermissionModel> getSchoolPermissions(); List<PermissionModel> getVaultPermissions(); RoleModel getRole(long id); RoleModel getIsAdmin(); RoleModel getDataOwner(); List<RoleModel> getEditableRoles(); List<RoleModel> getViewableRoles(); List<RoleModel> getSchoolRoles(); List<RoleModel> getVaultRoles(); RoleAssignment getRoleAssignment(long id); List<RoleAssignment> getRoleAssignmentsForSchool(String schoolId); List<RoleAssignment> getRoleAssignmentsForVault(String vaultId); User getVaultOwner(String vaultId); List<RoleAssignment> getRoleAssignmentsForUser(String userId); List<RoleAssignment> getRoleAssignmentsForRole(Long roleId); boolean hasAdminDashboardPermissions(String userId); Set<Permission> getUserPermissions(String userId); boolean hasPermission(String userId, Permission permission); boolean isAdminUser(String userId); RoleModel updateRole(RoleModel role); RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment); void deleteRole(Long roleId); void deleteRoleAssignment(Long roleAssignmentId);  }