From 1494dac2272c73ca4d13c25e895716ec5c356897 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 1 Oct 2015 16:59:24 +0200 Subject: Improve deletion of project to deal with subviews/tech projects --- .../resources/org/sonar/db/purge/PurgeMapper.xml | 2 +- .../test/java/org/sonar/db/purge/PurgeDaoTest.java | 30 ++++++++++++++++++++++ .../db/purge/PurgeDaoTest/shouldDeleteProject.xml | 6 ++--- .../view_sub_view_and_tech_project.xml | 30 ++++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml (limited to 'sonar-db') diff --git a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index 6307b26275b..8dcfbf87609 100644 --- a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -83,7 +83,7 @@ diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 0ff1acd378f..ac64984651a 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -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"); diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml index fac178de73e..dc6abb440dc 100644 --- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml @@ -2,7 +2,7 @@ @@ -54,7 +54,7 @@ @@ -72,7 +72,7 @@ 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 index 00000000000..f2e519eb559 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/view_sub_view_and_tech_project.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + -- cgit v1.2.3