Search in sources :

Example 76 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerTest method indexOnStartup_indexes_all_projects.

@Test
public void indexOnStartup_indexes_all_projects() {
    SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto());
    SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto());
    SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto());
    underTest.indexOnStartup(emptySet());
    assertThatIndexContainsOnly(project1, project2, project3);
    assertThatQualifierIs("TRK", project1, project2, project3);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Test(org.junit.Test)

Example 77 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class AsyncIssueIndexingImplTest method insertSnapshot.

private SnapshotDto insertSnapshot(String analysisUuid, String projectUuid, long createdAt) {
    SnapshotDto snapshot = new SnapshotDto().setUuid(analysisUuid).setComponentUuid(projectUuid).setStatus(STATUS_PROCESSED).setCreatedAt(createdAt).setLast(true);
    dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), snapshot);
    dbTester.commit();
    return snapshot;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 78 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class WebhookQGChangeEventListener method buildWebHookPayload.

private WebhookPayload buildWebHookPayload(DbSession dbSession, QGChangeEvent event, @Nullable EvaluatedQualityGate evaluatedQualityGate) {
    ProjectDto project = event.getProject();
    BranchDto branch = event.getBranch();
    SnapshotDto analysis = event.getAnalysis();
    Map<String, String> analysisProperties = dbClient.analysisPropertiesDao().selectByAnalysisUuid(dbSession, analysis.getUuid()).stream().collect(Collectors.toMap(AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue));
    ProjectAnalysis projectAnalysis = new ProjectAnalysis(new Project(project.getUuid(), project.getKey(), project.getName()), null, new Analysis(analysis.getUuid(), analysis.getCreatedAt(), analysis.getRevision()), new Branch(branch.isMain(), branch.getKey(), Type.valueOf(branch.getBranchType().name())), evaluatedQualityGate, null, analysisProperties);
    return webhookPayloadFactory.create(projectAnalysis);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 79 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method application_search_project_issues_on_leak.

@Test
public void application_search_project_issues_on_leak() {
    Date now = new Date();
    when(clock.millis()).thenReturn(now.getTime());
    ComponentDto project1 = db.components().insertPublicProject();
    SnapshotDto analysis1 = db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
    ComponentDto project2 = db.components().insertPublicProject();
    db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
    ComponentDto project3 = db.components().insertPublicProject();
    ComponentDto project4 = db.components().insertPublicProject();
    SnapshotDto analysis2 = db.components().insertSnapshot(project4, s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
    ComponentDto application = db.components().insertPublicApplication();
    db.components().insertComponents(newProjectCopy("PC1", project1, application));
    db.components().insertComponents(newProjectCopy("PC2", project2, application));
    db.components().insertComponents(newProjectCopy("PC3", project3, application));
    db.components().insertComponents(newProjectCopy("PC4", project4, application));
    userSession.registerApplication(application, project1, project2, project3, project4);
    IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid())).setSinceLeakPeriod(true));
    assertThat(result.createdAfterByProjectUuids()).hasSize(1);
    assertThat(result.createdAfterByProjectUuids().entrySet()).extracting(Map.Entry::getKey, e -> e.getValue().date(), e -> e.getValue().inclusive()).containsOnly(tuple(project1.uuid(), new Date(analysis1.getPeriodDate()), false));
    assertThat(result.newCodeOnReferenceByProjectUuids()).hasSize(1);
    assertThat(result.newCodeOnReferenceByProjectUuids()).containsOnly(project4.uuid());
    assertThat(result.viewUuids()).containsExactlyInAnyOrder(application.uuid());
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RuleDbTester(org.sonar.db.rule.RuleDbTester) RuleTesting.newRule(org.sonar.db.rule.RuleTesting.newRule) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) DateUtils.addDays(org.sonar.api.utils.DateUtils.addDays) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) APP(org.sonar.api.resources.Qualifiers.APP) REFERENCE_BRANCH(org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ZoneId(java.time.ZoneId) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTesting.newSubPortfolio(org.sonar.db.component.ComponentTesting.newSubPortfolio) Rule(org.junit.Rule) Qualifiers(org.sonar.api.resources.Qualifiers) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) RuleKey(org.sonar.api.rule.RuleKey) Clock(java.time.Clock) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) SearchRequest(org.sonar.server.issue.SearchRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Example 80 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method in_new_code_period_start_date_is_exclusive.

@Test
public void in_new_code_period_start_date_is_exclusive() {
    long newCodePeriodStart = addDays(new Date(), -14).getTime();
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodDate(newCodePeriodStart));
    SearchRequest request = new SearchRequest().setComponentUuids(Collections.singletonList(file.uuid())).setOnComponentOnly(true).setInNewCodePeriod(true);
    IssueQuery query = underTest.create(request);
    assertThat(query.componentUuids()).containsOnly(file.uuid());
    assertThat(query.createdAfter().date()).isEqualTo(new Date(newCodePeriodStart));
    assertThat(query.createdAfter().inclusive()).isFalse();
    assertThat(query.newCodeOnReference()).isNull();
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SnapshotDto (org.sonar.db.component.SnapshotDto)326 Test (org.junit.Test)257 ComponentDto (org.sonar.db.component.ComponentDto)219 MetricDto (org.sonar.db.metric.MetricDto)54 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 EventDto (org.sonar.db.event.EventDto)30 ProjectDto (org.sonar.db.project.ProjectDto)27 DbSession (org.sonar.db.DbSession)26 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)21 BranchDto (org.sonar.db.component.BranchDto)20 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)20 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 DbClient (org.sonar.db.DbClient)14 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 List (java.util.List)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 UserRole (org.sonar.api.web.UserRole)13 DbTester (org.sonar.db.DbTester)13