Search in sources :

Example 41 with Component

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

the class ViewsComputeMeasureVariationsStepTest method do_nothing_when_no_period.

@Test
public void do_nothing_when_no_period() {
    Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).build();
    treeRootHolder.setRoot(view);
    periodsHolder.setPeriod(null);
    underTest.execute();
    assertThat(measureRepository.getRawMeasures(view).keys()).isEmpty();
}
Also used : ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 42 with Component

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

the class ViewsPersistAnalysisStepTest method persist_analysis.

@Test
public void persist_analysis() {
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setKey("KEY_VIEW"));
    save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW"));
    save(newProjectDto(organizationDto, "proj"));
    dbTester.getSession().commit();
    Component projectView = ViewsComponent.builder(PROJECT_VIEW, "KEY_PROJECT_COPY").setUuid("UUID_PROJECT_COPY").build();
    Component subView = ViewsComponent.builder(SUBVIEW, "KEY_SUBVIEW").setUuid("UUID_SUBVIEW").addChildren(projectView).build();
    Component view = ViewsComponent.builder(VIEW, "KEY_VIEW").setUuid("UUID_VIEW").addChildren(subView).build();
    treeRootHolder.setRoot(view);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
    SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid());
    assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
    assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid());
    assertThat(viewSnapshot.getVersion()).isNull();
    assertThat(viewSnapshot.getLast()).isFalse();
    assertThat(viewSnapshot.getStatus()).isEqualTo("U");
    assertThat(viewSnapshot.getCreatedAt()).isEqualTo(analysisDate);
    assertThat(viewSnapshot.getBuildDate()).isEqualTo(now);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 43 with Component

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

the class PersistMeasuresStepTest method setupReportComponents.

private void setupReportComponents() {
    Component project = ReportComponent.builder(PROJECT, ROOT_REF).setUuid("root-uuid").addChildren(ReportComponent.builder(MODULE, INTERMEDIATE_1_REF).setUuid("intermediate1-uuid").addChildren(ReportComponent.builder(DIRECTORY, INTERMEDIATE_2_REF).setUuid("intermediate2-uuid").addChildren(ReportComponent.builder(FILE, LEAF_REF).setUuid("leaf-uuid").build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    setupDbIds();
}
Also used : ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent)

Example 44 with Component

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

the class ReportComputeMeasureVariationsStepTest method set_variation_to_raw_value_on_new_component.

@Test
public void set_variation_to_raw_value_on_new_component() throws Exception {
    // Project
    SnapshotDto past1ProjectSnapshot = newAnalysis(project).setCreatedAt(1000_000_000L);
    SnapshotDto currentProjectSnapshot = newAnalysis(project).setCreatedAt(2000_000_000L);
    dbClient.snapshotDao().insert(session, past1ProjectSnapshot);
    dbClient.snapshotDao().insert(session, currentProjectSnapshot);
    dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, past1ProjectSnapshot.getUuid(), 60d));
    dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, currentProjectSnapshot.getUuid(), 60d));
    session.commit();
    periodsHolder.setPeriod(newPeriod(past1ProjectSnapshot));
    // Directory has just been added => no snapshot
    Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("DIRECTORY").build();
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
    treeRootHolder.setRoot(project);
    addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(90, null));
    addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(10, null));
    underTest.execute();
    assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(30d);
    // Variation should be the raw value
    assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 45 with Component

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

the class PersistEventsStepTest method keep_one_event_by_version.

@Test
public void keep_one_event_by_version() {
    dbTester.prepareDbUnit(getClass(), "keep_one_event_by_version.xml");
    Component project = builder(PROJECT, 1).setUuid("ABCD").setVersion("1.5-SNAPSHOT").addChildren(builder(MODULE, 2).setUuid("BCDE").addChildren(builder(DIRECTORY, 3).setUuid("Q").addChildren(builder(FILE, 4).setUuid("Z").build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    underTest.execute();
    dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", new String[] { "uuid" }, "events");
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

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