@Test public void updateRoleAssignmentShouldThrowExceptionIfUpdatedStateIsInvalid() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Cannot create role assignment without user"); RoleAssignment original = aRoleAssignment(aRole(RoleType.SCHOOL)); original.setSchoolId("school1"); original.setId(1L); given(mockRoleAssignmentDao.find(1L)).willReturn(original); RoleAssignment update = aRoleAssignment(null); update.setUserId(null); update.setId(1L); underTest.updateRoleAssignment(update); }
public RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment) { RoleAssignment original = roleAssignmentDao.find(roleAssignment.getId()); if (original == null) { throw new IllegalStateException("Cannot update a role assignment that does not exist"); } if (!roleAssignment.equals(original)) { validateRoleAssignment(roleAssignment); roleAssignmentDao.update(roleAssignment); } return roleAssignment; }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment) { RoleAssignment original = roleAssignmentDao.find(roleAssignment.getId()); if (original == null) { throw new IllegalStateException("Cannot update a role assignment that does not exist"); } if (!roleAssignment.equals(original)) { validateRoleAssignment(roleAssignment); roleAssignmentDao.update(roleAssignment); } return roleAssignment; } }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment) { RoleAssignment original = roleAssignmentDao.find(roleAssignment.getId()); if (original == null) { throw new IllegalStateException("Cannot update a role assignment that does not exist"); } if (!roleAssignment.equals(original)) { validateRoleAssignment(roleAssignment); roleAssignmentDao.update(roleAssignment); } return roleAssignment; }  }
RolesAndPermissionsService implements ApplicationListener<ContextRefreshedEvent> { public RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment) { RoleAssignment original = roleAssignmentDao.find(roleAssignment.getId()); if (original == null) { throw new IllegalStateException("Cannot update a role assignment that does not exist"); } if (!roleAssignment.equals(original)) { validateRoleAssignment(roleAssignment); roleAssignmentDao.update(roleAssignment); } return roleAssignment; }  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 RoleAssignment updateRoleAssignment(RoleAssignment roleAssignment) { RoleAssignment original = roleAssignmentDao.find(roleAssignment.getId()); if (original == null) { throw new IllegalStateException("Cannot update a role assignment that does not exist"); } if (!roleAssignment.equals(original)) { validateRoleAssignment(roleAssignment); roleAssignmentDao.update(roleAssignment); } return roleAssignment; }  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);  }