Search in sources :

Example 71 with Component

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

the class PersistMeasuresStepTest method prepareProject.

private void prepareProject() {
    // tree of components as defined by scanner report
    Component project = ReportComponent.builder(PROJECT, REF_1).setUuid("project-uuid").addChildren(ReportComponent.builder(DIRECTORY, REF_3).setUuid("dir-uuid").addChildren(ReportComponent.builder(FILE, REF_4).setUuid("file-uuid").build()).build()).build();
    treeRootHolder.setRoot(project);
    // components as persisted in db
    ComponentDto projectDto = insertComponent("project-key", "project-uuid");
    ComponentDto dirDto = insertComponent("dir-key", "dir-uuid");
    ComponentDto fileDto = insertComponent("file-key", "file-uuid");
    db.components().insertSnapshot(projectDto, s -> s.setUuid(ANALYSIS_UUID));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent)

Example 72 with Component

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

the class PersistMeasuresStepTest method preparePortfolio.

private void preparePortfolio() {
    // tree of components
    Component portfolio = ViewsComponent.builder(VIEW, REF_1).setUuid("view-uuid").addChildren(ViewsComponent.builder(SUBVIEW, REF_2).setUuid("subview-uuid").addChildren(ViewsComponent.builder(PROJECT_VIEW, REF_3).setUuid("project-uuid").build()).build()).build();
    treeRootHolder.setRoot(portfolio);
    // components as persisted in db
    ComponentDto viewDto = insertComponent("view-key", "view-uuid");
    ComponentDto subViewDto = insertComponent("subview-key", "subview-uuid");
    ComponentDto projectDto = insertComponent("project-key", "project-uuid");
    db.components().insertSnapshot(viewDto, s -> s.setUuid(ANALYSIS_UUID));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent)

Example 73 with Component

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

the class NewSizeMeasuresStepTest method setFirstTwoLinesAsNew.

private void setFirstTwoLinesAsNew(Component... components) {
    when(newLinesRepository.newLinesAvailable()).thenReturn(true);
    Set<Integer> newLines = new HashSet<>(Arrays.asList(1, 2));
    for (Component c : components) {
        when(newLinesRepository.getNewLines(c)).thenReturn(Optional.of(newLines));
    }
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) HashSet(java.util.HashSet)

Example 74 with Component

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

the class PersistComponentsStepTest method should_fail_if_project_is_not_stored_in_database_yet.

@Test
public void should_fail_if_project_is_not_stored_in_database_yet() {
    TreeRootHolder treeRootHolder = mock(TreeRootHolder.class);
    Component component = mock(Component.class);
    DbClient dbClient = mock(DbClient.class);
    ComponentDao componentDao = mock(ComponentDao.class);
    String projectKey = randomAlphabetic(20);
    doReturn(component).when(treeRootHolder).getRoot();
    doReturn(projectKey).when(component).getDbKey();
    doReturn(componentDao).when(dbClient).componentDao();
    doReturn(emptyList()).when(componentDao).selectAllComponentsFromProjectKey(any(DbSession.class), eq(projectKey));
    assertThatThrownBy(() -> {
        new PersistComponentsStep(dbClient, treeRootHolder, System2.INSTANCE, mock(MutableDisabledComponentsHolder.class), mock(AnalysisMetadataHolder.class), mock(BranchPersister.class), mock(ProjectPersister.class)).execute(new TestComputationStepContext());
    }).isInstanceOf(IllegalStateException.class).hasMessageContaining("The project '" + projectKey + "' is not stored in the database, during a project analysis");
}
Also used : DbSession(org.sonar.db.DbSession) DbClient(org.sonar.db.DbClient) Component(org.sonar.ce.task.projectanalysis.component.Component) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) ComponentDao(org.sonar.db.component.ComponentDao) Test(org.junit.Test)

Example 75 with Component

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

the class LoadDuplicationsFromReportStepTest method loads_never_consider_originals_from_batch_on_same_lines_as_the_equals.

@Test
public void loads_never_consider_originals_from_batch_on_same_lines_as_the_equals() {
    reportReader.putDuplications(FILE_2_REF, createDuplication(singleLineTextRange(LINE), createInnerDuplicate(LINE + 1), createInnerDuplicate(LINE + 2), createInProjectDuplicate(FILE_1_REF, LINE + 2)), createDuplication(singleLineTextRange(LINE), createInnerDuplicate(LINE + 2), createInnerDuplicate(LINE + 3), createInProjectDuplicate(FILE_1_REF, LINE + 2)));
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    Component file1Component = treeRootHolder.getComponentByRef(FILE_1_REF);
    assertThat(duplicationRepository.getDuplications(FILE_2_REF)).containsOnly(duplication(singleLineDetailedTextBlock(1, LINE), new InnerDuplicate(singleLineTextBlock(LINE + 1)), new InnerDuplicate(singleLineTextBlock(LINE + 2)), new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 2))), duplication(singleLineDetailedTextBlock(2, LINE), new InnerDuplicate(singleLineTextBlock(LINE + 2)), new InnerDuplicate(singleLineTextBlock(LINE + 3)), new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 2))));
    assertNbOfDuplications(context, 2);
}
Also used : InnerDuplicate(org.sonar.ce.task.projectanalysis.duplication.InnerDuplicate) InProjectDuplicate(org.sonar.ce.task.projectanalysis.duplication.InProjectDuplicate) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Aggregations

Component (org.sonar.ce.task.projectanalysis.component.Component)118 Test (org.junit.Test)82 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)47 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 ComponentDto (org.sonar.db.component.ComponentDto)25 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)14 DefaultIssue (org.sonar.core.issue.DefaultIssue)14 DbSession (org.sonar.db.DbSession)11 Period (org.sonar.ce.task.projectanalysis.period.Period)8 SnapshotDto (org.sonar.db.component.SnapshotDto)8 FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)6 DbClient (org.sonar.db.DbClient)6 List (java.util.List)5 ComputationStep (org.sonar.ce.task.step.ComputationStep)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 DepthTraversalTypeAwareCrawler (org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Map (java.util.Map)3