Search in sources :

Example 16 with Component

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

the class ScmInfoRepositoryImplTest method return_empty_if_component_is_not_file.

@Test
public void return_empty_if_component_is_not_file() {
    Component c = mock(Component.class);
    when(c.getType()).thenReturn(Type.DIRECTORY);
    assertThat(underTest.getScmInfo(c)).isEmpty();
}
Also used : ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 17 with Component

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

the class DbLineHashVersionTest method should_cache_line_hash_version_from_db.

@Test
public void should_cache_line_hash_version_from_db() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
    db.fileSources().insertFileSource(file, dto -> dto.setLineHashesVersion(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue()));
    Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid(file.uuid()).build();
    assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
    assertThat(db.countRowsOfTable("file_sources")).isOne();
    db.executeUpdateSql("delete from file_sources");
    db.commit();
    assertThat(db.countRowsOfTable("file_sources")).isZero();
    // still true because it uses cache
    assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 18 with Component

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

the class DbLineHashVersionTest method hasLineHashWithSignificantCode_should_return_true_if_pr_reference_has_file_and_it_is_in_db.

@Test
public void hasLineHashWithSignificantCode_should_return_true_if_pr_reference_has_file_and_it_is_in_db() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
    db.fileSources().insertFileSource(file, dto -> dto.setLineHashesVersion(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue()));
    when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
    when(referenceBranchComponentUuids.getComponentUuid("key")).thenReturn(file.uuid());
    Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid("123").build();
    assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
    verify(analysisMetadataHolder).isPullRequest();
    verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 19 with Component

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

the class DbLineHashVersionTest method hasLineHashWithSignificantCode_should_return_false_if_pr_reference_doesnt_have_file.

@Test
public void hasLineHashWithSignificantCode_should_return_false_if_pr_reference_doesnt_have_file() {
    when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
    Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid("123").build();
    assertThat(underTest.hasLineHashesWithSignificantCode(component)).isFalse();
    verify(analysisMetadataHolder).isPullRequest();
    verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey());
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 20 with Component

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

the class FileSourceDataWarningsTest method addWarning_fails_with_NPE_if_readError_is_null.

@Test
public void addWarning_fails_with_NPE_if_readError_is_null() {
    Component component = mock(Component.class);
    assertThatThrownBy(() -> underTest.addWarning(component, null)).isInstanceOf(NullPointerException.class).hasMessage("readError can't be null");
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) 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