Search in sources :

Example 31 with FileSourceDto

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

the class ScmActionTest method group_lines_by_commit.

@Test
public void group_lines_by_commit() {
    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
    // lines 1 and 2 are the same commit, but not 3 (different date)
    dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto().setUuid(Uuids.createFast()).setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setSourceData(DbFileSources.Data.newBuilder().addLines(newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).addLines(newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 2)).addLines(newSourceLine("julien", "456-789-101", DateUtils.parseDateTime("2015-03-27T12:34:56+0000"), 3)).addLines(newSourceLine("simon", "789-101-112", DateUtils.parseDateTime("2015-03-31T12:34:56+0000"), 4)).build()));
    dbSession.commit();
    tester.newRequest().setParam("key", FILE_KEY).setParam("commits_by_line", "false").execute().assertJson(getClass(), "group_lines_by_commit.json");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 32 with FileSourceDto

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

the class ScmActionTest method accept_negative_value_in_from_parameter.

@Test
public void accept_negative_value_in_from_parameter() {
    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
    dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto().setUuid(Uuids.createFast()).setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setSourceData(DbFileSources.Data.newBuilder().addLines(newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).addLines(newSourceLine("julien", "123-456-710", DateUtils.parseDateTime("2015-03-29T12:34:56+0000"), 2)).addLines(newSourceLine("julien", "456-789-101", DateUtils.parseDateTime("2015-03-27T12:34:56+0000"), 3)).addLines(newSourceLine("simon", "789-101-112", DateUtils.parseDateTime("2015-03-31T12:34:56+0000"), 4)).build()));
    dbSession.commit();
    tester.newRequest().setParam("key", FILE_KEY).setParam("from", "-2").setParam("to", "3").execute().assertJson(getClass(), "accept_negative_value_in_from_parameter.json");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 33 with FileSourceDto

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

the class ScmActionTest method not_group_lines_by_commit.

@Test
public void not_group_lines_by_commit() {
    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
    // lines 1 and 2 are the same commit, but not 3 (different date)
    dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto().setUuid(Uuids.createFast()).setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setSourceData(DbFileSources.Data.newBuilder().addLines(newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).addLines(newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 2)).addLines(newSourceLine("julien", "456-789-101", DateUtils.parseDateTime("2015-03-27T12:34:56+0000"), 3)).addLines(newSourceLine("simon", "789-101-112", DateUtils.parseDateTime("2015-03-31T12:34:56+0000"), 4)).build()));
    dbSession.commit();
    tester.newRequest().setParam("key", FILE_KEY).setParam("commits_by_line", "true").execute().assertJson(getClass(), "not_group_lines_by_commit.json");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 34 with FileSourceDto

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

the class ScmActionTest method show_scm.

@Test
public void show_scm() {
    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
    dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto().setUuid(Uuids.createFast()).setProjectUuid(PROJECT_UUID).setFileUuid(FILE_UUID).setSourceData(DbFileSources.Data.newBuilder().addLines(newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).build()));
    dbSession.commit();
    tester.newRequest().setParam("key", FILE_KEY).execute().assertJson(getClass(), "show_scm.json");
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Test(org.junit.Test)

Example 35 with FileSourceDto

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

the class SourceServiceTest method injectFakeLines.

@Before
public void injectFakeLines() {
    FileSourceDto dto = new FileSourceDto();
    dto.setFileUuid(FILE_UUID).setUuid(Uuids.createFast()).setProjectUuid("PROJECT_UUID");
    dto.setSourceData(FileSourceTesting.newFakeData(10).build());
    dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), dto);
    dbTester.commit();
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) Before(org.junit.Before)

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