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.

CreateBuiltInQualityGateTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.v70;
  21. import java.sql.SQLException;
  22. import java.util.Date;
  23. import java.util.List;
  24. import java.util.Map;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.sonar.api.impl.utils.TestSystem2;
  28. import org.sonar.api.utils.System2;
  29. import org.sonar.core.util.UuidFactoryFast;
  30. import org.sonar.core.util.Uuids;
  31. import org.sonar.db.CoreDbTester;
  32. import static org.assertj.core.api.Assertions.assertThat;
  33. import static org.assertj.core.groups.Tuple.tuple;
  34. public class CreateBuiltInQualityGateTest {
  35. private final static long PAST = 10_000_000_000L;
  36. private final static long NOW = 50_000_000_000L;
  37. private System2 system2 = new TestSystem2().setNow(NOW);
  38. @Rule
  39. public CoreDbTester db = CoreDbTester.createForSchema(CreateBuiltInQualityGateTest.class, "quality_gates.sql");
  40. private CreateBuiltInQualityGate underTest = new CreateBuiltInQualityGate(db.database(), system2, UuidFactoryFast.getInstance());
  41. @Test
  42. public void should_create_builtin_quality_gate() throws SQLException {
  43. underTest.execute();
  44. assertThat(selectAllQualityGates())
  45. .extracting(map -> map.get("NAME"), map -> map.get("IS_BUILT_IN"), map -> map.get("CREATED_AT"))
  46. .containsExactlyInAnyOrder(
  47. tuple("Sonar way", true, new Date(NOW))
  48. );
  49. }
  50. @Test
  51. public void should_not_create_builtin_quality_gate_if_existing() throws SQLException {
  52. insertQualityGate("Whatever", true);
  53. underTest.execute();
  54. assertThat(selectAllQualityGates())
  55. .extracting(map -> map.get("NAME"), map -> map.get("IS_BUILT_IN"), map -> map.get("CREATED_AT"))
  56. .containsExactlyInAnyOrder(
  57. tuple("Whatever", true, new Date(PAST))
  58. );
  59. }
  60. private List<Map<String, Object>> selectAllQualityGates() {
  61. return db.select("select id, uuid, name, is_built_in, created_at, updated_at from quality_gates");
  62. }
  63. private void insertQualityGate(String name, boolean builtIn) {
  64. db.executeInsert(
  65. "QUALITY_GATES",
  66. "UUID", Uuids.createFast(),
  67. "NAME", name,
  68. "IS_BUILT_IN", String.valueOf(builtIn),
  69. "CREATED_AT", new Date(PAST),
  70. "UPDATED_AT", new Date(PAST));
  71. }
  72. }