Search in sources :

Example 6 with ReportComponent

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

the class TrackerExecutionTest method track_does_not_track_nonClosed_issues_if_tracking_returns_incomplete_but_this_is_first_analysis.

@Test
public void track_does_not_track_nonClosed_issues_if_tracking_returns_incomplete_but_this_is_first_analysis() {
    ReportComponent component = ReportComponent.builder(Component.Type.FILE, 1).build();
    when(baseInputFactory.create(component)).thenReturn(openIssuesInput);
    when(closedIssuesInputFactory.create(any())).thenThrow(new IllegalStateException("closedIssuesInputFactory should not be called"));
    when(nonClosedTracking.isComplete()).thenReturn(false);
    when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
    when(tracker.trackNonClosed(rawInput, openIssuesInput)).thenReturn(nonClosedTracking);
    when(tracker.trackClosed(any(), any())).thenThrow(new IllegalStateException("trackClosed should not be called"));
    Tracking<DefaultIssue, DefaultIssue> tracking = underTest.track(component, rawInput);
    assertThat(tracking).isSameAs(nonClosedTracking);
    verify(tracker).trackNonClosed(rawInput, openIssuesInput);
    verifyNoMoreInteractions(tracker);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 7 with ReportComponent

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

the class CommonRuleEngineImplTest method do_not_process_files_with_unknown_language.

@Test
public void do_not_process_files_with_unknown_language() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, null, 1)).build();
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).isEmpty();
    verifyZeroInteractions(rule1, rule2);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 8 with ReportComponent

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

the class CommonRuleEngineImplTest method process_files_with_known_language.

@Test
public void process_files_with_known_language() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, "java", 1)).build();
    DefaultIssue issue = new DefaultIssue();
    when(rule1.processFile(file, "java")).thenReturn(issue);
    when(rule2.processFile(file, "java")).thenReturn(null);
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).containsOnly(issue);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 9 with ReportComponent

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

the class NotificationFactoryTest method newIssuesChangesNotification_creates_AnalysisChange_with_analysis_date.

@Test
public void newIssuesChangesNotification_creates_AnalysisChange_with_analysis_date() {
    RuleKey ruleKey = RuleKey.of("foo", "bar");
    DefaultIssue issue = new DefaultIssue().setRuleKey(ruleKey).setKey("issueKey").setStatus(STATUS_OPEN);
    Map<String, UserDto> assigneesByUuid = nonEmptyAssigneesByUuid();
    ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
    long analysisDate = new Random().nextLong();
    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(ImmutableSet.of(issue), assigneesByUuid);
    assertThat(notification).isSameAs(expected);
    IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
    assertThat(builder.getIssues()).hasSize(1);
    assertThat(builder.getChange()).isInstanceOf(AnalysisChange.class).extracting(IssuesChangesNotificationBuilder.Change::getDate).isEqualTo(analysisDate);
}
Also used : Random(java.util.Random) RuleKey(org.sonar.api.rule.RuleKey) UserDto(org.sonar.db.user.UserDto) 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)

Example 10 with ReportComponent

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

the class LastCommitVisitorTest method aggregate_date_of_last_commit_to_directories_and_project.

@Test
public void aggregate_date_of_last_commit_to_directories_and_project() {
    final long FILE_1_DATE = 1_100_000_000_000L;
    // FILE_2 is the most recent file in DIR_1
    final long FILE_2_DATE = 1_200_000_000_000L;
    // FILE_3 is the most recent file in the project
    final long FILE_3_DATE = 1_300_000_000_000L;
    // simulate the output of visitFile()
    LastCommitVisitor visitor = new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository) {

        @Override
        public void visitFile(Component file, Path<LastCommit> path) {
            long fileDate;
            switch(file.getReportAttributes().getRef()) {
                case FILE_1_REF:
                    fileDate = FILE_1_DATE;
                    break;
                case FILE_2_REF:
                    fileDate = FILE_2_DATE;
                    break;
                case FILE_3_REF:
                    fileDate = FILE_3_DATE;
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            path.parent().addDate(fileDate);
        }
    };
    // project with 1 module, 2 directories and 3 files
    ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).addChildren(ReportComponent.builder(DIRECTORY, DIR_REF).addChildren(ReportComponent.builder(DIRECTORY, DIR_1_REF).addChildren(createFileComponent(FILE_1_REF), createFileComponent(FILE_2_REF)).build(), ReportComponent.builder(DIRECTORY, DIR_2_REF).addChildren(createFileComponent(FILE_3_REF)).build()).build()).build();
    treeRootHolder.setRoot(project);
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.newArrayList(visitor));
    underTest.visit(project);
    assertDate(DIR_1_REF, FILE_2_DATE);
    assertDate(DIR_2_REF, FILE_3_DATE);
    assertDate(DIR_REF, FILE_3_DATE);
    // project
    assertDate(PROJECT_REF, FILE_3_DATE);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) 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