3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.platform.db.migration.version.v101;
22 import java.sql.SQLException;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.sonar.core.util.UuidFactory;
26 import org.sonar.core.util.UuidFactoryFast;
27 import org.sonar.db.MigrationDbTester;
28 import org.sonar.server.platform.db.migration.step.DataChange;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.assertj.core.api.Assertions.tuple;
33 public class PopulateReportSchedulesIT {
35 public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateReportSchedules.class);
37 private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
38 private final DataChange underTest = new PopulateReportSchedules(db.database());
41 public void execute_shouldPopulateFromPortfolioProperties() throws SQLException {
42 insertPortfolio("uuid1");
43 insertPortfolioProperty("uuid1", "1234");
47 assertThat(db.select("select * from report_schedules"))
48 .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("LAST_SEND_TIME_IN_MS"))
49 .containsOnly(tuple("uuid1", null, 1234L));
53 public void execute_shouldPopulateFromBranchProperties() throws SQLException {
54 insertBranch("uuid1");
55 insertProjectBranchProperty("uuid1", "1234");
59 assertThat(db.select("select * from report_schedules"))
60 .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("LAST_SEND_TIME_IN_MS"))
61 .containsOnly(tuple(null, "uuid1", 1234L));
65 public void execute_whenPropertyMatchesBothBranchAndPortfolio_shouldNotPopulate() throws SQLException {
66 insertBranch("uuid1");
67 insertPortfolio("uuid1");
68 insertProjectBranchProperty("uuid1", "1234");
73 assertThat(db.select("select * from report_schedules")).isEmpty();
76 private void insertPortfolio(String uuid) {
77 db.executeInsert("portfolios",
80 "name", "name_" + uuid,
83 "selection_mode", "manual",
89 private void insertProjectBranchProperty(String portfolioUuid, String value) {
90 db.executeInsert("properties",
91 "uuid", uuidFactory.create(),
92 "prop_key", "sonar.governance.report.project.branch.lastSendTimeInMs",
96 "entity_uuid", portfolioUuid
100 private void insertPortfolioProperty(String portfolioUuid, String value) {
101 db.executeInsert("properties",
102 "uuid", uuidFactory.create(),
103 "prop_key", "sonar.governance.report.lastSendTimeInMs",
107 "entity_uuid", portfolioUuid
111 private void insertBranch(String uuid) {
112 db.executeInsert("project_branches",
114 "project_uuid", "project_" + uuid,
115 "kee", "kee_" + uuid,
116 "branch_type", "BRANCH",
119 "need_issue_sync", false,