Search in sources :

Example 21 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_symbols.

@Test
public void persist_symbols() {
    DbFileSources.Data dbData = DbFileSources.Data.newBuilder().addAllLines(Arrays.asList(DbFileSources.Line.newBuilder().setSymbols("2,4,1").build(), DbFileSources.Line.newBuilder().build(), DbFileSources.Line.newBuilder().setSymbols("1,3,1").build())).build();
    setComputedData(dbData);
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
    assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData);
    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 22 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method not_update_sources_when_nothing_has_changed.

@Test
public void not_update_sources_when_nothing_has_changed() {
    dbClient.fileSourceDao().insert(dbTester.getSession(), createDto());
    dbTester.getSession().commit();
    Changeset changeset = Changeset.newChangesetBuilder().setDate(1L).setRevision("rev-1").build();
    setComputedData(DbFileSources.Data.newBuilder().build(), Collections.singletonList("lineHash"), "sourceHash", changeset);
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
    assertThat(fileSourceDto.getSrcHash()).isEqualTo("sourceHash");
    assertThat(fileSourceDto.getLineHashes()).isEqualTo(Collections.singletonList("lineHash"));
    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(PAST);
    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(PAST);
    verify(fileSourceDataWarnings).commitWarnings();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 23 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_scm.

@Test
public void persist_scm() {
    DbFileSources.Data dbData = DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setScmAuthor("john").setScmDate(123456789L).setScmRevision("rev-1").build()).build();
    setComputedData(dbData);
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
    assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData);
    assertThat(fileSourceDto.getRevision()).isNull();
    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 24 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method save_revision.

@Test
public void save_revision() {
    Changeset latest = Changeset.newChangesetBuilder().setDate(0L).setRevision("rev-1").build();
    setComputedData(DbFileSources.Data.newBuilder().build(), Collections.singletonList("lineHashes"), "srcHash", latest);
    underTest.execute(new TestComputationStepContext());
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
    assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1");
    verify(fileSourceDataWarnings).commitWarnings();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) BaseStepTest(org.sonar.ce.task.projectanalysis.step.BaseStepTest) Test(org.junit.Test)

Example 25 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PurgeDatastoresStepTest method verify_call_purge_method_of_the_purge_task.

private void verify_call_purge_method_of_the_purge_task(Component project) {
    treeRootHolder.setRoot(project);
    when(settingsRepository.getConfiguration()).thenReturn(new MapSettings().asConfig());
    underTest.execute(new TestComputationStepContext());
    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(projectCleaner).purge(any(), argumentCaptor.capture(), anyString(), any(), any());
    assertThat(argumentCaptor.getValue()).isEqualTo(PROJECT_UUID);
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext)

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