Search in sources :

Example 11 with ReportComponent

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

the class NewReliabilityAndSecurityRatingMeasuresVisitorTest method measures_created_for_project_are_all_A_when_they_have_no_FILE_child.

@Test
public void measures_created_for_project_are_all_A_when_they_have_no_FILE_child() {
    ReportComponent root = builder(PROJECT, 1).build();
    treeRootHolder.setRoot(root);
    underTest.visit(root);
    verifyAddedRawMeasureOnLeakPeriod(1, NEW_SECURITY_RATING_KEY, A);
    verifyAddedRawMeasureOnLeakPeriod(1, NEW_RELIABILITY_RATING_KEY, A);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 12 with ReportComponent

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

the class ComputeQProfileMeasureStepTest method nothing_to_add_when_no_files.

@Test
public void nothing_to_add_when_no_files() {
    ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).build();
    treeRootHolder.setRoot(project);
    underTest.execute(new TestComputationStepContext());
    assertThat(measureRepository.getAddedRawMeasures(PROJECT_REF)).isEmpty();
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 13 with ReportComponent

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

the class NewMaintainabilityMeasuresVisitorTest method file_has_0_new_debt_ratio_if_no_line_is_new.

@Test
public void file_has_0_new_debt_ratio_if_no_line_is_new() {
    ReportComponent file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(file).build());
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50));
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    setNewLines(file);
    underTest.visit(treeRootHolder.getRoot());
    assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0);
    assertNewDebtRatioValues(ROOT_REF, 0);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 14 with ReportComponent

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

the class NewMaintainabilityMeasuresVisitorTest method compute_new_maintainability_rating.

@Test
public void compute_new_maintainability_rating() {
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    ReportComponent file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(file).build()).build());
    Measure newDebtMeasure = createNewDebtMeasure(50);
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
    measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
    measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
    // 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(file, 3, 4);
    underTest.visit(treeRootHolder.getRoot());
    assertNewMaintainability(LANGUAGE_1_FILE_REF, D);
    assertNewMaintainability(111, D);
    assertNewMaintainability(ROOT_REF, D);
}
Also used : Measure(org.sonar.ce.task.projectanalysis.measure.Measure) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 15 with ReportComponent

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

the class ReliabilityAndSecurityRatingMeasuresVisitorTest method measures_created_for_project_are_all_A_when_they_have_no_FILE_child.

@Test
public void measures_created_for_project_are_all_A_when_they_have_no_FILE_child() {
    ReportComponent root = builder(PROJECT, 1).build();
    treeRootHolder.setRoot(root);
    underTest.visit(root);
    assertThat(measureRepository.getRawMeasures(root).entrySet().stream().map(e -> entryOf(e.getKey(), e.getValue()))).containsOnly(entryOf(RELIABILITY_RATING_KEY, createRatingMeasure(A)), entryOf(SECURITY_RATING_KEY, createRatingMeasure(A)));
}
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