Search in sources :

Example 66 with SnapshotDto

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

the class EventDaoTest method update_name_and_description.

@Test
public void update_name_and_description() {
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto());
    dbTester.events().insertEvent(newEvent(analysis).setUuid("E1"));
    underTest.update(dbSession, "E1", "New Name", "New Description");
    EventDto result = dbClient.eventDao().selectByUuid(dbSession, "E1").get();
    assertThat(result.getName()).isEqualTo("New Name");
    assertThat(result.getDescription()).isEqualTo("New Description");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Test(org.junit.Test)

Example 67 with SnapshotDto

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

the class EventDaoTest method select_by_component_uuid.

@Test
public void select_by_component_uuid() {
    ComponentDto project1 = ComponentTesting.newPrivateProjectDto();
    ComponentDto project2 = ComponentTesting.newPrivateProjectDto();
    SnapshotDto analysis1 = dbTester.components().insertProjectAndSnapshot(project1);
    SnapshotDto analysis2 = dbTester.components().insertProjectAndSnapshot(project2);
    String[] eventUuids1 = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> dbTester.events().insertEvent(newEvent(analysis1).setUuid("1_" + i))).map(EventDto::getUuid).toArray(String[]::new);
    EventDto event2 = dbTester.events().insertEvent(new EventDto().setAnalysisUuid(analysis2.getUuid()).setComponentUuid(analysis2.getComponentUuid()).setName("name_2_").setUuid("2_").setCategory("cat_2_").setDescription("desc_2_").setData("dat_2_").setDate(2_000L).setCreatedAt(4_000L));
    assertThat(underTest.selectByComponentUuid(dbTester.getSession(), project1.uuid())).extracting(EventDto::getUuid).containsOnly(eventUuids1);
    List<EventDto> events2 = underTest.selectByComponentUuid(dbTester.getSession(), project2.uuid());
    assertThat(events2).extracting(EventDto::getUuid).containsOnly(event2.getUuid());
    assertThat(underTest.selectByComponentUuid(dbTester.getSession(), "does not exist")).isEmpty();
    EventDto dto = events2.get(0);
    assertThat(dto.getUuid()).isEqualTo(event2.getUuid());
    assertThat(dto.getAnalysisUuid()).isEqualTo(event2.getAnalysisUuid());
    assertThat(dto.getComponentUuid()).isEqualTo(event2.getComponentUuid());
    assertThat(dto.getName()).isEqualTo(event2.getName());
    assertThat(dto.getCategory()).isEqualTo(event2.getCategory());
    assertThat(dto.getDescription()).isEqualTo(event2.getDescription());
    assertThat(dto.getData()).isEqualTo(event2.getData());
    assertThat(dto.getDate()).isEqualTo(event2.getDate());
    assertThat(dto.getCreatedAt()).isEqualTo(event2.getCreatedAt());
}
Also used : Random(java.util.Random) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 68 with SnapshotDto

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

the class EventDaoTest method select_by_analysis_uuid.

@Test
public void select_by_analysis_uuid() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto();
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    SnapshotDto otherAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
    dbTester.commit();
    dbTester.events().insertEvent(newEvent(analysis).setUuid("A1"));
    dbTester.events().insertEvent(newEvent(otherAnalysis).setUuid("O1"));
    dbTester.events().insertEvent(newEvent(analysis).setUuid("A2"));
    dbTester.events().insertEvent(newEvent(otherAnalysis).setUuid("O2"));
    dbTester.events().insertEvent(newEvent(analysis).setUuid("A3"));
    dbTester.events().insertEvent(newEvent(otherAnalysis).setUuid("O3"));
    List<EventDto> result = underTest.selectByAnalysisUuid(dbSession, analysis.getUuid());
    assertThat(result).hasSize(3);
    assertThat(result).extracting(EventDto::getUuid).containsOnly("A1", "A2", "A3");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 69 with SnapshotDto

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

the class PurgeDaoTest method shouldDeleteAnalyses.

@Test
public void shouldDeleteAnalyses() {
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto analysis1 = db.components().insertSnapshot(project);
    SnapshotDto analysis2 = db.components().insertSnapshot(project);
    SnapshotDto analysis3 = db.components().insertSnapshot(project);
    ComponentDto otherProject = db.components().insertPrivateProject();
    SnapshotDto otherAnalysis1 = db.components().insertSnapshot(otherProject);
    underTest.deleteAnalyses(dbSession, new PurgeProfiler(), singletonList(analysis1.getUuid()));
    assertThat(uuidsIn("snapshots")).containsOnly(analysis2.getUuid(), analysis3.getUuid(), otherAnalysis1.getUuid());
    underTest.deleteAnalyses(dbSession, new PurgeProfiler(), asList(analysis1.getUuid(), analysis3.getUuid(), otherAnalysis1.getUuid()));
    assertThat(uuidsIn("snapshots")).containsOnly(analysis2.getUuid());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 70 with SnapshotDto

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

the class PurgeDaoTest method delete_application_branch.

@Test
public void delete_application_branch() {
    MetricDto metric = db.measures().insertMetric();
    ComponentDto project = db.components().insertPrivateProject();
    BranchDto projectBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid()).get();
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto app = db.components().insertPrivateApplication();
    ComponentDto appBranch = db.components().insertProjectBranch(app);
    ComponentDto otherApp = db.components().insertPrivateApplication();
    ComponentDto otherAppBranch = db.components().insertProjectBranch(otherApp);
    SnapshotDto appAnalysis = db.components().insertSnapshot(app);
    SnapshotDto appBranchAnalysis = db.components().insertSnapshot(appBranch);
    SnapshotDto otherAppAnalysis = db.components().insertSnapshot(otherApp);
    SnapshotDto otherAppBranchAnalysis = db.components().insertSnapshot(otherAppBranch);
    MeasureDto appMeasure = db.measures().insertMeasure(app, appAnalysis, metric);
    MeasureDto appBranchMeasure = db.measures().insertMeasure(appBranch, appBranchAnalysis, metric);
    MeasureDto otherAppMeasure = db.measures().insertMeasure(otherApp, otherAppAnalysis, metric);
    MeasureDto otherAppBranchMeasure = db.measures().insertMeasure(otherAppBranch, otherAppBranchAnalysis, metric);
    db.components().addApplicationProject(app, project);
    db.components().addApplicationProject(otherApp, project);
    db.components().addProjectBranchToApplicationBranch(dbClient.branchDao().selectByUuid(dbSession, appBranch.uuid()).get(), projectBranch);
    db.components().addProjectBranchToApplicationBranch(dbClient.branchDao().selectByUuid(dbSession, otherAppBranch.uuid()).get(), projectBranch);
    // properties exist or active and for inactive branch
    insertPropertyFor(appBranch, otherAppBranch);
    underTest.deleteBranch(dbSession, appBranch.uuid());
    dbSession.commit();
    assertThat(uuidsIn("components")).containsOnly(project.uuid(), app.uuid(), otherApp.uuid(), otherAppBranch.uuid());
    assertThat(uuidsIn("projects")).containsOnly(project.uuid(), app.uuid(), otherApp.uuid());
    assertThat(uuidsIn("snapshots")).containsOnly(otherAppAnalysis.getUuid(), appAnalysis.getUuid(), otherAppBranchAnalysis.getUuid());
    assertThat(uuidsIn("project_branches")).containsOnly(project.uuid(), app.uuid(), otherApp.uuid(), otherAppBranch.uuid());
    assertThat(uuidsIn("project_measures")).containsOnly(appMeasure.getUuid(), otherAppMeasure.getUuid(), otherAppBranchMeasure.getUuid());
    assertThat(uuidsIn("app_projects", "application_uuid")).containsOnly(app.uuid(), otherApp.uuid());
    assertThat(uuidsIn("app_branch_project_branch", "application_branch_uuid")).containsOnly(otherAppBranch.uuid());
    assertThat(componentUuidsIn("properties")).containsOnly(otherAppBranch.uuid());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) MetricDto(org.sonar.db.metric.MetricDto) BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) 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