Search in sources :

Example 41 with ReportComponent

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

the class AverageFormulaExecutionTest method not_add_measures_when_no_data_on_file.

@Test
public void not_add_measures_when_no_data_on_file() {
    ReportComponent project = builder(PROJECT, 1).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build()).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(underTest).visit(project);
    assertThat(measureRepository.getAddedRawMeasures(1)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(111)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 42 with ReportComponent

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

the class DistributionFormulaExecutionTest method not_add_measures_when_no_data_on_file.

@Test
public void not_add_measures_when_no_data_on_file() {
    ReportComponent project = builder(PROJECT, 1).addChildren(builder(DIRECTORY, 11).addChildren(builder(DIRECTORY, 111).addChildren(builder(Component.Type.FILE, 1111).build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(underTest).visit(project);
    assertThat(measureRepository.getAddedRawMeasures(1)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(11)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(111)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 43 with ReportComponent

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

the class ReportFormulaExecutorComponentVisitorTest method add_measure_even_when_leaf_is_not_FILE.

@Test
public void add_measure_even_when_leaf_is_not_FILE() {
    ReportComponent project = ReportComponent.builder(PROJECT, ROOT_REF).addChildren(ReportComponent.builder(DIRECTORY, 111).build()).build();
    treeRootHolder.setRoot(project);
    new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(project);
    assertAddedRawMeasure(DIRECTORY_1_REF, 0);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 44 with ReportComponent

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

the class ReportFormulaExecutorComponentVisitorTest method ignore_measure_defined_on_project_when_measure_is_defined_on_leaf.

@Test
public void ignore_measure_defined_on_project_when_measure_is_defined_on_leaf() {
    ReportComponent root = builder(PROJECT, ROOT_REF).addChildren(builder(Component.Type.FILE, FILE_1_REF).build()).build();
    treeRootHolder.setRoot(root);
    measureRepository.addRawMeasure(ROOT_REF, LINES_KEY, newMeasureBuilder().create(10));
    measureRepository.addRawMeasure(FILE_1_REF, LINES_KEY, newMeasureBuilder().create(2));
    new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(root);
    assertAddedRawMeasure(ROOT_REF, 2);
    assertAddedRawMeasure(FILE_1_REF, 2);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 45 with ReportComponent

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

the class ReportFormulaExecutorComponentVisitorTest method fail_when_trying_to_compute_file_measure_already_existing_in_report.

@Test
public void fail_when_trying_to_compute_file_measure_already_existing_in_report() {
    ReportComponent root = builder(PROJECT, ROOT_REF).addChildren(builder(Component.Type.FILE, FILE_1_REF).build()).build();
    treeRootHolder.setRoot(root);
    measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(2));
    // expectedException.expectCause(
    // hasType(UnsupportedOperationException.class)
    // .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY))
    // );
    assertThatThrownBy(() -> new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(root)).hasCause(new UnsupportedOperationException(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY)));
}
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