@Test public void sends_email_to_all_former_project_users_as_bcc_containing_projectid() throws Exception { SimpleMailMessage mockedMailMessage = mock(SimpleMailMessage.class); when(mockedMailMessageFactory.createMessage(any())).thenReturn(mockedMailMessage); ProjectMessage message = mock(ProjectMessage.class); when(message.getProjectId()).thenReturn("projectId1"); Set<String> userList= new LinkedHashSet<>(); userList.add("test1@example.org"); userList.add("test2@example.org"); when(message.getUserEmailAdresses()).thenReturn(userList); serviceToTest.notify(message,"base1"); ArgumentCaptor<SimpleMailMessage> mailMessageCaptor = ArgumentCaptor.forClass(SimpleMailMessage.class); verify(mockedEmailService).send(mailMessageCaptor.capture()); assertSame(mockedMailMessage, mailMessageCaptor.getValue()); verify(mockedMailMessage).setBcc("test1@example.org","test2@example.org"); ArgumentCaptor<String> stringMessageCaptor = ArgumentCaptor.forClass(String.class); verify(mockedMailMessage).setText(stringMessageCaptor.capture()); String textInMessageBody = stringMessageCaptor.getValue(); assertTrue(textInMessageBody.contains("projectId1")); assertTrue(textInMessageBody.contains("deleted")); }
@UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) public void notify(ProjectMessage projectMessage, String baseUrl) { requireNonNull(projectMessage); Set<String> mailAdresses = projectMessage.getUserEmailAdresses(); if (mailAdresses == null || mailAdresses.isEmpty()) { LOG.info("No users found for project {} so ignore sending info mail about delete", projectMessage.getProjectId()); return; } SimpleMailMessage message = factory.createMessage("A SecHub project where you have been a user was deleted: " + projectMessage.getProjectId()); StringBuilder emailContent = new StringBuilder(); emailContent.append("Project '" + projectMessage.getProjectId() + "' in environment " + baseUrl + "\n"); emailContent.append("has been deleted.\n\n"); emailContent.append("This means that all report data has been deleted, and thus sechub scans for this project are no longer accessible.\n"); String[] userAdresses = projectMessage.getUserEmailAdresses().toArray(new String[mailAdresses.size()]); message.setBcc(userAdresses); message.setText(emailContent.toString()); emailService.send(message); }
InformUsersThatProjectHasBeenDeletedNotificationService { @UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) public void notify(ProjectMessage projectMessage, String baseUrl) { requireNonNull(projectMessage); Set<String> mailAdresses = projectMessage.getUserEmailAdresses(); if (mailAdresses == null || mailAdresses.isEmpty()) { LOG.info("No users found for project {} so ignore sending info mail about delete", projectMessage.getProjectId()); return; } SimpleMailMessage message = factory.createMessage("A SecHub project where you have been a user was deleted: " + projectMessage.getProjectId()); StringBuilder emailContent = new StringBuilder(); emailContent.append("Project '" + projectMessage.getProjectId() + "' in environment " + baseUrl + "\n"); emailContent.append("has been deleted.\n\n"); emailContent.append("This means that all report data has been deleted, and thus sechub scans for this project are no longer accessible.\n"); String[] userAdresses = projectMessage.getUserEmailAdresses().toArray(new String[mailAdresses.size()]); message.setBcc(userAdresses); message.setText(emailContent.toString()); emailService.send(message); } }
InformUsersThatProjectHasBeenDeletedNotificationService { @UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) public void notify(ProjectMessage projectMessage, String baseUrl) { requireNonNull(projectMessage); Set<String> mailAdresses = projectMessage.getUserEmailAdresses(); if (mailAdresses == null || mailAdresses.isEmpty()) { LOG.info("No users found for project {} so ignore sending info mail about delete", projectMessage.getProjectId()); return; } SimpleMailMessage message = factory.createMessage("A SecHub project where you have been a user was deleted: " + projectMessage.getProjectId()); StringBuilder emailContent = new StringBuilder(); emailContent.append("Project '" + projectMessage.getProjectId() + "' in environment " + baseUrl + "\n"); emailContent.append("has been deleted.\n\n"); emailContent.append("This means that all report data has been deleted, and thus sechub scans for this project are no longer accessible.\n"); String[] userAdresses = projectMessage.getUserEmailAdresses().toArray(new String[mailAdresses.size()]); message.setBcc(userAdresses); message.setText(emailContent.toString()); emailService.send(message); }  }
InformUsersThatProjectHasBeenDeletedNotificationService { @UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) public void notify(ProjectMessage projectMessage, String baseUrl) { requireNonNull(projectMessage); Set<String> mailAdresses = projectMessage.getUserEmailAdresses(); if (mailAdresses == null || mailAdresses.isEmpty()) { LOG.info("No users found for project {} so ignore sending info mail about delete", projectMessage.getProjectId()); return; } SimpleMailMessage message = factory.createMessage("A SecHub project where you have been a user was deleted: " + projectMessage.getProjectId()); StringBuilder emailContent = new StringBuilder(); emailContent.append("Project '" + projectMessage.getProjectId() + "' in environment " + baseUrl + "\n"); emailContent.append("has been deleted.\n\n"); emailContent.append("This means that all report data has been deleted, and thus sechub scans for this project are no longer accessible.\n"); String[] userAdresses = projectMessage.getUserEmailAdresses().toArray(new String[mailAdresses.size()]); message.setBcc(userAdresses); message.setText(emailContent.toString()); emailService.send(message); }  @UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) void notify(ProjectMessage projectMessage, String baseUrl); }
InformUsersThatProjectHasBeenDeletedNotificationService { @UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) public void notify(ProjectMessage projectMessage, String baseUrl) { requireNonNull(projectMessage); Set<String> mailAdresses = projectMessage.getUserEmailAdresses(); if (mailAdresses == null || mailAdresses.isEmpty()) { LOG.info("No users found for project {} so ignore sending info mail about delete", projectMessage.getProjectId()); return; } SimpleMailMessage message = factory.createMessage("A SecHub project where you have been a user was deleted: " + projectMessage.getProjectId()); StringBuilder emailContent = new StringBuilder(); emailContent.append("Project '" + projectMessage.getProjectId() + "' in environment " + baseUrl + "\n"); emailContent.append("has been deleted.\n\n"); emailContent.append("This means that all report data has been deleted, and thus sechub scans for this project are no longer accessible.\n"); String[] userAdresses = projectMessage.getUserEmailAdresses().toArray(new String[mailAdresses.size()]); message.setBcc(userAdresses); message.setText(emailContent.toString()); emailService.send(message); }  @UseCaseAdministratorDeleteProject(@Step(number = 5, name = "Inform users that the project has been deleted")) void notify(ProjectMessage projectMessage, String baseUrl);  }