Search in sources :

Example 46 with ReportComponent

use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.

the class ClosedIssuesInputFactoryTest method underTest_returns_inputFactory_loading_closed_issues_from_moved_component_when_present.

@Test
public void underTest_returns_inputFactory_loading_closed_issues_from_moved_component_when_present() {
    String componentUuid = randomAlphanumeric(12);
    String originalComponentUuid = randomAlphanumeric(12);
    ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).setUuid(componentUuid).build();
    when(movedFilesRepository.getOriginalFile(component)).thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(originalComponentUuid, randomAlphanumeric(2))));
    Input<DefaultIssue> input = underTest.create(component);
    verifyZeroInteractions(dbClient, issuesLoader);
    List<DefaultIssue> issues = ImmutableList.of();
    when(issuesLoader.loadClosedIssues(originalComponentUuid)).thenReturn(issues);
    assertThat(input.getIssues()).isSameAs(issues);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 47 with ReportComponent

use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.

the class ClosedIssuesInputFactoryTest method underTest_returns_inputFactory_which_caches_loaded_issues.

@Test
public void underTest_returns_inputFactory_which_caches_loaded_issues() {
    String componentUuid = randomAlphanumeric(12);
    ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).setUuid(componentUuid).build();
    when(movedFilesRepository.getOriginalFile(component)).thenReturn(Optional.empty());
    Input<DefaultIssue> input = underTest.create(component);
    verifyZeroInteractions(dbClient, issuesLoader);
    List<DefaultIssue> issues = ImmutableList.of(new DefaultIssue());
    when(issuesLoader.loadClosedIssues(componentUuid)).thenReturn(issues);
    assertThat(input.getIssues()).isSameAs(issues);
    reset(issuesLoader);
    assertThat(input.getIssues()).isSameAs(issues);
    verifyZeroInteractions(issuesLoader);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 48 with ReportComponent

use of org.sonar.ce.task.projectanalysis.component.ReportComponent in project sonarqube by SonarSource.

the class SumFormulaExecutionTest method add_measures.

@Test
public void add_measures() {
    ReportComponent project = builder(PROJECT, 1).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build(), builder(Component.Type.FILE, 1112).build()).build(), builder(DIRECTORY, 121).addChildren(builder(Component.Type.FILE, 1211).build()).build()).build();
    treeRootHolder.setRoot(project);
    measureRepository.addRawMeasure(1111, LINES_KEY, newMeasureBuilder().create(10));
    measureRepository.addRawMeasure(1112, LINES_KEY, newMeasureBuilder().create(8));
    measureRepository.addRawMeasure(1211, LINES_KEY, newMeasureBuilder().create(2));
    new PathAwareCrawler<>(underTest).visit(project);
    assertThat(toEntries(measureRepository.getAddedRawMeasures(1))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(20)));
    assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(18)));
    assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(1112)).isEmpty();
    assertThat(toEntries(measureRepository.getAddedRawMeasures(121))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(2)));
    assertThat(measureRepository.getAddedRawMeasures(1211)).isEmpty();
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)48 Test (org.junit.Test)46 DefaultIssue (org.sonar.core.issue.DefaultIssue)16 Random (java.util.Random)10 RuleKey (org.sonar.api.rule.RuleKey)7 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)7 UserDto (org.sonar.db.user.UserDto)7 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)6 IssuesChangesNotificationBuilder (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 LineReader (org.sonar.ce.task.projectanalysis.source.linereader.LineReader)5 ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)5 IntStream (java.util.stream.IntStream)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.verify (org.mockito.Mockito.verify)4 Mockito.when (org.mockito.Mockito.when)4 CeTaskMessages (org.sonar.ce.task.log.CeTaskMessages)4 Component (org.sonar.ce.task.projectanalysis.component.Component)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)3