Search in sources :

Example 36 with Component

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

the class AddedFileRepositoryImplTest method register_fails_with_IAE_if_component_is_not_a_file.

@Test
@UseDataProvider("anyTypeButFile")
public void register_fails_with_IAE_if_component_is_not_a_file(Component.Type anyTypeButFile) {
    Component component = newComponent(anyTypeButFile);
    assertThatThrownBy(() -> underTest.register(component)).isInstanceOf(IllegalArgumentException.class).hasMessage("component must be a file");
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 37 with Component

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

the class TrackerSourceBranchInputFactoryTest method gets_nothing_when_there_is_no_matching_component.

@Test
public void gets_nothing_when_there_is_no_matching_component() {
    Component component = mock(Component.class);
    when(component.getDbKey()).thenReturn(COMPONENT_KEY);
    when(component.getType()).thenReturn(Component.Type.FILE);
    Input<DefaultIssue> input = underTest.createForSourceBranch(component);
    assertThat(input.getIssues()).isEmpty();
    assertThat(input.getLineHashSequence().length()).isZero();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 38 with Component

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

the class TrackerSourceBranchInputFactoryTest method get_issues_without_line_hashes.

@Test
public void get_issues_without_line_hashes() {
    DefaultIssue issue1 = new DefaultIssue();
    when(sourceBranchComponentUuids.getSourceBranchComponentUuid(COMPONENT_KEY)).thenReturn(COMPONENT_UUID);
    when(componentIssuesLoader.loadOpenIssuesWithChanges(COMPONENT_UUID)).thenReturn(Collections.singletonList(issue1));
    ComponentDto fileDto = ComponentTesting.newFileDto(ComponentTesting.newPublicProjectDto()).setUuid(COMPONENT_UUID);
    db.fileSources().insertFileSource(fileDto, 0);
    Component component = mock(Component.class);
    when(component.getDbKey()).thenReturn(COMPONENT_KEY);
    when(component.getType()).thenReturn(Component.Type.FILE);
    Input<DefaultIssue> input = underTest.createForSourceBranch(component);
    assertThat(input.getIssues()).containsOnly(issue1);
    assertThat(input.getLineHashSequence().length()).isZero();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 39 with Component

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

the class NewIssueClassifierTest method isNew_returns_false_for_issue_which_was_new_but_it_is_not_located_on_changed_lines_anymore.

@Test
public void isNew_returns_false_for_issue_which_was_new_but_it_is_not_located_on_changed_lines_anymore() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
    Component file = mock(Component.class);
    DefaultIssue issue = mock(DefaultIssue.class);
    when(file.getType()).thenReturn(Component.Type.FILE);
    when(file.getUuid()).thenReturn("fileUuid");
    when(newLinesRepository.getNewLines(file)).thenReturn(Optional.of(Set.of(2, 3)));
    when(issue.getLocations()).thenReturn(DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(10).setStartOffset(1).setEndLine(10).setEndOffset(2).build()).build());
    when(issue.isNewCodeReferenceIssue()).thenReturn(true);
    assertThat(newIssueClassifier.isNew(file, issue)).isFalse();
    assertThat(newIssueClassifier.isOnBranchUsingReferenceBranch()).isTrue();
    assertThat(newIssueClassifier.hasAtLeastOneLocationOnChangedLines(file, issue)).isFalse();
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period) DefaultIssue(org.sonar.core.issue.DefaultIssue) Component(org.sonar.ce.task.projectanalysis.component.Component) Test(org.junit.Test)

Example 40 with Component

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

the class FillComponentIssuesVisitorRule method setIssues.

public void setIssues(int componentRef, DefaultIssue... issues) {
    Component component = treeRootHolder.getComponentByRef(componentRef);
    checkArgument(component != null, String.format("Component '%s' does not exists in the report ", componentRef));
    this.issues.get(component).clear();
    this.issues.putAll(component, asList(issues));
}
Also used : Component(org.sonar.ce.task.projectanalysis.component.Component)

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