3 * Copyright (C) 2009-2017 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 org.junit.Test;
23 import org.sonar.core.issue.DefaultIssue;
24 import org.sonar.core.issue.FieldDiffs;
25 import org.sonar.db.component.ComponentDto;
27 import static org.assertj.core.api.Assertions.assertThat;
29 public class IssueChangeNotificationTest {
31 IssueChangeNotification notification = new IssueChangeNotification();
34 public void set_issue() {
35 DefaultIssue issue = new DefaultIssue()
38 .setMessage("Remove this useless method")
39 .setComponentKey("MyService")
40 .setCurrentChange(new FieldDiffs().setDiff("resolution", "FALSE-POSITIVE", "FIXED"));
42 IssueChangeNotification result = notification.setIssue(issue);
44 assertThat(result.getFieldValue("key")).isEqualTo("ABCD");
45 assertThat(result.getFieldValue("assignee")).isEqualTo("simon");
46 assertThat(result.getFieldValue("message")).isEqualTo("Remove this useless method");
47 assertThat(result.getFieldValue("old.resolution")).isEqualTo("FALSE-POSITIVE");
48 assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
52 public void set_issue_with_current_change_having_no_old_value() {
53 DefaultIssue issue = new DefaultIssue()
56 .setMessage("Remove this useless method")
57 .setComponentKey("MyService");
59 IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", null, "FIXED")));
60 assertThat(result.getFieldValue("old.resolution")).isNull();
61 assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
63 result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", "", "FIXED")));
64 assertThat(result.getFieldValue("old.resolution")).isNull();
65 assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
69 public void set_issue_with_current_change_having_no_new_value() {
70 DefaultIssue issue = new DefaultIssue()
73 .setMessage("Remove this useless method")
74 .setComponentKey("MyService");
76 IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", null)));
77 assertThat(result.getFieldValue("old.assignee")).isEqualTo("john");
78 assertThat(result.getFieldValue("new.assignee")).isNull();
80 result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", "")));
81 assertThat(result.getFieldValue("old.assignee")).isEqualTo("john");
82 assertThat(result.getFieldValue("new.assignee")).isNull();
86 public void set_project_without_branch() {
87 IssueChangeNotification result = notification.setProject("MyService", "My Service", null, "uuid1");
88 assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService");
89 assertThat(result.getFieldValue("projectUuid")).isEqualTo("uuid1");
90 assertThat(result.getFieldValue("projectName")).isEqualTo("My Service");
91 assertThat(result.getFieldValue("branch")).isNull();
95 public void set_project_with_branch() {
96 IssueChangeNotification result = notification.setProject("MyService", "My Service", "feature1", "uuid2");
97 assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService");
98 assertThat(result.getFieldValue("projectUuid")).isEqualTo("uuid2");
99 assertThat(result.getFieldValue("projectName")).isEqualTo("My Service");
100 assertThat(result.getFieldValue("branch")).isEqualTo("feature1");
104 public void set_component() {
105 IssueChangeNotification result = notification.setComponent(new ComponentDto().setDbKey("MyService").setLongName("My Service"));
106 assertThat(result.getFieldValue("componentName")).isEqualTo("My Service");
107 assertThat(result.getFieldValue("componentKey")).isEqualTo("MyService");
111 public void set_change_author_login() {
112 IssueChangeNotification result = notification.setChangeAuthorLogin("stephane");
113 assertThat(result.getFieldValue("changeAuthor")).isEqualTo("stephane");
117 public void set_rule_name() {
118 IssueChangeNotification result = notification.setRuleName("Xoo Rule");
119 assertThat(result.getFieldValue("ruleName")).isEqualTo("Xoo Rule");
123 public void setComment() {
124 IssueChangeNotification result = notification.setComment("My comment");
125 assertThat(result.getFieldValue("comment")).isEqualTo("My comment");