]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19556 updated webhooks to not rely on component_uuid
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Thu, 22 Jun 2023 10:16:00 +0000 (12:16 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 22 Jun 2023 20:02:53 +0000 (20:02 +0000)
35 files changed:
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/webhook/WebhookDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/webhook/WebhookDeliveryDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDeliveryDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDeliveryDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDeliveryLiteDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDeliveryMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/webhook/WebhookDeliveryMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryTesting.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveries.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveries.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveries.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/RenameVarcharColumnAbstractTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveriesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveriesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/it/java/org/sonar/server/webhook/WebhookDeliveryStorageIT.java
server/sonar-server-common/src/main/java/org/sonar/server/webhook/Webhook.java
server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookDeliveryStorage.java
server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/webhook/ws/CreateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/webhook/ws/DeleteActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/webhook/ws/ListActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/webhook/ws/UpdateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/webhook/ws/WebhookDeliveryActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveriesAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveryAction.java

index 36562a4257003591a176ba42de173ae5e4a20202..ed9bfdc128954a2d79f474fb93e25593b9f54fc1 100644 (file)
@@ -1446,8 +1446,8 @@ public class PurgeDaoIT {
   @Test
   public void deleteProject_deletes_webhook_deliveries() {
     ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    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"));
+    dbClient.webhookDeliveryDao().insert(dbSession, newDto().setProjectUuid(project.uuid()).setUuid("D1").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
+    dbClient.webhookDeliveryDao().insert(dbSession, newDto().setProjectUuid("P2").setUuid("D2").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
 
     underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
 
index d957f15bb4e3b26547a0fe7251adc1b697f32570..bdaf37fb2e624530a0f0fac445451a943c1de5d3 100644 (file)
@@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class WebhookDaoIT {
 
   @Rule
-  public final DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private final System2 system2 = System2.INSTANCE;
   private final DbClient dbClient = dbTester.getDbClient();
index 84bb7cb39c91e8718eefd024a69869eb18c159d7..ac9abf2081958ea54ede9a53c113d54c26a27e81 100644 (file)
@@ -39,8 +39,7 @@ public class WebhookDeliveryDaoIT {
   private static final long BEFORE = NOW - 1_000L;
 
   @Rule
-  public final DbTester dbTester = DbTester.create(System2.INSTANCE);
-
+  public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
 
   private final DbClient dbClient = dbTester.getDbClient();
   private final DbSession dbSession = dbTester.getSession();
@@ -55,30 +54,30 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void selectOrderedByComponentUuid_returns_empty_if_no_records() {
-    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1"));
 
-    List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "ANOTHER_COMPONENT", 0, 10);
+    List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByProjectUuid(dbSession, "ANOTHER_PROJECT", 0, 10);
 
     assertThat(deliveries).isEmpty();
   }
 
   @Test
   public void selectOrderedByComponentUuid_returns_records_ordered_by_date() {
-    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);
+    WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(BEFORE);
+    WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(NOW);
+    WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "PROJECT_2", "TASK_1").setCreatedAt(NOW);
     underTest.insert(dbSession, dto3);
     underTest.insert(dbSession, dto2);
     underTest.insert(dbSession, dto1);
 
-    List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "COMPONENT_1", 0, 10);
+    List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByProjectUuid(dbSession, "PROJECT_1", 0, 10);
 
     assertThat(deliveries).extracting(WebhookDeliveryLiteDto::getUuid).containsExactly("D2", "D1");
   }
 
   @Test
   public void selectOrderedByCeTaskUuid_returns_empty_if_no_records() {
-    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1"));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByCeTaskUuid(dbSession, "ANOTHER_TASK", 0, 10);
 
@@ -87,9 +86,9 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void selectOrderedByCeTaskUuid_returns_records_ordered_by_date() {
-    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);
+    WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(BEFORE);
+    WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(NOW);
+    WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "PROJECT_2", "TASK_2").setCreatedAt(NOW);
     underTest.insert(dbSession, dto3);
     underTest.insert(dbSession, dto2);
     underTest.insert(dbSession, dto1);
@@ -102,7 +101,7 @@ public class WebhookDeliveryDaoIT {
   @Test
   public void selectByWebhookUuid_returns_empty_if_no_records() {
 
-    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1"));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, "a-webhook-uuid", 0, 10);
 
@@ -111,10 +110,10 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void selectByWebhookUuid_returns_records_ordered_by_date() {
-    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
-    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);
+    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+    WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(BEFORE);
+    WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW);
+    WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "PROJECT_2", "TASK_1").setCreatedAt(NOW);
     underTest.insert(dbSession, dto3);
     underTest.insert(dbSession, dto2);
     underTest.insert(dbSession, dto1);
@@ -126,13 +125,13 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void selectByWebhookUuid_returns_records_according_to_pagination() {
-    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
-    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));
+    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D4", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D5", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D6", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW));
 
     List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, webhookDto.getUuid(), 2, 2);
 
@@ -141,13 +140,13 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void selectLatestDelivery_of_a_webhook() {
-    WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
-    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 webhook1 = dbWebhooks.insert(newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(BEFORE));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW));
 
-    WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
-    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));
+    WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(BEFORE));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW));
 
     Map<String, WebhookDeliveryLiteDto> map = underTest.selectLatestDeliveries(dbSession, of(webhook1, webhook2));
 
@@ -160,7 +159,7 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void insert_row_with_only_mandatory_columns() {
-    WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
+    WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1")
       .setDurationMs(1000)
       .setHttpStatus(null)
       .setErrorStacktrace(null);
@@ -179,7 +178,7 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void insert_row_with_all_columns() {
-    WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
+    WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1");
 
     underTest.insert(dbSession, dto);
 
@@ -194,11 +193,11 @@ public class WebhookDeliveryDaoIT {
   @Test
   public void deleteByWebhook() {
 
-    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
+    WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
 
-    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.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(2_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "PROJECT_2", "TASK_3").setCreatedAt(1_000_000L));
 
     underTest.deleteByWebhook(dbSession, webhookDto);
 
@@ -207,12 +206,12 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void deleteComponentBeforeDate_deletes_rows_before_date() {
-    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));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_2").setCreatedAt(2_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "PROJECT_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);
+    // should delete the old delivery on PROJECT_1 and keep the one of PROJECT_2
+    underTest.deleteProjectBeforeDate(dbSession, "PROJECT_1", 1_500_000L);
 
     List<Map<String, Object>> uuids = dbTester.select(dbSession, "select uuid as \"uuid\" from webhook_deliveries");
     assertThat(uuids).extracting(column -> column.get("uuid")).containsOnly("DELIVERY_2", "DELIVERY_3");
@@ -220,23 +219,23 @@ public class WebhookDeliveryDaoIT {
 
   @Test
   public void deleteComponentBeforeDate_does_nothing_on_empty_table() {
-    underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_1", 1_500_000L);
+    underTest.deleteProjectBeforeDate(dbSession, "PROJECT_1", 1_500_000L);
 
     assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isZero();
   }
 
   @Test
   public void deleteComponentBeforeDate_does_nothing_on_invalid_uuid() {
-    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+    underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(1_000_000L));
 
-    underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_2", 1_500_000L);
+    underTest.deleteProjectBeforeDate(dbSession, "PROJECT_2", 1_500_000L);
 
     assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isOne();
   }
 
   private void verifyMandatoryFields(WebhookDeliveryDto expected, WebhookDeliveryDto actual) {
     assertThat(actual.getUuid()).isEqualTo(expected.getUuid());
-    assertThat(actual.getComponentUuid()).isEqualTo(expected.getComponentUuid());
+    assertThat(actual.getProjectUuid()).isEqualTo(expected.getProjectUuid());
     assertThat(actual.getCeTaskUuid()).isEqualTo(expected.getCeTaskUuid());
     assertThat(actual.getName()).isEqualTo(expected.getName());
     assertThat(actual.getUrl()).isEqualTo(expected.getUrl());
index bba30ed17656f186aa24301911db99d79f201e7d..d71ab8370c8529dba548da923c2826860705c3f0 100644 (file)
@@ -46,15 +46,15 @@ public class WebhookDeliveryDao implements Dao {
     return mapper(dbSession).selectByWebhookUuid(webhookUuid, new RowBounds(offset, limit));
   }
 
-  public int countDeliveriesByComponentUuid(DbSession dbSession, String componentUuid) {
-    return mapper(dbSession).countByComponentUuid(componentUuid);
+  public int countDeliveriesByProjectUuid(DbSession dbSession, String projectUuid) {
+    return mapper(dbSession).countByProjectUuid(projectUuid);
   }
 
   /**
-   * All the deliveries for the specified component. Results are ordered by descending date.
+   * All the deliveries for the specified project. Results are ordered by descending date.
    */
-  public List<WebhookDeliveryLiteDto> selectOrderedByComponentUuid(DbSession dbSession, String componentUuid, int offset, int limit) {
-    return mapper(dbSession).selectOrderedByComponentUuid(componentUuid, new RowBounds(offset, limit));
+  public List<WebhookDeliveryLiteDto> selectOrderedByProjectUuid(DbSession dbSession, String projectUuid, int offset, int limit) {
+    return mapper(dbSession).selectOrderedByProjectUuid(projectUuid, new RowBounds(offset, limit));
   }
 
   public int countDeliveriesByCeTaskUuid(DbSession dbSession, String ceTaskId) {
@@ -72,8 +72,8 @@ public class WebhookDeliveryDao implements Dao {
     mapper(dbSession).insert(dto);
   }
 
-  public void deleteComponentBeforeDate(DbSession dbSession, String componentUuid, long beforeDate) {
-    mapper(dbSession).deleteComponentBeforeDate(componentUuid, beforeDate);
+  public void deleteProjectBeforeDate(DbSession dbSession, String projectUuid, long beforeDate) {
+    mapper(dbSession).deleteProjectBeforeDate(projectUuid, beforeDate);
   }
 
   public Map<String, WebhookDeliveryLiteDto> selectLatestDeliveries(DbSession dbSession, List<WebhookDto> webhooks) {
index babab6315cdbec60432bb0ef3bf664bd30d677bd..0f212cfa83ccb3b84e5d02b37706e1048cd13c9b 100644 (file)
@@ -52,7 +52,7 @@ public class WebhookDeliveryDto extends WebhookDeliveryLiteDto<WebhookDeliveryDt
   public String toString() {
     return new ToStringBuilder(this)
       .append("uuid", uuid)
-      .append("componentUuid", componentUuid)
+      .append("projectUuid", projectUuid)
       .append("name", name)
       .append("success", success)
       .append("httpStatus", httpStatus)
index 9a586d9046db6c019dbf342a9ec26008b5cda2bf..97ba4cf8fd506a0a66dfb9bdd0554700547841e2 100644 (file)
@@ -28,8 +28,8 @@ public class WebhookDeliveryLiteDto<T extends WebhookDeliveryLiteDto> {
   protected String uuid;
   /** Technical unique identifier, can be null for migration */
   protected String webhookUuid;
-  /** Component UUID, can't be null */
-  protected String componentUuid;
+  /** Project UUID, can't be null */
+  protected String projectUuid;
   /** Compute Engine task UUID, can be null */
   protected String ceTaskUuid;
   /** analysis UUID, can be null */
@@ -64,12 +64,12 @@ public class WebhookDeliveryLiteDto<T extends WebhookDeliveryLiteDto> {
     return (T) this;
   }
 
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getProjectUuid() {
+    return projectUuid;
   }
 
-  public T setComponentUuid(String s) {
-    this.componentUuid = s;
+  public T setProjectUuid(String s) {
+    this.projectUuid = s;
     return (T) this;
   }
 
@@ -153,7 +153,7 @@ public class WebhookDeliveryLiteDto<T extends WebhookDeliveryLiteDto> {
   public String toString() {
     return new ToStringBuilder(this)
       .append("uuid", uuid)
-      .append("componentUuid", componentUuid)
+      .append("componentUuid", projectUuid)
       .append("ceTaskUuid", ceTaskUuid)
       .append("name", name)
       .append("success", success)
index a19ef41fde06b2a14a7e423dd78cbd4ad8810467..66f4dead9831e0171393613405b8f58ec3958877 100644 (file)
@@ -33,9 +33,9 @@ public interface WebhookDeliveryMapper {
 
   List<WebhookDeliveryLiteDto> selectByWebhookUuid(@Param("webhookUuid") String webhookUuid, RowBounds rowBounds);
 
-  int countByComponentUuid(@Param("componentUuid") String componentUuid);
+  int countByProjectUuid(@Param("projectUuid") String projectUuid);
 
-  List<WebhookDeliveryLiteDto> selectOrderedByComponentUuid(@Param("componentUuid") String componentUuid, RowBounds rowBounds);
+  List<WebhookDeliveryLiteDto> selectOrderedByProjectUuid(@Param("projectUuid") String projectUuid, RowBounds rowBounds);
 
   int countByCeTaskUuid(@Param("ceTaskUuid") String ceTaskId);
 
@@ -43,7 +43,7 @@ public interface WebhookDeliveryMapper {
 
   void insert(WebhookDeliveryDto dto);
 
-  void deleteComponentBeforeDate(@Param("componentUuid") String componentUuid, @Param("beforeDate") long beforeDate);
+  void deleteProjectBeforeDate(@Param("projectUuid") String projectUuid, @Param("beforeDate") long beforeDate);
 
   void deleteByWebhookUuid(@Param("webhookUuid") String webhookUuid);
 }
index 03a38b3e3f51b136fed25a7f8a999140d3106d77..c4c8bd4b96f0480c07c64dc93a12494b3c4c2eb2 100644 (file)
   </delete>
 
   <delete id="deleteWebhookDeliveriesByProjectUuid">
-    delete from webhook_deliveries where component_uuid=#{projectUuid,jdbcType=VARCHAR}
+    delete from webhook_deliveries where project_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteProjectAlmSettingsByProjectUuid">
index 94af29d28f3a0bd0d87aea9d281e6d553a3fc077..cbb17b6a747263b22c53cb21ecfc0bb40ee65d54 100644 (file)
@@ -6,7 +6,7 @@
 
   <sql id="sqlLiteColumns">
     uuid,
-    component_uuid as componentUuid,
+    project_uuid as projectUuid,
     webhook_uuid as webhookUuid,
     ce_task_uuid as ceTaskUuid,
     name,
     order by created_at desc
   </select>
 
-  <select id="countByComponentUuid" parameterType="String" resultType="int">
+  <select id="countByProjectUuid" parameterType="String" resultType="int">
     select
     count(1)
     from webhook_deliveries
-    where component_uuid = #{componentUuid,jdbcType=VARCHAR}
+    where project_uuid = #{projectUuid,jdbcType=VARCHAR}
   </select>
 
-  <select id="selectOrderedByComponentUuid" parameterType="String" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
+  <select id="selectOrderedByProjectUuid" parameterType="String" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
     select <include refid="sqlLiteColumns" />
     from webhook_deliveries
-    where component_uuid = #{componentUuid,jdbcType=VARCHAR}
+    where project_uuid = #{projectUuid,jdbcType=VARCHAR}
     order by created_at desc
   </select>
 
@@ -72,7 +72,7 @@
     insert into webhook_deliveries (
     uuid,
     webhook_uuid,
-    component_uuid,
+    project_uuid,
     ce_task_uuid,
     analysis_uuid,
     name,
@@ -86,7 +86,7 @@
     ) values (
     #{uuid,jdbcType=VARCHAR},
     #{webhookUuid,jdbcType=VARCHAR},
-    #{componentUuid,jdbcType=VARCHAR},
+    #{projectUuid,jdbcType=VARCHAR},
     #{ceTaskUuid,jdbcType=VARCHAR},
     #{analysisUuid,jdbcType=VARCHAR},
     #{name,jdbcType=VARCHAR},
     where webhook_uuid = #{webhookUuid,jdbcType=VARCHAR}
   </select>
 
-  <delete id="deleteComponentBeforeDate" parameterType="map">
+  <delete id="deleteProjectBeforeDate" parameterType="map">
     delete from webhook_deliveries
     where
-    component_uuid = #{componentUuid,jdbcType=VARCHAR} and
+    project_uuid = #{projectUuid,jdbcType=VARCHAR} and
     created_at &lt; #{beforeDate,jdbcType=BIGINT}
   </delete>
 </mapper>
index e66274ae90c96ba82b8c0ffd0a574d2ea314ea4b..7188c4d8c2efe8a9aac80c4f51845045c2e9a471 100644 (file)
@@ -1047,7 +1047,7 @@ CREATE INDEX "USERS_EMAIL" ON "USERS"("EMAIL" NULLS FIRST);
 CREATE TABLE "WEBHOOK_DELIVERIES"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
-    "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL,
+    "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
     "CE_TASK_UUID" CHARACTER VARYING(40),
     "ANALYSIS_UUID" CHARACTER VARYING(40),
     "NAME" CHARACTER VARYING(100) NOT NULL,
@@ -1060,9 +1060,9 @@ CREATE TABLE "WEBHOOK_DELIVERIES"(
     "CREATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
-CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES"("COMPONENT_UUID" NULLS FIRST);
 CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
 CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
+CREATE INDEX "WD_PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST);
 
 CREATE TABLE "WEBHOOKS"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
index 036872b5be8d02a8dc580cd5649d34da440c8a68..59d8de1651f2454cd56ab446ea903b6de65c59e4 100644 (file)
@@ -54,7 +54,7 @@ public class WebhookDeliveryDbTester {
     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.setProjectUuid(Objects.requireNonNull(projectUuid, "Project uuid of webhook cannot be null"));
     dto.setWebhookUuid(webhook.getUuid());
     dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
     dbTester.getSession().commit();
index ae149ffefc93435b12941bfa1b5bdf409f378fb7..3df5dae99362c1a311d0fad496376fd3e44663ed 100644 (file)
@@ -39,11 +39,11 @@ public class WebhookDeliveryTesting {
    * 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) {
+  public static WebhookDeliveryDto newDto(String uuid, String webhookUuid, String projectUuid, String ceTaskUuid) {
     return newDto()
       .setUuid(uuid)
       .setWebhookUuid(webhookUuid)
-      .setComponentUuid(componentUuid)
+      .setProjectUuid(projectUuid)
       .setCeTaskUuid(ceTaskUuid);
   }
 
@@ -51,7 +51,7 @@ public class WebhookDeliveryTesting {
     return new WebhookDeliveryDto()
       .setUuid(Uuids.createFast())
       .setWebhookUuid(randomAlphanumeric(40))
-      .setComponentUuid(randomAlphanumeric(40))
+      .setProjectUuid(randomAlphanumeric(40))
       .setCeTaskUuid(randomAlphanumeric(40))
       .setAnalysisUuid(randomAlphanumeric(40))
       .setName(randomAlphanumeric(10))
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveries.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveries.java
new file mode 100644 (file)
index 0000000..cadc8fa
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
+
+public class CreateIndexProjectUuidInWebhookDeliveries extends CreateIndexOnColumn {
+
+  private static final String TABLE_NAME = "webhook_deliveries";
+  private static final String COLUMN_NAME = "project_uuid";
+
+  public CreateIndexProjectUuidInWebhookDeliveries(Database db) {
+    super(db, TABLE_NAME, COLUMN_NAME, false);
+  }
+
+  /**
+   * There is a limit of 30 characters for index name, that's why this one has a different name
+   */
+  @Override
+  public String newIndexName() {
+    return "wd_" + COLUMN_NAME;
+  }
+}
index 55331e975c1995ad587b9b036f62cceea0a3294b..95d4e5aab62effceb604dd6b73579856ebe7d8e3 100644 (file)
@@ -62,6 +62,12 @@ public class DbVersion102 implements DbVersion {
 
       .add(10_2_013, "Drop index on 'components.main_branch_project_uuid", DropIndexOnMainBranchProjectUuid.class)
       .add(10_2_014, "Drop column 'main_branch_project_uuid' in the components table", DropMainBranchProjectUuidInComponents.class)
+
+      .add(10_2_015, "Drop index 'component_uuid' in 'webhook_deliveries' table", DropIndexComponentUuidInWebhookDeliveries.class)
+      .add(10_2_016, "Rename 'component_uuid' in 'webhook_deliveries' table to 'project_uuid'", RenameComponentUuidInWebhookDeliveries.class)
+      .add(10_2_017, "Create index 'webhook_deliveries_project_uuid' in 'webhook_deliveries' table", CreateIndexProjectUuidInWebhookDeliveries.class)
+
     ;
   }
+
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveries.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveries.java
new file mode 100644 (file)
index 0000000..dbbeedc
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropIndexChange;
+
+public class DropIndexComponentUuidInWebhookDeliveries extends DropIndexChange {
+
+  private static final String TABLE_NAME = "webhook_deliveries";
+  private static final String INDEX_NAME = "component_uuid";
+
+  public DropIndexComponentUuidInWebhookDeliveries(Database db) {
+    super(db, INDEX_NAME, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveries.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveries.java
new file mode 100644 (file)
index 0000000..79c9d18
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameComponentUuidInWebhookDeliveries extends RenameVarcharColumnChange {
+
+  private static final String TABLE_NAME = "webhook_deliveries";
+  private static final String OLD_COLUMN_NAME = "component_uuid";
+  private static final String NEW_COLUMN_NAME = "project_uuid";
+
+  public RenameComponentUuidInWebhookDeliveries(Database db) {
+    super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/RenameVarcharColumnAbstractTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/RenameVarcharColumnAbstractTest.java
new file mode 100644 (file)
index 0000000..24caeaf
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+import static java.sql.Types.VARCHAR;
+
+public abstract class RenameVarcharColumnAbstractTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(getClass(), "schema.sql");
+  private final String tableName;
+  private final String columnName;
+  private final boolean isNullable;
+
+  public RenameVarcharColumnAbstractTest(String tableName, String columnName, boolean isNullable) {
+    this.tableName = tableName;
+    this.columnName = columnName;
+    this.isNullable = isNullable;
+  }
+
+  protected void verifyMigrationIsReentrant() throws SQLException {
+    db.assertColumnDoesNotExist(tableName, columnName);
+    getClassUnderTest().execute();
+    getClassUnderTest().execute();
+    db.assertColumnDefinition(tableName, columnName, VARCHAR, 40, isNullable);
+  }
+
+  protected void verifyColumnIsRenamed() throws SQLException {
+    db.assertColumnDoesNotExist(tableName, columnName);
+    getClassUnderTest().execute();
+    db.assertColumnDefinition(tableName, columnName, VARCHAR, 40, isNullable);
+  }
+
+  protected abstract RenameVarcharColumnChange getClassUnderTest();
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveriesTest.java
new file mode 100644 (file)
index 0000000..51f36d3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class CreateIndexProjectUuidInWebhookDeliveriesTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexProjectUuidInWebhookDeliveriesTest.class, "schema.sql");
+
+  private final CreateIndexProjectUuidInWebhookDeliveries createIndex = new CreateIndexProjectUuidInWebhookDeliveries(db.database());
+
+  @Test
+  public void migration_should_create_index() throws SQLException {
+    db.assertIndexDoesNotExist("webhook_deliveries", "wd_project_uuid");
+
+    createIndex.execute();
+
+    db.assertIndex("webhook_deliveries", "wd_project_uuid", "project_uuid");
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    createIndex.execute();
+    createIndex.execute();
+
+    db.assertIndex("webhook_deliveries", "wd_project_uuid", "project_uuid");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java
new file mode 100644 (file)
index 0000000..2d1428b
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropIndexComponentUuidInWebhookDeliveriesTest {
+
+  private static final String TABLE_NAME = "webhook_deliveries";
+  private static final String COLUMN_NAME = "component_uuid";
+  private static final String INDEX_NAME = "component_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInWebhookDeliveriesTest.class, "schema.sql");
+
+  private final DropIndexComponentUuidInWebhookDeliveries underTest = new DropIndexComponentUuidInWebhookDeliveries(db.database());
+
+  @Test
+  public void index_is_dropped() throws SQLException {
+    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+
+    underTest.execute();
+
+    db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+
+    underTest.execute();
+    underTest.execute();
+
+    db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java
new file mode 100644 (file)
index 0000000..d3c205d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Test;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+import org.sonar.server.platform.db.migration.version.RenameVarcharColumnAbstractTest;
+
+public class RenameComponentUuidInWebhookDeliveriesTest extends RenameVarcharColumnAbstractTest {
+
+  public RenameComponentUuidInWebhookDeliveriesTest() {
+    super("webhook_deliveries", "project_uuid", false);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    super.verifyMigrationIsReentrant();
+  }
+
+  @Test
+  public void column_is_renamed() throws SQLException {
+    super.verifyColumnIsRenamed();
+  }
+
+  @Override
+  protected RenameVarcharColumnChange getClassUnderTest() {
+    return new RenameComponentUuidInWebhookDeliveries(db.database());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveriesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInWebhookDeliveriesTest/schema.sql
new file mode 100644 (file)
index 0000000..add1899
--- /dev/null
@@ -0,0 +1,18 @@
+CREATE TABLE "WEBHOOK_DELIVERIES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
+    "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
+    "CE_TASK_UUID" CHARACTER VARYING(40),
+    "ANALYSIS_UUID" CHARACTER VARYING(40),
+    "NAME" CHARACTER VARYING(100) NOT NULL,
+    "URL" CHARACTER VARYING(2000) NOT NULL,
+    "SUCCESS" BOOLEAN NOT NULL,
+    "HTTP_STATUS" INTEGER,
+    "DURATION_MS" BIGINT NOT NULL,
+    "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
+    "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
+CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest/schema.sql
new file mode 100644 (file)
index 0000000..b6b5b09
--- /dev/null
@@ -0,0 +1,19 @@
+CREATE TABLE "WEBHOOK_DELIVERIES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL,
+    "CE_TASK_UUID" CHARACTER VARYING(40),
+    "ANALYSIS_UUID" CHARACTER VARYING(40),
+    "NAME" CHARACTER VARYING(100) NOT NULL,
+    "URL" CHARACTER VARYING(2000) NOT NULL,
+    "SUCCESS" BOOLEAN NOT NULL,
+    "HTTP_STATUS" INTEGER,
+    "DURATION_MS" BIGINT NOT NULL,
+    "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
+    "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
+CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
+CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest/schema.sql
new file mode 100644 (file)
index 0000000..b6b5b09
--- /dev/null
@@ -0,0 +1,19 @@
+CREATE TABLE "WEBHOOK_DELIVERIES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL,
+    "CE_TASK_UUID" CHARACTER VARYING(40),
+    "ANALYSIS_UUID" CHARACTER VARYING(40),
+    "NAME" CHARACTER VARYING(100) NOT NULL,
+    "URL" CHARACTER VARYING(2000) NOT NULL,
+    "SUCCESS" BOOLEAN NOT NULL,
+    "HTTP_STATUS" INTEGER,
+    "DURATION_MS" BIGINT NOT NULL,
+    "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
+    "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
+CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
+CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
\ No newline at end of file
index 6805bfeafc15829184de3d536db5d140076645fa..e7bde6cbf023507f68a62b814a3c7d226d64a53a 100644 (file)
@@ -64,7 +64,7 @@ public class WebhookDeliveryStorageIT {
     WebhookDeliveryDto dto = dbClient.webhookDeliveryDao().selectByUuid(dbSession, DELIVERY_UUID).get();
     assertThat(dto.getUuid()).isEqualTo(DELIVERY_UUID);
     assertThat(dto.getWebhookUuid()).isEqualTo("WEBHOOK_UUID_1");
-    assertThat(dto.getComponentUuid()).isEqualTo(delivery.getWebhook().getComponentUuid());
+    assertThat(dto.getProjectUuid()).isEqualTo(delivery.getWebhook().getProjectUuid());
     assertThat(dto.getCeTaskUuid()).isEqualTo(delivery.getWebhook().getCeTaskUuid().get());
     assertThat(dto.getName()).isEqualTo(delivery.getWebhook().getName());
     assertThat(dto.getUrl()).isEqualTo(delivery.getWebhook().getUrl());
@@ -128,7 +128,7 @@ public class WebhookDeliveryStorageIT {
   private static WebhookDeliveryDto newDto(String uuid, String componentUuid, long at) {
     return WebhookDeliveryTesting.newDto()
       .setUuid(uuid)
-      .setComponentUuid(componentUuid)
+      .setProjectUuid(componentUuid)
       .setCreatedAt(at);
   }
 }
index 10d3279643dbec1379e512ccb673dbcd12fb4250..472859f2a149b34876fec3ef21ec60dbe1e3b1af 100644 (file)
@@ -30,7 +30,7 @@ import static java.util.Optional.ofNullable;
 public class Webhook {
 
   private final String uuid;
-  private final String componentUuid;
+  private final String projectUuid;
   @Nullable
   private final String ceTaskUuid;
   @Nullable
@@ -40,10 +40,10 @@ public class Webhook {
   @Nullable
   private final String secret;
 
-  public Webhook(String uuid, String componentUuid, @Nullable String ceTaskUuid,
+  public Webhook(String uuid, String projectUuid, @Nullable String ceTaskUuid,
     @Nullable String analysisUuid, String name, String url, @Nullable String secret) {
     this.uuid = uuid;
-    this.componentUuid = requireNonNull(componentUuid);
+    this.projectUuid = requireNonNull(projectUuid);
     this.ceTaskUuid = ceTaskUuid;
     this.analysisUuid = analysisUuid;
     this.name = requireNonNull(name);
@@ -51,8 +51,8 @@ public class Webhook {
     this.secret = secret;
   }
 
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getProjectUuid() {
+    return projectUuid;
   }
 
   public Optional<String> getCeTaskUuid() {
index a2c7ade3721894a4c878b64b7c0f9f12506c8a33..4a0182e84e84f39b76ed208bc9831b578e9b866f 100644 (file)
@@ -56,10 +56,10 @@ public class WebhookDeliveryStorage {
     }
   }
 
-  public void purge(String componentUuid) {
+  public void purge(String projectUuid) {
     long beforeDate = system.now() - ALIVE_DELAY_MS;
     try (DbSession dbSession = dbClient.openSession(false)) {
-      dbClient.webhookDeliveryDao().deleteComponentBeforeDate(dbSession, componentUuid, beforeDate);
+      dbClient.webhookDeliveryDao().deleteProjectBeforeDate(dbSession, projectUuid, beforeDate);
       dbSession.commit();
     }
   }
@@ -68,7 +68,7 @@ public class WebhookDeliveryStorage {
     WebhookDeliveryDto dto = new WebhookDeliveryDto();
     dto.setUuid(uuidFactory.create());
     dto.setWebhookUuid(delivery.getWebhook().getUuid());
-    dto.setComponentUuid(delivery.getWebhook().getComponentUuid());
+    dto.setProjectUuid(delivery.getWebhook().getProjectUuid());
     delivery.getWebhook().getCeTaskUuid().ifPresent(dto::setCeTaskUuid);
     delivery.getWebhook().getAnalysisUuid().ifPresent(dto::setAnalysisUuid);
     dto.setName(delivery.getWebhook().getName());
index 189cce58d936c9df64694a91f3549d58c793f8ef..e8f5fd9fb7688eaffc14760f9b373f27b0c42d7b 100644 (file)
@@ -27,10 +27,10 @@ public class WebhookTest {
 
   @Test
   public void webhook_with_only_required_fields() {
-    Webhook underTest = new Webhook("a_uuid", "a_component_uuid", null, null, "a_name", "an_url", null);
+    Webhook underTest = new Webhook("a_uuid", "a_project_uuid", null, null, "a_name", "an_url", null);
 
     assertThat(underTest.getUuid()).isEqualTo("a_uuid");
-    assertThat(underTest.getComponentUuid()).isEqualTo("a_component_uuid");
+    assertThat(underTest.getProjectUuid()).isEqualTo("a_project_uuid");
     assertThat(underTest.getCeTaskUuid()).isEmpty();
     assertThat(underTest.getAnalysisUuid()).isEmpty();
     assertThat(underTest.getName()).isEqualTo("a_name");
@@ -43,7 +43,7 @@ public class WebhookTest {
     Webhook underTest = new Webhook("a_uuid", "a_component_uuid", "a_task_uuid", "an_analysis", "a_name", "an_url", "a_secret");
 
     assertThat(underTest.getUuid()).isEqualTo("a_uuid");
-    assertThat(underTest.getComponentUuid()).isEqualTo("a_component_uuid");
+    assertThat(underTest.getProjectUuid()).isEqualTo("a_component_uuid");
     assertThat(underTest.getCeTaskUuid()).hasValue("a_task_uuid");
     assertThat(underTest.getAnalysisUuid()).hasValue("an_analysis");
     assertThat(underTest.getName()).isEqualTo("a_name");
index 10bca756e8451c16ca7ea349c83a997455bacdf0..c66e27ec981453e4544fecf93ab43c1907a30622 100644 (file)
@@ -62,7 +62,7 @@ public class CreateActionIT {
   public UserSessionRule userSession = standalone();
 
   @Rule
-  public DbTester db = create();
+  public DbTester db = create(true);
   private final DbClient dbClient = db.getDbClient();
   private final WebhookDbTester webhookDbTester = db.webhooks();
   private final ComponentDbTester componentDbTester = db.components();
@@ -96,7 +96,7 @@ public class CreateActionIT {
   @Test
   public void create_a_webhook_with_400_length_project_key() {
     String longProjectKey = generateStringWithLength(400);
-    ComponentDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setKey(longProjectKey)).getMainBranchComponent();
+    ProjectDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setKey(longProjectKey)).getProjectDto();
 
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
@@ -158,7 +158,7 @@ public class CreateActionIT {
 
   @Test
   public void create_a_webhook_on_project() {
-    ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+    ProjectDto project = componentDbTester.insertPrivateProject().getProjectDto();
 
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
index 48de6658adb71a2691e220c8cf858574917c89d2..0f0172c65751aab598d8f2de1174657fae149379 100644 (file)
@@ -59,7 +59,7 @@ public class DeleteActionIT {
   public UserSessionRule userSession = standalone();
 
   @Rule
-  public DbTester db = create();
+  public DbTester db = create(true);
   private final DbClient dbClient = db.getDbClient();
   private final DbSession dbSession = db.getSession();
   private final WebhookDbTester webhookDbTester = db.webhooks();
index 1d00b4085678fbf3f7bd9d562397046a13f4da48..637538187ebb7444fbcb5edcb15ccbcd94d89da3 100644 (file)
@@ -66,7 +66,7 @@ public class ListActionIT {
   public UserSessionRule userSession = standalone();
 
   @Rule
-  public DbTester db = create();
+  public DbTester db = create(true);
 
   private final DbClient dbClient = db.getDbClient();
   private final Configuration configuration = mock(Configuration.class);
index ef84925ecda5c5fb4aa4966c0233da9e756b9cf6..49c7176841c91c8ed78b285d4beb1cd6312ee52d 100644 (file)
@@ -58,7 +58,7 @@ public class UpdateActionIT {
   public UserSessionRule userSession = standalone();
 
   @Rule
-  public DbTester db = create();
+  public DbTester db = create(true);
   private final DbClient dbClient = db.getDbClient();
   private final WebhookDbTester webhookDbTester = db.webhooks();
   private final ComponentDbTester componentDbTester = db.components();
index 0086cec2480c1813556096f8cc9a5e5ba5b537b0..aeb4c395d5ecaf1b01f075da54dd62a10cc68d57 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.webhook.WebhookDeliveryDbTester;
 import org.sonar.db.webhook.WebhookDeliveryDto;
 import org.sonar.server.component.ComponentFinder;
@@ -51,22 +51,22 @@ public class WebhookDeliveriesActionIT {
   public UserSessionRule userSession = UserSessionRule.standalone();
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private DbClient dbClient = db.getDbClient();
   private WebhookDeliveryDbTester webhookDeliveryDbTester = db.webhookDelivery();
 
   private WsActionTester ws;
-  private ComponentDto project;
-  private ComponentDto otherProject;
+  private ProjectDto project;
+  private ProjectDto otherProject;
 
   @Before
   public void setUp() {
     ComponentFinder componentFinder = TestComponentFinder.from(db);
     WebhookDeliveriesAction underTest = new WebhookDeliveriesAction(dbClient, userSession, componentFinder);
     ws = new WsActionTester(underTest);
-    project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getMainBranchComponent();
-    otherProject = db.components().insertPrivateProject(c -> c.setKey("other-project")).getMainBranchComponent();
+    project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getProjectDto();
+    otherProject = db.components().insertPrivateProject(c -> c.setKey("other-project")).getProjectDto();
   }
 
   @Test
@@ -121,7 +121,7 @@ public class WebhookDeliveriesActionIT {
   public void search_by_component_and_return_records_of_example() {
     WebhookDeliveryDto dto = newDto()
       .setUuid("d1")
-      .setComponentUuid(project.uuid())
+      .setProjectUuid(project.getUuid())
       .setCeTaskUuid("task-1")
       .setName("Jenkins")
       .setUrl("http://jenkins")
@@ -143,9 +143,9 @@ public class WebhookDeliveriesActionIT {
 
   @Test
   public void search_by_task_and_return_records() {
-    WebhookDeliveryDto dto1 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1");
-    WebhookDeliveryDto dto2 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1");
-    WebhookDeliveryDto dto3 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t2");
+    WebhookDeliveryDto dto1 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1");
+    WebhookDeliveryDto dto2 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1");
+    WebhookDeliveryDto dto3 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t2");
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto1);
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto3);
@@ -161,12 +161,12 @@ public class WebhookDeliveriesActionIT {
 
   @Test
   public void search_by_webhook_and_return_records() {
-    WebhookDeliveryDto dto1 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
-    WebhookDeliveryDto dto2 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
-    WebhookDeliveryDto dto3 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t2").setWebhookUuid("wh-2-uuid");
+    WebhookDeliveryDto dto1 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
+    WebhookDeliveryDto dto2 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
+    WebhookDeliveryDto dto3 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t2").setWebhookUuid("wh-2-uuid");
 
-    WebhookDeliveryDto dto4 = newDto().setComponentUuid(otherProject.uuid()).setCeTaskUuid("t4").setWebhookUuid("wh-1-uuid");
-    WebhookDeliveryDto dto5 = newDto().setComponentUuid(otherProject.uuid()).setCeTaskUuid("t5").setWebhookUuid("wh-1-uuid");
+    WebhookDeliveryDto dto4 = newDto().setProjectUuid(otherProject.getUuid()).setCeTaskUuid("t4").setWebhookUuid("wh-1-uuid");
+    WebhookDeliveryDto dto5 = newDto().setProjectUuid(otherProject.getUuid()).setCeTaskUuid("t5").setWebhookUuid("wh-1-uuid");
 
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto1);
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
@@ -194,7 +194,7 @@ public class WebhookDeliveriesActionIT {
   public void validate_default_pagination() {
 
     for (int i = 0; i < 15; i++) {
-      webhookDeliveryDbTester.insert(newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
+      webhookDeliveryDbTester.insert(newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
     }
 
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@@ -211,7 +211,7 @@ public class WebhookDeliveriesActionIT {
   public void validate_pagination_first_page() {
 
     for (int i = 0; i < 12; i++) {
-      webhookDeliveryDbTester.insert(newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
+      webhookDeliveryDbTester.insert(newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
     }
 
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@@ -231,7 +231,7 @@ public class WebhookDeliveriesActionIT {
   public void validate_pagination_last_page() {
 
     for (int i = 0; i < 12; i++) {
-      webhookDeliveryDbTester.insert(newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
+      webhookDeliveryDbTester.insert(newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
     }
 
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@@ -250,7 +250,7 @@ public class WebhookDeliveriesActionIT {
   @Test
   public void search_by_component_and_throw_ForbiddenException_if_not_admin_of_project() {
     WebhookDeliveryDto dto = newDto()
-      .setComponentUuid(project.uuid());
+      .setProjectUuid(project.getUuid());
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
     userSession.logIn().addProjectPermission(UserRole.USER, project);
@@ -265,7 +265,7 @@ public class WebhookDeliveriesActionIT {
   @Test
   public void search_by_task_and_throw_ForbiddenException_if_not_admin_of_project() {
     WebhookDeliveryDto dto = newDto()
-      .setComponentUuid(project.uuid());
+      .setProjectUuid(project.getUuid());
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
     userSession.logIn().addProjectPermission(UserRole.USER, project);
index 782afb9d43e4af4f6694338dae448e53591fd2e5..b12e175b40eeacbc9b535d960cd8cb84ae35a05c 100644 (file)
@@ -23,11 +23,10 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.webhook.WebhookDeliveryDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.component.TestComponentFinder;
@@ -50,18 +49,18 @@ public class WebhookDeliveryActionIT {
   public UserSessionRule userSession = UserSessionRule.standalone();
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(true);
 
   private DbClient dbClient = db.getDbClient();
   private WsActionTester ws;
-  private ComponentDto project;
+  private ProjectDto project;
 
   @Before
   public void setUp() {
     ComponentFinder componentFinder = TestComponentFinder.from(db);
     WebhookDeliveryAction underTest = new WebhookDeliveryAction(dbClient, userSession, componentFinder);
     ws = new WsActionTester(underTest);
-    project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getMainBranchComponent();
+    project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getProjectDto();
   }
 
   @Test
@@ -96,7 +95,7 @@ public class WebhookDeliveryActionIT {
   public void load_the_delivery_of_example() {
     WebhookDeliveryDto dto = newDto()
       .setUuid("d1")
-      .setComponentUuid(project.uuid())
+      .setProjectUuid(project.getUuid())
       .setCeTaskUuid("task-1")
       .setName("Jenkins")
       .setUrl("http://jenkins")
@@ -120,7 +119,7 @@ public class WebhookDeliveryActionIT {
   @Test
   public void return_delivery_that_failed_to_be_sent() {
     WebhookDeliveryDto dto = newDto()
-      .setComponentUuid(project.uuid())
+      .setProjectUuid(project.getUuid())
       .setSuccess(false)
       .setHttpStatus(null)
       .setErrorStacktrace("IOException -> can not connect");
@@ -140,7 +139,7 @@ public class WebhookDeliveryActionIT {
   @Test
   public void return_delivery_with_none_of_optional_fields() {
     WebhookDeliveryDto dto = newDto()
-      .setComponentUuid(project.uuid())
+      .setProjectUuid(project.getUuid())
       .setCeTaskUuid(null)
       .setHttpStatus(null)
       .setErrorStacktrace(null)
@@ -162,7 +161,7 @@ public class WebhookDeliveryActionIT {
   @Test
   public void throw_ForbiddenException_if_not_admin_of_project() {
     WebhookDeliveryDto dto = newDto()
-      .setComponentUuid(project.uuid());
+      .setProjectUuid(project.getUuid());
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
     userSession.logIn().addProjectPermission(UserRole.USER, project);
index c871b5be029db0f6b0e8df0e59c844904174a2af..07d8ea74669e6fd9ecb1c3c6725c54f30fc62932 100644 (file)
@@ -127,8 +127,8 @@ public class WebhookDeliveriesAction implements WebhooksWsAction {
         ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
         projectUuidMap = new HashMap<>();
         projectUuidMap.put(project.getUuid(), project);
-        totalElements = dbClient.webhookDeliveryDao().countDeliveriesByComponentUuid(dbSession, project.getUuid());
-        deliveries = dbClient.webhookDeliveryDao().selectOrderedByComponentUuid(dbSession, project.getUuid(), offset(page, pageSize), pageSize);
+        totalElements = dbClient.webhookDeliveryDao().countDeliveriesByProjectUuid(dbSession, project.getUuid());
+        deliveries = dbClient.webhookDeliveryDao().selectOrderedByProjectUuid(dbSession, project.getUuid(), offset(page, pageSize), pageSize);
       } else {
         totalElements = dbClient.webhookDeliveryDao().countDeliveriesByCeTaskUuid(dbSession, ceTaskId);
         deliveries = dbClient.webhookDeliveryDao().selectOrderedByCeTaskUuid(dbSession, ceTaskId, offset(page, pageSize), pageSize);
@@ -141,7 +141,7 @@ public class WebhookDeliveriesAction implements WebhooksWsAction {
   private Map<String, ProjectDto> getProjectsDto(DbSession dbSession, List<WebhookDeliveryLiteDto> deliveries) {
     Map<String, String> deliveredComponentUuid = deliveries
       .stream()
-      .collect(Collectors.toMap(WebhookDeliveryLiteDto::getUuid, WebhookDeliveryLiteDto::getComponentUuid));
+      .collect(Collectors.toMap(WebhookDeliveryLiteDto::getUuid, WebhookDeliveryLiteDto::getProjectUuid));
 
     if (!deliveredComponentUuid.isEmpty()) {
       return dbClient.projectDao().selectByUuids(dbSession, new HashSet<>(deliveredComponentUuid.values()))
@@ -183,7 +183,7 @@ public class WebhookDeliveriesAction implements WebhooksWsAction {
       Webhooks.DeliveriesWsResponse.Builder responseBuilder = Webhooks.DeliveriesWsResponse.newBuilder();
       Webhooks.Delivery.Builder deliveryBuilder = Webhooks.Delivery.newBuilder();
       for (WebhookDeliveryLiteDto dto : deliveryDtos) {
-        ProjectDto project = projectUuidMap.get(dto.getComponentUuid());
+        ProjectDto project = projectUuidMap.get(dto.getProjectUuid());
         copyDtoToProtobuf(project, dto, deliveryBuilder);
         responseBuilder.addDeliveries(deliveryBuilder);
       }
index 9ba09c28c6963fbc237301582808150c5110afb5..3e2631f3b9063ce063d07b5a33c172d5c3535ce7 100644 (file)
@@ -81,7 +81,7 @@ public class WebhookDeliveryAction implements WebhooksWsAction {
     try (DbSession dbSession = dbClient.openSession(false)) {
       WebhookDeliveryDto delivery = dbClient.webhookDeliveryDao().selectByUuid(dbSession, deliveryUuid)
         .orElseThrow(() -> new NotFoundException("Webhook delivery not found"));
-      ProjectDto project = componentFinder.getProjectByUuid(dbSession, delivery.getComponentUuid());
+      ProjectDto project = componentFinder.getProjectByUuid(dbSession, delivery.getProjectUuid());
       return new Data(project, delivery);
     }
   }