use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class BackupServiceIntegrationTest method shouldSendEmailToAdminWhenTheBackupFails.
@Test
public void shouldSendEmailToAdminWhenTheBackupFails() throws Exception {
GoConfigService configService = mock(GoConfigService.class);
when(configService.adminEmail()).thenReturn("mail@admin.com");
GoMailSender goMailSender = mock(GoMailSender.class);
when(configService.getMailSender()).thenReturn(goMailSender);
when(configService.isUserAdmin(admin)).thenReturn(true);
DateTime now = new DateTime();
TimeProvider timeProvider = mock(TimeProvider.class);
when(timeProvider.currentDateTime()).thenReturn(now);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Database databaseStrategyMock = mock(Database.class);
doThrow(new RuntimeException("Oh no!")).when(databaseStrategyMock).backup(any(File.class));
BackupService service = new BackupService(dataSource, artifactsDirHolder, configService, timeProvider, backupInfoRepository, systemEnvironment, serverVersion, configRepository, databaseStrategyMock);
service.initialize();
service.startBackup(admin, result);
String ipAddress = SystemUtil.getFirstLocalNonLoopbackIpAddress();
String body = String.format("Backup of the Go server at '%s' has failed. The reason is: %s", ipAddress, "Oh no!");
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Failed to perform backup. Reason: Oh no!"));
verify(goMailSender).send(new SendEmailMessage("Server Backup Failed", body, "mail@admin.com"));
verifyNoMoreInteractions(goMailSender);
assertThat(FileUtils.listFiles(backupsDirectory, TrueFileFilter.TRUE, TrueFileFilter.TRUE).isEmpty(), is(true));
}
use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class BackupServiceIntegrationTest method shouldSendEmailToAdminAfterTakingBackup.
@Test
public void shouldSendEmailToAdminAfterTakingBackup() throws InvalidCipherTextException {
GoConfigService configService = mock(GoConfigService.class);
GoMailSender goMailSender = mock(GoMailSender.class);
when(configService.getMailSender()).thenReturn(goMailSender);
when(configService.adminEmail()).thenReturn("mail@admin.com");
when(configService.isUserAdmin(admin)).thenReturn(true);
TimeProvider timeProvider = mock(TimeProvider.class);
DateTime now = new DateTime();
when(timeProvider.currentDateTime()).thenReturn(now);
BackupService service = new BackupService(dataSource, artifactsDirHolder, configService, timeProvider, backupInfoRepository, systemEnvironment, serverVersion, configRepository, databaseStrategy);
service.initialize();
service.startBackup(admin, new HttpLocalizedOperationResult());
String ipAddress = SystemUtil.getFirstLocalNonLoopbackIpAddress();
String body = String.format("Backup of the Go server at '%s' was successfully completed. The backup is stored at location: %s. This backup was triggered by 'admin'.", ipAddress, backupDir(now).getAbsolutePath());
verify(goMailSender).send(new SendEmailMessage("Server Backup Completed Successfully", body, "mail@admin.com"));
verifyNoMoreInteractions(goMailSender);
}
use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class UniqueEmailSenderTest method shouldBeAbleToSend2Emails.
@Test
public void shouldBeAbleToSend2Emails() {
ClassMockery mockery = new ClassMockery();
final EmailNotificationTopic topic = mockery.mock(EmailNotificationTopic.class);
final SendEmailMessage message = new SendEmailMessage("pavan", "hu kai", "someone");
mockery.checking(new Expectations() {
{
exactly(2).of(topic).post(message);
}
});
EmailSender sender = new AsynchronousEmailSender(topic);
sender.sendEmail(message);
sender.sendEmail(message);
}
Aggregations