Search in sources :

Example 1 with Component

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

the class TrackerReferenceBranchInputFactoryTest 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.create(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 2 with Component

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

the class TrackerReferenceBranchInputFactoryTest method gets_issues_and_hashes_in_matching_component.

@Test
public void gets_issues_and_hashes_in_matching_component() {
    DefaultIssue issue1 = new DefaultIssue();
    when(referenceBranchComponentUuids.getComponentUuid(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, 3);
    Component component = mock(Component.class);
    when(component.getDbKey()).thenReturn(COMPONENT_KEY);
    when(component.getType()).thenReturn(Component.Type.FILE);
    Input<DefaultIssue> input = underTest.create(component);
    assertThat(input.getIssues()).containsOnly(issue1);
    assertThat(input.getLineHashSequence().length()).isEqualTo(3);
}
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 3 with Component

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

the class TrackerTargetBranchInputFactoryTest method get_issues_without_line_hashes.

@Test
public void get_issues_without_line_hashes() {
    DefaultIssue issue1 = new DefaultIssue();
    when(targetBranchComponentUuids.getTargetBranchComponentUuid(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.createForTargetBranch(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 4 with Component

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

the class TrackerTargetBranchInputFactoryTest method gets_issues_and_hashes_in_matching_component.

@Test
public void gets_issues_and_hashes_in_matching_component() {
    DefaultIssue issue1 = new DefaultIssue();
    when(targetBranchComponentUuids.getTargetBranchComponentUuid(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, 3);
    Component component = mock(Component.class);
    when(component.getDbKey()).thenReturn(COMPONENT_KEY);
    when(component.getType()).thenReturn(Component.Type.FILE);
    Input<DefaultIssue> input = underTest.createForTargetBranch(component);
    assertThat(input.getIssues()).containsOnly(issue1);
    assertThat(input.getLineHashSequence().length()).isEqualTo(3);
}
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 5 with Component

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

the class NotificationFactory method getProject.

private Project getProject() {
    Component project = treeRootHolder.getRoot();
    Branch branch = analysisMetadataHolder.getBranch();
    Project.Builder builder = new Project.Builder(project.getUuid()).setKey(project.getKey()).setProjectName(project.getName());
    if (branch.getType() != PULL_REQUEST && !branch.isMain()) {
        builder.setBranchName(branch.getName());
    }
    return builder.build();
}
Also used : Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) 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