]> source.dussan.org Git - sonarqube.git/blob
0d02dcbd8cd1e1eebc2aca36f80d7b4c52598b1a
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.issue.notification;
21
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;
26
27 import static org.assertj.core.api.Assertions.assertThat;
28
29 public class IssueChangeNotificationTest {
30
31   IssueChangeNotification notification = new IssueChangeNotification();
32
33   @Test
34   public void set_issue() {
35     DefaultIssue issue = new DefaultIssue()
36       .setKey("ABCD")
37       .setAssignee("simon")
38       .setMessage("Remove this useless method")
39       .setComponentKey("MyService")
40       .setCurrentChange(new FieldDiffs().setDiff("resolution", "FALSE-POSITIVE", "FIXED"));
41
42     IssueChangeNotification result = notification.setIssue(issue);
43
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");
50   }
51
52   @Test
53   public void set_issue_with_current_change_having_no_old_value() {
54     DefaultIssue issue = new DefaultIssue()
55       .setKey("ABCD")
56       .setAssignee("simon")
57       .setMessage("Remove this useless method")
58       .setComponentKey("MyService");
59
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");
63
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");
67   }
68
69   @Test
70   public void set_issue_with_current_change_having_no_new_value() {
71     DefaultIssue issue = new DefaultIssue()
72       .setKey("ABCD")
73       .setAssignee("simon")
74       .setMessage("Remove this useless method")
75       .setComponentKey("MyService");
76
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();
80
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();
84   }
85
86   @Test
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");
91   }
92
93   @Test
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");
97   }
98
99   @Test
100   public void set_change_author_login() {
101     IssueChangeNotification result = notification.setChangeAuthorLogin("stephane");
102     assertThat(result.getFieldValue("changeAuthor")).isEqualTo("stephane");
103   }
104
105   @Test
106   public void set_rule_name() {
107     IssueChangeNotification result = notification.setRuleName("Xoo Rule");
108     assertThat(result.getFieldValue("ruleName")).isEqualTo("Xoo Rule");
109   }
110
111   @Test
112   public void setComment() {
113     IssueChangeNotification result = notification.setComment("My comment");
114     assertThat(result.getFieldValue("comment")).isEqualTo("My comment");
115   }
116 }