use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class IgnoreOrphanBranchStepTest method execute.
@Test
public void execute() {
BranchDto branchDto = new BranchDto().setBranchType(BRANCH).setKey("branchName").setUuid(BRANCH_UUID).setProjectUuid("project_uuid").setNeedIssueSync(true);
dbClient.branchDao().insert(dbTester.getSession(), branchDto);
dbTester.commit();
underTest.execute(() -> null);
Optional<BranchDto> branch = dbClient.branchDao().selectByUuid(dbTester.getSession(), BRANCH_UUID);
assertThat(branch.get().isNeedIssueSync()).isFalse();
assertThat(branch.get().isExcludeFromPurge()).isFalse();
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class NewCodePeriodDaoTest method select_branches_referencing.
@Test
public void select_branches_referencing() {
ProjectDto project = db.components().insertPrivateProjectDto();
BranchDto mainBranch = db.getDbClient().branchDao().selectByUuid(dbSession, project.getUuid()).get();
BranchDto branch1 = db.components().insertProjectBranch(project);
BranchDto branch2 = db.components().insertProjectBranch(project);
BranchDto branch3 = db.components().insertProjectBranch(project);
insert("1", project.getUuid(), null, REFERENCE_BRANCH, mainBranch.getKey());
insert("2", project.getUuid(), branch1.getUuid(), REFERENCE_BRANCH, mainBranch.getKey());
insert("3", project.getUuid(), branch2.getUuid(), NUMBER_OF_DAYS, "5");
insert("4", project.getUuid(), project.getUuid(), PREVIOUS_VERSION, null);
db.commit();
assertThat(underTest.selectBranchesReferencing(dbSession, project.getUuid(), mainBranch.getKey())).containsOnly(branch1.getUuid(), branch3.getUuid());
}
use of org.sonar.db.component.BranchDto 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());
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_branch_content_when_deleting_project.
@Test
public void delete_branch_content_when_deleting_project() {
ComponentDto anotherLivingProject = insertProjectWithBranchAndRelatedData();
int projectEntryCount = db.countRowsOfTable("components");
int issueCount = db.countRowsOfTable("issues");
int branchCount = db.countRowsOfTable("project_branches");
Collection<BranchDto> anotherLivingProjectBranches = db.getDbClient().branchDao().selectByComponent(db.getSession(), anotherLivingProject);
insertPropertyFor(anotherLivingProjectBranches);
assertThat(db.countRowsOfTable("properties")).isEqualTo(anotherLivingProjectBranches.size());
ComponentDto projectToDelete = insertProjectWithBranchAndRelatedData();
Collection<BranchDto> projectToDeleteBranches = db.getDbClient().branchDao().selectByComponent(db.getSession(), projectToDelete);
insertPropertyFor(projectToDeleteBranches);
assertThat(db.countRowsOfTable("properties")).isEqualTo(anotherLivingProjectBranches.size() + projectToDeleteBranches.size());
assertThat(db.countRowsOfTable("components")).isGreaterThan(projectEntryCount);
assertThat(db.countRowsOfTable("issues")).isGreaterThan(issueCount);
assertThat(db.countRowsOfTable("project_branches")).isGreaterThan(branchCount);
underTest.deleteProject(dbSession, projectToDelete.uuid(), projectToDelete.qualifier(), projectToDelete.name(), projectToDelete.getKey());
dbSession.commit();
assertThat(db.countRowsOfTable("components")).isEqualTo(projectEntryCount);
assertThat(db.countRowsOfTable("issues")).isEqualTo(issueCount);
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(branchCount);
assertThat(db.countRowsOfTable("properties")).isEqualTo(anotherLivingProjectBranches.size());
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_row_in_events_and_event_component_changes_when_deleting_project.
@Test
public void delete_row_in_events_and_event_component_changes_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project);
SnapshotDto projectAnalysis2 = db.components().insertSnapshot(project);
EventDto projectEvent1 = db.events().insertEvent(projectAnalysis1);
EventDto projectEvent2 = db.events().insertEvent(projectAnalysis2);
EventDto projectEvent3 = db.events().insertEvent(db.components().insertSnapshot(project));
SnapshotDto branchAnalysis1 = db.components().insertSnapshot(branch);
SnapshotDto branchAnalysis2 = db.components().insertSnapshot(branch);
EventDto branchEvent1 = db.events().insertEvent(branchAnalysis1);
EventDto branchEvent2 = db.events().insertEvent(branchAnalysis2);
SnapshotDto anotherBranchAnalysis = db.components().insertSnapshot(anotherBranch);
EventDto anotherBranchEvent = db.events().insertEvent(anotherBranchAnalysis);
SnapshotDto anotherProjectAnalysis = db.components().insertSnapshot(anotherProject);
EventDto anotherProjectEvent = db.events().insertEvent(anotherProjectAnalysis);
ComponentDto referencedProjectA = db.components().insertPublicProject();
ComponentDto referencedProjectB = db.components().insertPublicProject();
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectA, null);
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null);
BranchDto branchProjectA = newBranchDto(referencedProjectA);
ComponentDto cptBranchProjectA = ComponentTesting.newBranchComponent(referencedProjectA, branchProjectA);
db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA);
// note: projectEvent3 has no component change
db.events().insertEventComponentChanges(branchEvent1, branchAnalysis1, randomChangeCategory(), referencedProjectB, null);
db.events().insertEventComponentChanges(branchEvent2, branchAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA);
db.events().insertEventComponentChanges(anotherBranchEvent, anotherBranchAnalysis, randomChangeCategory(), referencedProjectB, null);
db.events().insertEventComponentChanges(anotherProjectEvent, anotherProjectAnalysis, randomChangeCategory(), referencedProjectB, null);
// deleting referenced project does not delete any data
underTest.deleteProject(dbSession, referencedProjectA.uuid(), referencedProjectA.qualifier(), project.name(), project.getKey());
assertThat(db.countRowsOfTable("event_component_changes")).isEqualTo(7);
assertThat(db.countRowsOfTable("events")).isEqualTo(7);
underTest.deleteProject(dbSession, branch.uuid(), branch.qualifier(), project.name(), project.getKey());
assertThat(uuidsIn("event_component_changes", "event_component_uuid")).containsOnly(project.uuid(), anotherBranch.uuid(), anotherProject.uuid());
assertThat(db.countRowsOfTable("event_component_changes")).isEqualTo(5);
assertThat(uuidsIn("events")).containsOnly(projectEvent1.getUuid(), projectEvent2.getUuid(), projectEvent3.getUuid(), anotherBranchEvent.getUuid(), anotherProjectEvent.getUuid());
underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
assertThat(uuidsIn("event_component_changes", "event_component_uuid")).containsOnly(anotherBranch.uuid(), anotherProject.uuid());
assertThat(db.countRowsOfTable("event_component_changes")).isEqualTo(2);
assertThat(uuidsIn("events")).containsOnly(anotherBranchEvent.getUuid(), anotherProjectEvent.getUuid());
}
Aggregations