Search in sources :

Example 11 with Component

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

the class FileMoveDetectionStepTest method execute_detects_several_moves.

@Test
public void execute_detects_several_moves() {
    // testing:
    // - file1 renamed to file3
    // - file2 deleted
    // - file4 untouched
    // - file5 renamed to file6 with a small change
    analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
    Component file4 = fileComponent(5);
    Component file5 = fileComponent(6);
    Component file6 = fileComponent(7);
    ComponentDto[] dtos = mockComponents(FILE_1.getKey(), FILE_2.getKey(), file4.getKey(), file5.getKey());
    mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
    mockContentOfFileInDb(FILE_2.getKey(), LESS_CONTENT1);
    mockContentOfFileInDb(file4.getKey(), new String[] { "e", "f", "g", "h", "i" });
    mockContentOfFileInDb(file5.getKey(), CONTENT2);
    setFilesInReport(FILE_3, file4, file6);
    setFileContentInReport(FILE_3_REF, CONTENT1);
    setFileContentInReport(file4.getReportAttributes().getRef(), new String[] { "a", "b" });
    setFileContentInReport(file6.getReportAttributes().getRef(), LESS_CONTENT2);
    underTest.execute();
    assertThat(movedFilesRepository.getComponentsWithOriginal()).containsOnly(FILE_3, file6);
    MovedFilesRepository.OriginalFile originalFile2 = movedFilesRepository.getOriginalFile(FILE_3).get();
    assertThat(originalFile2.getId()).isEqualTo(dtos[0].getId());
    assertThat(originalFile2.getKey()).isEqualTo(dtos[0].getKey());
    assertThat(originalFile2.getUuid()).isEqualTo(dtos[0].uuid());
    MovedFilesRepository.OriginalFile originalFile5 = movedFilesRepository.getOriginalFile(file6).get();
    assertThat(originalFile5.getId()).isEqualTo(dtos[3].getId());
    assertThat(originalFile5.getKey()).isEqualTo(dtos[3].getKey());
    assertThat(originalFile5.getUuid()).isEqualTo(dtos[3].uuid());
}
Also used : 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 12 with Component

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

the class MutableMovedFilesRepositoryImplTest method setOriginalFile_throws_IAE_when_type_is_no_FILE.

@Test
public void setOriginalFile_throws_IAE_when_type_is_no_FILE() {
    for (Component component : COMPONENTS_BUT_FILE) {
        try {
            underTest.setOriginalFile(component, SOME_ORIGINAL_FILE);
            fail("should have raised a NPE");
        } catch (IllegalArgumentException e) {
            assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("file must be of type FILE");
        }
    }
}
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 13 with Component

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

the class MutableMovedFilesRepositoryImplTest method getOriginalFile_returns_absent_for_any_type_of_Component_but_file_when_non_empty.

@Test
public void getOriginalFile_returns_absent_for_any_type_of_Component_but_file_when_non_empty() {
    underTest.setOriginalFile(SOME_FILE, SOME_ORIGINAL_FILE);
    for (Component component : COMPONENTS_BUT_FILE) {
        assertThat(underTest.getOriginalFile(component)).isAbsent();
    }
    assertThat(underTest.getOriginalFile(SOME_FILE)).contains(SOME_ORIGINAL_FILE);
}
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 14 with Component

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

the class DuplicationRepositoryImplTest method mockComponentGetType.

private Component mockComponentGetType(Component.Type type) {
    Component component = mock(Component.class);
    when(component.getType()).thenReturn(type);
    return component;
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent)

Example 15 with Component

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

the class DuplicationRepositoryImplTest method addDuplication_inner_throws_IAE_if_file_type_is_not_FILE.

@Test
@UseDataProvider("allComponentTypesButFile")
public void addDuplication_inner_throws_IAE_if_file_type_is_not_FILE(Component.Type type) {
    expectFileTypeIAE();
    Component component = mockComponentGetType(type);
    underTest.add(component, SOME_DUPLICATION);
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

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