Search in sources :

Example 51 with Component

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

the class ReportComputeMeasureVariationsStepTest method set_variation.

@Test
public void set_variation() {
    // Project
    SnapshotDto period1Snapshot = newAnalysis(project);
    dbClient.snapshotDao().insert(session, period1Snapshot);
    dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1Snapshot.getUuid(), 60d));
    // Directory
    ComponentDto directoryDto = ComponentTesting.newDirectory(project, "dir");
    dbClient.componentDao().insert(session, directoryDto);
    dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
    session.commit();
    periodsHolder.setPeriod(newPeriod(period1Snapshot));
    Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
    treeRootHolder.setRoot(project);
    addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(80, null));
    addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(20, null));
    underTest.execute();
    assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
    assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 52 with Component

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

the class ReportPersistAnalysisStepTest method only_persist_snapshots_with_leak_period_on_project_and_module.

@Test
public void only_persist_snapshots_with_leak_period_on_project_and_module() {
    periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1"));
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
    dbClient.componentDao().insert(dbTester.getSession(), projectDto);
    SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto);
    dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot);
    ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module");
    dbClient.componentDao().insert(dbTester.getSession(), moduleDto);
    ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir");
    dbClient.componentDao().insert(dbTester.getSession(), directoryDto);
    ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java");
    dbClient.componentDao().insert(dbTester.getSession(), fileDto);
    dbTester.getSession().commit();
    Component file = ReportComponent.builder(Component.Type.FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
    Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
    Component module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_KEY").addChildren(directory).build();
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(module).build();
    treeRootHolder.setRoot(project);
    dbIdsRepository.setComponentId(project, projectDto.getId());
    dbIdsRepository.setComponentId(module, moduleDto.getId());
    dbIdsRepository.setComponentId(directory, directoryDto.getId());
    dbIdsRepository.setComponentId(file, fileDto.getId());
    underTest.execute();
    SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 53 with Component

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

the class ReportPersistAnalysisStepTest method persist_snapshots_with_leak_period.

@Test
public void persist_snapshots_with_leak_period() {
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
    dbClient.componentDao().insert(dbTester.getSession(), projectDto);
    SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime());
    dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
    dbTester.getSession().commit();
    periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_DATE, "2015-01-01", analysisDate, "u1"));
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
    treeRootHolder.setRoot(project);
    dbIdsRepository.setComponentId(project, projectDto.getId());
    underTest.execute();
    SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(projectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_DATE);
    assertThat(projectSnapshot.getPeriodDate()).isEqualTo(analysisDate);
    assertThat(projectSnapshot.getPeriodModeParameter()).isNotNull();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 54 with Component

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

the class ReportPersistAnalysisStepTest method set_no_period_on_snapshots_when_no_period.

@Test
public void set_no_period_on_snapshots_when_no_period() {
    ComponentDto projectDto = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
    dbClient.componentDao().insert(dbTester.getSession(), projectDto);
    SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto);
    dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
    dbTester.getSession().commit();
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
    treeRootHolder.setRoot(project);
    dbIdsRepository.setComponentId(project, projectDto.getId());
    underTest.execute();
    SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(projectSnapshot.getPeriodMode()).isNull();
    assertThat(projectSnapshot.getPeriodDate()).isNull();
    assertThat(projectSnapshot.getPeriodModeParameter()).isNull();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 55 with Component

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

the class DuplicationRepositoryRule method addDuplication.

public DuplicationRepositoryRule addDuplication(int fileRef, TextBlock original, int otherFileRef, TextBlock duplicate) {
    ensureComponentProviderInitialized();
    Component component = componentProvider.getByRef(fileRef);
    checkArgument(!componentRefsWithInProjectDuplications.containsEntry(component, original), "InProject duplications for file %s and original %s already set", fileRef, original);
    checkArgument(!componentRefsWithInnerDuplications.containsEntry(component, original), "Inner duplications for file %s and original %s already set. Use add(int, Duplication) instead", fileRef, original);
    componentRefsWithInProjectDuplications.put(component, original);
    delegate.add(component, new Duplication(original, Arrays.<Duplicate>asList(new InProjectDuplicate(componentProvider.getByRef(otherFileRef), duplicate))));
    return this;
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Aggregations

Component (org.sonar.server.computation.task.projectanalysis.component.Component)55 Test (org.junit.Test)33 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)24 ViewsComponent (org.sonar.server.computation.task.projectanalysis.component.ViewsComponent)15 ComponentDto (org.sonar.db.component.ComponentDto)12 SnapshotDto (org.sonar.db.component.SnapshotDto)10 DbSession (org.sonar.db.DbSession)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 OrganizationDto (org.sonar.db.organization.OrganizationDto)5 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 Period (org.sonar.server.computation.task.projectanalysis.period.Period)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)2 TypeAwareVisitorAdapter (org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter)2 InProjectDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InProjectDuplicate)2 InnerDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate)2 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1