Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CreateDeprecatedRuleKeysTableTest.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 java.sql.Types;
  23. import org.junit.Rule;
  24. import org.junit.Test;
  25. import org.sonar.db.CoreDbTester;
  26. import static org.assertj.core.api.Assertions.assertThat;
  27. public class CreateDeprecatedRuleKeysTableTest {
  28. private static final String TABLE = "deprecated_rule_keys";
  29. @Rule
  30. public final CoreDbTester db = CoreDbTester.createForSchema(CreateDeprecatedRuleKeysTableTest.class, "empty.sql");
  31. private CreateDeprecatedRuleKeysTable underTest = new CreateDeprecatedRuleKeysTable(db.database());
  32. @Test
  33. public void creates_table_on_empty_db() throws SQLException {
  34. underTest.execute();
  35. checkTable();
  36. }
  37. @Test
  38. public void migration_is_reentrant() throws SQLException {
  39. underTest.execute();
  40. underTest.execute();
  41. checkTable();
  42. }
  43. private void checkTable() {
  44. db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false);
  45. db.assertColumnDefinition(TABLE, "rule_id", Types.INTEGER, 11, false);
  46. db.assertColumnDefinition(TABLE, "old_repository_key", Types.VARCHAR, 255, false);
  47. db.assertColumnDefinition(TABLE, "old_rule_key", Types.VARCHAR, 200, false);
  48. db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, 20, false);
  49. db.assertUniqueIndex(TABLE, "uniq_deprecated_rule_keys", "old_repository_key", "old_rule_key");
  50. db.assertUniqueIndex(TABLE, "rule_id_deprecated_rule_keys", "rule_id");
  51. assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0);
  52. }
  53. }