use of org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail 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();
}
use of org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail 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);
}
Aggregations