use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldSendLostContactEmailWhenAgentStateIsLostContact_FEATURE_HIDDEN.
@Test
public void shouldSendLostContactEmailWhenAgentStateIsLostContact_FEATURE_HIDDEN() throws Exception {
new SystemEnvironment().setProperty("agent.connection.timeout", "-1");
CONFIG_HELPER.addMailHost(new MailHost("ghost.name", 25, "loser", "boozer", true, false, "go@foo.mail.com", "admin@foo.mail.com"));
Date date = new Date(70, 1, 1, 1, 1, 1);
AgentInstance instance = AgentInstanceMother.idle(date, "CCeDev01");
((AgentRuntimeInfo) ReflectionUtil.getField(instance, "agentRuntimeInfo")).setOperatingSystem("Minix");
EmailSender mailSender = mock(EmailSender.class);
AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), environmentConfigService, securityService, agentDao, new UuidGenerator(), serverHealthService, mailSender, agentStatusChangeNotifier());
AgentInstances agentInstances = (AgentInstances) ReflectionUtil.getField(agentService, "agentInstances");
agentInstances.add(instance);
AgentInstances agents = agentService.findRegisteredAgents();
assertThat(agents.size(), is(1));
AgentInstance agentInstance = agents.findAgentAndRefreshStatus(instance.agentConfig().getUuid());
assertThat(agentInstance.getStatus(), is(AgentStatus.LostContact));
String body = String.format("The email has been sent out automatically by the Go server at (%s) to Go administrators.\n" + "\n" + "The Go server has lost contact with agent:\n" + "\n" + "Agent name: CCeDev01\n" + "Free Space: 10.0 KB\n" + "Sandbox: /var/lib/foo\n" + "IP Address: 10.18.5.1\n" + "OS: Minix\n" + "Resources: \n" + "Environments: \n" + "\n" + "Lost contact at: %s", SystemUtil.getFirstLocalNonLoopbackIpAddress(), date);
// verify(mailSender).sendEmail(new SendEmailMessage("[Lost Contact] Go agent host: " + instance.getHostname(), body, "admin@foo.mail.com"));
verify(mailSender, never()).sendEmail(new SendEmailMessage("[Lost Contact] Go agent host: " + instance.getHostname(), body, "admin@foo.mail.com"));
}
use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class StageNotificationService method sendNotifications.
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);
}
use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class DiskSpaceFullCheckerTest method shouldFormatLowDiskSpaceWarningMailWithHelpLinksHttpAndSiteUrl.
@Test
public void shouldFormatLowDiskSpaceWarningMailWithHelpLinksHttpAndSiteUrl() throws URISyntaxException {
String expectedHelpUrl = docsUrl("/installation/configuring_server_details.html");
ServerConfig serverConfig = new ServerConfig(null, null, new SiteUrl("http://test.host"), new SecureSiteUrl("https://test.host"));
CruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setServerConfig(serverConfig);
GoConfigService goConfigService = mock(GoConfigService.class);
when(goConfigService.artifactsDir()).thenReturn(null);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(goConfigService.adminEmail()).thenReturn("admin@email.com");
ArtifactsDiskSpaceFullChecker diskSpaceFullChecker = new ArtifactsDiskSpaceFullChecker(new SystemEnvironment(), null, goConfigService, null) {
@Override
protected String targetFolderCanonicalPath() {
return "";
}
};
SendEmailMessage actual = diskSpaceFullChecker.createEmail();
assertThat(actual.getBody(), Matchers.containsString(expectedHelpUrl));
}
use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class UniqueEmailSenderTest method shouldSendEmailIfNotEnoughSpaceForFirstTime.
@Test
public void shouldSendEmailIfNotEnoughSpaceForFirstTime() {
final EmailNotificationTopic topic = mock(EmailNotificationTopic.class);
final SendEmailMessage message = new SendEmailMessage("pavan", "hu kai", "someone");
EmailSender sender = new AsynchronousEmailSender(topic);
sender.sendEmail(message);
verify(topic).post(message);
}
use of com.thoughtworks.go.server.messaging.SendEmailMessage in project gocd by gocd.
the class UniqueEmailSenderTest method shouldBeAbleToSend2Emails.
@Test
public void shouldBeAbleToSend2Emails() {
final EmailNotificationTopic topic = mock(EmailNotificationTopic.class);
final SendEmailMessage message = new SendEmailMessage("pavan", "hu kai", "someone");
EmailSender sender = new AsynchronousEmailSender(topic);
sender.sendEmail(message);
sender.sendEmail(message);
verify(topic, times(2)).post(message);
}
Aggregations