]> source.dussan.org Git - sonarqube.git/commitdiff
Improve deletion of project to deal with subviews/tech projects
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 1 Oct 2015 14:59:24 +0000 (16:59 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 2 Oct 2015 14:06:01 +0000 (16:06 +0200)
sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml [new file with mode: 0644]

index 6307b26275be4a20bcf4735e9c125c2f272772ea..8dcfbf876091ff2eed1144178ddeb2b63a755a11 100644 (file)
@@ -83,7 +83,7 @@
   </select>
 
   <select id="selectComponentsByProjectUuid" resultType="org.sonar.db.purge.IdUuidPair" parameterType="String">
-    select id, uuid from projects where project_uuid=#{uuid}
+    select id, uuid from projects where project_uuid=#{uuid} or uuid=#{uuid}
   </select>
 
   <delete id="deleteSnapshotMeasures" parameterType="map">
index 0ff1acd378fb2a59a64234a1be9666947a853ac3..ac64984651ab56b2b9a3ff9096f88ea8698cb69f 100644 (file)
@@ -116,6 +116,36 @@ public class PurgeDaoTest {
     assertThat(dbTester.countRowsOfTable("file_sources")).isZero();
   }
 
+  @Test
+  public void delete_view_and_child() {
+    dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
+
+    underTest.deleteProject(dbSession, "A");
+    dbSession.commit();
+    assertThat(dbTester.countSql("select count(id) from projects where uuid='A'")).isZero();
+    assertThat(dbTester.countRowsOfTable("projects")).isZero();
+  }
+
+  @Test
+  public void delete_view_sub_view_and_tech_project() {
+    dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
+
+    // technical project
+    underTest.deleteProject(dbSession, "D");
+    dbSession.commit();
+    assertThat(dbTester.countSql("select count(id) from projects where uuid='D'")).isZero();
+
+    // sub view
+    underTest.deleteProject(dbSession, "B");
+    dbSession.commit();
+    assertThat(dbTester.countSql("select count(id) from projects where uuid='B'")).isZero();
+
+    // view
+    underTest.deleteProject(dbSession, "A");
+    dbSession.commit();
+    assertThat(dbTester.countSql("select count(id) from projects where uuid='A'")).isZero();
+  }
+
   @Test
   public void should_delete_old_closed_issues() {
     dbTester.prepareDbUnit(getClass(), "should_delete_old_closed_issues.xml");
index fac178de73eecf31952caf8dc95b851a7591de86..dc6abb440dc9c5074869dfc81034a1e26ee33644 100644 (file)
@@ -2,7 +2,7 @@
 
   <!-- root -->
   <projects id="1" enabled="[true]" root_id="[null]"
-            uuid="A" project_uuid="A" module_uuid="[null]" module_uuid_path="."
+            uuid="A" project_uuid="A" module_uuid="[null]" module_uuid_path=".A."
             long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project"
             description="[null]" language="java" copy_resource_id="[null]" person_id="[null]"
             authorization_updated_at="[null]"/>
@@ -54,7 +54,7 @@
 
   <!-- modules -->
   <projects id="2" enabled="[true]" root_id="1"
-            uuid="B" project_uuid="A" module_uuid="A" module_uuid_path=".A."
+            uuid="B" project_uuid="A" module_uuid="A" module_uuid_path=".A.B."
             long_name="[null]" scope="PRJ" qualifier="BRC" kee="module1" name="module1"
             description="[null]" language="java" copy_resource_id="[null]" person_id="[null]"
             authorization_updated_at="[null]"/>
@@ -72,7 +72,7 @@
 
 
   <projects id="3" enabled="[false]" root_id="1"
-            uuid="C" project_uuid="A" module_uuid="A" module_uuid_path=".A."
+            uuid="C" project_uuid="A" module_uuid="A" module_uuid_path=".A.C."
             long_name="[null]" scope="PRJ" qualifier="BRC" kee="module2" name="module2"
             description="[null]" language="java" copy_resource_id="[null]" person_id="[null]"
             authorization_updated_at="[null]"/>
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml
new file mode 100644 (file)
index 0000000..f2e519e
--- /dev/null
@@ -0,0 +1,30 @@
+<dataset>
+
+  <!-- view -->
+  <projects id="1" enabled="[true]" root_id="[null]"
+            uuid="A" project_uuid="A" module_uuid="[null]" module_uuid_path=".A."
+            long_name="[null]" scope="PRJ" qualifier="VW" kee="view" name="view"
+            description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]"
+            authorization_updated_at="[null]"/>
+
+  <!-- sub views -->
+  <projects id="2" enabled="[true]" root_id="1"
+            uuid="B" project_uuid="A" module_uuid="A" module_uuid_path=".A.B."
+            long_name="[null]" scope="PRJ" qualifier="SVW" kee="subview1" name="subview2"
+            description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]"
+            authorization_updated_at="[null]"/>
+
+  <projects id="3" enabled="[false]" root_id="1"
+            uuid="C" project_uuid="A" module_uuid="A" module_uuid_path=".A.C."
+            long_name="[null]" scope="PRJ" qualifier="SVW" kee="subview2" name="subview2"
+            description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]"
+            authorization_updated_at="[null]"/>
+
+  <!-- technical project of module 2-->
+  <projects id="4" enabled="[false]" root_id="3"
+            uuid="D" project_uuid="A" module_uuid="C" module_uuid_path=".A.C."
+            long_name="[null]" scope="FIL" qualifier="TRK" kee="TechProject" name="TechProject"
+            description="[null]" language="[null]" copy_resource_id="[null]" person_id="[null]"
+            authorization_updated_at="[null]"/>
+
+</dataset>