Search in sources :

Example 1 with SendEmailMessage

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"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) Test(org.junit.Test)

Example 2 with SendEmailMessage

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);
}
Also used : SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 3 with SendEmailMessage

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));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ServerConfig(com.thoughtworks.go.config.ServerConfig) SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) SecureSiteUrl(com.thoughtworks.go.domain.SecureSiteUrl) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) SiteUrl(com.thoughtworks.go.domain.SiteUrl) SecureSiteUrl(com.thoughtworks.go.domain.SecureSiteUrl) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Example 4 with SendEmailMessage

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);
}
Also used : SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) EmailNotificationTopic(com.thoughtworks.go.server.messaging.EmailNotificationTopic) Test(org.junit.jupiter.api.Test)

Example 5 with SendEmailMessage

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);
}
Also used : SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) EmailNotificationTopic(com.thoughtworks.go.server.messaging.EmailNotificationTopic) Test(org.junit.jupiter.api.Test)

Aggregations

SendEmailMessage (com.thoughtworks.go.server.messaging.SendEmailMessage)8 Test (org.junit.jupiter.api.Test)6 EmailNotificationTopic (com.thoughtworks.go.server.messaging.EmailNotificationTopic)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)2 DateTime (org.joda.time.DateTime)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 ServerConfig (com.thoughtworks.go.config.ServerConfig)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 SecureSiteUrl (com.thoughtworks.go.domain.SecureSiteUrl)1 SiteUrl (com.thoughtworks.go.domain.SiteUrl)1 Database (com.thoughtworks.go.server.database.Database)1 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)1 ServerBackup (com.thoughtworks.go.server.domain.ServerBackup)1 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)1 UuidGenerator (com.thoughtworks.go.server.util.UuidGenerator)1 File (java.io.File)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1