summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-email-notifications-plugin
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-06-19 11:24:51 +0200
committerDavid Gageot <david@gageot.net>2012-06-19 13:59:19 +0200
commit38e6273a9d182dc20746c928211269ee304c294f (patch)
tree50516a3f66f5ffa140c38479dcd827caa7b9ca34 /plugins/sonar-email-notifications-plugin
parente167b3c546f0a6ea1cb50348b29cac9f6f242e36 (diff)
downloadsonarqube-38e6273a9d182dc20746c928211269ee304c294f.tar.gz
sonarqube-38e6273a9d182dc20746c928211269ee304c294f.zip
SONARPLUGINS-1948 Move EmailConfiguration to the core
+ Rename to EmailSettings + Use Settings instead of Configuration
Diffstat (limited to 'plugins/sonar-email-notifications-plugin')
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java86
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java11
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java11
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java6
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java6
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java53
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java10
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java11
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java14
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java18
10 files changed, 42 insertions, 184 deletions
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java
deleted file mode 100644
index 9c0b10642e2..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.emailnotifications;
-
-import org.apache.commons.configuration.Configuration;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.ServerExtension;
-
-/**
- * Ruby uses constants from this class.
- *
- * @since 2.10
- */
-public class EmailConfiguration implements ServerExtension {
-
- public static final String SMTP_HOST = "email.smtp_host.secured";
- public static final String SMTP_HOST_DEFAULT = "";
- public static final String SMTP_PORT = "email.smtp_port.secured";
- public static final String SMTP_PORT_DEFAULT = "25";
- public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured";
- public static final String SMTP_SECURE_CONNECTION_DEFAULT = "";
- public static final String SMTP_USERNAME = "email.smtp_username.secured";
- public static final String SMTP_USERNAME_DEFAULT = "";
- public static final String SMTP_PASSWORD = "email.smtp_password.secured";
- public static final String SMTP_PASSWORD_DEFAULT = "";
- public static final String FROM = "email.from";
- public static final String FROM_DEFAULT = "noreply@nowhere";
- public static final String PREFIX = "email.prefix";
- public static final String PREFIX_DEFAULT = "[SONAR]";
-
- private Configuration configuration;
-
- public EmailConfiguration(Configuration configuration) {
- this.configuration = configuration;
- }
-
- public String getSmtpHost() {
- return configuration.getString(SMTP_HOST, SMTP_HOST_DEFAULT);
- }
-
- public String getSmtpPort() {
- return configuration.getString(SMTP_PORT, SMTP_PORT_DEFAULT);
- }
-
- public String getSecureConnection() {
- return configuration.getString(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT);
- }
-
- public String getSmtpUsername() {
- return configuration.getString(SMTP_USERNAME, SMTP_USERNAME_DEFAULT);
- }
-
- public String getSmtpPassword() {
- return configuration.getString(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT);
- }
-
- public String getFrom() {
- return configuration.getString(FROM, FROM_DEFAULT);
- }
-
- public String getPrefix() {
- return configuration.getString(PREFIX, PREFIX_DEFAULT);
- }
-
- public String getServerBaseURL() {
- return configuration.getString(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
index c397efc4996..382e9ce4f95 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
@@ -19,9 +19,6 @@
*/
package org.sonar.plugins.emailnotifications;
-import java.net.MalformedURLException;
-import java.net.URL;
-
import org.apache.commons.lang.StringUtils;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
@@ -30,11 +27,15 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
+import org.sonar.api.platform.EmailSettings;
import org.sonar.api.security.UserFinder;
import org.sonar.api.utils.SonarException;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
+import java.net.MalformedURLException;
+import java.net.URL;
+
/**
* References:
* <ul>
@@ -82,11 +83,11 @@ public class EmailNotificationChannel extends NotificationChannel {
private static final String FROM_NAME_DEFAULT = "Sonar";
private static final String SUBJECT_DEFAULT = "Notification";
- private EmailConfiguration configuration;
+ private EmailSettings configuration;
private EmailTemplate[] templates;
private UserFinder userFinder;
- public EmailNotificationChannel(EmailConfiguration configuration, EmailTemplate[] templates, UserFinder userFinder) {
+ public EmailNotificationChannel(EmailSettings configuration, EmailTemplate[] templates, UserFinder userFinder) {
this.configuration = configuration;
this.templates = templates;
this.userFinder = userFinder;
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
index 49e7befdf79..bf46289eb47 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
@@ -30,17 +30,12 @@ import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
import java.util.List;
public class EmailNotificationsPlugin extends SonarPlugin {
-
public List<Class<? extends ServerExtension>> getExtensions() {
return ImmutableList.of(
- EmailConfiguration.class,
- EmailNotificationChannel.class,
-
- ReviewEmailTemplate.class,
ChangesInReviewAssignedToMeOrCreatedByMe.class,
-
+ EmailNotificationChannel.class,
NewViolationsEmailTemplate.class,
- NewViolationsOnMyFavouriteProject.class);
+ NewViolationsOnMyFavouriteProject.class,
+ ReviewEmailTemplate.class);
}
-
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java
index 690b60335b2..8db4314562c 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java
@@ -20,7 +20,7 @@
package org.sonar.plugins.emailnotifications.newviolations;
import org.sonar.api.notifications.Notification;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
+import org.sonar.api.platform.EmailSettings;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
@@ -31,9 +31,9 @@ import org.sonar.plugins.emailnotifications.api.EmailTemplate;
*/
public class NewViolationsEmailTemplate extends EmailTemplate {
- private EmailConfiguration configuration;
+ private EmailSettings configuration;
- public NewViolationsEmailTemplate(EmailConfiguration configuration) {
+ public NewViolationsEmailTemplate(EmailSettings configuration) {
this.configuration = configuration;
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java
index 21f54d81387..93a41c9b7c8 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java
@@ -22,8 +22,8 @@ package org.sonar.plugins.emailnotifications.reviews;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.EmailSettings;
import org.sonar.api.security.UserFinder;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
@@ -34,10 +34,10 @@ import org.sonar.plugins.emailnotifications.api.EmailTemplate;
*/
public class ReviewEmailTemplate extends EmailTemplate {
- private EmailConfiguration configuration;
+ private EmailSettings configuration;
private UserFinder userFinder;
- public ReviewEmailTemplate(EmailConfiguration configuration, UserFinder userFinder) {
+ public ReviewEmailTemplate(EmailSettings configuration, UserFinder userFinder) {
this.configuration = configuration;
this.userFinder = userFinder;
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java
deleted file mode 100644
index c9474ec9582..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.emailnotifications;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-
-public class EmailConfigurationTest {
-
- private EmailConfiguration emailConfiguration;
-
- @Before
- public void setUp() {
- Configuration configuration = new BaseConfiguration();
- emailConfiguration = new EmailConfiguration(configuration);
- }
-
- @Test
- public void shouldReturnDefaultValues() {
- assertThat(emailConfiguration.getSmtpHost(), is(""));
- assertThat(emailConfiguration.getSmtpPort(), is("25"));
- assertThat(emailConfiguration.getSmtpUsername(), is(""));
- assertThat(emailConfiguration.getSmtpPassword(), is(""));
- assertThat(emailConfiguration.getSecureConnection(), is(""));
- assertThat(emailConfiguration.getFrom(), is("noreply@nowhere"));
- assertThat(emailConfiguration.getPrefix(), is("[SONAR]"));
- assertThat(emailConfiguration.getServerBaseURL(), is(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE));
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
index ed485db690f..3940b7d7809 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
@@ -23,16 +23,20 @@ import org.apache.commons.mail.EmailException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.platform.EmailSettings;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
import javax.mail.internet.MimeMessage;
+
import java.io.IOException;
import java.net.ServerSocket;
import java.util.List;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -42,7 +46,7 @@ public class EmailNotificationChannelTest {
private int port;
private Wiser server;
- private EmailConfiguration configuration;
+ private EmailSettings configuration;
private EmailNotificationChannel channel;
private static int getNextAvailablePort() {
@@ -63,7 +67,7 @@ public class EmailNotificationChannelTest {
server.setPort(port);
server.start();
- configuration = mock(EmailConfiguration.class);
+ configuration = mock(EmailSettings.class);
channel = new EmailNotificationChannel(configuration, null, null);
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
index 4ee7d5f9d99..eceb69f392e 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
@@ -19,16 +19,13 @@
*/
package org.sonar.plugins.emailnotifications;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
-
import org.junit.Test;
-public class EmailNotificationsPluginTest {
+import static org.fest.assertions.Assertions.assertThat;
+public class EmailNotificationsPluginTest {
@Test
- public void testGetExtensions() {
- assertThat(new EmailNotificationsPlugin().getExtensions().size(), greaterThan(1));
+ public void should_get_extensions() {
+ assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(5);
}
-
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java
index 3982ac4fd2a..43b0368e636 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java
@@ -19,25 +19,25 @@
*/
package org.sonar.plugins.emailnotifications.newviolations;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.EmailSettings;
+import org.sonar.plugins.emailnotifications.api.EmailMessage;
+
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.notifications.Notification;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
-import org.sonar.plugins.emailnotifications.api.EmailMessage;
-
public class NewViolationsEmailTemplateTest {
private NewViolationsEmailTemplate template;
@Before
public void setUp() {
- EmailConfiguration configuration = mock(EmailConfiguration.class);
+ EmailSettings configuration = mock(EmailSettings.class);
when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org");
template = new NewViolationsEmailTemplate(configuration);
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java
index a55bc3502e0..d9605a36935 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java
@@ -19,28 +19,28 @@
*/
package org.sonar.plugins.emailnotifications.reviews;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.EmailSettings;
import org.sonar.api.security.UserFinder;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class ReviewEmailTemplateTest {
private ReviewEmailTemplate template;
@Before
public void setUp() {
- EmailConfiguration configuration = mock(EmailConfiguration.class);
+ EmailSettings configuration = mock(EmailSettings.class);
when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org");
UserFinder userFinder = mock(UserFinder.class);
when(userFinder.findByLogin(eq("freddy.mallet"))).thenReturn(new User().setName("Freddy Mallet"));