diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-07-03 16:17:37 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-07-09 10:39:33 +0200 |
commit | e43471671222ac80e9016e71646389b13d4677ba (patch) | |
tree | 4c03ab0e03ff75959847ea0dc1e59400f7f209c3 /server | |
parent | 9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2 (diff) | |
download | sonarqube-e43471671222ac80e9016e71646389b13d4677ba.tar.gz sonarqube-e43471671222ac80e9016e71646389b13d4677ba.zip |
finish moving report task code out of sonar-server
and completely remove use of package org.sonar.ce in sonar-server module
Diffstat (limited to 'server')
25 files changed, 22 insertions, 661 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotification.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotification.java index e6342fd538b..e6342fd538b 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotification.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotification.java diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java index 865a75ff782..865a75ff782 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java index cd7b95162e1..cd7b95162e1 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java index ce73b74e3d0..ce73b74e3d0 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java index 7f43bb0d7d1..7f43bb0d7d1 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java index 4d459cb94ba..4d459cb94ba 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/ReportTaskProcessor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/ReportTaskProcessor.java index 9bc1c36570e..cea238029e5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/ReportTaskProcessor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/ReportTaskProcessor.java @@ -60,6 +60,14 @@ public class ReportTaskProcessor implements CeTaskProcessor { this.componentProviders = null; } + /** + * Used when loaded in WebServer where none of the dependencies are available and where only + * {@link #getHandledCeTaskTypes()} will be called. + */ + public ReportTaskProcessor() { + this(null, null, null); + } + @Override public Set<String> getHandledCeTaskTypes() { return HANDLED_TYPES; diff --git a/server/sonar-server/build.gradle b/server/sonar-server/build.gradle index 95255ea4f48..87d902ee6df 100644 --- a/server/sonar-server/build.gradle +++ b/server/sonar-server/build.gradle @@ -48,6 +48,7 @@ dependencies { compile project(':server:sonar-ce-common') compile project(':server:sonar-ce-task') + compile project(':server:sonar-ce-task-projectanalysis') compile project(':server:sonar-db-dao') compile project(':server:sonar-db-migration') compile project(':server:sonar-plugin-bridge') diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/ReportTaskProcessorDeclaration.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/ReportTaskProcessorDeclaration.java deleted file mode 100644 index c2a19e56b3e..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/ReportTaskProcessorDeclaration.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis; - -import java.util.Collections; -import java.util.Set; -import org.sonar.ce.task.CeTask; -import org.sonar.ce.task.CeTaskResult; -import org.sonar.ce.task.taskprocessor.CeTaskProcessor; -import org.sonar.db.ce.CeTaskTypes; - -/** - * CeTaskProcessor without any real implementation used to declare the CeTask type to the WebServer only. - */ -public class ReportTaskProcessorDeclaration implements CeTaskProcessor { - - private static final Set<String> HANDLED_TYPES = Collections.singleton(CeTaskTypes.REPORT); - - @Override - public Set<String> getHandledCeTaskTypes() { - return HANDLED_TYPES; - } - - @Override - public CeTaskResult process(CeTask task) { - throw new UnsupportedOperationException("process must not be called in WebServer"); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/package-info.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/package-info.java deleted file mode 100644 index 908ed6991b5..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.ce.task.projectanalysis; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/CeModule.java b/server/sonar-server/src/main/java/org/sonar/server/ce/CeModule.java index 00442c1ef3c..66ee97b1465 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/CeModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/CeModule.java @@ -19,11 +19,11 @@ */ package org.sonar.server.ce; -import org.sonar.ce.http.CeHttpClientImpl; import org.sonar.ce.queue.CeQueueImpl; import org.sonar.ce.task.log.CeTaskLogging; -import org.sonar.ce.task.projectanalysis.ReportTaskProcessorDeclaration; +import org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor; import org.sonar.core.platform.Module; +import org.sonar.server.ce.http.CeHttpClientImpl; import org.sonar.server.ce.queue.ReportSubmitter; public class CeModule extends Module { @@ -37,6 +37,6 @@ public class CeModule extends Module { ReportSubmitter.class, // Core tasks processors - ReportTaskProcessorDeclaration.class); + ReportTaskProcessor.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java b/server/sonar-server/src/main/java/org/sonar/server/ce/http/CeHttpClient.java index 5d3afe9463b..5bb79bdf3a9 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/http/CeHttpClient.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.ce.http; +package org.sonar.server.ce.http; import java.util.Optional; import org.sonar.api.utils.log.LoggerLevel; diff --git a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClientImpl.java b/server/sonar-server/src/main/java/org/sonar/server/ce/http/CeHttpClientImpl.java index 76b22ba570b..10be9371722 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClientImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/http/CeHttpClientImpl.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.ce.http; +package org.sonar.server.ce.http; import java.io.File; import java.io.IOException; diff --git a/server/sonar-server/src/main/java/org/sonar/ce/http/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/ce/http/package-info.java index 63f5f708cb5..b345c76d54b 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/http/package-info.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/http/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.ce.http; +package org.sonar.server.ce.http; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelStandaloneService.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelStandaloneService.java index 9048e973d43..6ad2bc28e28 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelStandaloneService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelStandaloneService.java @@ -20,7 +20,7 @@ package org.sonar.server.platform.ws; import org.sonar.api.utils.log.LoggerLevel; -import org.sonar.ce.http.CeHttpClient; +import org.sonar.server.ce.http.CeHttpClient; import org.sonar.server.log.ServerLogging; public class ChangeLogLevelStandaloneService implements ChangeLogLevelService { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java index 252d7d8f6a5..95c4d0e8a53 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriter.java @@ -21,7 +21,7 @@ package org.sonar.server.platform.ws; import java.util.List; import org.sonar.api.utils.text.JsonWriter; -import org.sonar.ce.http.CeHttpClient; +import org.sonar.server.ce.http.CeHttpClient; import org.sonar.core.util.stream.MoreCollectors; import org.sonar.process.systeminfo.SystemInfoSection; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; diff --git a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/ReportTaskProcessorDeclarationTest.java b/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/ReportTaskProcessorDeclarationTest.java deleted file mode 100644 index 971c3e8cf93..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/ReportTaskProcessorDeclarationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.ce.task.CeTask; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -public class ReportTaskProcessorDeclarationTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private ReportTaskProcessorDeclaration underTest = new ReportTaskProcessorDeclaration(); - - @Test - public void getHandledCeTaskTypes_returns_REPORT() { - assertThat(underTest.getHandledCeTaskTypes()).containsOnly("REPORT"); - } - - @Test - public void process_throws_UOE() { - expectedException.expect(UnsupportedOperationException.class); - expectedException.expectMessage("process must not be called in WebServer"); - - underTest.process(mock(CeTask.class)); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcherTest.java deleted file mode 100644 index 30182bdd6ef..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcherTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis.notification; - -import com.google.common.collect.HashMultimap; -import org.junit.Test; -import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.web.UserRole; -import org.sonar.server.notification.NotificationDispatcher; -import org.sonar.server.notification.NotificationDispatcherMetadata; -import org.sonar.server.notification.NotificationManager; -import org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class ReportAnalysisFailureNotificationDispatcherTest { - private NotificationManager notificationManager = mock(NotificationManager.class); - private Notification notificationMock = mock(Notification.class); - private NotificationDispatcher.Context contextMock = mock(NotificationDispatcher.Context.class); - private ReportAnalysisFailureNotificationDispatcher underTest = new ReportAnalysisFailureNotificationDispatcher(notificationManager); - - @Test - public void dispatcher_defines_key() { - assertThat(underTest.getKey()).isNotEmpty(); - } - - @Test - public void newMetadata_indicates_enabled_global_and_project_level_notifications() { - NotificationDispatcherMetadata metadata = ReportAnalysisFailureNotificationDispatcher.newMetadata(); - - assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true"); - assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true"); - } - - @Test - public void performDispatch_has_no_effect_if_type_is_empty() { - when(notificationMock.getType()).thenReturn(""); - - underTest.performDispatch(notificationMock, contextMock); - - verify(notificationMock).getType(); - verifyNoMoreInteractions(notificationMock, contextMock); - } - - @Test - public void performDispatch_has_no_effect_if_type_is_not_ReportAnalysisFailureNotification_TYPE() { - when(notificationMock.getType()).thenReturn(randomAlphanumeric(6)); - - underTest.performDispatch(notificationMock, contextMock); - - verify(notificationMock).getType(); - verifyNoMoreInteractions(notificationMock, contextMock); - } - - @Test - public void performDispatch_adds_user_for_each_recipient_and_channel_for_the_component_uuid_in_the_notification() { - when(notificationMock.getType()).thenReturn(ReportAnalysisFailureNotification.TYPE); - String projectKey = randomAlphanumeric(9); - when(notificationMock.getFieldValue("project.key")).thenReturn(projectKey); - HashMultimap<String, NotificationChannel> multimap = HashMultimap.create(); - String login1 = randomAlphanumeric(3); - String login2 = randomAlphanumeric(3); - NotificationChannel channel1 = mock(NotificationChannel.class); - NotificationChannel channel2 = mock(NotificationChannel.class); - NotificationChannel channel3 = mock(NotificationChannel.class); - multimap.put(login1, channel1); - multimap.put(login1, channel2); - multimap.put(login2, channel2); - multimap.put(login2, channel3); - when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectKey, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER))) - .thenReturn(multimap); - - underTest.performDispatch(notificationMock, contextMock); - - verify(contextMock).addUser(login1, channel1); - verify(contextMock).addUser(login1, channel2); - verify(contextMock).addUser(login2, channel2); - verify(contextMock).addUser(login2, channel3); - verifyNoMoreInteractions(contextMock); - } - - @Test - public void performDispatch_adds_no_user_if_notification_manager_returns_none() { - when(notificationMock.getType()).thenReturn(ReportAnalysisFailureNotification.TYPE); - String projectKey = randomAlphanumeric(9); - when(notificationMock.getFieldValue("project.key")).thenReturn(projectKey); - HashMultimap<String, NotificationChannel> multimap = HashMultimap.create(); - when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectKey, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER))) - .thenReturn(multimap); - - underTest.performDispatch(notificationMock, contextMock); - - verifyNoMoreInteractions(contextMock); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplateTest.java deleted file mode 100644 index 2767bda0f1f..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplateTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis.notification; - -import java.util.Random; -import org.apache.commons.lang.RandomStringUtils; -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.config.EmailSettings; -import org.sonar.api.notifications.Notification; -import org.sonar.api.utils.DateUtils; -import org.sonar.plugins.emailnotifications.api.EmailMessage; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class ReportAnalysisFailureNotificationEmailTemplateTest { - private String serverUrl = RandomStringUtils.randomAlphanumeric(12); - private Notification notification = new Notification(ReportAnalysisFailureNotification.TYPE); - private Random random = new Random(); - private ReportAnalysisFailureNotification.Project projectNoBranch = new ReportAnalysisFailureNotification.Project( - randomAlphanumeric(2), - randomAlphanumeric(3), - randomAlphanumeric(4), - null); - private ReportAnalysisFailureNotification.Project projectWithBranch = new ReportAnalysisFailureNotification.Project( - randomAlphanumeric(6), - randomAlphanumeric(7), - randomAlphanumeric(8), - randomAlphanumeric(9)); - private ReportAnalysisFailureNotification.Task task = new ReportAnalysisFailureNotification.Task( - randomAlphanumeric(10), - random.nextInt(99), - random.nextInt(99)); - private String errorMessage = randomAlphanumeric(11); - - private ReportAnalysisFailureNotificationSerializer serializer = mock(ReportAnalysisFailureNotificationSerializer.class); - private EmailSettings emailSettings = mock(EmailSettings.class); - private ReportAnalysisFailureNotificationEmailTemplate underTest = new ReportAnalysisFailureNotificationEmailTemplate(serializer, emailSettings); - - @Before - public void setUp() throws Exception { - when(emailSettings.getServerBaseURL()).thenReturn(serverUrl); - } - - @Test - public void returns_null_if_notification_type_is_not_ReportAnalysisFailureNotification_TYPE() { - Notification notification = new Notification(RandomStringUtils.randomAlphanumeric(5)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage).isNull(); - } - - @Test - public void format_returns_email_with_subject_without_branch() { - when(serializer.fromNotification(notification)).thenReturn(new ReportAnalysisFailureNotification( - projectNoBranch, task, errorMessage)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage.getSubject()).isEqualTo(projectNoBranch.getName() + ": Background task in failure"); - } - - @Test - public void format_returns_email_with_subject_with_branch() { - when(serializer.fromNotification(notification)).thenReturn(new ReportAnalysisFailureNotification( - projectWithBranch, task, errorMessage)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage.getSubject()).isEqualTo(projectWithBranch.getName() + " (" + projectWithBranch.getBranchName() + "): Background task in failure"); - } - - @Test - public void format_returns_email_with_message_without_branch() { - when(serializer.fromNotification(notification)).thenReturn(new ReportAnalysisFailureNotification( - projectNoBranch, task, errorMessage)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage.getMessage()) - .contains("Project:\t" + projectNoBranch.getName() + "\n"); - } - - @Test - public void format_returns_email_with_message_with_branch() { - when(serializer.fromNotification(notification)).thenReturn(new ReportAnalysisFailureNotification( - projectWithBranch, task, errorMessage)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage.getMessage()) - .contains("Project:\t" + projectWithBranch.getName() + " (" + projectWithBranch.getBranchName() + ")\n"); - } - - @Test - public void format_returns_email_with_message_containing_all_information() { - when(serializer.fromNotification(notification)).thenReturn(new ReportAnalysisFailureNotification( - projectNoBranch, task, errorMessage)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage.getMessage()) - .isEqualTo("Project:\t" + projectNoBranch.getName() + "\n" + - "Background task:\t" + task.getUuid() + "\n" + - "Submission time:\t" + DateUtils.formatDateTime(task.getCreatedAt()) + "\n" + - "Failure time:\t" + DateUtils.formatDateTime(task.getFailedAt()) + "\n" + - "\n" + - "Error message:\t" + errorMessage + "\n" + - "\n" + - "More details at: " + serverUrl + "/project/background_tasks?id=" + projectNoBranch.getKey()); - } - - @Test - public void format_returns_email_with_message_with_error_message_when_null() { - when(serializer.fromNotification(notification)).thenReturn(new ReportAnalysisFailureNotification( - projectNoBranch, task, null)); - - EmailMessage emailMessage = underTest.format(notification); - - assertThat(emailMessage.getMessage()) - .doesNotContain("Error message:\t"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModuleTest.java b/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModuleTest.java deleted file mode 100644 index b34c32f12a8..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModuleTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis.notification; - -import org.junit.Test; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.notification.NotificationDispatcherMetadata; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ReportAnalysisFailureNotificationModuleTest { - private ReportAnalysisFailureNotificationModule underTest = new ReportAnalysisFailureNotificationModule(); - - @Test - public void adds_dispatcher_and_its_metadata() { - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - assertThat(container.getPicoContainer().getComponentAdapters(NotificationDispatcherMetadata.class)).isNotNull(); - assertThat(container.getPicoContainer().getComponentAdapters(ReportAnalysisFailureNotificationDispatcher.class)).isNotNull(); - } - - @Test - public void adds_template_and_serializer() { - ComponentContainer container = new ComponentContainer(); - - underTest.configure(container); - - assertThat(container.getPicoContainer().getComponentAdapters(ReportAnalysisFailureNotificationEmailTemplate.class)).isNotNull(); - assertThat(container.getPicoContainer().getComponentAdapters(ReportAnalysisFailureNotificationSerializer.class)).isNotNull(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImplTest.java b/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImplTest.java deleted file mode 100644 index 1ef6a601117..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImplTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis.notification; - -import java.util.Random; -import org.junit.Test; -import org.sonar.api.notifications.Notification; - -import static java.lang.String.valueOf; -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; - -public class ReportAnalysisFailureNotificationSerializerImplTest { - private Random random = new Random(); - private ReportAnalysisFailureNotification.Project project = new ReportAnalysisFailureNotification.Project( - randomAlphanumeric(2), - randomAlphanumeric(3), - randomAlphanumeric(4), - randomAlphanumeric(5)); - private ReportAnalysisFailureNotification.Task task = new ReportAnalysisFailureNotification.Task( - randomAlphanumeric(6), - random.nextInt(99), - random.nextInt(99)); - private String errorMessage = randomAlphanumeric(7); - private ReportAnalysisFailureNotificationSerializerImpl underTest = new ReportAnalysisFailureNotificationSerializerImpl(); - - @Test - public void verify_toNotification() { - - Notification notification = underTest.toNotification(new ReportAnalysisFailureNotification(project, task, errorMessage)); - - assertThat(notification.getFieldValue("project.uuid")).isEqualTo(project.getUuid()); - assertThat(notification.getFieldValue("project.name")).isEqualTo(project.getName()); - assertThat(notification.getFieldValue("project.key")).isEqualTo(project.getKey()); - assertThat(notification.getFieldValue("project.branchName")).isEqualTo(project.getBranchName()); - assertThat(notification.getFieldValue("task.uuid")).isEqualTo(task.getUuid()); - assertThat(notification.getFieldValue("task.createdAt")).isEqualTo(valueOf(task.getCreatedAt())); - assertThat(notification.getFieldValue("task.failedAt")).isEqualTo(valueOf(task.getFailedAt())); - assertThat(notification.getFieldValue("error.message")).isEqualTo(errorMessage); - } - - @Test - public void verify_fromNotification() { - Notification notification = new Notification(randomAlphanumeric(1)) - .setFieldValue("project.uuid", project.getUuid()) - .setFieldValue("project.name", project.getName()) - .setFieldValue("project.key", project.getKey()) - .setFieldValue("project.branchName", project.getBranchName()) - .setFieldValue("task.uuid", task.getUuid()) - .setFieldValue("task.createdAt", valueOf(task.getCreatedAt())) - .setFieldValue("task.failedAt", valueOf(task.getFailedAt())) - .setFieldValue("error.message", errorMessage); - - ReportAnalysisFailureNotification reportAnalysisFailureNotification = underTest.fromNotification(notification); - - assertThat(reportAnalysisFailureNotification.getProject().getUuid()).isEqualTo(project.getUuid()); - assertThat(reportAnalysisFailureNotification.getProject().getKey()).isEqualTo(project.getKey()); - assertThat(reportAnalysisFailureNotification.getProject().getName()).isEqualTo(project.getName()); - assertThat(reportAnalysisFailureNotification.getProject().getBranchName()).isEqualTo(project.getBranchName()); - assertThat(reportAnalysisFailureNotification.getTask().getUuid()).isEqualTo(task.getUuid()); - assertThat(reportAnalysisFailureNotification.getTask().getCreatedAt()).isEqualTo(task.getCreatedAt()); - assertThat(reportAnalysisFailureNotification.getTask().getFailedAt()).isEqualTo(task.getFailedAt()); - assertThat(reportAnalysisFailureNotification.getErrorMessage()).isEqualTo(errorMessage); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationTest.java b/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationTest.java deleted file mode 100644 index c12407b9dd9..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.ce.task.projectanalysis.notification; - -import java.util.Random; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; - -public class ReportAnalysisFailureNotificationTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private Random random = new Random(); - private ReportAnalysisFailureNotification.Task task = new ReportAnalysisFailureNotification.Task( - randomAlphanumeric(2), random.nextInt(5_996), random.nextInt(9_635)); - private ReportAnalysisFailureNotification.Project project = new ReportAnalysisFailureNotification.Project( - randomAlphanumeric(6), randomAlphanumeric(7), randomAlphanumeric(8), randomAlphanumeric(9)); - - @Test - public void project_constructor_fails_if_uuid_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("uuid can't be null"); - - new ReportAnalysisFailureNotification.Project(null, randomAlphanumeric(2), randomAlphanumeric(3), randomAlphanumeric(4)); - } - - @Test - public void project_constructor_fails_if_key_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("key can't be null"); - - new ReportAnalysisFailureNotification.Project(randomAlphanumeric(2), null, randomAlphanumeric(3), randomAlphanumeric(4)); - } - - @Test - public void project_constructor_fails_if_name_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("name can't be null"); - - new ReportAnalysisFailureNotification.Project(randomAlphanumeric(2), randomAlphanumeric(3), null, randomAlphanumeric(4)); - } - - @Test - public void verify_report_getters() { - String uuid = randomAlphanumeric(2); - String key = randomAlphanumeric(3); - String name = randomAlphanumeric(4); - String branchName = randomAlphanumeric(5); - ReportAnalysisFailureNotification.Project underTest = new ReportAnalysisFailureNotification.Project(uuid, key, name, branchName); - - assertThat(underTest.getUuid()).isEqualTo(uuid); - assertThat(underTest.getName()).isEqualTo(name); - assertThat(underTest.getKey()).isEqualTo(key); - assertThat(underTest.getBranchName()).isEqualTo(branchName); - } - - @Test - public void project_supports_null_branch() { - ReportAnalysisFailureNotification.Project underTest = new ReportAnalysisFailureNotification.Project(randomAlphanumeric(2), randomAlphanumeric(3), randomAlphanumeric(4), null); - - assertThat(underTest.getBranchName()).isNull(); - } - - @Test - public void task_constructor_fails_if_uuid_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("uuid can't be null"); - - new ReportAnalysisFailureNotification.Task(null, random.nextInt(5_996), random.nextInt(9_635)); - } - - @Test - public void verify_task_getters() { - String uuid = randomAlphanumeric(6); - int createdAt = random.nextInt(5_996); - int failedAt = random.nextInt(9_635); - - ReportAnalysisFailureNotification.Task underTest = new ReportAnalysisFailureNotification.Task(uuid, createdAt, failedAt); - - assertThat(underTest.getUuid()).isEqualTo(uuid); - assertThat(underTest.getCreatedAt()).isEqualTo(createdAt); - assertThat(underTest.getFailedAt()).isEqualTo(failedAt); - } - - @Test - public void constructor_fails_with_NPE_if_Project_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("project can't be null"); - - new ReportAnalysisFailureNotification(null, task, randomAlphanumeric(99)); - } - - @Test - public void constructor_fails_with_NPE_if_Task_is_null() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("task can't be null"); - - new ReportAnalysisFailureNotification(project, null, randomAlphanumeric(99)); - } - - @Test - public void verify_getters() { - String message = randomAlphanumeric(99); - ReportAnalysisFailureNotification underTest = new ReportAnalysisFailureNotification(project, task, message); - - assertThat(underTest.getProject()).isSameAs(project); - assertThat(underTest.getTask()).isSameAs(task); - assertThat(underTest.getErrorMessage()).isSameAs(message); - } - - @Test - public void null_error_message_is_supported() { - ReportAnalysisFailureNotification underTest = new ReportAnalysisFailureNotification(project, task, null); - - assertThat(underTest.getErrorMessage()).isNull(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/http/CeHttpClientTest.java index 00396ca9a64..bd918c6782d 100644 --- a/server/sonar-server/src/test/java/org/sonar/ce/http/CeHttpClientTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/http/CeHttpClientTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.ce.http; +package org.sonar.server.ce.http; import java.io.File; import java.io.IOException; diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java index 1741dfeb2c1..7a200f35f50 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java @@ -23,8 +23,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.log.LoggerLevel; -import org.sonar.ce.http.CeHttpClient; -import org.sonar.ce.http.CeHttpClientImpl; +import org.sonar.server.ce.http.CeHttpClient; +import org.sonar.server.ce.http.CeHttpClientImpl; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.log.ServerLogging; import org.sonar.server.tester.UserSessionRule; diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriterTest.java index 1f2ef685011..a05c8bb7e8b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/StandaloneSystemInfoWriterTest.java @@ -26,8 +26,8 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; import org.sonar.api.utils.text.JsonWriter; -import org.sonar.ce.http.CeHttpClient; -import org.sonar.ce.http.CeHttpClientImpl; +import org.sonar.server.ce.http.CeHttpClient; +import org.sonar.server.ce.http.CeHttpClientImpl; import org.sonar.process.systeminfo.SystemInfoSection; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; import org.sonar.server.health.TestStandaloneHealthChecker; |