]> source.dussan.org Git - sonarqube.git/blob
94ff9af63e89cce64e79fa37fd5b1117380afa0f
[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("old.resolution")).isEqualTo("FALSE-POSITIVE");
48     assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
49   }
50
51   @Test
52   public void set_issue_with_current_change_having_no_old_value() {
53     DefaultIssue issue = new DefaultIssue()
54       .setKey("ABCD")
55       .setAssignee("simon")
56       .setMessage("Remove this useless method")
57       .setComponentKey("MyService");
58
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");
62
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");
66   }
67
68   @Test
69   public void set_issue_with_current_change_having_no_new_value() {
70     DefaultIssue issue = new DefaultIssue()
71       .setKey("ABCD")
72       .setAssignee("simon")
73       .setMessage("Remove this useless method")
74       .setComponentKey("MyService");
75
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();
79
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();
83   }
84
85   @Test
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();
92   }
93
94   @Test
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");
101   }
102
103   @Test
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");
108   }
109
110   @Test
111   public void set_change_author_login() {
112     IssueChangeNotification result = notification.setChangeAuthorLogin("stephane");
113     assertThat(result.getFieldValue("changeAuthor")).isEqualTo("stephane");
114   }
115
116   @Test
117   public void set_rule_name() {
118     IssueChangeNotification result = notification.setRuleName("Xoo Rule");
119     assertThat(result.getFieldValue("ruleName")).isEqualTo("Xoo Rule");
120   }
121
122   @Test
123   public void setComment() {
124     IssueChangeNotification result = notification.setComment("My comment");
125     assertThat(result.getFieldValue("comment")).isEqualTo("My comment");
126   }
127 }