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("componentKey")).isEqualTo("MyService");
48 assertThat(result.getFieldValue("old.resolution")).isEqualTo("FALSE-POSITIVE");
49 assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
53 public void set_issue_with_current_change_having_no_old_value() {
54 DefaultIssue issue = new DefaultIssue()
57 .setMessage("Remove this useless method")
58 .setComponentKey("MyService");
60 IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", null, "FIXED")));
61 assertThat(result.getFieldValue("old.resolution")).isNull();
62 assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
64 result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", "", "FIXED")));
65 assertThat(result.getFieldValue("old.resolution")).isNull();
66 assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
70 public void set_issue_with_current_change_having_no_new_value() {
71 DefaultIssue issue = new DefaultIssue()
74 .setMessage("Remove this useless method")
75 .setComponentKey("MyService");
77 IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", null)));
78 assertThat(result.getFieldValue("old.assignee")).isEqualTo("john");
79 assertThat(result.getFieldValue("new.assignee")).isNull();
81 result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", "")));
82 assertThat(result.getFieldValue("old.assignee")).isEqualTo("john");
83 assertThat(result.getFieldValue("new.assignee")).isNull();
87 public void set_project() {
88 IssueChangeNotification result = notification.setProject("MyService", "My Service");
89 assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService");
90 assertThat(result.getFieldValue("projectName")).isEqualTo("My Service");
94 public void set_component() {
95 IssueChangeNotification result = notification.setComponent(new ComponentDto().setDbKey("MyService").setLongName("My Service"));
96 assertThat(result.getFieldValue("componentName")).isEqualTo("My Service");
100 public void set_change_author_login() {
101 IssueChangeNotification result = notification.setChangeAuthorLogin("stephane");
102 assertThat(result.getFieldValue("changeAuthor")).isEqualTo("stephane");
106 public void set_rule_name() {
107 IssueChangeNotification result = notification.setRuleName("Xoo Rule");
108 assertThat(result.getFieldValue("ruleName")).isEqualTo("Xoo Rule");
112 public void setComment() {
113 IssueChangeNotification result = notification.setComment("My comment");
114 assertThat(result.getFieldValue("comment")).isEqualTo("My comment");