use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.
the class ComputeQProfileMeasureStepTest method nothing_to_add_when_no_files.
@Test
public void nothing_to_add_when_no_files() {
ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).build();
treeRootHolder.setRoot(project);
underTest.execute(new TestComputationStepContext());
assertThat(measureRepository.getAddedRawMeasures(PROJECT_REF)).isEmpty();
}
use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.
the class ComputeQProfileMeasureStepTest method add_quality_profile_measure_on_project.
@Test
public void add_quality_profile_measure_on_project() {
treeRootHolder.setRoot(MULTI_MODULE_PROJECT);
QualityProfile qpJava = createQProfile(QP_NAME_1, LANGUAGE_KEY_1);
QualityProfile qpPhp = createQProfile(QP_NAME_2, LANGUAGE_KEY_2);
analysisMetadataHolder.setQProfilesByLanguage(ImmutableMap.of(LANGUAGE_KEY_1, qpJava, LANGUAGE_KEY_2, qpPhp));
underTest.execute(new TestComputationStepContext());
assertThat(measureRepository.getAddedRawMeasures(PROJECT_REF).get(QUALITY_PROFILES_KEY)).extracting("data").isEqualTo(toJson(qpJava, qpPhp));
}
use of org.sonar.ce.task.step.TestComputationStepContext 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() {
dbClient.fileSourceDao().insert(dbTester.getSession(), createDto(dto -> dto.setSrcHash(null)));
dbTester.getSession().commit();
DbFileSources.Data sourceData = DbFileSources.Data.newBuilder().build();
setComputedData(sourceData, Collections.singletonList("lineHash"), "newSourceHash", null);
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(PAST);
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
assertThat(fileSourceDto.getSrcHash()).isEqualTo("newSourceHash");
verify(fileSourceDataWarnings).commitWarnings();
}
use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.
the class PersistFileSourcesStepTest method persist_sources.
@Test
public void persist_sources() {
List<String> lineHashes = Arrays.asList("137f72c3708c6bd0de00a0e5a69c699b", "e6251bcf1a7dc3ba5e7933e325bbe605");
String sourceHash = "ee5a58024a155466b43bc559d953e018";
DbFileSources.Data fileSourceData = DbFileSources.Data.newBuilder().addAllLines(Arrays.asList(DbFileSources.Line.newBuilder().setSource("line1").setLine(1).build(), DbFileSources.Line.newBuilder().setSource("line2").setLine(2).build())).build();
when(fileSourceDataComputer.compute(fileComponent().build(), fileSourceDataWarnings)).thenReturn(new FileSourceDataComputer.Data(fileSourceData, lineHashes, sourceHash, null));
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getProjectUuid()).isEqualTo(PROJECT_UUID);
assertThat(fileSourceDto.getFileUuid()).isEqualTo(FILE1_UUID);
assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
assertThat(fileSourceDto.getDataHash()).isNotEmpty();
assertThat(fileSourceDto.getLineHashesVersion()).isEqualTo(LineHashVersion.WITHOUT_SIGNIFICANT_CODE.getDbValue());
assertThat(fileSourceDto.getLineHashes()).isNotEmpty();
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(NOW);
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW);
DbFileSources.Data data = fileSourceDto.getSourceData();
assertThat(data.getLinesCount()).isEqualTo(2);
assertThat(data.getLines(0).getLine()).isOne();
assertThat(data.getLines(0).getSource()).isEqualTo("line1");
assertThat(data.getLines(1).getLine()).isEqualTo(2);
assertThat(data.getLines(1).getSource()).isEqualTo("line2");
verify(fileSourceDataWarnings).commitWarnings();
}
use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.
the class PersistFileSourcesStepTest method not_save_revision.
@Test
public void not_save_revision() {
setComputedData(DbFileSources.Data.newBuilder().build());
underTest.execute(new TestComputationStepContext());
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
assertThat(fileSourceDto.getRevision()).isNull();
verify(fileSourceDataWarnings).commitWarnings();
}
Aggregations