3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.issue.notification;
22 import java.util.Random;
23 import org.sonar.api.rule.RuleKey;
24 import org.sonar.db.DbTester;
25 import org.sonar.db.component.BranchDto;
26 import org.sonar.db.component.ComponentDto;
27 import org.sonar.db.rule.RuleDefinitionDto;
28 import org.sonar.db.rule.RuleDto;
29 import org.sonar.db.user.UserDto;
30 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange;
31 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue;
32 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project;
33 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule;
34 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User;
35 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange;
37 import static com.google.common.base.Preconditions.checkArgument;
38 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
40 public class IssuesChangesNotificationBuilderTesting {
42 public static Rule ruleOf(RuleDto rule) {
43 return new Rule(rule.getKey(), rule.getName());
46 public static Rule ruleOf(RuleDefinitionDto rule) {
47 return new Rule(rule.getKey(), rule.getName());
50 public static User userOf(UserDto changeAuthor) {
51 return new User(changeAuthor.getUuid(), changeAuthor.getLogin(), changeAuthor.getName());
54 public static Project projectBranchOf(DbTester db, ComponentDto branch) {
55 BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid()).get();
56 checkArgument(!branchDto.isMain(), "should be a branch");
57 return new Project.Builder(branch.uuid())
58 .setKey(branch.getKey())
59 .setProjectName(branch.name())
60 .setBranchName(branchDto.getKey())
64 public static Project projectOf(ComponentDto project) {
65 return new Project.Builder(project.uuid())
66 .setKey(project.getKey())
67 .setProjectName(project.name())
71 static ChangedIssue newChangedIssue(String key, Project project, Rule rule) {
72 return new ChangedIssue.Builder(key)
73 .setNewStatus(randomAlphabetic(19))
79 static ChangedIssue newChangedIssue(String key, String status, Project project, String ruleName) {
80 return newChangedIssue(key, status, project, newRule(ruleName));
83 static ChangedIssue newChangedIssue(String key, String status, Project project, Rule rule) {
84 return new ChangedIssue.Builder(key)
91 static Rule newRule(String ruleName) {
92 return new Rule(RuleKey.of(randomAlphabetic(6), randomAlphabetic(7)), ruleName);
95 static Project newProject(String uuid) {
96 return new Project.Builder(uuid).setProjectName(uuid + "_name").setKey(uuid + "_key").build();
99 static Project newBranch(String uuid, String branchName) {
100 return new Project.Builder(uuid).setProjectName(uuid + "_name").setKey(uuid + "_key").setBranchName(branchName).build();
103 static UserChange newUserChange() {
104 return new UserChange(new Random().nextLong(), new User(randomAlphabetic(4), randomAlphabetic(5), randomAlphabetic(6)));
107 static AnalysisChange newAnalysisChange() {
108 return new AnalysisChange(new Random().nextLong());