]> source.dussan.org Git - sonarqube.git/commitdiff
Delete webhooks and webhook deliveries only once (#667)
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 30 Aug 2018 14:58:58 +0000 (16:58 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 30 Aug 2018 18:22:23 +0000 (20:22 +0200)
- Deletion were done at 3 places when deleting an organization :
-- In the api/organization/delete WS
-- In component cleaner
-- In PurgeDao
- Moreover, the deletion of webhook deliveries in the last 2 classes were not done by project, but by selecting all webhook deliveries of the project and deleting them one by one

19 files changed:
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDbTesting.java [deleted file]
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDbTester.java
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryTesting.java [new file with mode: 0644]
server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookDeliveryStorageTest.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java
server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java

index 18b68506d10d1d2edde2db922b8bb730fcbc6b53..dfb19a480f4435606425b11838139ea328f692d1 100644 (file)
@@ -107,6 +107,7 @@ public final class SqTables {
     "users",
     "user_roles",
     "user_tokens",
+    "webhooks",
     "webhook_deliveries")));
 
   private SqTables() {
index 80634fd8fa3d727b1fc0dea2e8d5fe569514749c..fd869e96a7d9d4c6d2130b3af6f973439a476353 100644 (file)
@@ -284,6 +284,13 @@ class PurgeCommands {
     profiler.stop();
   }
 
+  void deleteWebhooks(String rootUuid) {
+    profiler.start("deleteWebhooks (webhooks)");
+    purgeMapper.deleteWebhooksByProjectUuid(rootUuid);
+    session.commit();
+    profiler.stop();
+  }
+
   void deleteWebhookDeliveries(String rootUuid) {
     profiler.start("deleteWebhookDeliveries (webhook_deliveries)");
     purgeMapper.deleteWebhookDeliveriesByProjectUuid(rootUuid);
index c62dcbd14f2e5ee441a2d276da24d403e48e17f0..2a16fc806f9a68f44624ec80b801cc54fa5ef950 100644 (file)
@@ -201,6 +201,7 @@ public class PurgeDao implements Dao {
     commands.deleteFileSources(rootUuid);
     commands.deleteCeActivity(rootUuid);
     commands.deleteCeQueue(rootUuid);
+    commands.deleteWebhooks(rootUuid);
     commands.deleteWebhookDeliveries(rootUuid);
     commands.deleteProjectMappings(rootUuid);
     commands.deleteProjectAlmBindings(rootUuid);
index de1b8f47bfdd9b64c4fc747625fb00284769c5e0..3a6dbd86f41a0f57410f3b76ce566d9854ee8cb5 100644 (file)
@@ -106,6 +106,8 @@ public interface PurgeMapper {
 
   void deleteCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
 
+  void deleteWebhooksByProjectUuid(@Param("projectUuid") String projectUuid);
+
   void deleteWebhookDeliveriesByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void deleteProjectMappingsByProjectUuid(@Param("projectUuid") String projectUuid);
index 5e8535cd978b8a450fad2e542a1c832aca266eed..5051ad485c5a0796cb69b6ae4a07ca2696b445b2 100644 (file)
     delete from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
 
+  <delete id="deleteWebhooksByProjectUuid">
+    delete from webhooks where project_uuid=#{projectUuid,jdbcType=VARCHAR}
+  </delete>
+
   <delete id="deleteWebhookDeliveriesByProjectUuid">
     delete from webhook_deliveries where component_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
index afa7636baf60900ad325f952d4f48eda14f058bc..a6247601c0b013fee9df99c7c76f37ce4a1fd6fb 100644 (file)
@@ -56,9 +56,12 @@ import org.sonar.db.issue.IssueDto;
 import org.sonar.db.measure.MeasureDto;
 import org.sonar.db.measure.custom.CustomMeasureDto;
 import org.sonar.db.metric.MetricDto;
+import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.property.PropertyDto;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.source.FileSourceDto;
+import org.sonar.db.webhook.WebhookDeliveryLiteDto;
+import org.sonar.db.webhook.WebhookDto;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyList;
@@ -66,7 +69,6 @@ import static java.util.Collections.singletonList;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.ce.CeTaskTypes.REPORT;
@@ -74,8 +76,8 @@ import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
-import static org.sonar.db.webhook.WebhookDbTesting.selectAllDeliveryUuids;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.selectAllDeliveryUuids;
 
 public class PurgeDaoTest {
 
@@ -85,49 +87,49 @@ public class PurgeDaoTest {
   private System2 system2 = mock(System2.class);
 
   @Rule
-  public DbTester dbTester = DbTester.create(system2);
+  public DbTester db = DbTester.create(system2);
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private DbClient dbClient = dbTester.getDbClient();
-  private DbSession dbSession = dbTester.getSession();
-  private PurgeDao underTest = dbTester.getDbClient().purgeDao();
+  private DbClient dbClient = db.getDbClient();
+  private DbSession dbSession = db.getSession();
+  private PurgeDao underTest = db.getDbClient().purgeDao();
 
   @Test
   public void purge_failed_ce_tasks() {
-    dbTester.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml");
+    db.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml");
 
     underTest.purge(dbSession, newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
     dbSession.commit();
 
-    dbTester.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots");
+    db.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots");
   }
 
   @Test
   public void purge_history_of_project() {
-    dbTester.prepareDbUnit(getClass(), "shouldPurgeProject.xml");
+    db.prepareDbUnit(getClass(), "shouldPurgeProject.xml");
     underTest.purge(dbSession, newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
     dbSession.commit();
-    dbTester.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots");
+    db.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots");
   }
 
   @Test
   public void purge_inactive_short_living_branches() {
     when(system2.now()).thenReturn(new Date().getTime());
-    RuleDefinitionDto rule = dbTester.rules().insert();
-    ComponentDto project = dbTester.components().insertMainBranch();
-    ComponentDto longBranch = dbTester.components().insertProjectBranch(project);
-    ComponentDto recentShortBranch = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
+    RuleDefinitionDto rule = db.rules().insert();
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto longBranch = db.components().insertProjectBranch(project);
+    ComponentDto recentShortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
 
     // short branch with other components and issues, updated 31 days ago
     when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
-    ComponentDto shortBranch = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
-    ComponentDto module = dbTester.components().insertComponent(newModuleDto(shortBranch));
-    ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
-    dbTester.issues().insert(rule, shortBranch, file);
-    dbTester.issues().insert(rule, shortBranch, subModule);
-    dbTester.issues().insert(rule, shortBranch, module);
+    ComponentDto shortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
+    ComponentDto module = db.components().insertComponent(newModuleDto(shortBranch));
+    ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+    ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+    db.issues().insert(rule, shortBranch, file);
+    db.issues().insert(rule, shortBranch, subModule);
+    db.issues().insert(rule, shortBranch, module);
 
     // back to present
     when(system2.now()).thenReturn(new Date().getTime());
@@ -140,20 +142,20 @@ public class PurgeDaoTest {
   @Test
   public void purge_inactive_pull_request() {
     when(system2.now()).thenReturn(new Date().getTime());
-    RuleDefinitionDto rule = dbTester.rules().insert();
-    ComponentDto project = dbTester.components().insertMainBranch();
-    ComponentDto longBranch = dbTester.components().insertProjectBranch(project);
-    ComponentDto recentPullRequest = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
+    RuleDefinitionDto rule = db.rules().insert();
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto longBranch = db.components().insertProjectBranch(project);
+    ComponentDto recentPullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
 
     // pull request with other components and issues, updated 31 days ago
     when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
-    ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
-    ComponentDto module = dbTester.components().insertComponent(newModuleDto(pullRequest));
-    ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
-    dbTester.issues().insert(rule, pullRequest, file);
-    dbTester.issues().insert(rule, pullRequest, subModule);
-    dbTester.issues().insert(rule, pullRequest, module);
+    ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
+    ComponentDto module = db.components().insertComponent(newModuleDto(pullRequest));
+    ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+    ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+    db.issues().insert(rule, pullRequest, file);
+    db.issues().insert(rule, pullRequest, subModule);
+    db.issues().insert(rule, pullRequest, module);
 
     // back to present
     when(system2.now()).thenReturn(new Date().getTime());
@@ -165,47 +167,47 @@ public class PurgeDaoTest {
 
   @Test
   public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
-    dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
+    db.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
     PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "PROJECT_UUID"), asList(Scopes.DIRECTORY, Scopes.FILE),
       30, Optional.of(30), System2.INSTANCE, Collections.emptyList());
 
     underTest.purge(dbSession, conf, PurgeListener.EMPTY, new PurgeProfiler());
     dbSession.commit();
 
-    dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots", "project_measures");
+    db.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots", "project_measures");
   }
 
   @Test
   public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() {
     // components and issues, updated 31 days ago
     when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
-    RuleDefinitionDto rule = dbTester.rules().insert();
-    ComponentDto project = dbTester.components().insertMainBranch(p -> p.setEnabled(false));
-    dbTester.components().insertSnapshot(project);
-    dbTester.components().insertSnapshot(project);
-    dbTester.components().insertSnapshot(project, s -> s.setLast(false));
-
-    ComponentDto module = dbTester.components().insertComponent(newModuleDto(project).setEnabled(false));
-    ComponentDto dir = dbTester.components().insertComponent(newDirectory(module, "sub").setEnabled(false));
-    ComponentDto srcFile = dbTester.components().insertComponent(newFileDto(module, dir).setEnabled(false));
-    ComponentDto testFile = dbTester.components().insertComponent(newFileDto(module, dir).setEnabled(false));
-    ComponentDto nonSelectedFile = dbTester.components().insertComponent(newFileDto(module, dir).setEnabled(false));
-    IssueDto openOnFile = dbTester.issues().insert(rule, project, srcFile, issue -> issue.setStatus("OPEN"));
-    IssueDto confirmOnFile = dbTester.issues().insert(rule, project, srcFile, issue -> issue.setStatus("CONFIRM"));
-    IssueDto openOnDir = dbTester.issues().insert(rule, project, dir, issue -> issue.setStatus("OPEN"));
-    IssueDto confirmOnDir = dbTester.issues().insert(rule, project, dir, issue -> issue.setStatus("CONFIRM"));
-    IssueDto openOnNonSelected = dbTester.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("OPEN"));
-    IssueDto confirmOnNonSelected = dbTester.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("CONFIRM"));
-
-    assertThat(dbTester.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(0);
-
-    assertThat(dbTester.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(0);
-    assertThat(dbTester.countSql("select count(*) from issues where resolution = 'REMOVED'")).isEqualTo(0);
-
-    dbTester.fileSources().insertFileSource(srcFile);
-    dbTester.fileSources().insertFileSource(testFile, f -> f.setDataType("TEST"));
-    FileSourceDto nonSelectedFileSource = dbTester.fileSources().insertFileSource(nonSelectedFile);
-    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(3);
+    RuleDefinitionDto rule = db.rules().insert();
+    ComponentDto project = db.components().insertMainBranch(p -> p.setEnabled(false));
+    db.components().insertSnapshot(project);
+    db.components().insertSnapshot(project);
+    db.components().insertSnapshot(project, s -> s.setLast(false));
+
+    ComponentDto module = db.components().insertComponent(newModuleDto(project).setEnabled(false));
+    ComponentDto dir = db.components().insertComponent(newDirectory(module, "sub").setEnabled(false));
+    ComponentDto srcFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
+    ComponentDto testFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
+    ComponentDto nonSelectedFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
+    IssueDto openOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("OPEN"));
+    IssueDto confirmOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("CONFIRM"));
+    IssueDto openOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("OPEN"));
+    IssueDto confirmOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("CONFIRM"));
+    IssueDto openOnNonSelected = db.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("OPEN"));
+    IssueDto confirmOnNonSelected = db.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("CONFIRM"));
+
+    assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(0);
+
+    assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(0);
+    assertThat(db.countSql("select count(*) from issues where resolution = 'REMOVED'")).isEqualTo(0);
+
+    db.fileSources().insertFileSource(srcFile);
+    db.fileSources().insertFileSource(testFile, f -> f.setDataType("TEST"));
+    FileSourceDto nonSelectedFileSource = db.fileSources().insertFileSource(nonSelectedFile);
+    assertThat(db.countRowsOfTable("file_sources")).isEqualTo(3);
 
     // back to present
     when(system2.now()).thenReturn(new Date().getTime());
@@ -213,37 +215,37 @@ public class PurgeDaoTest {
     dbSession.commit();
 
     // set purge_status=1 for non-last snapshot
-    assertThat(dbTester.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(1);
+    assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(1);
 
     // close open issues of selected
-    assertThat(dbTester.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4);
+    assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4);
     for (IssueDto issue : Arrays.asList(openOnFile, confirmOnFile, openOnDir, confirmOnDir)) {
-      assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
+      assertThat(db.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
         .extracting("status", "resolution")
         .containsExactlyInAnyOrder("CLOSED", "REMOVED");
     }
     for (IssueDto issue : Arrays.asList(openOnNonSelected, confirmOnNonSelected)) {
-      assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
+      assertThat(db.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
         .extracting("status", "resolution")
         .containsExactlyInAnyOrder(issue.getStatus(), null);
     }
 
     // delete file sources of selected
-    assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
-    assertThat(dbTester.getDbClient().fileSourceDao().selectSourceByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull();
+    assertThat(db.countRowsOfTable("file_sources")).isEqualTo(1);
+    assertThat(db.getDbClient().fileSourceDao().selectSourceByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull();
   }
 
   @Test
   public void shouldDeleteAnalyses() {
-    dbTester.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml");
+    db.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml");
 
     underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3")));
-    dbTester.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots");
+    db.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots");
   }
 
   @Test
   public void selectPurgeableAnalyses() {
-    dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableAnalysis.xml");
+    db.prepareDbUnit(getClass(), "shouldSelectPurgeableAnalysis.xml");
     List<PurgeableAnalysisDto> analyses = underTest.selectPurgeableAnalyses(THE_PROJECT_UUID, dbSession);
 
     assertThat(analyses).hasSize(3);
@@ -260,33 +262,53 @@ public class PurgeDaoTest {
 
   @Test
   public void delete_project_and_associated_data() {
-    dbTester.prepareDbUnit(getClass(), "shouldDeleteProject.xml");
+    db.prepareDbUnit(getClass(), "shouldDeleteProject.xml");
 
     underTest.deleteProject(dbSession, "A");
     dbSession.commit();
 
-    assertThat(dbTester.countRowsOfTable("projects")).isZero();
-    assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
-    assertThat(dbTester.countRowsOfTable("issues")).isZero();
-    assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
-    assertThat(dbTester.countRowsOfTable("file_sources")).isZero();
+    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_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 delete_branch_and_associated_data() {
-    ComponentDto project = dbTester.components().insertMainBranch();
-    ComponentDto branch = dbTester.components().insertProjectBranch(project);
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(project);
 
     underTest.deleteBranch(dbSession, project.uuid());
     dbSession.commit();
-    assertThat(dbTester.countRowsOfTable("project_branches")).isEqualTo(1);
-    assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1);
+    assertThat(db.countRowsOfTable("project_branches")).isEqualTo(1);
+    assertThat(db.countRowsOfTable("projects")).isEqualTo(1);
   }
 
   @Test
   public void delete_row_in_ce_activity_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -297,13 +319,13 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.countRowsOfTable("ce_activity")).isEqualTo(1);
+    assertThat(db.countRowsOfTable("ce_activity")).isEqualTo(1);
   }
 
   @Test
   public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -317,18 +339,18 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+    assertThat(db.select("select uuid as \"UUID\" from ce_activity"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid());
-    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_input"))
+    assertThat(db.select("select task_uuid as \"UUID\" from ce_task_input"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
   @Test
   public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -342,18 +364,18 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+    assertThat(db.select("select uuid as \"UUID\" from ce_activity"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid());
-    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_scanner_context"))
+    assertThat(db.select("select task_uuid as \"UUID\" from ce_scanner_context"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
   @Test
   public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -367,18 +389,18 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+    assertThat(db.select("select uuid as \"UUID\" from ce_activity"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid());
-    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
+    assertThat(db.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
   @Test
   public void delete_tasks_in_ce_queue_when_deleting_project() {
-    ComponentDto projectToBeDeleted = dbTester.components().insertPrivateProject();
-    ComponentDto anotherLivingProject = dbTester.components().insertPrivateProject();
+    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
@@ -390,14 +412,14 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.countRowsOfTable("ce_queue")).isEqualTo(1);
-    assertThat(dbTester.countSql("select count(*) from ce_queue where component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0);
+    assertThat(db.countRowsOfTable("ce_queue")).isEqualTo(1);
+    assertThat(db.countSql("select count(*) from ce_queue where component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0);
   }
 
   @Test
   public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -411,18 +433,18 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+    assertThat(db.select("select uuid as \"UUID\" from ce_queue"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid());
-    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_input"))
+    assertThat(db.select("select task_uuid as \"UUID\" from ce_task_input"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
   @Test
   public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -436,18 +458,18 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+    assertThat(db.select("select uuid as \"UUID\" from ce_queue"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid());
-    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_scanner_context"))
+    assertThat(db.select("select task_uuid as \"UUID\" from ce_scanner_context"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
   @Test
   public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() {
-    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
-    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    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
@@ -461,61 +483,61 @@ public class PurgeDaoTest {
     underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
     dbSession.commit();
 
-    assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+    assertThat(db.select("select uuid as \"UUID\" from ce_queue"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid());
-    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
+    assertThat(db.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
       .extracting(row -> (String) row.get("UUID"))
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
   private ComponentDto insertProjectWithBranchAndRelatedData() {
-    RuleDefinitionDto rule = dbTester.rules().insert();
-    ComponentDto project = dbTester.components().insertMainBranch();
-    ComponentDto branch = dbTester.components().insertProjectBranch(project);
-    ComponentDto module = dbTester.components().insertComponent(newModuleDto(branch));
-    ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
-    dbTester.issues().insert(rule, branch, file);
-    dbTester.issues().insert(rule, branch, subModule);
-    dbTester.issues().insert(rule, branch, module);
+    RuleDefinitionDto rule = db.rules().insert();
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(project);
+    ComponentDto module = db.components().insertComponent(newModuleDto(branch));
+    ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+    ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+    db.issues().insert(rule, branch, file);
+    db.issues().insert(rule, branch, subModule);
+    db.issues().insert(rule, branch, module);
     return project;
   }
 
   @Test
   public void delete_branch_content_when_deleting_project() {
     ComponentDto anotherLivingProject = insertProjectWithBranchAndRelatedData();
-    int projectEntryCount = dbTester.countRowsOfTable("projects");
-    int issueCount = dbTester.countRowsOfTable("issues");
-    int branchCount = dbTester.countRowsOfTable("project_branches");
+    int projectEntryCount = db.countRowsOfTable("projects");
+    int issueCount = db.countRowsOfTable("issues");
+    int branchCount = db.countRowsOfTable("project_branches");
 
     ComponentDto projectToDelete = insertProjectWithBranchAndRelatedData();
-    assertThat(dbTester.countRowsOfTable("projects")).isGreaterThan(projectEntryCount);
-    assertThat(dbTester.countRowsOfTable("issues")).isGreaterThan(issueCount);
-    assertThat(dbTester.countRowsOfTable("project_branches")).isGreaterThan(branchCount);
+    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(dbTester.countRowsOfTable("projects")).isEqualTo(projectEntryCount);
-    assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(issueCount);
-    assertThat(dbTester.countRowsOfTable("project_branches")).isEqualTo(branchCount);
+    assertThat(db.countRowsOfTable("projects")).isEqualTo(projectEntryCount);
+    assertThat(db.countRowsOfTable("issues")).isEqualTo(issueCount);
+    assertThat(db.countRowsOfTable("project_branches")).isEqualTo(branchCount);
   }
 
   @Test
   public void delete_view_and_child() {
-    dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
+    db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
 
     underTest.deleteProject(dbSession, "A");
     dbSession.commit();
-    assertThat(dbTester.countSql("select count(1) from projects where uuid='A'")).isZero();
-    assertThat(dbTester.countRowsOfTable("projects")).isZero();
+    assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero();
+    assertThat(db.countRowsOfTable("projects")).isZero();
   }
 
   @Test
   public void deleteProject_fails_with_IAE_if_specified_component_is_module() {
-    ComponentDto privateProject = dbTester.components().insertPrivateProject();
-    ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(privateProject));
+    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());
@@ -525,8 +547,8 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteProject_fails_with_IAE_if_specified_component_is_directory() {
-    ComponentDto privateProject = dbTester.components().insertPrivateProject();
-    ComponentDto directory = dbTester.components().insertComponent(newDirectory(privateProject, "A/B"));
+    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());
@@ -536,8 +558,8 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteProject_fails_with_IAE_if_specified_component_is_file() {
-    ComponentDto privateProject = dbTester.components().insertPrivateProject();
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(privateProject));
+    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());
@@ -547,8 +569,8 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteProject_fails_with_IAE_if_specified_component_is_subview() {
-    ComponentDto view = dbTester.components().insertView();
-    ComponentDto subview = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
+    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());
@@ -558,60 +580,60 @@ public class PurgeDaoTest {
 
   @Test
   public void delete_view_sub_view_and_tech_project() {
-    dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
+    db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
 
     // view
     underTest.deleteProject(dbSession, "A");
     dbSession.commit();
-    assertThat(dbTester.countSql("select count(1) from projects where uuid='A'")).isZero();
+    assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero();
   }
 
   @Test
   public void should_delete_old_closed_issues() {
-    RuleDefinitionDto rule = dbTester.rules().insert();
-    ComponentDto project = dbTester.components().insertMainBranch();
+    RuleDefinitionDto rule = db.rules().insert();
+    ComponentDto project = db.components().insertMainBranch();
 
-    ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(module));
+    ComponentDto module = db.components().insertComponent(newModuleDto(project));
+    ComponentDto file = db.components().insertComponent(newFileDto(module));
 
-    IssueDto oldClosed = dbTester.issues().insert(rule, project, file, issue -> {
+    IssueDto oldClosed = db.issues().insert(rule, project, file, issue -> {
       issue.setStatus("CLOSED");
       issue.setIssueCloseDate(DateUtils.addDays(new Date(), -31));
     });
 
-    IssueDto notOldEnoughClosed = dbTester.issues().insert(rule, project, file, issue -> {
+    IssueDto notOldEnoughClosed = db.issues().insert(rule, project, file, issue -> {
       issue.setStatus("CLOSED");
       issue.setIssueCloseDate(new Date());
     });
-    IssueDto notClosed = dbTester.issues().insert(rule, project, file);
+    IssueDto notClosed = db.issues().insert(rule, project, file);
 
     when(system2.now()).thenReturn(new Date().getTime());
     underTest.purge(dbSession, newConfigurationWith30Days(system2, project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
     dbSession.commit();
 
     // old closed got deleted
-    assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey())).isEmpty();
+    assertThat(db.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey())).isEmpty();
 
     // others remain
-    assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(2);
-    assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, notOldEnoughClosed.getKey())).isNotEmpty();
-    assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, notClosed.getKey())).isNotEmpty();
+    assertThat(db.countRowsOfTable("issues")).isEqualTo(2);
+    assertThat(db.getDbClient().issueDao().selectByKey(dbSession, notOldEnoughClosed.getKey())).isNotEmpty();
+    assertThat(db.getDbClient().issueDao().selectByKey(dbSession, notClosed.getKey())).isNotEmpty();
   }
 
   @Test
   public void deleteProject_deletes_webhook_deliveries() {
-    ComponentDto project = dbTester.components().insertPublicProject();
+    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(dbTester, dbSession)).containsOnly("D2");
+    assertThat(selectAllDeliveryUuids(db, dbSession)).containsOnly("D2");
   }
 
   @Test
   public void deleteProject_deletes_project_mappings() {
-    ComponentDto project = dbTester.components().insertPublicProject();
+    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");
 
@@ -627,8 +649,8 @@ public class PurgeDaoTest {
     String repoId = "123";
     String otherRepoId = repoId + "-foo";
 
-    ComponentDto project = dbTester.components().insertPublicProject();
-    ComponentDto otherProject = dbTester.components().insertPublicProject();
+    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");
 
@@ -649,7 +671,7 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteNonRootComponents_has_no_effect_when_parameter_contains_only_projects_and_or_views() {
-    ComponentDbTester componentDbTester = dbTester.components();
+    ComponentDbTester componentDbTester = db.components();
 
     verifyNoEffect(componentDbTester.insertPrivateProject());
     verifyNoEffect(componentDbTester.insertPublicProject());
@@ -659,17 +681,17 @@ public class PurgeDaoTest {
 
   @Test
   public void delete_live_measures_when_deleting_project() {
-    MetricDto metric = dbTester.measures().insertMetric();
+    MetricDto metric = db.measures().insertMetric();
 
-    ComponentDto project1 = dbTester.components().insertPublicProject();
-    ComponentDto module1 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project1));
-    dbTester.measures().insertLiveMeasure(project1, metric);
-    dbTester.measures().insertLiveMeasure(module1, metric);
+    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 = dbTester.components().insertPublicProject();
-    ComponentDto module2 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project2));
-    dbTester.measures().insertLiveMeasure(project2, metric);
-    dbTester.measures().insertLiveMeasure(module2, 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());
 
@@ -689,20 +711,20 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_PROJECTS() {
-    ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPublicProject() : dbTester.components().insertPrivateProject();
-    ComponentDto module1 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
-    ComponentDto module2 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(module1));
-    ComponentDto dir1 = dbTester.components().insertComponent(newDirectory(module1, "A/B"));
+    ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject();
+    ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
+    ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
+    ComponentDto dir1 = db.components().insertComponent(newDirectory(module1, "A/B"));
 
     List<ComponentDto> components = asList(
       project,
       module1,
       module2,
       dir1,
-      dbTester.components().insertComponent(newDirectory(module2, "A/C")),
-      dbTester.components().insertComponent(newFileDto(dir1)),
-      dbTester.components().insertComponent(newFileDto(module2)),
-      dbTester.components().insertComponent(newFileDto(project)));
+      db.components().insertComponent(newDirectory(module2, "A/C")),
+      db.components().insertComponent(newFileDto(dir1)),
+      db.components().insertComponent(newFileDto(module2)),
+      db.components().insertComponent(newFileDto(project)));
     Collections.shuffle(components);
 
     underTest.deleteNonRootComponentsInView(dbSession, components);
@@ -714,21 +736,21 @@ public class PurgeDaoTest {
   @Test
   public void deleteNonRootComponents_deletes_only_non_root_components_of_a_view_from_table_PROJECTS() {
     ComponentDto[] projects = {
-      dbTester.components().insertPrivateProject(),
-      dbTester.components().insertPrivateProject(),
-      dbTester.components().insertPrivateProject()
+      db.components().insertPrivateProject(),
+      db.components().insertPrivateProject(),
+      db.components().insertPrivateProject()
     };
 
-    ComponentDto view = dbTester.components().insertView();
-    ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
+    ComponentDto view = db.components().insertView();
+    ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
     List<ComponentDto> components = asList(
       view,
       subview1,
       subview2,
-      dbTester.components().insertComponent(newProjectCopy("a", projects[0], view)),
-      dbTester.components().insertComponent(newProjectCopy("b", projects[1], subview1)),
-      dbTester.components().insertComponent(newProjectCopy("c", projects[2], subview2)));
+      db.components().insertComponent(newProjectCopy("a", projects[0], view)),
+      db.components().insertComponent(newProjectCopy("b", projects[1], subview1)),
+      db.components().insertComponent(newProjectCopy("c", projects[2], subview2)));
     Collections.shuffle(components);
 
     underTest.deleteNonRootComponentsInView(dbSession, components);
@@ -738,19 +760,19 @@ public class PurgeDaoTest {
   }
 
   private Stream<String> getUuidsInTableProjects() {
-    return dbTester.select("select uuid as \"UUID\" from projects").stream().map(row -> (String) row.get("UUID"));
+    return db.select("select uuid as \"UUID\" from projects").stream().map(row -> (String) row.get("UUID"));
   }
 
   @Test
   public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_PROJECTS() {
-    ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPublicProject() : dbTester.components().insertPrivateProject();
-    ComponentDto module1 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
-    ComponentDto module2 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(module1));
-    ComponentDto dir1 = dbTester.components().insertComponent(newDirectory(module1, "A/B"));
-    ComponentDto dir2 = dbTester.components().insertComponent(newDirectory(module2, "A/C"));
-    ComponentDto file1 = dbTester.components().insertComponent(newFileDto(dir1));
-    ComponentDto file2 = dbTester.components().insertComponent(newFileDto(module2));
-    ComponentDto file3 = dbTester.components().insertComponent(newFileDto(project));
+    ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject();
+    ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
+    ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
+    ComponentDto dir1 = db.components().insertComponent(newDirectory(module1, "A/B"));
+    ComponentDto dir2 = db.components().insertComponent(newDirectory(module2, "A/C"));
+    ComponentDto file1 = db.components().insertComponent(newFileDto(dir1));
+    ComponentDto file2 = db.components().insertComponent(newFileDto(module2));
+    ComponentDto file3 = db.components().insertComponent(newFileDto(project));
 
     underTest.deleteNonRootComponentsInView(dbSession, singletonList(file3));
     assertThat(getUuidsInTableProjects())
@@ -764,17 +786,17 @@ public class PurgeDaoTest {
   @Test
   public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_view_from_table_PROJECTS() {
     ComponentDto[] projects = {
-      dbTester.components().insertPrivateProject(),
-      dbTester.components().insertPrivateProject(),
-      dbTester.components().insertPrivateProject()
+      db.components().insertPrivateProject(),
+      db.components().insertPrivateProject(),
+      db.components().insertPrivateProject()
     };
 
-    ComponentDto view = dbTester.components().insertView();
-    ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
-    ComponentDto pc1 = dbTester.components().insertComponent(newProjectCopy("a", projects[0], view));
-    ComponentDto pc2 = dbTester.components().insertComponent(newProjectCopy("b", projects[1], subview1));
-    ComponentDto pc3 = dbTester.components().insertComponent(newProjectCopy("c", projects[2], subview2));
+    ComponentDto view = db.components().insertView();
+    ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
+    ComponentDto pc1 = db.components().insertComponent(newProjectCopy("a", projects[0], view));
+    ComponentDto pc2 = db.components().insertComponent(newProjectCopy("b", projects[1], subview1));
+    ComponentDto pc3 = db.components().insertComponent(newProjectCopy("c", projects[2], subview2));
 
     underTest.deleteNonRootComponentsInView(dbSession, singletonList(pc3));
     assertThat(getUuidsInTableProjects())
@@ -788,9 +810,9 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteNonRootComponents_deletes_measures_of_any_non_root_component_of_a_view() {
-    ComponentDto view = dbTester.components().insertView();
-    ComponentDto subview = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto pc = dbTester.components().insertComponent(newProjectCopy("a", dbTester.components().insertPrivateProject(), view));
+    ComponentDto view = db.components().insertView();
+    ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
     insertMeasureFor(view, subview, pc);
     assertThat(getComponentUuidsOfMeasures()).containsOnly(view.uuid(), subview.uuid(), pc.uuid());
 
@@ -805,11 +827,11 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteNonRootComponents_deletes_properties_of_subviews_of_a_view() {
-    ComponentDto view = dbTester.components().insertView();
-    ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
-    ComponentDto subview3 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto pc = dbTester.components().insertComponent(newProjectCopy("a", dbTester.components().insertPrivateProject(), view));
+    ComponentDto view = db.components().insertView();
+    ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
+    ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
     insertPropertyFor(view, subview1, subview2, subview3, pc);
     assertThat(getResourceIdOfProperties()).containsOnly(view.getId(), subview1.getId(), subview2.getId(), subview3.getId(), pc.getId());
 
@@ -824,11 +846,11 @@ public class PurgeDaoTest {
 
   @Test
   public void deleteNonRootComponentsInView_deletes_manual_measures_of_subviews_of_a_view() {
-    ComponentDto view = dbTester.components().insertView();
-    ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
-    ComponentDto subview3 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
-    ComponentDto pc = dbTester.components().insertComponent(newProjectCopy("a", dbTester.components().insertPrivateProject(), view));
+    ComponentDto view = db.components().insertView();
+    ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
+    ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view));
+    ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
     insertManualMeasureFor(view, subview1, subview2, subview3, pc);
     assertThat(getComponentUuidsOfManualMeasures()).containsOnly(view.uuid(), subview1.uuid(), subview2.uuid(), subview3.uuid(), pc.uuid());
 
@@ -849,29 +871,29 @@ public class PurgeDaoTest {
   }
 
   private Stream<String> getComponentUuidsOfManualMeasures() {
-    return dbTester.select("select component_uuid as \"COMPONENT_UUID\" from manual_measures").stream()
+    return db.select("select component_uuid as \"COMPONENT_UUID\" from manual_measures").stream()
       .map(row -> (String) row.get("COMPONENT_UUID"));
   }
 
   private Stream<Long> getResourceIdOfProperties() {
-    return dbTester.select("select resource_id as \"ID\" from properties").stream()
+    return db.select("select resource_id as \"ID\" from properties").stream()
       .map(row -> (Long) row.get("ID"));
   }
 
   private void insertPropertyFor(ComponentDto... components) {
-    Stream.of(components).forEach(componentDto -> dbTester.properties().insertProperty(new PropertyDto()
+    Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto()
       .setKey(randomAlphabetic(3))
       .setValue(randomAlphabetic(3))
       .setResourceId(componentDto.getId())));
   }
 
   private Stream<String> getComponentUuidsOfMeasures() {
-    return dbTester.select("select component_uuid as \"COMPONENT_UUID\" from project_measures").stream()
+    return db.select("select component_uuid as \"COMPONENT_UUID\" from project_measures").stream()
       .map(row -> (String) row.get("COMPONENT_UUID"));
   }
 
   private void insertMeasureFor(ComponentDto... components) {
-    Arrays.stream(components).forEach(componentDto -> dbTester.getDbClient().measureDao().insert(dbSession, new MeasureDto()
+    Arrays.stream(components).forEach(componentDto -> db.getDbClient().measureDao().insert(dbSession, new MeasureDto()
       .setMetricId(new Random().nextInt())
       .setComponentUuid(componentDto.uuid())
       .setAnalysisUuid(randomAlphabetic(3))));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDbTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDbTesting.java
deleted file mode 100644 (file)
index c883a87..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.webhook;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.math.RandomUtils.nextBoolean;
-import static org.apache.commons.lang.math.RandomUtils.nextInt;
-import static org.apache.commons.lang.math.RandomUtils.nextLong;
-
-public class WebhookDbTesting {
-
-  private WebhookDbTesting() {
-    // only statics
-  }
-
-  /**
-   * Build a {@link WebhookDeliveryDto} with all mandatory fields.
-   * Optional fields are kept null.
-   */
-  public static WebhookDeliveryDto newDto(String uuid, String webhookUuid, String componentUuid, String ceTaskUuid) {
-    return newDto()
-            .setUuid(uuid)
-            .setWebhookUuid(webhookUuid)
-            .setComponentUuid(componentUuid)
-            .setCeTaskUuid(ceTaskUuid);
-  }
-
-  public static WebhookDeliveryDto newDto() {
-    return new WebhookDeliveryDto()
-      .setUuid(randomAlphanumeric(40))
-      .setWebhookUuid(randomAlphanumeric(40))
-      .setComponentUuid(randomAlphanumeric(40))
-      .setCeTaskUuid(randomAlphanumeric(40))
-      .setAnalysisUuid(randomAlphanumeric(40))
-      .setName(randomAlphanumeric(10))
-      .setUrl(randomAlphanumeric(10))
-      .setDurationMs(nextInt())
-      .setHttpStatus(nextInt())
-      .setSuccess(nextBoolean())
-      .setPayload(randomAlphanumeric(10))
-      .setCreatedAt(nextLong());
-  }
-
-  public static List<String> selectAllDeliveryUuids(DbTester dbTester, DbSession dbSession) {
-    return dbTester.select(dbSession, "select uuid as \"uuid\" from webhook_deliveries")
-      .stream()
-      .map(columns -> (String)columns.get("uuid"))
-      .collect(Collectors.toList());
-  }
-}
index c3c83a7cb3a6147371d9ebd24d228fb9c22af7c7..1223d27001d6f287ffb8d501a63db6e6113780ce 100644 (file)
@@ -58,7 +58,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectOrderedByComponentUuid_returns_empty_if_no_records() {
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "ANOTHER_COMPONENT", 0, 10);
 
@@ -67,9 +67,9 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectOrderedByComponentUuid_returns_records_ordered_by_date() {
-    WebhookDeliveryDto dto1 = WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
-    WebhookDeliveryDto dto2 = WebhookDbTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
-    WebhookDeliveryDto dto3 = WebhookDbTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
+    WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
+    WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
+    WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
     underTest.insert(dbSession, dto3);
     underTest.insert(dbSession, dto2);
     underTest.insert(dbSession, dto1);
@@ -81,7 +81,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectOrderedByCeTaskUuid_returns_empty_if_no_records() {
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByCeTaskUuid(dbSession, "ANOTHER_TASK", 0, 10);
 
@@ -90,9 +90,9 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void selectOrderedByCeTaskUuid_returns_records_ordered_by_date() {
-    WebhookDeliveryDto dto1 = WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
-    WebhookDeliveryDto dto2 = WebhookDbTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
-    WebhookDeliveryDto dto3 = WebhookDbTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_2").setCreatedAt(NOW);
+    WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
+    WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
+    WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_2").setCreatedAt(NOW);
     underTest.insert(dbSession, dto3);
     underTest.insert(dbSession, dto2);
     underTest.insert(dbSession, dto1);
@@ -105,7 +105,7 @@ public class WebhookDeliveryDaoTest {
   @Test
   public void selectByWebhookUuid_returns_empty_if_no_records() {
 
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, "a-webhook-uuid", 0, 10);
 
@@ -115,9 +115,9 @@ public class WebhookDeliveryDaoTest {
   @Test
   public void selectByWebhookUuid_returns_records_ordered_by_date() {
     WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
-    WebhookDeliveryDto dto1 = WebhookDbTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
-    WebhookDeliveryDto dto2 = WebhookDbTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
-    WebhookDeliveryDto dto3 = WebhookDbTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
+    WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
+    WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
+    WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
     underTest.insert(dbSession, dto3);
     underTest.insert(dbSession, dto2);
     underTest.insert(dbSession, dto1);
@@ -130,12 +130,12 @@ public class WebhookDeliveryDaoTest {
   @Test
   public void selectByWebhookUuid_returns_records_according_to_pagination() {
     WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D4", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D5", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("D6", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D4", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D5", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D6", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, webhookDto.getUuid(), 2, 2);
 
@@ -145,12 +145,12 @@ public class WebhookDeliveryDaoTest {
   @Test
   public void selectLatestDelivery_of_a_webhook() {
     WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
     WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
 
     Map<String, WebhookDeliveryLiteDto> map = underTest.selectLatestDeliveries(dbSession, of(webhook1, webhook2));
 
@@ -163,7 +163,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void insert_row_with_only_mandatory_columns() {
-    WebhookDeliveryDto dto = WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
+    WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
       .setDurationMs(1000)
       .setHttpStatus(null)
       .setErrorStacktrace(null);
@@ -182,7 +182,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void insert_row_with_all_columns() {
-    WebhookDeliveryDto dto = WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
+    WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
 
     underTest.insert(dbSession, dto);
 
@@ -199,9 +199,9 @@ public class WebhookDeliveryDaoTest {
 
     WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
 
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
 
     underTest.deleteByWebhook(dbSession, webhookDto);
 
@@ -209,9 +209,9 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void deleteComponentBeforeDate_deletes_rows_before_date() {
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
 
     // should delete the old delivery on COMPONENT_1 and keep the one of COMPONENT_2
     underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_1", 1_500_000L);
@@ -229,7 +229,7 @@ public class WebhookDeliveryDaoTest {
 
   @Test
   public void deleteComponentBeforeDate_does_nothing_on_invalid_uuid() {
-    underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
 
     underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_2", 1_500_000L);
 
index d31d270018ed37b74cc108ee28660bec310ad79f..7bde2a4612160a47a3923915c2d618d2088bab6b 100644 (file)
  */
 package org.sonar.db.webhook;
 
-import org.sonar.db.DbSession;
+import java.util.Objects;
+import java.util.function.Consumer;
 import org.sonar.db.DbTester;
 
+import static java.util.Arrays.stream;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
+
 public class WebhookDeliveryDbTester {
 
   private final DbTester dbTester;
@@ -31,9 +35,29 @@ public class WebhookDeliveryDbTester {
   }
 
   public WebhookDeliveryLiteDto insert(WebhookDeliveryDto dto) {
-    DbSession dbSession = dbTester.getSession();
-    dbTester.getDbClient().webhookDeliveryDao().insert(dbSession, dto);
-    dbSession.commit();
+    dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
+    dbTester.getSession().commit();
+    return dto;
+  }
+
+  @SafeVarargs
+  public final WebhookDeliveryLiteDto insert(Consumer<WebhookDeliveryDto>... dtoPopulators) {
+    WebhookDeliveryDto dto = newDto();
+    stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(dto));
+    dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
+    dbTester.getSession().commit();
+    return dto;
+  }
+
+  @SafeVarargs
+  public final WebhookDeliveryLiteDto insert(WebhookDto webhook, Consumer<WebhookDeliveryDto>... dtoPopulators) {
+    WebhookDeliveryDto dto = newDto();
+    stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(dto));
+    String projectUuid = webhook.getProjectUuid();
+    dto.setComponentUuid(Objects.requireNonNull(projectUuid, "Project uuid of webhook cannot be null"));
+    dto.setWebhookUuid(webhook.getUuid());
+    dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
+    dbTester.getSession().commit();
     return dto;
   }
 
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryTesting.java
new file mode 100644 (file)
index 0000000..fbe67d5
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.webhook;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.apache.commons.lang.math.RandomUtils.nextBoolean;
+import static org.apache.commons.lang.math.RandomUtils.nextInt;
+import static org.apache.commons.lang.math.RandomUtils.nextLong;
+
+public class WebhookDeliveryTesting {
+
+  private WebhookDeliveryTesting() {
+    // only statics
+  }
+
+  /**
+   * Build a {@link WebhookDeliveryDto} with all mandatory fields.
+   * Optional fields are kept null.
+   */
+  public static WebhookDeliveryDto newDto(String uuid, String webhookUuid, String componentUuid, String ceTaskUuid) {
+    return newDto()
+      .setUuid(uuid)
+      .setWebhookUuid(webhookUuid)
+      .setComponentUuid(componentUuid)
+      .setCeTaskUuid(ceTaskUuid);
+  }
+
+  public static WebhookDeliveryDto newDto() {
+    return new WebhookDeliveryDto()
+      .setUuid(Uuids.createFast())
+      .setWebhookUuid(randomAlphanumeric(40))
+      .setComponentUuid(randomAlphanumeric(40))
+      .setCeTaskUuid(randomAlphanumeric(40))
+      .setAnalysisUuid(randomAlphanumeric(40))
+      .setName(randomAlphanumeric(10))
+      .setUrl(randomAlphanumeric(10))
+      .setDurationMs(nextInt())
+      .setHttpStatus(nextInt())
+      .setSuccess(nextBoolean())
+      .setPayload(randomAlphanumeric(10))
+      .setCreatedAt(nextLong());
+  }
+
+  public static List<String> selectAllDeliveryUuids(DbTester dbTester, DbSession dbSession) {
+    return dbTester.select(dbSession, "select uuid as \"uuid\" from webhook_deliveries")
+      .stream()
+      .map(columns -> (String) columns.get("uuid"))
+      .collect(Collectors.toList());
+  }
+}
index 7273b947c86f6305394fadad6af48741a982daef..f90edd08d8f2f896f0f15f830fbea91140b8e3ea 100644 (file)
@@ -28,13 +28,13 @@ import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.webhook.WebhookDbTesting;
 import org.sonar.db.webhook.WebhookDeliveryDto;
+import org.sonar.db.webhook.WebhookDeliveryTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.db.webhook.WebhookDbTesting.selectAllDeliveryUuids;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.selectAllDeliveryUuids;
 
 public class WebhookDeliveryStorageTest {
 
@@ -111,7 +111,7 @@ public class WebhookDeliveryStorageTest {
   }
 
   private static WebhookDeliveryDto newDto(String uuid, String componentUuid, long at) {
-    return WebhookDbTesting.newDto()
+    return WebhookDeliveryTesting.newDto()
       .setUuid(uuid)
       .setComponentUuid(componentUuid)
       .setCreatedAt(at);
index a6662676dec5c6e6064d3d32d3fc20d1c512a041..6766c3f99e1757e41266adc0d1c8b3f421d04eb7 100644 (file)
@@ -27,11 +27,11 @@ import org.sonar.api.server.ServerSide;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.server.es.ProjectIndexer;
 import org.sonar.server.es.ProjectIndexers;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Collections.singletonList;
+import static org.sonar.server.es.ProjectIndexer.Cause.PROJECT_DELETION;
 
 @ServerSide
 public class ComponentCleanerService {
@@ -55,17 +55,14 @@ public class ComponentCleanerService {
   public void deleteBranch(DbSession dbSession, ComponentDto branch) {
     // TODO: detect if other branches depend on it?
     dbClient.purgeDao().deleteBranch(dbSession, branch.uuid());
-    projectIndexers.commitAndIndex(dbSession, singletonList(branch), ProjectIndexer.Cause.PROJECT_DELETION);
+    projectIndexers.commitAndIndex(dbSession, singletonList(branch), PROJECT_DELETION);
   }
 
   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);
-    dbClient.webhookDao().selectByProject(dbSession, project)
-      .forEach(wh -> dbClient.webhookDeliveryDao().deleteByWebhook(dbSession, wh));
-    dbClient.webhookDao().deleteByProject(dbSession, project);
-    projectIndexers.commitAndIndex(dbSession, singletonList(project), ProjectIndexer.Cause.PROJECT_DELETION);
+    projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_DELETION);
   }
 
   private static boolean hasNotProjectScope(ComponentDto project) {
index 446642308d3a75096f11859b7ac75bf05b1ab15b..57f5f96696a369a2e0f28fa7f65811c1b693a226 100644 (file)
@@ -129,9 +129,6 @@ public class DeleteAction implements OrganizationsWsAction {
 
   private void deleteProjects(DbSession dbSession, OrganizationDto organization) {
     List<ComponentDto> roots = dbClient.componentDao().selectAllRootsByOrganization(dbSession, organization.getUuid());
-    roots.forEach(project -> dbClient.webhookDao().selectByProject(dbSession, project)
-      .forEach(wh -> dbClient.webhookDeliveryDao().deleteByWebhook(dbSession, wh)));
-    roots.forEach(project -> dbClient.webhookDao().deleteByProject(dbSession, project));
     try {
       componentCleanerService.delete(dbSession, roots);
     } finally {
index bd2a8b0a69ff93f697026740ef176353a3a18fc6..bc40e7fc62b044e02233600630f2426be3b5261d 100644 (file)
  */
 package org.sonar.server.component;
 
-import java.util.Date;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypes;
-import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -33,11 +31,10 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.component.SnapshotTesting;
 import org.sonar.db.issue.IssueDto;
-import org.sonar.db.issue.IssueTesting;
+import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.rule.RuleDefinitionDto;
-import org.sonar.db.rule.RuleTesting;
+import org.sonar.db.webhook.WebhookDto;
 import org.sonar.server.es.TestProjectIndexers;
 
 import static java.util.Arrays.asList;
@@ -46,7 +43,6 @@ import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.server.es.ProjectIndexer.Cause.PROJECT_DELETION;
 
 public class ComponentCleanerServiceTest {
@@ -67,8 +63,8 @@ public class ComponentCleanerServiceTest {
 
   @Test
   public void delete_project_from_db_and_index() {
-    DbData data1 = insertData(1);
-    DbData data2 = insertData(2);
+    DbData data1 = insertData();
+    DbData data2 = insertData();
 
     underTest.delete(dbSession, data1.project);
 
@@ -78,9 +74,9 @@ public class ComponentCleanerServiceTest {
 
   @Test
   public void delete_list_of_projects_from_db_and_index() {
-    DbData data1 = insertData(1);
-    DbData data2 = insertData(2);
-    DbData data3 = insertData(3);
+    DbData data1 = insertData();
+    DbData data2 = insertData();
+    DbData data3 = insertData();
 
     underTest.delete(dbSession, asList(data1.project, data2.project));
     dbSession.commit();
@@ -92,9 +88,9 @@ public class ComponentCleanerServiceTest {
 
   @Test
   public void delete_branch() {
-    DbData data1 = insertData(1);
-    DbData data2 = insertData(2);
-    DbData data3 = insertData(3);
+    DbData data1 = insertData();
+    DbData data2 = insertData();
+    DbData data3 = insertData();
 
     underTest.deleteBranch(dbSession, data1.project);
     dbSession.commit();
@@ -104,6 +100,26 @@ public class ComponentCleanerServiceTest {
     assertExists(data3);
   }
 
+  @Test
+  public void delete_webhooks_from_projects() {
+    OrganizationDto organization = db.organizations().insert();
+    ComponentDto project1 = db.components().insertPrivateProject(organization);
+    WebhookDto webhook1 = db.webhooks().insertWebhook(project1);
+    db.webhookDelivery().insert(webhook1);
+    ComponentDto project2 = db.components().insertPrivateProject(organization);
+    WebhookDto webhook2 = db.webhooks().insertWebhook(project2);
+    db.webhookDelivery().insert(webhook2);
+    ComponentDto projectNotToBeDeleted = db.components().insertPrivateProject(organization);
+    WebhookDto webhook3 = db.webhooks().insertWebhook(projectNotToBeDeleted);
+    db.webhookDelivery().insert(webhook3);
+    mockResourceTypeAsValidProject();
+
+    underTest.delete(dbSession, asList(project1, project2));
+
+    assertThat(db.countRowsOfTable(db.getSession(), "webhooks")).isEqualTo(1);
+    assertThat(db.countRowsOfTable(db.getSession(), "webhook_deliveries")).isEqualTo(1);
+  }
+
   @Test
   public void fail_with_IAE_if_not_a_project() {
     mockResourceTypeAsValidProject();
@@ -151,19 +167,14 @@ public class ComponentCleanerServiceTest {
     underTest.delete(dbSession, branch);
   }
 
-  private DbData insertData(int id) {
-    String suffix = String.valueOf(id);
-    ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid-" + suffix)
-      .setDbKey("project-key-" + suffix);
-    RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("sonarqube", "rule-" + suffix));
-    dbClient.ruleDao().insert(dbSession, rule);
-    IssueDto issue = IssueTesting.newIssue(rule, project, project).setKee("issue-key-" + suffix).setUpdatedAt(new Date().getTime());
-    dbClient.componentDao().insert(dbSession, project);
-    SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, SnapshotTesting.newAnalysis(project));
-    dbClient.issueDao().insert(dbSession, issue);
-    dbSession.commit();
+  private DbData insertData() {
+    OrganizationDto organization = db.organizations().insert();
+    ComponentDto project = db.components().insertPrivateProject(organization);
+    RuleDefinitionDto rule = db.rules().insert();
+    IssueDto issue = db.issues().insert(rule, project, project);
+    SnapshotDto analysis = db.components().insertSnapshot(project);
     mockResourceTypeAsValidProject();
-    return new DbData(project, snapshot, issue);
+    return new DbData(project, analysis, issue);
   }
 
   private void mockResourceTypeAsValidProject() {
index 5790c4e44f9ea326b9e669a461bdefc09c762f2c..e78a9e140bb5e38e0f0298620a9dadc34978ade8 100644 (file)
@@ -24,7 +24,6 @@ import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Random;
 import java.util.Set;
 import java.util.stream.IntStream;
@@ -93,7 +92,6 @@ import static org.sonar.api.resources.Qualifiers.VIEW;
 import static org.sonar.core.util.stream.MoreCollectors.toSet;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
 import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_ORGANIZATION;
 
 @RunWith(DataProviderRunner.class)
@@ -148,24 +146,18 @@ public class DeleteActionTest {
   @Test
   public void organization_deletion_also_ensure_that_webhooks_of_this_organization_if_they_exist_are_cleared() {
     OrganizationDto organization = db.organizations().insert();
-    webhookDbTester.insertWebhook(organization);
-    webhookDbTester.insertWebhook(organization);
-    WebhookDto dto = webhookDbTester.insertWebhook(organization);
-    webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
-    webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
-
+    db.webhooks().insertWebhook(organization);
+    ComponentDto project = db.components().insertPrivateProject(organization);
+    WebhookDto projectWebhook = db.webhooks().insertWebhook(project);
+    db.webhookDelivery().insert(projectWebhook);
     userSession.logIn().addPermission(ADMINISTER, organization);
 
     wsTester.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
-    List<WebhookDto> webhookDtos = dbClient.webhookDao().selectByOrganization(dbSession, organization);
-    assertThat(webhookDtos).isEmpty();
-
-    int deliveriesCount = deliveryDao.countDeliveriesByWebhookUuid(dbSession, dto.getUuid());
-    assertThat(deliveriesCount).isEqualTo(0);
-
+    assertThat(db.countRowsOfTable(db.getSession(), "webhooks")).isZero();
+    assertThat(db.countRowsOfTable(db.getSession(), "webhook_deliveries")).isZero();
   }
 
   @Test
@@ -383,7 +375,7 @@ public class DeleteActionTest {
 
   @DataProvider
   public static Object[][] OneOrMoreIterations() {
-    return new Object[][]{
+    return new Object[][] {
       {1},
       {1 + new Random().nextInt(10)},
     };
@@ -527,7 +519,7 @@ public class DeleteActionTest {
   @UseDataProvider("indexOfFailingProjectDeletion")
   public void projectLifeCycleListener_are_notified_even_if_deletion_of_a_project_throws_an_Exception(int failingProjectIndex) {
     OrganizationDto organization = db.organizations().insert();
-    ComponentDto[] projects = new ComponentDto[]{
+    ComponentDto[] projects = new ComponentDto[] {
       db.components().insertPrivateProject(organization),
       db.components().insertPrivateProject(organization),
       db.components().insertPrivateProject(organization)
@@ -558,7 +550,7 @@ public class DeleteActionTest {
 
   @DataProvider
   public static Object[][] indexOfFailingProjectDeletion() {
-    return new Object[][]{
+    return new Object[][] {
       {0},
       {1},
       {2}
index 429f2bcb536aaba644b8b0fa097c5d6d0e7e9eed..d2c15a8a6fb8a78fa07391a8381fc3eca57e3f14 100644 (file)
@@ -50,7 +50,7 @@ import static org.junit.rules.ExpectedException.none;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.db.DbTester.create;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
 import static org.sonar.server.organization.TestDefaultOrganizationProvider.from;
 import static org.sonar.server.tester.UserSessionRule.standalone;
 import static org.sonar.server.webhook.ws.WebhooksWsParameters.KEY_PARAM;
index 0a6505d2f143d35a66e9f33a59b89212850c49d2..04dd941d7e7a06462e5db3b42c59dd251ee15689 100644 (file)
@@ -50,7 +50,7 @@ import static org.junit.rules.ExpectedException.none;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.db.DbTester.create;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
 import static org.sonar.db.webhook.WebhookTesting.newOrganizationWebhook;
 import static org.sonar.server.organization.TestDefaultOrganizationProvider.from;
 import static org.sonar.server.tester.UserSessionRule.standalone;
index 4637386f5be766f2b3007554caec1bdd7f8458cd..fa6a72a822ee38cfd8a016895245befd8279ae20 100644 (file)
@@ -41,7 +41,7 @@ import org.sonarqube.ws.Webhooks;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class WebhookDeliveriesActionTest {
index 2beed1e2723d952e43d1abf685088b67c79d9048..7aeaaf7b580f799c6216e92b2d2a2f314e415c4d 100644 (file)
@@ -42,7 +42,7 @@ import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.Webhooks;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class WebhookDeliveryActionTest {