use of javax.mail.internet.MimeMessage in project camel by apache.
the class MailSortTermThreeTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "bill", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 3 messages, one with earlier, one with later sent date and one with invalid subject (not returned in search)
Message[] messages = new Message[3];
messages[0] = new MimeMessage(sender.getSession());
messages[0].setText("Earlier date");
messages[0].setHeader("Message-ID", "0");
messages[0].setSentDate(new Date(10000));
messages[0].setSubject("Camel");
messages[1] = new MimeMessage(sender.getSession());
messages[1].setText("Later date");
messages[1].setHeader("Message-ID", "1");
messages[1].setSentDate(new Date(20000));
messages[1].setSubject("Camel");
messages[2] = new MimeMessage(sender.getSession());
messages[2].setText("Even later date");
messages[2].setHeader("Message-ID", "2");
messages[2].setSentDate(new Date(30000));
messages[2].setSubject("Invalid");
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.internet.MimeMessage in project camel by apache.
the class MailSortTermTwoTest method prepareMailbox.
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "bill", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 3 messages, one with earlier, one with later sent date and one with invalid subject (not returned in search)
Message[] messages = new Message[3];
messages[0] = new MimeMessage(sender.getSession());
messages[0].setText("Earlier date");
messages[0].setHeader("Message-ID", "0");
messages[0].setSentDate(new Date(10000));
messages[0].setSubject("Camel");
messages[1] = new MimeMessage(sender.getSession());
messages[1].setText("Later date");
messages[1].setHeader("Message-ID", "1");
messages[1].setSentDate(new Date(20000));
messages[1].setSubject("Camel");
messages[2] = new MimeMessage(sender.getSession());
messages[2].setText("Even later date");
messages[2].setHeader("Message-ID", "2");
messages[2].setSentDate(new Date(30000));
messages[2].setSubject("Invalid");
folder.appendMessages(messages);
folder.close(true);
}
use of javax.mail.internet.MimeMessage 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();
}
use of javax.mail.internet.MimeMessage 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();
}
use of javax.mail.internet.MimeMessage 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();
}
Aggregations