Search in sources :

Example 1 with WiserMessage

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

the class IssueNotificationsTest method notifications_for_bulk_change_ws.

/**
   * SONAR-4606
   */
@Test
public void notifications_for_bulk_change_ws() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.projectDate", "2015-12-15");
    Issues issues = issueClient.find(IssueQuery.create().componentRoots(PROJECT_KEY));
    Issue issue = issues.list().get(0);
    // bulk change without notification by default
    issuesService.bulkChange(BulkChangeRequest.builder().setIssues(singletonList(issue.key())).setAssign(USER_LOGIN).setSetSeverity("MINOR").build());
    // bulk change with notification
    issuesService.bulkChange(BulkChangeRequest.builder().setIssues(singletonList(issue.key())).setSetSeverity("BLOCKER").setSendNotifications(true).build());
    waitUntilAllNotificationsAreDelivered(2);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    emails.next();
    MimeMessage 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("Severity: BLOCKER (was MINOR)");
    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 2 with WiserMessage

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

the class EmailsTest method send_test_email.

@Test
public void send_test_email() throws Exception {
    updateEmailSettings("localhost", Integer.toString(SMTP_SERVER.getServer().getPort()), null, null, null, null, null);
    sendEmail("test@example.org", "Test Message from SonarQube", "This is a test message from SonarQube");
    // We need to wait until all notifications will be delivered
    waitUntilAllNotificationsAreDelivered();
    Iterator<WiserMessage> emails = SMTP_SERVER.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
    assertThat(message.getSubject()).contains("Test Message from SonarQube");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isFalse();
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 3 with WiserMessage

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

the class QualityGateNotificationTest method status_on_metric_variation_and_send_notifications.

@Test
public void status_on_metric_variation_and_send_notifications() throws Exception {
    setServerProperty(orchestrator, "email.smtp_host.secured", "localhost");
    setServerProperty(orchestrator, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
    // Create user, who will receive notifications for new violations
    userRule.createUser("tester", "Tester", "tester@example.org", "tester");
    // Send test email to the test user
    newAdminWsClient(orchestrator).wsConnector().call(new PostRequest("api/emails/send").setParam("to", "test@example.org").setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
    // Add notifications to the test user
    WsClient wsClient = newUserWsClient(orchestrator, "tester", "tester");
    wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewAlerts").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
    // Create quality gate with conditions on variations
    QualityGate simple = qgClient().create("SimpleWithDifferential");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").period(1).operator("EQ").warningThreshold("0"));
    SonarScanner analysis = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
    orchestrator.executeBuild(analysis);
    assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
    orchestrator.executeBuild(analysis);
    assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
    qgClient().unsetDefault();
    qgClient().destroy(simple.id());
    waitUntilAllNotificationsAreDelivered(smtpServer);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isTrue();
    message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("Quality gate status: Orange (was Green)");
    assertThat((String) message.getContent()).contains("Quality gate threshold: Lines of Code variation = 0 since previous analysis");
    assertThat((String) message.getContent()).contains("/dashboard/index/sample");
    assertThat(emails.hasNext()).isFalse();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newUserWsClient(util.ItUtils.newUserWsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 4 with WiserMessage

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

the class EmailSendTaskTest method testSimpleTextMail.

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

Example 5 with WiserMessage

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

the class EmailSendTaskTest method testTextMailWithFileAttachmentsByPath.

@Deployment
public void testTextMailWithFileAttachmentsByPath() throws Exception {
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("attachmentsBean", new AttachmentsBean());
    runtimeService.startProcessInstanceByKey("textMailWithFileAttachmentsByPath", vars);
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
    WiserMessage message = messages.get(0);
    MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
    File[] files = new AttachmentsBean().getFiles();
    assertEquals(1 + files.length, mm.getCount());
    for (int i = 0; i < files.length; i++) {
        String attachmentFileName = mm.getBodyPart(1 + i).getDataHandler().getName();
        assertEquals(files[i].getName(), attachmentFileName);
    }
}
Also used : HashMap(java.util.HashMap) MimeMultipart(javax.mail.internet.MimeMultipart) WiserMessage(org.subethamail.wiser.WiserMessage) File(java.io.File) Deployment(org.activiti.engine.test.Deployment)

Aggregations

WiserMessage (org.subethamail.wiser.WiserMessage)67 MimeMessage (javax.mail.internet.MimeMessage)34 Test (org.junit.Test)27 HashMap (java.util.HashMap)26 Deployment (org.activiti.engine.test.Deployment)22 ArrayList (java.util.ArrayList)12 MimeMultipart (javax.mail.internet.MimeMultipart)12 Deployment (org.camunda.bpm.engine.test.Deployment)10 Date (java.util.Date)9 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)6 InputStreamReader (java.io.InputStreamReader)5 Reader (java.io.Reader)5 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)5 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)5 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 File (java.io.File)4 LinkedHashSet (java.util.LinkedHashSet)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)4