@Test public void when_a_project_is_found_2_events_will_be_triggered_first_project_deleted_second_owner_recalc() { ArgumentCaptor<DomainMessage> captorMessage = ArgumentCaptor.forClass(DomainMessage.class); Project project1 = new Project(); project1.id="project1"; User owner1 = mock(User.class); when(owner1.getName()).thenReturn("owner1"); project1.owner=owner1; when(projectRepository.findOrFailProject("project1")).thenReturn(project1); serviceToTest.deleteProject("project1"); verify(eventBusService,times(2)).sendAsynchron(captorMessage.capture()); List<DomainMessage> allMessages = captorMessage.getAllValues(); DomainMessage value1 = allMessages.get(0); assertEquals(MessageID.PROJECT_DELETED, value1.getMessageId()); assertEquals("project1", value1.get(MessageDataKeys.PROJECT_DELETE_DATA).getProjectId()); DomainMessage value2 = allMessages.get(1); assertEquals(MessageID.REQUEST_USER_ROLE_RECALCULATION, value2.getMessageId()); assertEquals("owner1", value2.get(MessageDataKeys.USER_ID_DATA).getUserId()); }
@UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) public void deleteProject(String projectId) { auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30)); assertion.isValidProjectId(projectId); Project project = projectRepository.findOrFailProject(projectId); ProjectMessage message = new ProjectMessage(); message.setProjectId(project.getId()); message.setProjectActionTriggeredBy(userContext.getUserId()); User owner = project.getOwner(); if (owner == null) { LOG.warn("No owner found for project {} while deleting", project.getId()); } else { message.setProjectOwnerEmailAddress(owner.getEmailAdress()); } for (User user : project.getUsers()) { message.addUserEmailAddress(user.getEmailAdress()); } transactionService.deleteWithAssociationsInOwnTransaction(projectId); informProjectDeleted(message); if (owner != null) { sendRefreshUserAuth(owner); } }
ProjectDeleteService { @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) public void deleteProject(String projectId) { auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30)); assertion.isValidProjectId(projectId); Project project = projectRepository.findOrFailProject(projectId); ProjectMessage message = new ProjectMessage(); message.setProjectId(project.getId()); message.setProjectActionTriggeredBy(userContext.getUserId()); User owner = project.getOwner(); if (owner == null) { LOG.warn("No owner found for project {} while deleting", project.getId()); } else { message.setProjectOwnerEmailAddress(owner.getEmailAdress()); } for (User user : project.getUsers()) { message.addUserEmailAddress(user.getEmailAdress()); } transactionService.deleteWithAssociationsInOwnTransaction(projectId); informProjectDeleted(message); if (owner != null) { sendRefreshUserAuth(owner); } } }
ProjectDeleteService { @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) public void deleteProject(String projectId) { auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30)); assertion.isValidProjectId(projectId); Project project = projectRepository.findOrFailProject(projectId); ProjectMessage message = new ProjectMessage(); message.setProjectId(project.getId()); message.setProjectActionTriggeredBy(userContext.getUserId()); User owner = project.getOwner(); if (owner == null) { LOG.warn("No owner found for project {} while deleting", project.getId()); } else { message.setProjectOwnerEmailAddress(owner.getEmailAdress()); } for (User user : project.getUsers()) { message.addUserEmailAddress(user.getEmailAdress()); } transactionService.deleteWithAssociationsInOwnTransaction(projectId); informProjectDeleted(message); if (owner != null) { sendRefreshUserAuth(owner); } }  }
ProjectDeleteService { @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) public void deleteProject(String projectId) { auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30)); assertion.isValidProjectId(projectId); Project project = projectRepository.findOrFailProject(projectId); ProjectMessage message = new ProjectMessage(); message.setProjectId(project.getId()); message.setProjectActionTriggeredBy(userContext.getUserId()); User owner = project.getOwner(); if (owner == null) { LOG.warn("No owner found for project {} while deleting", project.getId()); } else { message.setProjectOwnerEmailAddress(owner.getEmailAdress()); } for (User user : project.getUsers()) { message.addUserEmailAddress(user.getEmailAdress()); } transactionService.deleteWithAssociationsInOwnTransaction(projectId); informProjectDeleted(message); if (owner != null) { sendRefreshUserAuth(owner); } }  @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) void deleteProject(String projectId); }
ProjectDeleteService { @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) public void deleteProject(String projectId) { auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30)); assertion.isValidProjectId(projectId); Project project = projectRepository.findOrFailProject(projectId); ProjectMessage message = new ProjectMessage(); message.setProjectId(project.getId()); message.setProjectActionTriggeredBy(userContext.getUserId()); User owner = project.getOwner(); if (owner == null) { LOG.warn("No owner found for project {} while deleting", project.getId()); } else { message.setProjectOwnerEmailAddress(owner.getEmailAdress()); } for (User user : project.getUsers()) { message.addUserEmailAddress(user.getEmailAdress()); } transactionService.deleteWithAssociationsInOwnTransaction(projectId); informProjectDeleted(message); if (owner != null) { sendRefreshUserAuth(owner); } }  @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) void deleteProject(String projectId);  }