Search in sources :

Example 6 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistTestsStepTest method aggregate_coverage_details.

@Test
public void aggregate_coverage_details() {
    reportReader.putTests(TEST_FILE_REF_1, Arrays.asList(newTest(1)));
    reportReader.putCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 1, 3), newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 2, 4)));
    underTest.execute();
    FileSourceDto dto = dbClient.fileSourceDao().selectTest(db.getSession(), TEST_FILE_UUID_1);
    List<Integer> coveredLines = dto.getTestData().get(0).getCoveredFile(0).getCoveredLineList();
    assertThat(coveredLines).containsOnly(1, 2, 3, 4);
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 7 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistTestsStepTest method insert_several_tests_in_a_report.

@Test
public void insert_several_tests_in_a_report() {
    List<ScannerReport.Test> batchTests = Arrays.asList(newTest(1), newTest(2));
    reportReader.putTests(TEST_FILE_REF_1, batchTests);
    List<CoverageDetail> coverageDetails = Arrays.asList(newCoverageDetail(1, MAIN_FILE_REF_1));
    reportReader.putCoverageDetails(TEST_FILE_REF_1, coverageDetails);
    underTest.execute();
    assertThat(db.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto dto = dbClient.fileSourceDao().selectTest(db.getSession(), TEST_FILE_UUID_1);
    assertThat(dto.getCreatedAt()).isEqualTo(now);
    assertThat(dto.getUpdatedAt()).isEqualTo(now);
    assertThat(dto.getProjectUuid()).isEqualTo(PROJECT_UUID);
    assertThat(dto.getFileUuid()).isEqualTo(TEST_FILE_UUID_1);
    assertThat(dto.getTestData()).hasSize(2);
    assertThat(dto.getTestData()).extracting("name", "coveredFileCount").containsOnly(tuple("name#1", 1), tuple("name#2", 0));
    assertThat(log.logs()).isEmpty();
}
Also used : CoverageDetail(org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail) FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test) Test(org.junit.Test)

Example 8 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_symbols.

@Test
public void persist_symbols() {
    initBasicReport(3);
    reportReader.putSymbols(FILE_REF, newArrayList(ScannerReport.Symbol.newBuilder().setDeclaration(ScannerReport.TextRange.newBuilder().setStartLine(1).setEndLine(1).setStartOffset(2).setEndOffset(4).build()).addReference(ScannerReport.TextRange.newBuilder().setStartLine(3).setEndLine(3).setStartOffset(1).setEndOffset(3).build()).build()));
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesList()).hasSize(3);
    assertThat(data.getLines(0).getSymbols()).isEqualTo("2,4,1");
    assertThat(data.getLines(1).getSymbols()).isEmpty();
    assertThat(data.getLines(2).getSymbols()).isEqualTo("1,3,1");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) Test(org.junit.Test)

Example 9 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method clear_revision_when_no_ChangeSet.

@Test
public void clear_revision_when_no_ChangeSet() {
    // Existing sources
    long past = 150000L;
    dbClient.fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setDataType(Type.SOURCE).setSrcHash("137f72c3708c6bd0de00a0e5a69c699b").setLineHashes("137f72c3708c6bd0de00a0e5a69c699b").setDataHash("8e84c0d961cfe364e43833c4cc4ddef5").setSourceData(DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setLine(1).setSource("line").build()).build()).setCreatedAt(past).setUpdatedAt(past));
    dbTester.getSession().commit();
    initBasicReport(1);
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past);
    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
    assertThat(fileSourceDto.getRevision()).isNull();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 10 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_coverage.

@Test
public void persist_coverage() {
    initBasicReport(1);
    reportReader.putCoverage(FILE_REF, newArrayList(ScannerReport.LineCoverage.newBuilder().setLine(1).setConditions(10).setHits(true).setCoveredConditions(2).build()));
    underTest.execute();
    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE_UUID);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data.getLinesList()).hasSize(1);
    assertThat(data.getLines(0).getLineHits()).isEqualTo(1);
    assertThat(data.getLines(0).getConditions()).isEqualTo(10);
    assertThat(data.getLines(0).getCoveredConditions()).isEqualTo(2);
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) Test(org.junit.Test)

Aggregations

FileSourceDto (org.sonar.db.source.FileSourceDto)24 Test (org.junit.Test)19 DbFileSources (org.sonar.db.protobuf.DbFileSources)8 CoverageDetail (org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail)2 CheckForNull (javax.annotation.CheckForNull)1 Before (org.junit.Before)1 SourceLinesHashesComputer (org.sonar.core.hash.SourceLinesHashesComputer)1 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)1 Duplicate (org.sonar.server.computation.task.projectanalysis.duplication.Duplicate)1 Duplication (org.sonar.server.computation.task.projectanalysis.duplication.Duplication)1 InnerDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate)1 TextBlock (org.sonar.server.computation.task.projectanalysis.duplication.TextBlock)1 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)1