Search in sources :

Example 51 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class PersistFileSourcesStepTest method persist_highlighting.

@Test
public void persist_highlighting() {
    DbFileSources.Data dbData = DbFileSources.Data.newBuilder().addLines(DbFileSources.Line.newBuilder().setHighlighting("2,4,a").build()).build();
    setComputedData(dbData);
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable("file_sources")).isOne();
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID);
    DbFileSources.Data data = fileSourceDto.getSourceData();
    assertThat(data).isEqualTo(dbData);
    assertThat(data.getLinesList()).hasSize(1);
    assertThat(data.getLines(0).getHighlighting()).isEqualTo("2,4,a");
    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 52 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class ScmInfoDbLoaderTest method addFileSourceInDb.

private void addFileSourceInDb(@Nullable String author, @Nullable Long date, @Nullable String revision, String srcHash, String fileUuid) {
    DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
    DbFileSources.Line.Builder builder = fileDataBuilder.addLinesBuilder().setLine(1);
    if (author != null) {
        builder.setScmAuthor(author);
    }
    if (date != null) {
        builder.setScmDate(date);
    }
    if (revision != null) {
        builder.setScmRevision(revision);
    }
    dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), new FileSourceDto().setUuid(Uuids.createFast()).setLineHashes(Collections.singletonList("lineHash")).setFileUuid(fileUuid).setProjectUuid("PROJECT_UUID").setSourceData(fileDataBuilder.build()).setSrcHash(srcHash));
    dbTester.commit();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto)

Example 53 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class ExportLineHashesStepTest method createDto.

private FileSourceDto createDto(String fileUuid, String componentUuid, String hashes) {
    FileSourceDto fileSourceDto = new FileSourceDto().setUuid(Uuids.createFast()).setFileUuid(fileUuid).setProjectUuid(componentUuid);
    fileSourceDto.setRawLineHashes(hashes);
    return fileSourceDto;
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto)

Example 54 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class ExportLineHashesStepTest method execute_maps_ref_of_component_and_hashes_from_fileSources.

@Test
public void execute_maps_ref_of_component_and_hashes_from_fileSources() {
    int fileRef = 984615;
    componentRepository.register(fileRef, FILE_UUID, true);
    FileSourceDto dto = createDto(FILE_UUID, PROJECT_MASTER_UUID, "B");
    insertFileSource(dto);
    underTest.execute(new TestComputationStepContext());
    List<ProjectDump.LineHashes> messages = dumpWriter.getWrittenMessagesOf(DumpElement.LINES_HASHES);
    assertThat(messages).hasSize(1);
    ProjectDump.LineHashes lineHashes = messages.iterator().next();
    assertThat(lineHashes.getHashes()).isEqualTo(dto.getRawLineHashes());
    assertThat(lineHashes.getComponentRef()).isEqualTo(fileRef);
}
Also used : ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) FileSourceDto(org.sonar.db.source.FileSourceDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 55 with FileSourceDto

use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.

the class LinesActionTest method pull_request.

@Test
public void pull_request() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
    ComponentDto file = db.components().insertComponent(newFileDto(branch));
    db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto().setUuid(Uuids.createFast()).setProjectUuid(branch.uuid()).setFileUuid(file.uuid()).setSourceData(FileSourceTesting.newFakeData(3).build()));
    db.commit();
    userSession.logIn("login").addProjectPermission(UserRole.CODEVIEWER, project, file);
    tester.newRequest().setParam("key", file.getKey()).setParam("pullRequest", file.getPullRequest()).execute().assertJson(getClass(), "show_source.json");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

FileSourceDto (org.sonar.db.source.FileSourceDto)58 Test (org.junit.Test)46 DbFileSources (org.sonar.db.protobuf.DbFileSources)19 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Changeset (org.sonar.ce.task.projectanalysis.scm.Changeset)5 ComponentDto (org.sonar.db.component.ComponentDto)5 Before (org.junit.Before)3 DbSession (org.sonar.db.DbSession)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 DigestUtils (org.apache.commons.codec.digest.DigestUtils)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 Mockito (org.mockito.Mockito)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2