@Test public void sendQualityEmail_should_not_call_sendHtmlMessage_when_no_recipient_address_configured() throws NotFoundException { long anyProjectId = -42; long executionId = 1; ExecutionHistoryPointDTO execution = new ExecutionHistoryPointDTO(); when(executionHistoryService.getExecution(anyProjectId, executionId)).thenReturn(execution); cut.sendQualityEmail(anyProjectId, executionId); verify(emailService, never()).sendHtmlMessage(anyString(), anyString(), anyString(), anyString(), any(), any()); }
@Transactional(readOnly = true, noRollbackFor = Exception.class) public void sendQualityEmail(long projectId, long executionId) throws NotFoundException { ExecutionHistoryPointDTO execution = executionHistoryService.getExecution(projectId, executionId); final String from = settingService.get(projectId, Settings.EMAIL_FROM); Optional<String> to = getRecipient(projectId, execution); if (from != null && to.isPresent()) { final List<Team> teamsAssignableToProblems = teamRepository.findAllByProjectIdOrderByName(projectId).stream() .filter(Team::isAssignableToProblems) .collect(Collectors.toList()); Map<String, Object> variables = new HashMap<>(); variables.put("execution", execution); variables.put("teamsAssignableToProblems", teamsAssignableToProblems); variables.put("qualitiesPerTeamAndSeverity", aggregateQualitiesPerTeamAndSeverity(execution)); variables.put("NO_TEAM", new Team().withId(Long.valueOf(-404)).withName("(No team)")); variables.put("buildDate", formatDate(execution.getBuildDateTime())); variables.put("testDate", formatDate(execution.getTestDateTime())); variables.put("eligibilityMessage", getEligibilityMessage(execution)); final String clientBaseUrl = araConfiguration.getClientBaseUrl(); final Long projectIdLong = Long.valueOf(projectId); final Project project = projectRepository.findById(projectIdLong) .orElse(new Project().withCode(projectIdLong.toString()).withName("Project " + projectId)); final String url = clientBaseUrl + "#/projects/" + project.getCode() + "/executions/" + execution.getId(); variables.put("executionUrl", url); variables.put("projectName", project.getName()); Map<String, Resource> inlineResources = new HashMap<>(); addInlineResource(inlineResources, "favicon.png", "templates/mail/html/favicon.png"); emailService.sendHtmlMessage( from, to.get(), getSubject(project.getName(), execution), "execution-quality-status", variables, inlineResources); } }
QualityEmailService { @Transactional(readOnly = true, noRollbackFor = Exception.class) public void sendQualityEmail(long projectId, long executionId) throws NotFoundException { ExecutionHistoryPointDTO execution = executionHistoryService.getExecution(projectId, executionId); final String from = settingService.get(projectId, Settings.EMAIL_FROM); Optional<String> to = getRecipient(projectId, execution); if (from != null && to.isPresent()) { final List<Team> teamsAssignableToProblems = teamRepository.findAllByProjectIdOrderByName(projectId).stream() .filter(Team::isAssignableToProblems) .collect(Collectors.toList()); Map<String, Object> variables = new HashMap<>(); variables.put("execution", execution); variables.put("teamsAssignableToProblems", teamsAssignableToProblems); variables.put("qualitiesPerTeamAndSeverity", aggregateQualitiesPerTeamAndSeverity(execution)); variables.put("NO_TEAM", new Team().withId(Long.valueOf(-404)).withName("(No team)")); variables.put("buildDate", formatDate(execution.getBuildDateTime())); variables.put("testDate", formatDate(execution.getTestDateTime())); variables.put("eligibilityMessage", getEligibilityMessage(execution)); final String clientBaseUrl = araConfiguration.getClientBaseUrl(); final Long projectIdLong = Long.valueOf(projectId); final Project project = projectRepository.findById(projectIdLong) .orElse(new Project().withCode(projectIdLong.toString()).withName("Project " + projectId)); final String url = clientBaseUrl + "#/projects/" + project.getCode() + "/executions/" + execution.getId(); variables.put("executionUrl", url); variables.put("projectName", project.getName()); Map<String, Resource> inlineResources = new HashMap<>(); addInlineResource(inlineResources, "favicon.png", "templates/mail/html/favicon.png"); emailService.sendHtmlMessage( from, to.get(), getSubject(project.getName(), execution), "execution-quality-status", variables, inlineResources); } } }
QualityEmailService { @Transactional(readOnly = true, noRollbackFor = Exception.class) public void sendQualityEmail(long projectId, long executionId) throws NotFoundException { ExecutionHistoryPointDTO execution = executionHistoryService.getExecution(projectId, executionId); final String from = settingService.get(projectId, Settings.EMAIL_FROM); Optional<String> to = getRecipient(projectId, execution); if (from != null && to.isPresent()) { final List<Team> teamsAssignableToProblems = teamRepository.findAllByProjectIdOrderByName(projectId).stream() .filter(Team::isAssignableToProblems) .collect(Collectors.toList()); Map<String, Object> variables = new HashMap<>(); variables.put("execution", execution); variables.put("teamsAssignableToProblems", teamsAssignableToProblems); variables.put("qualitiesPerTeamAndSeverity", aggregateQualitiesPerTeamAndSeverity(execution)); variables.put("NO_TEAM", new Team().withId(Long.valueOf(-404)).withName("(No team)")); variables.put("buildDate", formatDate(execution.getBuildDateTime())); variables.put("testDate", formatDate(execution.getTestDateTime())); variables.put("eligibilityMessage", getEligibilityMessage(execution)); final String clientBaseUrl = araConfiguration.getClientBaseUrl(); final Long projectIdLong = Long.valueOf(projectId); final Project project = projectRepository.findById(projectIdLong) .orElse(new Project().withCode(projectIdLong.toString()).withName("Project " + projectId)); final String url = clientBaseUrl + "#/projects/" + project.getCode() + "/executions/" + execution.getId(); variables.put("executionUrl", url); variables.put("projectName", project.getName()); Map<String, Resource> inlineResources = new HashMap<>(); addInlineResource(inlineResources, "favicon.png", "templates/mail/html/favicon.png"); emailService.sendHtmlMessage( from, to.get(), getSubject(project.getName(), execution), "execution-quality-status", variables, inlineResources); } }  }
QualityEmailService { @Transactional(readOnly = true, noRollbackFor = Exception.class) public void sendQualityEmail(long projectId, long executionId) throws NotFoundException { ExecutionHistoryPointDTO execution = executionHistoryService.getExecution(projectId, executionId); final String from = settingService.get(projectId, Settings.EMAIL_FROM); Optional<String> to = getRecipient(projectId, execution); if (from != null && to.isPresent()) { final List<Team> teamsAssignableToProblems = teamRepository.findAllByProjectIdOrderByName(projectId).stream() .filter(Team::isAssignableToProblems) .collect(Collectors.toList()); Map<String, Object> variables = new HashMap<>(); variables.put("execution", execution); variables.put("teamsAssignableToProblems", teamsAssignableToProblems); variables.put("qualitiesPerTeamAndSeverity", aggregateQualitiesPerTeamAndSeverity(execution)); variables.put("NO_TEAM", new Team().withId(Long.valueOf(-404)).withName("(No team)")); variables.put("buildDate", formatDate(execution.getBuildDateTime())); variables.put("testDate", formatDate(execution.getTestDateTime())); variables.put("eligibilityMessage", getEligibilityMessage(execution)); final String clientBaseUrl = araConfiguration.getClientBaseUrl(); final Long projectIdLong = Long.valueOf(projectId); final Project project = projectRepository.findById(projectIdLong) .orElse(new Project().withCode(projectIdLong.toString()).withName("Project " + projectId)); final String url = clientBaseUrl + "#/projects/" + project.getCode() + "/executions/" + execution.getId(); variables.put("executionUrl", url); variables.put("projectName", project.getName()); Map<String, Resource> inlineResources = new HashMap<>(); addInlineResource(inlineResources, "favicon.png", "templates/mail/html/favicon.png"); emailService.sendHtmlMessage( from, to.get(), getSubject(project.getName(), execution), "execution-quality-status", variables, inlineResources); } }  @Transactional(readOnly = true, noRollbackFor = Exception.class) void sendQualityEmail(long projectId, long executionId); }
QualityEmailService { @Transactional(readOnly = true, noRollbackFor = Exception.class) public void sendQualityEmail(long projectId, long executionId) throws NotFoundException { ExecutionHistoryPointDTO execution = executionHistoryService.getExecution(projectId, executionId); final String from = settingService.get(projectId, Settings.EMAIL_FROM); Optional<String> to = getRecipient(projectId, execution); if (from != null && to.isPresent()) { final List<Team> teamsAssignableToProblems = teamRepository.findAllByProjectIdOrderByName(projectId).stream() .filter(Team::isAssignableToProblems) .collect(Collectors.toList()); Map<String, Object> variables = new HashMap<>(); variables.put("execution", execution); variables.put("teamsAssignableToProblems", teamsAssignableToProblems); variables.put("qualitiesPerTeamAndSeverity", aggregateQualitiesPerTeamAndSeverity(execution)); variables.put("NO_TEAM", new Team().withId(Long.valueOf(-404)).withName("(No team)")); variables.put("buildDate", formatDate(execution.getBuildDateTime())); variables.put("testDate", formatDate(execution.getTestDateTime())); variables.put("eligibilityMessage", getEligibilityMessage(execution)); final String clientBaseUrl = araConfiguration.getClientBaseUrl(); final Long projectIdLong = Long.valueOf(projectId); final Project project = projectRepository.findById(projectIdLong) .orElse(new Project().withCode(projectIdLong.toString()).withName("Project " + projectId)); final String url = clientBaseUrl + "#/projects/" + project.getCode() + "/executions/" + execution.getId(); variables.put("executionUrl", url); variables.put("projectName", project.getName()); Map<String, Resource> inlineResources = new HashMap<>(); addInlineResource(inlineResources, "favicon.png", "templates/mail/html/favicon.png"); emailService.sendHtmlMessage( from, to.get(), getSubject(project.getName(), execution), "execution-quality-status", variables, inlineResources); } }  @Transactional(readOnly = true, noRollbackFor = Exception.class) void sendQualityEmail(long projectId, long executionId);  }