Search in sources :

Example 16 with TestComputationStepContext

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();
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 17 with TestComputationStepContext

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));
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 18 with TestComputationStepContext

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();
}
Also used : Arrays(java.util.Arrays) DbFileSources(org.sonar.db.protobuf.DbFileSources) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) DbSession(org.sonar.db.DbSession) Uuids(org.sonar.core.util.Uuids) ComputationStep(org.sonar.ce.task.step.ComputationStep) LineHashVersion(org.sonar.db.source.LineHashVersion) Before(org.junit.Before) Component(org.sonar.ce.task.projectanalysis.component.Component) DbTester(org.sonar.db.DbTester) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) System2(org.sonar.api.utils.System2) FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 19 with TestComputationStepContext

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();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) DbFileSources(org.sonar.db.protobuf.DbFileSources) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 20 with TestComputationStepContext

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();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Aggregations

TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)458 Test (org.junit.Test)431 ComponentDto (org.sonar.db.component.ComponentDto)91 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)38 Component (org.sonar.ce.task.projectanalysis.component.Component)38 SnapshotDto (org.sonar.db.component.SnapshotDto)31 Date (java.util.Date)30 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)28 ComputationStep (org.sonar.ce.task.step.ComputationStep)24 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)17 FileSourceDto (org.sonar.db.source.FileSourceDto)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Project (org.sonar.server.project.Project)14 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)13 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)13 Notification (org.sonar.api.notifications.Notification)12 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)11 IssueDto (org.sonar.db.issue.IssueDto)11 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)11