@Test public void createUserRoleTest() throws PacManException { CreateRoleDetailsRequest roleDetailsRequest = getUserRoleDetailsRequest(); Optional<UserRoles> userRolesDetail = getUserRoleDetails(); when(userRolesRepository.existsByRoleNameIgnoreCase(roleDetailsRequest.getRoleName())).thenReturn(false); when(userRolesRepository.save(userRolesDetail.get())).thenReturn(userRolesDetail.get()); assertThat(userRolesService.createUserRole(roleDetailsRequest, anyString()), is(USER_ROLE_CREATION_SUCCESS)); }
@Override public String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId) throws PacManException { boolean isRoleNameExits = userRolesRepository.existsByRoleNameIgnoreCase(roleDetailsRequest.getRoleName()); if (!isRoleNameExits) { try { Date currentDate = new Date(); UserRoles userRole = new UserRoles(); userRole.setRoleId(UUID.randomUUID().toString()); userRole.setClient("pacman2_api_client"); userRole.setRoleDesc(roleDetailsRequest.getDescription()); userRole.setCreatedDate(currentDate); userRole.setModifiedDate(currentDate); userRole.setOwner(userId); userRole.setRoleName(roleDetailsRequest.getRoleName()); userRole.setWritePermission(roleDetailsRequest.getWritePermission()); userRolesRepository.save(userRole); return USER_ROLE_CREATION_SUCCESS; } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); throw new PacManException(UNEXPECTED_ERROR_OCCURRED); } } else { throw new PacManException(USER_ROLE_ALREADY_EXITS); } }
UserRolesServiceImpl implements UserRolesService { @Override public String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId) throws PacManException { boolean isRoleNameExits = userRolesRepository.existsByRoleNameIgnoreCase(roleDetailsRequest.getRoleName()); if (!isRoleNameExits) { try { Date currentDate = new Date(); UserRoles userRole = new UserRoles(); userRole.setRoleId(UUID.randomUUID().toString()); userRole.setClient("pacman2_api_client"); userRole.setRoleDesc(roleDetailsRequest.getDescription()); userRole.setCreatedDate(currentDate); userRole.setModifiedDate(currentDate); userRole.setOwner(userId); userRole.setRoleName(roleDetailsRequest.getRoleName()); userRole.setWritePermission(roleDetailsRequest.getWritePermission()); userRolesRepository.save(userRole); return USER_ROLE_CREATION_SUCCESS; } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); throw new PacManException(UNEXPECTED_ERROR_OCCURRED); } } else { throw new PacManException(USER_ROLE_ALREADY_EXITS); } } }
UserRolesServiceImpl implements UserRolesService { @Override public String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId) throws PacManException { boolean isRoleNameExits = userRolesRepository.existsByRoleNameIgnoreCase(roleDetailsRequest.getRoleName()); if (!isRoleNameExits) { try { Date currentDate = new Date(); UserRoles userRole = new UserRoles(); userRole.setRoleId(UUID.randomUUID().toString()); userRole.setClient("pacman2_api_client"); userRole.setRoleDesc(roleDetailsRequest.getDescription()); userRole.setCreatedDate(currentDate); userRole.setModifiedDate(currentDate); userRole.setOwner(userId); userRole.setRoleName(roleDetailsRequest.getRoleName()); userRole.setWritePermission(roleDetailsRequest.getWritePermission()); userRolesRepository.save(userRole); return USER_ROLE_CREATION_SUCCESS; } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); throw new PacManException(UNEXPECTED_ERROR_OCCURRED); } } else { throw new PacManException(USER_ROLE_ALREADY_EXITS); } }  }
UserRolesServiceImpl implements UserRolesService { @Override public String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId) throws PacManException { boolean isRoleNameExits = userRolesRepository.existsByRoleNameIgnoreCase(roleDetailsRequest.getRoleName()); if (!isRoleNameExits) { try { Date currentDate = new Date(); UserRoles userRole = new UserRoles(); userRole.setRoleId(UUID.randomUUID().toString()); userRole.setClient("pacman2_api_client"); userRole.setRoleDesc(roleDetailsRequest.getDescription()); userRole.setCreatedDate(currentDate); userRole.setModifiedDate(currentDate); userRole.setOwner(userId); userRole.setRoleName(roleDetailsRequest.getRoleName()); userRole.setWritePermission(roleDetailsRequest.getWritePermission()); userRolesRepository.save(userRole); return USER_ROLE_CREATION_SUCCESS; } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); throw new PacManException(UNEXPECTED_ERROR_OCCURRED); } } else { throw new PacManException(USER_ROLE_ALREADY_EXITS); } }  @Override Page<UserRolesResponse> getAllUserRoles(String searchTerm, int page, int size); @Override String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId); @Override String updateUserRole(final UpdateRoleDetailsRequest roleDetailsRequest, final String userId); @Override UserRoles getUserRoleById(final String roleId); }
UserRolesServiceImpl implements UserRolesService { @Override public String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId) throws PacManException { boolean isRoleNameExits = userRolesRepository.existsByRoleNameIgnoreCase(roleDetailsRequest.getRoleName()); if (!isRoleNameExits) { try { Date currentDate = new Date(); UserRoles userRole = new UserRoles(); userRole.setRoleId(UUID.randomUUID().toString()); userRole.setClient("pacman2_api_client"); userRole.setRoleDesc(roleDetailsRequest.getDescription()); userRole.setCreatedDate(currentDate); userRole.setModifiedDate(currentDate); userRole.setOwner(userId); userRole.setRoleName(roleDetailsRequest.getRoleName()); userRole.setWritePermission(roleDetailsRequest.getWritePermission()); userRolesRepository.save(userRole); return USER_ROLE_CREATION_SUCCESS; } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); throw new PacManException(UNEXPECTED_ERROR_OCCURRED); } } else { throw new PacManException(USER_ROLE_ALREADY_EXITS); } }  @Override Page<UserRolesResponse> getAllUserRoles(String searchTerm, int page, int size); @Override String createUserRole(final CreateRoleDetailsRequest roleDetailsRequest, final String userId); @Override String updateUserRole(final UpdateRoleDetailsRequest roleDetailsRequest, final String userId); @Override UserRoles getUserRoleById(final String roleId);  }