@Test public void project_not_found_throws_not_found_exception() { expectedException.expect(NotFoundException.class); when(repository.findById("projectId")).thenReturn(Optional.empty()); serviceToTest.updateProjectWhitelist("projectId", null); }
@UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); } }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }  }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }  @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) /* @formatter:on */ void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist); }
ProjectUpdateWhitelistService { @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) public void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist) { auditLog.log("triggers update of whitelist for project {}. Allowed URIs shall be {}", logSanitizer.sanitize(projectId, 30), whitelist); assertion.isValidProjectId(projectId); Optional<Project> found = repository.findById(projectId); if (!found.isPresent()) { throw new NotFoundException("Project '" + projectId + "' does not exist or you have now "); } Project project = found.get(); Set<URI> oldWhiteList = project.getWhiteList(); oldWhiteList.clear(); whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(oldWhiteList::add); repository.save(project); sendProjectCreatedEvent(project.getId(), project.getWhiteList()); }  @UseCaseUpdateProjectWhitelist( @Step(number = 2, name = "Update project", description = "The service will update the <<section-shared-project, Project whitelist>>.")) /* @formatter:on */ void updateProjectWhitelist(String projectId, @NotNull List<URI> whitelist);  }