Search in sources :

Example 1 with PROJECT

use of org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT in project sonarqube by SonarSource.

the class NotificationFactoryTest method newIssuesChangesNotification_maps_all_issues.

@Test
public void newIssuesChangesNotification_maps_all_issues() {
    Set<DefaultIssue> issues = IntStream.range(0, 3 + new Random().nextInt(5)).mapToObj(i -> new DefaultIssue().setRuleKey(RuleKey.of("repo_" + i, "rule_" + i)).setKey("issue_key_" + i).setStatus("status_" + i)).collect(Collectors.toSet());
    ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
    long analysisDate = new Random().nextLong();
    issues.stream().map(DefaultIssue::ruleKey).forEach(ruleKey -> ruleRepository.add(ruleKey));
    treeRootHolder.setRoot(project);
    analysisMetadata.setAnalysisDate(analysisDate);
    analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, randomAlphabetic(12)));
    IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
    when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
    IssuesChangesNotification notification = underTest.newIssuesChangesNotification(issues, emptyMap());
    assertThat(notification).isSameAs(expected);
    IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
    assertThat(builder.getIssues()).hasSize(issues.size());
    Map<String, ChangedIssue> changedIssuesByKey = builder.getIssues().stream().collect(uniqueIndex(ChangedIssue::getKey));
    issues.forEach(issue -> {
        ChangedIssue changedIssue = changedIssuesByKey.get(issue.key());
        assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
        assertThat(changedIssue.getNewResolution()).isEmpty();
        assertThat(changedIssue.getAssignee()).isEmpty();
        assertThat(changedIssue.getRule().getKey()).isEqualTo(issue.ruleKey());
        assertThat(changedIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(issue.ruleKey()).getName());
    });
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) DIRECTORY(org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Collectors(java.util.stream.Collectors) PROJECT(org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT) FILE(org.sonar.ce.task.projectanalysis.component.Component.Type.FILE) Stream(java.util.stream.Stream) RuleKey(org.sonar.api.rule.RuleKey) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) UserTesting(org.sonar.db.user.UserTesting) IssuesChangesNotificationSerializer(org.sonar.server.issue.notification.IssuesChangesNotificationSerializer) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UserDto(org.sonar.db.user.UserDto) STATUS_OPEN(org.sonar.api.issue.Issue.STATUS_OPEN) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DumbRule(org.sonar.ce.task.projectanalysis.issue.DumbRule) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Collections.emptyMap(java.util.Collections.emptyMap) BranchType(org.sonar.db.component.BranchType) DefaultIssue(org.sonar.core.issue.DefaultIssue) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) RuleRepositoryRule(org.sonar.ce.task.projectanalysis.issue.RuleRepositoryRule) Collections(java.util.Collections) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Field (java.lang.reflect.Field)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1