use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class SourceServiceTest method injectFakeLines.
@Before
public void injectFakeLines() throws IOException {
FileSourceDto dto = new FileSourceDto();
dto.setFileUuid(FILE_UUID).setProjectUuid("PROJECT_UUID");
dto.setSourceData(FileSourceTesting.newFakeData(10).build());
dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), dto);
dbTester.commit();
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistTestsStepTest method update_existing_test.
@Test
public void update_existing_test() {
// ARRANGE
dbClient.fileSourceDao().insert(db.getSession(), new FileSourceDto().setProjectUuid(PROJECT_UUID).setFileUuid(TEST_FILE_UUID_1).setTestData(Arrays.asList(DbFileSources.Test.newBuilder().setUuid("test-uuid-1").setName("name#1").setStatus(DbFileSources.Test.TestStatus.ERROR).setStacktrace("old-stacktrace#1").setMsg("old-message#1").setExecutionTimeMs(987_654_321L).build())).setCreatedAt(100_000).setUpdatedAt(100_000));
db.getSession().commit();
assertThat(dbClient.fileSourceDao().selectTest(db.getSession(), TEST_FILE_UUID_1)).isNotNull();
ScannerReport.Test newBatchTest = newTest(1);
reportReader.putTests(TEST_FILE_REF_1, Arrays.asList(newBatchTest));
CoverageDetail newCoverageDetail = newCoverageDetail(1, MAIN_FILE_REF_1);
reportReader.putCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetail));
// ACT
underTest.execute();
// ASSERT
FileSourceDto dto = dbClient.fileSourceDao().selectTest(db.getSession(), TEST_FILE_UUID_1);
assertThat(dto.getCreatedAt()).isEqualTo(100_000);
assertThat(dto.getUpdatedAt()).isEqualTo(now);
assertThat(dto.getTestData()).hasSize(1);
DbFileSources.Test test = dto.getTestData().get(0);
assertThat(test.getUuid()).isNotEqualTo("test-uuid-1");
assertThat(test.getName()).isEqualTo("name#1");
assertThat(test.getStatus()).isEqualTo(DbFileSources.Test.TestStatus.valueOf(newBatchTest.getStatus().name()));
assertThat(test.getMsg()).isEqualTo(newBatchTest.getMsg());
assertThat(test.getStacktrace()).isEqualTo(newBatchTest.getStacktrace());
assertThat(test.getExecutionTimeMs()).isEqualTo(newBatchTest.getDurationInMs());
assertThat(test.getCoveredFileCount()).isEqualTo(1);
assertThat(test.getCoveredFile(0).getCoveredLineList()).containsOnly(1, 2, 3);
assertThat(test.getCoveredFile(0).getFileUuid()).isEqualTo(MAIN_FILE_UUID_1);
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistTestsStepTest method insert_all_data_of_a_test.
@Test
public void insert_all_data_of_a_test() {
reportReader.putTests(TEST_FILE_REF_1, Arrays.asList(newTest(1)));
reportReader.putCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetail(1, MAIN_FILE_REF_1)));
underTest.execute();
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(1);
DbFileSources.Test test1 = dto.getTestData().get(0);
assertThat(test1.getUuid()).isNotEmpty();
assertThat(test1.getName()).isEqualTo("name#1");
assertThat(test1.getMsg()).isEqualTo("message#1");
assertThat(test1.getStacktrace()).isEqualTo("stacktrace#1");
assertThat(test1.getStatus()).isEqualTo(DbFileSources.Test.TestStatus.FAILURE);
assertThat(test1.getExecutionTimeMs()).isEqualTo(1_000);
assertThat(test1.getCoveredFileCount()).isEqualTo(1);
assertThat(test1.getCoveredFile(0).getCoveredLineList()).containsOnly(1, 2, 3);
assertThat(test1.getCoveredFile(0).getFileUuid()).isEqualTo(MAIN_FILE_UUID_1);
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistTestsStepTest method insert_tests_without_coverage_details.
@Test
public void insert_tests_without_coverage_details() {
List<ScannerReport.Test> batchTests = Arrays.asList(newTest(1));
reportReader.putTests(TEST_FILE_REF_1, batchTests);
underTest.execute();
FileSourceDto dto = dbClient.fileSourceDao().selectTest(db.getSession(), TEST_FILE_UUID_1);
assertThat(dto.getFileUuid()).isEqualTo(TEST_FILE_UUID_1);
List<DbFileSources.Test> tests = dto.getTestData();
assertThat(tests).hasSize(1);
assertThat(tests.get(0).getCoveredFileList()).isEmpty();
assertThat(tests.get(0).getMsg()).isEqualTo("message#1");
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class PersistFileSourcesStepTest method update_sources_when_src_hash_is_missing.
@Test
public void update_sources_when_src_hash_is_missing() {
// Existing sources
long past = 150000L;
dbClient.fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setDataType(Type.SOURCE).setLineHashes("137f72c3708c6bd0de00a0e5a69c699b").setDataHash("29f25900140c94db38035128cb6de6a2").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.getSrcHash()).isEqualTo("137f72c3708c6bd0de00a0e5a69c699b");
}
Aggregations