@Test public void shouldReturnFalseWhenEmailIsEmpty() { assertThat( new User("UserName", new String[]{"README"}, null, true).matchNotification(null, StageEvent.All, null), is(false)); assertThat(new User("UserName", new String[]{"README"}, "", true).matchNotification(null, StageEvent.All, null), is(false)); }
public void sendNotifications(StageIdentifier stageIdentifier, StageEvent event, Username cancelledBy) { Users users = userService.findValidSubscribers(stageIdentifier.stageConfigIdentifier()); if (users.isEmpty()) { return; } Stage stage = stageService.findStageWithIdentifier(stageIdentifier); Pipeline pipeline = pipelineService.fullPipelineById(stage.getPipelineId()); MaterialRevisions materialRevisions = pipeline.getMaterialRevisions(); String emailBody = new EmailBodyGenerator(materialRevisions, cancelledBy, systemEnvironment, stageIdentifier).getContent(); String subject = "Stage [" + stageIdentifier.stageLocator() + "]" + event.describe(); LOGGER.debug("Processing notification titled [{}]", subject); for (User user : users) { if (user.matchNotification(stageIdentifier.stageConfigIdentifier(), event, materialRevisions)) { StringBuilder emailWithSignature = new StringBuilder(emailBody) .append("\n\n") .append("Sent by Go on behalf of ") .append(user.getName()); SendEmailMessage sendEmailMessage = new SendEmailMessage(subject, emailWithSignature.toString(), user.getEmail()); emailNotificationTopic.post(sendEmailMessage); } } LOGGER.debug("Finished processing notification titled [{}]", subject); }
@Test public void shouldReturnTrueWhenNotificationFilterMatchesAnyCheckinOnGivenStageFixed() { materialRevisions = new MaterialRevisions(new MaterialRevision(MaterialsMother.svnMaterial(), aCheckIn("100", "xyz"))); user = new User("UserName", new String[]{"README"}, "user@mail.com", true); user.setNotificationFilters( Arrays.asList(new NotificationFilter("cruise", "dev", StageEvent.Fixed, false))); assertThat( user.matchNotification(new StageConfigIdentifier("cruise", "dev"), StageEvent.Fixed, materialRevisions), is(true)); }
@Test public void shouldReturnTrueWhenNotificationFilterMatchesMyCheckinOnGivenStageFixed() { materialRevisions = new MaterialRevisions(new MaterialRevision(MaterialsMother.svnMaterial(), aCheckIn("100", "readme"))); user = new User("UserName", new String[]{"README"}, "user@mail.com", true); user.setNotificationFilters( Arrays.asList(new NotificationFilter("cruise", "dev", StageEvent.Fixed, true))); assertThat( user.matchNotification(new StageConfigIdentifier("cruise", "dev"), StageEvent.Fixed, materialRevisions), is(true)); }