Search in sources :

Example 16 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project sonarqube by SonarSource.

the class IssueNotificationsTest method notifications_for_new_issues_and_issue_changes.

@Test
public void notifications_for_new_issues_and_issue_changes() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.projectDate", "2015-12-15");
    // change assignee
    Issues issues = issueClient.find(IssueQuery.create().componentRoots(PROJECT_KEY));
    Issue issue = issues.list().get(0);
    issueClient.assign(issue.key(), USER_LOGIN);
    waitUntilAllNotificationsAreDelivered(2);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    assertThat(emails.hasNext()).isTrue();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("Sample");
    assertThat((String) message.getContent()).contains("17 new issues (new debt: 17min)");
    assertThat((String) message.getContent()).contains("Severity");
    assertThat((String) message.getContent()).contains("One Issue Per Line (xoo): 17");
    assertThat((String) message.getContent()).contains("See it in SonarQube: http://localhost:9000/component_issues?id=sample#createdAt=2015-12-15T00%3A00%3A00%2B");
    assertThat(emails.hasNext()).isTrue();
    message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("sample/Sample.xoo");
    assertThat((String) message.getContent()).contains("Assignee changed to Tester");
    assertThat((String) message.getContent()).contains("See it in SonarQube: http://localhost:9000/issues/search#issues=" + issue.key());
    assertThat(emails.hasNext()).isFalse();
}
Also used : Issue(org.sonar.wsclient.issue.Issue) MimeMessage(javax.mail.internet.MimeMessage) Issues(org.sonar.wsclient.issue.Issues) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 17 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project sonarqube by SonarSource.

the class IssueNotificationsTest method before.

@BeforeClass
public static void before() throws Exception {
    smtpServer = new Wiser(0);
    smtpServer.start();
    System.out.println("SMTP Server port: " + smtpServer.getServer().getPort());
    // Configure Sonar
    resetEmailSettings(ORCHESTRATOR);
    setServerProperty(ORCHESTRATOR, "email.smtp_host.secured", "localhost");
    setServerProperty(ORCHESTRATOR, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
    // Send test email to the test user
    newAdminWsClient(ORCHESTRATOR).wsConnector().call(new PostRequest("api/emails/send").setParam("to", USER_EMAIL).setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
    // We need to wait until all notifications will be delivered
    waitUntilAllNotificationsAreDelivered(1);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<" + USER_EMAIL + ">");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isFalse();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) BeforeClass(org.junit.BeforeClass)

Example 18 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project sonarqube by SonarSource.

the class IssueNotificationsTest method notifications_for_personalized_emails.

@Test
public void notifications_for_personalized_emails() throws Exception {
    setServerProperty(ORCHESTRATOR, "sonar.issues.defaultAssigneeLogin", USER_LOGIN);
    runProjectAnalysis(ORCHESTRATOR, "issue/xoo-with-scm", "sonar.scm.provider", "xoo", "sonar.scm.disabled", "false");
    waitUntilAllNotificationsAreDelivered(2);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    emails.next();
    // the second email sent is the personalized one
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat(message.getSubject()).contains("You have 13 new issues");
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 19 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.

the class AsyncEmailTaskTest method testSimpleTextMail.

// copied from org.activiti.engine.test.bpmn.mail.EmailServiceTaskTest
@Deployment
public void testSimpleTextMail() throws Exception {
    String procId = runtimeService.startProcessInstanceByKey("simpleTextOnly").getId();
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(0, messages.size());
    waitForJobExecutorToProcessAllJobs(5000L, 25L);
    messages = wiser.getMessages();
    assertEquals(1, messages.size());
    WiserMessage message = messages.get(0);
    EmailServiceTaskTest.assertEmailSend(message, false, "Hello Kermit!", "This a text only e-mail.", "activiti@localhost", Arrays.asList("kermit@activiti.org"), null);
    assertProcessEnded(procId);
}
Also used : WiserMessage(org.subethamail.wiser.WiserMessage) Deployment(org.activiti.engine.test.Deployment)

Example 20 with WiserMessage

use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.

the class EmailServiceTaskTest method testTextMailWithNotExistingFileAttachment.

@Deployment
public void testTextMailWithNotExistingFileAttachment() throws Exception {
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("attachmentsBean", new AttachmentsBean());
    runtimeService.startProcessInstanceByKey("textMailWithNotExistingFileAttachment", vars);
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
    WiserMessage message = messages.get(0);
    assertFalse(message.getMimeMessage().getContent() instanceof MimeMultipart);
}
Also used : HashMap(java.util.HashMap) MimeMultipart(javax.mail.internet.MimeMultipart) WiserMessage(org.subethamail.wiser.WiserMessage) Deployment(org.activiti.engine.test.Deployment)

Aggregations

WiserMessage (org.subethamail.wiser.WiserMessage)34 Deployment (org.activiti.engine.test.Deployment)22 HashMap (java.util.HashMap)16 MimeMultipart (javax.mail.internet.MimeMultipart)12 MimeMessage (javax.mail.internet.MimeMessage)11 Test (org.junit.Test)8 File (java.io.File)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 EmailMessage (org.sonar.plugins.emailnotifications.api.EmailMessage)2 Issue (org.sonar.wsclient.issue.Issue)2 Issues (org.sonar.wsclient.issue.Issues)2 PostRequest (org.sonarqube.ws.client.PostRequest)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 BeforeClass (org.junit.BeforeClass)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 WsClient (org.sonarqube.ws.client.WsClient)1 Wiser (org.subethamail.wiser.Wiser)1 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)1 ItUtils.newUserWsClient (util.ItUtils.newUserWsClient)1