IdeaService { public void rejectIdea(String campaignId, String ideaId, String rejectionComment, UserEntity approvingAdmin) { Assert.hasText(ideaId, "ideaId must not be null."); Assert.hasText(rejectionComment, "rejectionComment must not be null"); Assert.notNull(approvingAdmin, "approvingAdmin must not be null."); checkRequestorIsAdmin(approvingAdmin); validateIdeaExists(ideaId); validateCampaignExists(campaignId); final IdeasCampaignEntity campaign = ideasCampaignRepository.findOne(campaignId); final IdeaEntity ideaToReject = ideaRepository.findOne(ideaId); campaign.rejectIdea(ideaToReject, approvingAdmin, rejectionComment); userNotificationService.notifyCreatorOnIdeaRejected(ideaToReject, rejectionComment, campaign.getContent().getDe().getTitle()); ideaRepository.save(ideaToReject); }  IdeaOut fetchIdea(String ideaId, UserEntity requestor); Page<IdeaOut> fetchIdeasByStatus(String campaignId, Set<IdeaStatus> statusSet, Integer page, Integer pageSize, UserEntity requestor); Page<IdeaOut> fetchIdeasByRequestorHasVoted(String campaignId, boolean hasVoted, Integer page, Integer pageSize, UserEntity requestor); List<IdeaOut> fetchIdeasByCampaignAndCreator(String campaignId, UserEntity creator, UserEntity requestor); IdeaOut createNewIdea(String campaignId, IdeaIn cmd, UserEntity creator); IdeaOut modifyIdea(String ideaId, IdeaIn cmd, UserEntity requestingUser); void approveIdea(String campaignId, String ideaId, UserEntity approvingAdmin); void rejectIdea(String campaignId, String ideaId, String rejectionComment, UserEntity approvingAdmin); void voteForIdea(VoteCmd voteCmd, UserEntity voter);  }
@Test public void rejectIdea_shouldPersistRejectedIdea() { final String missingIdeaId = "idea27"; final UserEntity approver = givenUserEntity("test_adminId"); approver.setRoles(singletonList(Roles.ROLE_ADMIN)); final IdeasCampaignEntity campaign = givenIdeaCampaignExists("test_campaignId", true); givenIdeaExists(new IdeaIn("test_title", "test_pitch"), campaign.getId()); ideaService.rejectIdea(campaign.getId(), missingIdeaId, "you are rejected!", approver); final ArgumentCaptor<IdeaEntity> captor = ArgumentCaptor.forClass(IdeaEntity.class); verify(ideaRepository).save(captor.capture()); assertThat(captor.getValue().getStatus(), is(IdeaStatus.REJECTED)); assertThat(captor.getValue().getRejectionComment(), is("you are rejected!")); }
@Test(expected = ResourceNotFoundException.class) public void rejectIdea_shouldThrowException_OnNotExistingIdea() { final String missingIdeaId = "idea27"; final UserEntity approver = givenUserEntity("test_adminId"); approver.setRoles(singletonList(Roles.ROLE_ADMIN)); final IdeasCampaignEntity campaign = givenIdeaCampaignExists("test_campaignId", true); givenIdeaDoesntExist(missingIdeaId); ideaService.rejectIdea(campaign.getId(), missingIdeaId, "test comment", approver); }
@Test(expected = AuthorizationServiceException.class) public void rejectIdea_shouldThrowException_OnNonAdminRequesting() { final String missingIdeaId = "idea27"; final UserEntity approver = givenUserEntity("test_adminId"); approver.setRoles(Collections.emptyList()); final IdeasCampaignEntity campaignEntity = givenIdeaCampaignExists("test_campaignId", true); givenIdeaExists(new IdeaIn("test_title", "test_pitch"), campaignEntity.getId()); ideaService.rejectIdea(campaignEntity.getId(), missingIdeaId, "ich bin ein admin", approver); }
@Test public void rejectIdea_shouldThrowException_OnCampaignNotActive() { final UserEntity approver = givenUserEntity("test_adminId"); approver.setRoles(singletonList(Roles.ROLE_ADMIN)); final IdeasCampaignEntity campaign = givenIdeaCampaignExists("test_campaignId", false); final IdeaEntity ideaEntity = givenIdeaExists(new IdeaIn("test_title", "test_pitch"), campaign.getId()); try { ideaService.rejectIdea(campaign.getId(), ideaEntity.getCampaignId(), ideaEntity.getId(), approver); fail("Expected exception not thrown"); } catch (InvalidRequestException e) { assertThat(e.getMessage(), equalTo("campaign_not_active")); } }