You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddWebhookKeyToWebhookDeliveriesTableTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.platform.db.migration.version.v71;
  21. import java.sql.SQLException;
  22. import org.junit.Rule;
  23. import org.junit.Test;
  24. import org.junit.rules.ExpectedException;
  25. import org.sonar.db.CoreDbTester;
  26. import static java.lang.String.valueOf;
  27. import static java.sql.Types.BIGINT;
  28. import static java.sql.Types.VARCHAR;
  29. import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
  30. import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
  31. import static org.apache.commons.lang.RandomStringUtils.randomNumeric;
  32. import static org.assertj.core.api.Assertions.assertThat;
  33. import static org.sonar.db.CoreDbTester.createForSchema;
  34. public class AddWebhookKeyToWebhookDeliveriesTableTest {
  35. @Rule
  36. public final CoreDbTester dbTester = createForSchema(AddWebhookKeyToWebhookDeliveriesTableTest.class, "webhook-deliveries.sql");
  37. @Rule
  38. public ExpectedException expectedException = ExpectedException.none();
  39. private AddWebhookKeyToWebhookDeliveriesTable underTest = new AddWebhookKeyToWebhookDeliveriesTable(dbTester.database());
  40. @Test
  41. public void table_has_been_truncated() throws SQLException {
  42. insertDelivery();
  43. underTest.execute();
  44. int count = dbTester.countRowsOfTable("webhook_deliveries");
  45. assertThat(count).isEqualTo(0);
  46. }
  47. @Test
  48. public void column_webhook_uuid_has_been_added_to_table() throws SQLException {
  49. underTest.execute();
  50. dbTester.assertColumnDefinition("webhook_deliveries", "webhook_uuid", VARCHAR, 40, false);
  51. }
  52. @Test
  53. public void column_duration_ms_is_now_not_nullable() throws SQLException {
  54. underTest.execute();
  55. dbTester.assertColumnDefinition("webhook_deliveries", "duration_ms", BIGINT, null, false);
  56. }
  57. @Test
  58. public void migration_is_not_reentrant() throws SQLException {
  59. underTest.execute();
  60. expectedException.expect(IllegalStateException.class);
  61. underTest.execute();
  62. }
  63. private void insertDelivery() {
  64. dbTester.executeInsert("webhook_deliveries",
  65. "uuid", randomAlphanumeric(40),
  66. // "webhook_uuid", randomAlphanumeric(40),
  67. "component_uuid", randomAlphanumeric(40),
  68. "name", randomAlphabetic(60),
  69. "url", randomAlphabetic(200),
  70. "success", true,
  71. "duration_ms", randomNumeric(7),
  72. "payload", randomAlphanumeric(1000),
  73. "created_at", valueOf(1_55555_555));
  74. }
  75. }