private void appendFooter(StringBuilder sb, Notification notification) {
String issueKey = notification.getFieldValue("key");
- sb.append("See it in SonarQube: ").append(settings.getServerBaseURL()).append("/issue/show/").append(issueKey).append(NEW_LINE);
+ String componentKey = notification.getFieldValue("componentKey");
+ sb.append("See it in SonarQube: ").append(settings.getServerBaseURL()).append("/component/index#component=").append(componentKey)
+ .append("¤tIssue=").append(issueKey).append(NEW_LINE);
}
private void appendLine(StringBuilder sb, @Nullable String line) {
assertThat(email.getFrom()).isNull();
}
+ @Test
+ public void display_component_key_if_no_component_name() throws Exception {
+ Notification notification = generateNotification()
+ .setFieldValue("componentName", null);
+
+ EmailMessage email = template.format(notification);
+ assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
+ assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
+
+ String message = email.getMessage();
+ String expected = Resources.toString(Resources.getResource(
+ "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt"),
+ Charsets.UTF_8
+ );
+ expected = StringUtils.remove(expected, '\r');
+ assertThat(message).isEqualTo(expected);
+ }
+
@Test
public void test_email_with_multiple_changes() throws Exception {
Notification notification = generateNotification()
Notification notification = new Notification("issue-changes")
.setFieldValue("projectName", "Struts")
.setFieldValue("projectKey", "org.apache:struts")
- .setFieldValue("componentName", "org.apache.struts.Action")
+ .setFieldValue("componentName", "Action")
+ .setFieldValue("componentKey", "org.apache.struts.Action")
.setFieldValue("key", "ABCDE")
.setFieldValue("ruleName", "Avoid Cycles")
.setFieldValue("message", "Has 3 cycles");