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");
}
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());
}
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");
}
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());
}
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());
}
Aggregations