diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-12 14:48:36 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-10-02 13:03:35 +0200 |
commit | d47f7eac1a6880a4aeaedfb0bbff906240b72f07 (patch) | |
tree | 63d5339c005f7029f10385ca5e1d2a35005920b4 /tests | |
parent | c9f01d74767b55cad280b1056ea71a3d9650c908 (diff) | |
download | sonarqube-d47f7eac1a6880a4aeaedfb0bbff906240b72f07.tar.gz sonarqube-d47f7eac1a6880a4aeaedfb0bbff906240b72f07.zip |
SONAR-9144 send notifications only for issues on the leak period
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java | 73 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java | 7 |
2 files changed, 76 insertions, 4 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java index 98ab45d77d3..e05168fb497 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java @@ -19,23 +19,33 @@ */ package org.sonarqube.tests.issue; +import com.google.common.collect.ImmutableList; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; import java.io.File; +import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import javax.mail.MessagingException; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.sonar.wsclient.issue.Issue; import org.sonar.wsclient.issue.IssueQuery; +import org.sonarqube.tests.Tester; import org.sonarqube.ws.client.PostRequest; +import org.sonarqube.ws.client.WsClient; +import org.subethamail.wiser.Wiser; import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; +import static util.ItUtils.newUserWsClient; import static util.ItUtils.pluginArtifact; import static util.ItUtils.projectDir; import static util.ItUtils.xooPlugin; @@ -55,20 +65,59 @@ public class IssueCreationDatePluginChangedTest { private static final String SAMPLE_PROJECT_NAME = "Creation date sample"; private static final String SAMPLE_QUALITY_PROFILE_NAME = "creation-date-plugin"; + private final static String USER_LOGIN = "tester"; + private final static String USER_PASSWORD = "tester"; + private static final String USER_EMAIL = "tester@example.org"; + @ClassRule public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() .addPlugin(xooPlugin()) .addPlugin(ItUtils.pluginArtifact("backdating-plugin-v1")) .addPlugin(ItUtils.pluginArtifact("backdating-customplugin")) .build(); + @Rule + public Tester tester = new Tester(ORCHESTRATOR); + + private static Wiser smtpServer; + + @BeforeClass + public static void setUp() throws Exception { + smtpServer = new Wiser(0); + smtpServer.start(); + } @Before - public void cleanup() { + public void before() throws InterruptedException, MessagingException, IOException { ORCHESTRATOR.resetData(); + + // Configure Sonar + tester.settings().setGlobalSetting("email.smtp_host.secured", "localhost"); + tester.settings().setGlobalSetting("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort())); + + // Create a user and register her to receive notification on NewIssues + tester.users().generate(t -> t.setLogin(USER_LOGIN).setPassword(USER_PASSWORD).setEmail(USER_EMAIL) + .setScmAccounts(ImmutableList.of("jhenry"))); + // Add notifications to the test user + WsClient wsClient = newUserWsClient(ORCHESTRATOR, USER_LOGIN, USER_PASSWORD); + wsClient.wsConnector().call(new PostRequest("api/notifications/add") + .setParam("type", "NewIssues") + .setParam("channel", "EmailNotificationChannel")) + .failIfNotSuccessful(); + wsClient.wsConnector().call(new PostRequest("api/notifications/add") + .setParam("type", "SQ-MyNewIssues") + .setParam("channel", "EmailNotificationChannel")) + .failIfNotSuccessful(); + } + + @AfterClass + public static void stop() { + if (smtpServer != null) { + smtpServer.stop(); + } } @Test - public void should_use_scm_date_for_new_issues_if_plugin_updated() { + public void should_use_scm_date_for_new_issues_if_plugin_updated() throws InterruptedException, MessagingException, IOException { ItUtils.restoreProfile(ORCHESTRATOR, getClass().getResource("/issue/IssueCreationDatePluginChangedTest/profile.xml")); ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_NAME); @@ -80,13 +129,16 @@ public class IssueCreationDatePluginChangedTest { .setProperty("sonar.scm.disabled", "false"); ORCHESTRATOR.executeBuild(scanner); - List<Issue> issues = getIssues(issueQuery().components("creation-date-sample:src/main/xoo/sample/Sample.xoo")); - // Check that issue is backdated to SCM (because it is the first analysis) + List<Issue> issues = getIssues(issueQuery().components("creation-date-sample:src/main/xoo/sample/Sample.xoo")); assertThat(issues) .extracting(Issue::line, Issue::creationDate) .containsExactly(tuple(1, dateTimeParse("2005-01-01T00:00:00+0000"))); + // ensure no notification is sent as all issues are off the leak period + waitUntilAllNotificationsAreDelivered(); + assertThat(smtpServer.getMessages()).isEmpty(); + // Update the plugin // uninstall plugin V1 ItUtils.newAdminWsClient(ORCHESTRATOR).wsConnector().call(new PostRequest("api/plugins/uninstall").setParam("key", "backdating")).failIfNotSuccessful(); @@ -104,6 +156,10 @@ public class IssueCreationDatePluginChangedTest { .containsExactly(tuple(1, dateTimeParse("2005-01-01T00:00:00+0000")), tuple(2, dateTimeParse("2005-01-01T00:00:00+0000")), tuple(3, dateTimeParse("2005-01-01T00:00:00+0000"))); + + // ensure no notification is sent as all issues are off the leak period + waitUntilAllNotificationsAreDelivered(); + assertThat(smtpServer.getMessages()).isEmpty(); } private static List<Issue> getIssues(IssueQuery query) { @@ -122,4 +178,13 @@ public class IssueCreationDatePluginChangedTest { } } + private static void waitUntilAllNotificationsAreDelivered() throws InterruptedException { + for (int i = 0; i < 10; i++) { + if (smtpServer.getMessages().size() == 3) { + break; + } + Thread.sleep(1_000); + } + } + } diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java index 49e4cee8afc..c110478180b 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java @@ -172,6 +172,13 @@ public class IssueNotificationsTest extends AbstractIssueTest { @Test public void notifications_for_personalized_emails() throws Exception { setServerProperty(ORCHESTRATOR, "sonar.issues.defaultAssigneeLogin", USER_LOGIN); + // 1st analysis without any issue (because no file is analyzed) + runProjectAnalysis(ORCHESTRATOR, "issue/xoo-with-scm", "sonar.scm.provider", "xoo", "sonar.scm.disabled", "false", "sonar.exclusions", "**/*"); + + waitUntilAllNotificationsAreDelivered(2); + assertThat(smtpServer.getMessages()).isEmpty(); + + // run 2nd analysis which will generate issues on the leak period runProjectAnalysis(ORCHESTRATOR, "issue/xoo-with-scm", "sonar.scm.provider", "xoo", "sonar.scm.disabled", "false"); waitUntilAllNotificationsAreDelivered(2); |