public void delete(DbSession dbSession, ComponentDto project) { checkArgument(!hasNotProjectScope(project) && !isNotDeletable(project) && project.getMainBranchProjectUuid() == null, "Only projects can be deleted"); dbClient.purgeDao().deleteProject(dbSession, project.uuid()); dbClient.userDao().cleanHomepage(dbSession, project); projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_DELETION); }
@Test public void delete_view_sub_view_and_tech_project() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); // view underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); }
@Test public void delete_view_and_child() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); assertThat(db.countRowsOfTable("projects")).isZero(); }
@Test public void delete_project_and_associated_data() { db.prepareDbUnit(getClass(), "shouldDeleteProject.xml"); underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countRowsOfTable("projects")).isZero(); assertThat(db.countRowsOfTable("snapshots")).isZero(); assertThat(db.countRowsOfTable("issues")).isZero(); assertThat(db.countRowsOfTable("issue_changes")).isZero(); assertThat(db.countRowsOfTable("file_sources")).isZero(); }
@Test public void delete_branch_content_when_deleting_project() { ComponentDto anotherLivingProject = insertProjectWithBranchAndRelatedData(); int projectEntryCount = db.countRowsOfTable("projects"); int issueCount = db.countRowsOfTable("issues"); int branchCount = db.countRowsOfTable("project_branches"); ComponentDto projectToDelete = insertProjectWithBranchAndRelatedData(); assertThat(db.countRowsOfTable("projects")).isGreaterThan(projectEntryCount); assertThat(db.countRowsOfTable("issues")).isGreaterThan(issueCount); assertThat(db.countRowsOfTable("project_branches")).isGreaterThan(branchCount); underTest.deleteProject(dbSession, projectToDelete.uuid()); dbSession.commit(); assertThat(db.countRowsOfTable("projects")).isEqualTo(projectEntryCount); assertThat(db.countRowsOfTable("issues")).isEqualTo(issueCount); assertThat(db.countRowsOfTable("project_branches")).isEqualTo(branchCount); }
@Test public void delete_live_measures_when_deleting_project() { MetricDto metric = db.measures().insertMetric(); ComponentDto project1 = db.components().insertPublicProject(); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project1)); db.measures().insertLiveMeasure(project1, metric); db.measures().insertLiveMeasure(module1, metric); ComponentDto project2 = db.components().insertPublicProject(); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project2)); db.measures().insertLiveMeasure(project2, metric); db.measures().insertLiveMeasure(module2, metric); underTest.deleteProject(dbSession, project1.uuid()); assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getId()))).isEmpty(); assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getId()))).hasSize(2); }
@Test public void deleteProject_deletes_project_mappings() { ComponentDto project = db.components().insertPublicProject(); dbClient.projectMappingsDao().put(dbSession, "a.key.type", "a.key", project.uuid()); dbClient.projectMappingsDao().put(dbSession, "a.key.type", "another.key", "D2"); underTest.deleteProject(dbSession, project.uuid()); assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "a.key")).isEmpty(); assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "another.key")).isNotEmpty(); }
@Test public void delete_row_in_ce_activity_when_deleting_project() { ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject); // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project CeActivityDto toBeDeletedActivity = insertCeActivity(projectToBeDeleted); CeActivityDto notDeletedActivity = insertCeActivity(anotherLivingProject); dbSession.commit(); underTest.deleteProject(dbSession, projectToBeDeleted.uuid()); dbSession.commit(); assertThat(uuidsOfTable("ce_activity")) .containsOnly(notDeletedActivity.getUuid()) .hasSize(1); }
@Test public void delete_tasks_in_ce_queue_when_deleting_project() { ComponentDto projectToBeDeleted = db.components().insertPrivateProject(); ComponentDto anotherLivingProject = db.components().insertPrivateProject(); // Insert 3 rows in CE_QUEUE: two for the project that will be deleted (in order to check that status // is not involved in deletion), and one on another project dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.PENDING)); dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.IN_PROGRESS)); dbClient.ceQueueDao().insert(dbSession, createCeQueue(anotherLivingProject, Status.PENDING)); dbSession.commit(); underTest.deleteProject(dbSession, projectToBeDeleted.uuid()); dbSession.commit(); assertThat(db.countRowsOfTable("ce_queue")).isEqualTo(1); assertThat(db.countSql("select count(*) from ce_queue where main_component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0); }
@Test public void deleteProject_fails_with_IAE_if_specified_component_is_directory() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto directory = db.components().insertComponent(newDirectory(privateProject, "A/B")); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Couldn't find root component with uuid " + directory.uuid()); underTest.deleteProject(dbSession, directory.uuid()); }
@Test public void deleteProject_deletes_project_alm_bindings() { ALM alm = ALM.GITHUB; String repoId = "123"; String otherRepoId = repoId + "-foo"; ComponentDto project = db.components().insertPublicProject(); ComponentDto otherProject = db.components().insertPublicProject(); dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, repoId, project.uuid(), null, "foo"); dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, otherRepoId, otherProject.uuid(), null, "bar"); underTest.deleteProject(dbSession, project.uuid()); assertThat(dbClient.projectAlmBindingsDao().findProjectKey(dbSession, alm, repoId)).isEmpty(); assertThat(dbClient.projectAlmBindingsDao().findProjectKey(dbSession, alm, otherRepoId)).isNotEmpty(); }
@Test public void deleteProject_fails_with_IAE_if_specified_component_is_file() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(privateProject)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Couldn't find root component with uuid " + file.uuid()); underTest.deleteProject(dbSession, file.uuid()); }
@Test public void deleteProject_fails_with_IAE_if_specified_component_is_subview() { ComponentDto view = db.components().insertView(); ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Couldn't find root component with uuid " + subview.uuid()); underTest.deleteProject(dbSession, subview.uuid()); }
@Test public void deleteProject_fails_with_IAE_if_specified_component_is_module() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Couldn't find root component with uuid " + module.uuid()); underTest.deleteProject(dbSession, module.uuid()); }
@Test public void delete_webhooks_from_project() { OrganizationDto organization = db.organizations().insert(); ComponentDto project1 = db.components().insertPrivateProject(organization); WebhookDto webhook = db.webhooks().insertWebhook(project1); db.webhookDelivery().insert(webhook); ComponentDto projectNotToBeDeleted = db.components().insertPrivateProject(organization); WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted); WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted); underTest.deleteProject(dbSession, project1.uuid()); assertThat(db.select(db.getSession(), "select uuid as \"uuid\" from webhooks")) .extracting(m -> m.get("uuid")) .containsExactlyInAnyOrder(webhookNotDeleted.getUuid()); assertThat(db.select(db.getSession(), "select uuid as \"uuid\" from webhook_deliveries")) .extracting(m -> m.get("uuid")) .containsExactlyInAnyOrder(webhookDeliveryNotDeleted.getUuid()); }
@Test public void deleteProject_deletes_webhook_deliveries() { ComponentDto project = db.components().insertPublicProject(); dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid(project.uuid()).setUuid("D1").setDurationMs(1000).setWebhookUuid("webhook-uuid")); dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid("P2").setUuid("D2").setDurationMs(1000).setWebhookUuid("webhook-uuid")); underTest.deleteProject(dbSession, project.uuid()); assertThat(selectAllDeliveryUuids(db, dbSession)).containsOnly("D2"); }
@Test public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_queue_when_deleting_project() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeQueueDto projectTask = insertCeQueue(project); insertCeTaskMessages(projectTask.getUuid(), 3); CeQueueDto branchTask = insertCeQueue(branch); insertCeTaskMessages(branchTask.getUuid(), 1); CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); insertCeTaskMessages(anotherBranchTask.getUuid(), 5); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskMessages(anotherProjectTask.getUuid(), 2); insertCeTaskMessages("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")) .containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@Test public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeActivityDto projectTask = insertCeActivity(project); insertCeTaskCharacteristics(projectTask.getUuid(), 3); CeActivityDto branchTask = insertCeActivity(branch); insertCeTaskCharacteristics(branchTask.getUuid(), 2); CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 6); CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2); insertCeTaskCharacteristics("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@Test public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_activity_when_deleting_project() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeActivityDto projectTask = insertCeActivity(project); insertCeTaskMessages(projectTask.getUuid(), 3); CeActivityDto branchTask = insertCeActivity(branch); insertCeTaskMessages(branchTask.getUuid(), 2); CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); insertCeTaskMessages(anotherBranchTask.getUuid(), 6); CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); insertCeTaskMessages(anotherProjectTask.getUuid(), 2); insertCeTaskMessages("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@Test public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project)); ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeQueueDto projectTask = insertCeQueue(project); insertCeTaskCharacteristics(projectTask.getUuid(), 3); CeQueueDto branchTask = insertCeQueue(branch); insertCeTaskCharacteristics(branchTask.getUuid(), 1); CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 5); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2); insertCeTaskCharacteristics("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")) .containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }