use of org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier in project sonarqube by SonarSource.
the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_returns_name_and_language_from_RuleRepository.
@Test
public void newMyNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_returns_name_and_language_from_RuleRepository() {
RuleKey rulekey1 = RuleKey.of("foo", "bar");
RuleKey rulekey2 = RuleKey.of("foo", "donut");
RuleKey rulekey3 = RuleKey.of("no", "language");
DumbRule rule1 = ruleRepository.add(rulekey1).setName("rule1").setLanguage("lang1");
DumbRule rule2 = ruleRepository.add(rulekey2).setName("rule2").setLanguage("lang2");
DumbRule rule3 = ruleRepository.add(rulekey3).setName("rule3");
MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey1)).contains(new RuleDefinition(rule1.getName(), rule1.getLanguage()));
assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey2)).contains(new RuleDefinition(rule2.getName(), rule2.getLanguage()));
assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey3)).contains(new RuleDefinition(rule3.getName(), null));
assertThat(detailsSupplier.getRuleDefinitionByRuleKey(RuleKey.of("donut", "foo"))).isEmpty();
}
use of org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier in project sonarqube by SonarSource.
the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_returns_name_of_project_in_TreeRootHolder.
@Test
public void newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_returns_name_of_project_in_TreeRootHolder() {
treeRootHolder.setRoot(ReportComponent.builder(PROJECT, 1).setUuid("rootUuid").setName("root").build());
MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
assertThat(detailsSupplier.getComponentNameByUuid("rootUuid")).contains("root");
assertThat(detailsSupplier.getComponentNameByUuid("foo")).isEmpty();
}
use of org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier in project sonarqube by SonarSource.
the class NotificationFactoryTest method readDetailsSupplier.
private static DetailsSupplier readDetailsSupplier(NewIssuesNotification notification) {
try {
Field durationsField = NewIssuesNotification.class.getDeclaredField("detailsSupplier");
durationsField.setAccessible(true);
return (DetailsSupplier) durationsField.get(notification);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
use of org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier in project sonarqube by SonarSource.
the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_fails_with_ISE_if_TreeRootHolder_is_not_initialized.
@Test
public void newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_fails_with_ISE_if_TreeRootHolder_is_not_initialized() {
MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
assertThatThrownBy(() -> detailsSupplier.getComponentNameByUuid("foo")).isInstanceOf(IllegalStateException.class).hasMessage("Holder has not been initialized yet");
}
use of org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier in project sonarqube by SonarSource.
the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_returns_shortName_of_dir_and_file_in_TreeRootHolder.
@Test
public void newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_returns_shortName_of_dir_and_file_in_TreeRootHolder() {
treeRootHolder.setRoot(ReportComponent.builder(PROJECT, 1).setUuid("rootUuid").setName("root").addChildren(ReportComponent.builder(DIRECTORY, 2).setUuid("dir1Uuid").setName("dir1").setShortName("dir1_short").addChildren(ReportComponent.builder(FILE, 21).setUuid("file21Uuid").setName("file21").setShortName("file21_short").build()).build()).addChildren(ReportComponent.builder(DIRECTORY, 3).setUuid("dir2Uuid").setName("dir2").setShortName("dir2_short").addChildren(ReportComponent.builder(FILE, 31).setUuid("file31Uuid").setName("file31").setShortName("file31_short").build()).addChildren(ReportComponent.builder(FILE, 32).setUuid("file32Uuid").setName("file32").setShortName("file32_short").build()).build()).addChildren(ReportComponent.builder(FILE, 11).setUuid("file11Uuid").setName("file11").setShortName("file11_short").build()).build());
MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
Stream.of("dir1", "dir2", "file11", "file21", "file31", "file32").forEach(name -> {
assertThat(detailsSupplier.getComponentNameByUuid(name + "Uuid")).contains(name + "_short");
assertThat(detailsSupplier.getComponentNameByUuid(name)).isEmpty();
});
}
Aggregations