3 * Copyright (C) 2009-2023 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.v102;
22 import java.sql.SQLException;
23 import java.sql.Types;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.sonar.db.CoreDbTester;
27 import org.sonar.server.platform.db.migration.step.DdlChange;
29 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE;
30 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE;
31 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
32 import static org.sonar.server.platform.db.migration.version.v102.CreateAnticipatedTransitionsTable.ANTICIPATED_TRANSITIONS_TABLE_NAME;
34 public class CreateAnticipatedTransitionsTableTest {
36 public final CoreDbTester db = CoreDbTester.createEmpty();
38 private final DdlChange createAnticipatedTransitionsTable = new CreateAnticipatedTransitionsTable(db.database());
41 public void migration_should_create_a_table() throws SQLException {
42 db.assertTableDoesNotExist(ANTICIPATED_TRANSITIONS_TABLE_NAME);
44 createAnticipatedTransitionsTable.execute();
46 db.assertTableExists(ANTICIPATED_TRANSITIONS_TABLE_NAME);
47 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false);
48 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "project_uuid", Types.VARCHAR, UUID_SIZE, false);
49 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "user_uuid", Types.VARCHAR, USER_UUID_SIZE, false);
50 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "transition", Types.VARCHAR, 20, false);
51 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "status", Types.VARCHAR, 20, false);
52 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "transition_comment", Types.VARCHAR, MAX_SIZE, true);
53 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "line", Types.INTEGER, 11, true);
54 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "message", Types.VARCHAR, MAX_SIZE, true);
55 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "line_hash", Types.VARCHAR, 255, true);
56 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "rule_key", Types.VARCHAR, 200, false);
57 db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "file_path", Types.VARCHAR, 1500, false);
58 db.assertPrimaryKey(ANTICIPATED_TRANSITIONS_TABLE_NAME, "pk_anticipated_transitions", "uuid");
62 public void migration_should_be_reentrant() throws SQLException {
63 db.assertTableDoesNotExist(ANTICIPATED_TRANSITIONS_TABLE_NAME);
65 createAnticipatedTransitionsTable.execute();
67 createAnticipatedTransitionsTable.execute();
69 db.assertTableExists(ANTICIPATED_TRANSITIONS_TABLE_NAME);