Search in sources :

Example 1 with MyNewIssuesNotification

use of org.sonar.server.issue.notification.MyNewIssuesNotification in project sonarqube by SonarSource.

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_fails_with_NPE_if_uuid_is_null.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_fails_with_NPE_if_uuid_is_null() {
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThatThrownBy(() -> detailsSupplier.getUserNameByUuid(null)).isInstanceOf(NullPointerException.class).hasMessage("uuid can't be null");
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 2 with MyNewIssuesNotification

use of org.sonar.server.issue.notification.MyNewIssuesNotification 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();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) DumbRule(org.sonar.ce.task.projectanalysis.issue.DumbRule) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) Test(org.junit.Test)

Example 3 with MyNewIssuesNotification

use of org.sonar.server.issue.notification.MyNewIssuesNotification 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();
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 4 with MyNewIssuesNotification

use of org.sonar.server.issue.notification.MyNewIssuesNotification 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");
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 5 with MyNewIssuesNotification

use of org.sonar.server.issue.notification.MyNewIssuesNotification 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();
    });
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Aggregations

MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)16 Test (org.junit.Test)13 DetailsSupplier (org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier)11 UserDto (org.sonar.db.user.UserDto)4 Date (java.util.Date)3 Map (java.util.Map)3 RuleKey (org.sonar.api.rule.RuleKey)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Random (java.util.Random)2 Set (java.util.Set)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 IOException (java.io.IOException)1