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));
}
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));
}
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));
}
}
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");
}
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);
}
Aggregations