diff options
Diffstat (limited to 'server/sonar-server')
24 files changed, 14 insertions, 1061 deletions
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/notification/ReportAnalysisFailureNotification.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotification.java deleted file mode 100644 index e6342fd538b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotification.java +++ /dev/null @@ -1,107 +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 javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import static java.util.Objects.requireNonNull; - -public class ReportAnalysisFailureNotification { - public static final String TYPE = "ce-report-task-failure"; - - private final Project project; - private final Task task; - private final String errorMessage; - - public ReportAnalysisFailureNotification(Project project, Task task, @Nullable String errorMessage) { - this.project = requireNonNull(project, "project can't be null"); - this.task = requireNonNull(task, "task can't be null"); - this.errorMessage = errorMessage; - } - - public Project getProject() { - return project; - } - - public Task getTask() { - return task; - } - - @CheckForNull - public String getErrorMessage() { - return errorMessage; - } - - public static final class Project { - private final String uuid; - private final String key; - private final String name; - private final String branchName; - - public Project(String uuid, String key, String name, @Nullable String branchName) { - this.uuid = requireNonNull(uuid, "uuid can't be null"); - this.key = requireNonNull(key, "key can't be null"); - this.name = requireNonNull(name, "name can't be null"); - this.branchName = branchName; - } - - public String getUuid() { - return uuid; - } - - public String getKey() { - return key; - } - - public String getName() { - return name; - } - - @CheckForNull - public String getBranchName() { - return branchName; - } - } - - public static final class Task { - private final String uuid; - private final long createdAt; - private final long failedAt; - - public Task(String uuid, long createdAt, long failedAt) { - this.uuid = requireNonNull(uuid, "uuid can't be null"); - this.createdAt = createdAt; - this.failedAt = failedAt; - } - - public String getUuid() { - return uuid; - } - - public long getCreatedAt() { - return createdAt; - } - - public long getFailedAt() { - return failedAt; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java deleted file mode 100644 index 865a75ff782..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationDispatcher.java +++ /dev/null @@ -1,69 +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.Multimap; -import java.util.Collection; -import java.util.Map; -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; - -public class ReportAnalysisFailureNotificationDispatcher extends NotificationDispatcher { - - public static final String KEY = "CeReportTaskFailure"; - private static final SubscriberPermissionsOnProject REQUIRED_SUBSCRIBER_PERMISSIONS = new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER); - - private final NotificationManager manager; - - public ReportAnalysisFailureNotificationDispatcher(NotificationManager manager) { - super(ReportAnalysisFailureNotification.TYPE); - this.manager = manager; - } - - public static NotificationDispatcherMetadata newMetadata() { - return NotificationDispatcherMetadata.create(KEY) - .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) - .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true)); - } - - @Override - public String getKey() { - return KEY; - } - - @Override - public void dispatch(Notification notification, Context context) { - String projectKey = notification.getFieldValue("project.key"); - Multimap<String, NotificationChannel> subscribedRecipients = manager - .findSubscribedRecipientsForDispatcher(this, projectKey, REQUIRED_SUBSCRIBER_PERMISSIONS); - - for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { - String userLogin = channelsByRecipients.getKey(); - for (NotificationChannel channel : channelsByRecipients.getValue()) { - context.addUser(userLogin, channel); - } - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java deleted file mode 100644 index cd7b95162e1..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationEmailTemplate.java +++ /dev/null @@ -1,100 +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.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import org.sonar.api.config.EmailSettings; -import org.sonar.api.notifications.Notification; -import org.sonar.plugins.emailnotifications.api.EmailMessage; -import org.sonar.plugins.emailnotifications.api.EmailTemplate; - -import static org.sonar.api.utils.DateUtils.formatDateTime; - -public class ReportAnalysisFailureNotificationEmailTemplate extends EmailTemplate { - private static final char LINE_RETURN = '\n'; - private static final char TAB = '\t'; - - private final ReportAnalysisFailureNotificationSerializer serializer; - protected final EmailSettings settings; - - public ReportAnalysisFailureNotificationEmailTemplate(ReportAnalysisFailureNotificationSerializer serializer, EmailSettings settings) { - this.serializer = serializer; - this.settings = settings; - } - - @Override - public EmailMessage format(Notification notification) { - if (!ReportAnalysisFailureNotification.TYPE.equals(notification.getType())) { - return null; - } - - ReportAnalysisFailureNotification taskFailureNotification = serializer.fromNotification(notification); - String projectUuid = taskFailureNotification.getProject().getUuid(); - String projectFullName = computeProjectFullName(taskFailureNotification.getProject()); - - return new EmailMessage() - .setMessageId(notification.getType() + "/" + projectUuid) - .setSubject(subject(projectFullName)) - .setMessage(message(projectFullName, taskFailureNotification)); - } - - private static String computeProjectFullName(ReportAnalysisFailureNotification.Project project) { - String branchName = project.getBranchName(); - if (branchName != null) { - return String.format("%s (%s)", project.getName(), branchName); - } - return project.getName(); - } - - private static String subject(String projectFullName) { - return String.format("%s: Background task in failure", projectFullName); - } - - private String message(String projectFullName, ReportAnalysisFailureNotification taskFailureNotification) { - ReportAnalysisFailureNotification.Project project = taskFailureNotification.getProject(); - ReportAnalysisFailureNotification.Task task = taskFailureNotification.getTask(); - - StringBuilder res = new StringBuilder(); - res.append("Project:").append(TAB).append(projectFullName).append(LINE_RETURN); - res.append("Background task:").append(TAB).append(task.getUuid()).append(LINE_RETURN); - res.append("Submission time:").append(TAB).append(formatDateTime(task.getCreatedAt())).append(LINE_RETURN); - res.append("Failure time:").append(TAB).append(formatDateTime(task.getFailedAt())).append(LINE_RETURN); - - String errorMessage = taskFailureNotification.getErrorMessage(); - if (errorMessage != null) { - res.append(LINE_RETURN); - res.append("Error message:").append(TAB).append(errorMessage).append(LINE_RETURN); - } - - res.append(LINE_RETURN); - res.append("More details at: ").append(String.format("%s/project/background_tasks?id=%s", settings.getServerBaseURL(), encode(project.getKey()))); - - return res.toString(); - } - - private static String encode(String toEncode) { - try { - return URLEncoder.encode(toEncode, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("Encoding not supported", e); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java deleted file mode 100644 index ce73b74e3d0..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationModule.java +++ /dev/null @@ -1,33 +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.sonar.core.platform.Module; - -public class ReportAnalysisFailureNotificationModule extends Module { - @Override - protected void configureModule() { - add( - ReportAnalysisFailureNotificationDispatcher.class, - ReportAnalysisFailureNotificationDispatcher.newMetadata(), - ReportAnalysisFailureNotificationSerializerImpl.class, - ReportAnalysisFailureNotificationEmailTemplate.class); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java deleted file mode 100644 index 7f43bb0d7d1..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializer.java +++ /dev/null @@ -1,28 +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.sonar.api.notifications.Notification; - -public interface ReportAnalysisFailureNotificationSerializer { - Notification toNotification(ReportAnalysisFailureNotification reportAnalysisFailureNotification); - - ReportAnalysisFailureNotification fromNotification(Notification notification); -} diff --git a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java b/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java deleted file mode 100644 index 4d459cb94ba..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/ce/task/projectanalysis/notification/ReportAnalysisFailureNotificationSerializerImpl.java +++ /dev/null @@ -1,63 +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.sonar.api.notifications.Notification; - -import static java.lang.String.valueOf; - -public class ReportAnalysisFailureNotificationSerializerImpl implements ReportAnalysisFailureNotificationSerializer { - private static final String FIELD_PROJECT_UUID = "project.uuid"; - private static final String FIELD_PROJECT_KEY = "project.key"; - private static final String FIELD_PROJECT_NAME = "project.name"; - private static final String FIELD_PROJECT_BRANCH = "project.branchName"; - private static final String FIELD_TASK_UUID = "task.uuid"; - private static final String FIELD_TASK_CREATED_AT = "task.createdAt"; - private static final String FIELD_TASK_FAILED_AT = "task.failedAt"; - private static final String FIELD_ERROR_MESSAGE = "error.message"; - - @Override - public Notification toNotification(ReportAnalysisFailureNotification reportAnalysisFailureNotification) { - return new Notification(ReportAnalysisFailureNotification.TYPE) - .setFieldValue(FIELD_PROJECT_UUID, reportAnalysisFailureNotification.getProject().getUuid()) - .setFieldValue(FIELD_PROJECT_KEY, reportAnalysisFailureNotification.getProject().getKey()) - .setFieldValue(FIELD_PROJECT_NAME, reportAnalysisFailureNotification.getProject().getName()) - .setFieldValue(FIELD_PROJECT_BRANCH, reportAnalysisFailureNotification.getProject().getBranchName()) - .setFieldValue(FIELD_TASK_UUID, reportAnalysisFailureNotification.getTask().getUuid()) - .setFieldValue(FIELD_TASK_CREATED_AT, valueOf(reportAnalysisFailureNotification.getTask().getCreatedAt())) - .setFieldValue(FIELD_TASK_FAILED_AT, valueOf(reportAnalysisFailureNotification.getTask().getFailedAt())) - .setFieldValue(FIELD_ERROR_MESSAGE, reportAnalysisFailureNotification.getErrorMessage()); - } - - @Override - public ReportAnalysisFailureNotification fromNotification(Notification notification) { - return new ReportAnalysisFailureNotification( - new ReportAnalysisFailureNotification.Project( - notification.getFieldValue(FIELD_PROJECT_UUID), - notification.getFieldValue(FIELD_PROJECT_KEY), - notification.getFieldValue(FIELD_PROJECT_NAME), - notification.getFieldValue(FIELD_PROJECT_BRANCH)), - new ReportAnalysisFailureNotification.Task( - notification.getFieldValue(FIELD_TASK_UUID), - Long.valueOf(notification.getFieldValue(FIELD_TASK_CREATED_AT)), - Long.valueOf(notification.getFieldValue(FIELD_TASK_FAILED_AT))), - notification.getFieldValue(FIELD_ERROR_MESSAGE)); - } -} 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; |