]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Correctly delete branches when deleting organization
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 19 Sep 2017 09:28:37 +0000 (11:28 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 20 Sep 2017 11:54:35 +0000 (13:54 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java

index b8df226eb4e4a09e90e3b9927f4b8b192e1171ac..e3b3b556c6b2f98212387d717bbf13b03ae6ef56 100644 (file)
@@ -249,6 +249,8 @@ public class ComponentDao implements Dao {
 
   /**
    * Select all root components (projects and views), including disabled ones, for a given organization.
+   *
+   * Branches are not returned
    */
   public List<ComponentDto> selectAllRootsByOrganization(DbSession dbSession, String organizationUuid) {
     return mapper(dbSession).selectAllRootsByOrganization(organizationUuid);
index dec681a80fd824eca42e549b1ac550ff9265144d..feaa6661866429562726fc54b0ae992b3c9d9695 100644 (file)
       p.scope='PRJ'
     and (p.qualifier='TRK' or p.qualifier='VW' or p.qualifier='APP')
       and p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
+      and p.main_branch_project_uuid IS NULL
   </select>
 
   <select id="selectComponentsByQualifiers" resultType="Component">
index a48bcf8f5b796b4f695514710d042620ef6e421b..f37b5e0c2fcca4bc1490231bdadf49493a3fe7cf 100644 (file)
@@ -660,6 +660,36 @@ public class ComponentDaoTest {
       .containsOnly(project.uuid());
   }
 
+  @Test
+  public void select_all_roots_by_organization() {
+    OrganizationDto organization = db.organizations().insert();
+    ComponentDto project1 = db.components().insertPrivateProject(organization);
+    ComponentDto module = db.components().insertComponent(newModuleDto(project1));
+    ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
+    ComponentDto file = db.components().insertComponent(newFileDto(module, directory));
+    ComponentDto project2 = db.components().insertPrivateProject(organization);
+    ComponentDto view = db.components().insertView(organization);
+    ComponentDto application = db.components().insertApplication(organization);
+    OrganizationDto otherOrganization = db.organizations().insert();
+    ComponentDto projectOnOtherOrganization = db.components().insertPrivateProject(otherOrganization);
+
+    assertThat(underTest.selectAllRootsByOrganization(dbSession, organization.getUuid()))
+      .extracting(ComponentDto::uuid)
+      .containsExactlyInAnyOrder(project1.uuid(), project2.uuid(), view.uuid(), application.uuid());
+  }
+
+  @Test
+  public void select_all_roots_by_organization_does_not_return_branches() {
+    OrganizationDto organization = db.organizations().insert();
+    ComponentDto project = db.components().insertMainBranch(organization);
+    ComponentDto branch = db.components().insertProjectBranch(project);
+
+    assertThat(underTest.selectAllRootsByOrganization(dbSession, organization.getUuid()))
+      .extracting(ComponentDto::uuid)
+      .containsExactlyInAnyOrder(project.uuid())
+      .doesNotContain(branch.uuid());
+  }
+
   @Test
   public void select_provisioned() {
     OrganizationDto organization = db.organizations().insert();
index 6954effc1a7c989218a88d053e968e3764b68fd2..cdbe6cfab2247a163295a4033ab665c2bddd1c3f 100644 (file)
@@ -243,6 +243,20 @@ public class DeleteActionTest {
     assertThat(db.countRowsOfTable(db.getSession(), "projects")).isZero();
   }
 
+  @Test
+  public void delete_branches() {
+    OrganizationDto organization = db.organizations().insert();
+    ComponentDto project = db.components().insertMainBranch(organization);
+    ComponentDto branch = db.components().insertProjectBranch(project);
+    logInAsAdministrator(organization);
+
+    sendRequest(organization);
+
+    verifyOrganizationDoesNotExist(organization);
+    assertThat(db.countRowsOfTable(db.getSession(), "projects")).isZero();
+    assertThat(db.countRowsOfTable(db.getSession(), "project_branches")).isZero();
+  }
+
   @Test
   public void delete_permissions_templates_and_permissions_and_groups_of_specified_organization() {
     OrganizationDto org = db.organizations().insert();