Search in sources :

Example 36 with ReportComponent

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

the class FileSourceDataWarningsTest method create_highlighting_warning_when_one_file_HIGHLIGHT_read_error.

@Test
public void create_highlighting_warning_when_one_file_HIGHLIGHT_read_error() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setUuid("uuid").setName(path).build();
    LineReader.ReadError readError = new LineReader.ReadError(HIGHLIGHTING, line);
    when(system2.now()).thenReturn(timeStamp);
    underTest.addWarning(file, readError);
    verifyZeroInteractions(taskMessages);
    underTest.commitWarnings();
    verify(taskMessages, times(1)).add(new CeTaskMessages.Message("Inconsistent highlighting data detected on file '" + path + "'. " + "File source may have been modified while analysis was running.", timeStamp));
}
Also used : CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 37 with ReportComponent

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

the class FileSourceDataWarningsTest method create_symbol_warning_when_any_number_of_read_error_for_one_file.

@Test
public void create_symbol_warning_when_any_number_of_read_error_for_one_file() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setUuid("uuid").setName(path).build();
    LineReader.ReadError[] readErrors = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> new LineReader.ReadError(SYMBOLS, line + i)).toArray(LineReader.ReadError[]::new);
    when(system2.now()).thenReturn(timeStamp);
    Arrays.stream(readErrors).forEach(readError -> underTest.addWarning(file, readError));
    verifyZeroInteractions(taskMessages);
    underTest.commitWarnings();
    verify(taskMessages, times(1)).add(new CeTaskMessages.Message("Inconsistent symbol data detected on file '" + path + "'. " + "File source may have been modified while analysis was running.", timeStamp));
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.task.projectanalysis.component.Component) Arrays(java.util.Arrays) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) SYMBOLS(org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.SYMBOLS) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) HIGHLIGHTING(org.sonar.ce.task.projectanalysis.source.linereader.LineReader.Data.HIGHLIGHTING) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Mockito.mock(org.mockito.Mockito.mock) CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 38 with ReportComponent

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

the class NewMaintainabilityMeasuresVisitorTest method compute_new_development_cost.

@Test
public void compute_new_development_cost() {
    ReportComponent file1 = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 4)).build();
    ReportComponent file2 = builder(FILE, 22_222).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 6)).build();
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(file1, file2).build()).build());
    // 4 lines file, only first one is not ncloc
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
    setNewLines(file1, 3, 4);
    // 6 lines file, only last one is not ncloc
    measureRepository.addRawMeasure(22_222, NCLOC_DATA_KEY, createNclocDataMeasure(1, 2, 3, 4, 5));
    // first 2 lines are before all snapshots, 4 last lines are after PERIOD 2's snapshot date
    setNewLines(file2, 3, 4, 5, 6);
    underTest.visit(treeRootHolder.getRoot());
    assertNewDevelopmentCostValues(ROOT_REF, 5 * LANGUAGE_1_DEV_COST);
    assertNewDevelopmentCostValues(LANGUAGE_1_FILE_REF, 2 * LANGUAGE_1_DEV_COST);
    assertNewDevelopmentCostValues(22_222, 3 * LANGUAGE_1_DEV_COST);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 39 with ReportComponent

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

the class LastCommitVisitorTest method compute_date_of_file_from_scm_repo.

@Test
public void compute_date_of_file_from_scm_repo() {
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
    scmInfoRepository.setScmInfo(FILE_1_REF, Changeset.newChangesetBuilder().setAuthor("john").setDate(1_500_000_000_000L).setRevision("rev-1").build(), Changeset.newChangesetBuilder().setAuthor("tom").setDate(1_600_000_000_000L).setRevision("rev-2").build(), Changeset.newChangesetBuilder().setAuthor("john").setDate(1_500_000_000_000L).setRevision("rev-1").build());
    ReportComponent file = createFileComponent(FILE_1_REF);
    treeRootHolder.setRoot(file);
    underTest.visit(file);
    assertDate(FILE_1_REF, 1_600_000_000_000L);
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 40 with ReportComponent

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

the class LastCommitVisitorTest method date_is_not_computed_on_file_if_blame_is_not_in_scm_repo.

@Test
public void date_is_not_computed_on_file_if_blame_is_not_in_scm_repo() {
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.newArrayList(new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository)));
    ReportComponent file = createFileComponent(FILE_1_REF);
    treeRootHolder.setRoot(file);
    underTest.visit(file);
    Optional<Measure> measure = measureRepository.getAddedRawMeasure(FILE_1_REF, LAST_COMMIT_DATE_KEY);
    assertThat(measure).isEmpty();
}
Also used : VisitorsCrawler(org.sonar.ce.task.projectanalysis.component.VisitorsCrawler) Measure(org.sonar.ce.task.projectanalysis.measure.Measure) 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