diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-12-12 11:56:39 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-12-14 12:11:53 +0100 |
commit | 4ff133235967c094e486f472c06ac2b625fbca90 (patch) | |
tree | c2530770601b6977076430271c3d8f295351f2c4 /sonar-db/src/test | |
parent | d830b2989a51dba1207db5fcde182ce8a5ea22d4 (diff) | |
download | sonarqube-4ff133235967c094e486f472c06ac2b625fbca90.tar.gz sonarqube-4ff133235967c094e486f472c06ac2b625fbca90.zip |
SONAR-8445 move SQ 6.1 migrations out of Ruby
Diffstat (limited to 'sonar-db/src/test')
25 files changed, 1 insertions, 1487 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index 36c2faf4ff6..68b3e0c0eda 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(99); + assertThat(container.size()).isEqualTo(81); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest.java deleted file mode 100644 index 31085a73359..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static java.lang.String.valueOf; - -public class AddErrorColumnsToCeActivityTest { - - private static final String TABLE = "CE_ACTIVITY"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddErrorColumnsToCeActivityTest.class, "old_ce_activity.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private AddErrorColumnsToCeActivity underTest = new AddErrorColumnsToCeActivity(db.database()); - - @Test - public void migration_adds_column_to_empty_table() throws SQLException { - underTest.execute(); - - verifyAddedColumns(); - } - - @Test - public void migration_adds_columns_to_populated_table() throws SQLException { - for (int i = 0; i < 9; i++) { - db.executeInsert( - TABLE, - "uuid", valueOf(i), - "task_type", "PROJECT", - "component_uuid", valueOf(i + 20), - "analysis_uuid", valueOf(i + 30), - "status", "ok", - "is_last", "true", - "is_last_key", "aa", - "submitted_at", valueOf(84654), - "created_at", valueOf(9512), - "updated_at", valueOf(45120)); - } - db.commit(); - - underTest.execute(); - - verifyAddedColumns(); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to execute "); - underTest.execute(); - } - - private void verifyAddedColumns() { - db.assertColumnDefinition(TABLE, "error_message", Types.VARCHAR, 1000, true); - db.assertColumnDefinition(TABLE, "error_stacktrace", Types.CLOB, null, true); - } - -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CopyActivitiesToQprofileChangesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CopyActivitiesToQprofileChangesTest.java deleted file mode 100644 index 022de4b64af..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CopyActivitiesToQprofileChangesTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.util.Date; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - - -public class CopyActivitiesToQprofileChangesTest { - - private static final long A_DATE = 1_500_000_000_000L; - private static final String TABLE_ACTIVITIES = "activities"; - private static final String TABLE_QPROFILE_CHANGES = "qprofile_changes"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, CopyActivitiesToQprofileChangesTest.class, "schema.sql"); - - private CopyActivitiesToQprofileChanges underTest = new CopyActivitiesToQprofileChanges(db.database()); - - @Test - public void migration_has_no_effect_on_empty_table() throws SQLException { - underTest.execute(); - - assertThat(db.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(0); - } - - @Test - public void copy_qprofile_changes() throws SQLException { - String key = "U1"; - String profileKey = "P1"; - String login = "marcel"; - String type = "ACTIVATED"; - String data = "D1"; - insertActivity(key, profileKey, login, "QPROFILE", type, data, A_DATE); - - underTest.execute(); - - assertThat(db.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(1); - Map<String, Object> change = selectChangeByKey(key); - assertThat(change.get("qprofileKey")).isEqualTo(profileKey); - assertThat(change.get("createdAt")).isEqualTo(A_DATE); - assertThat(change.get("login")).isEqualTo(login); - assertThat(change.get("changeType")).isEqualTo(type); - assertThat(change.get("changeData")).isEqualTo(data); - } - - /** - * Do not copy twice the same row - */ - @Test - public void copy_is_reentrant() throws SQLException { - insertActivity("U1", "P1", "marcel", "QPROFILE", "ACTIVATED", "D1", A_DATE); - - // first run - underTest.execute(); - assertThat(db.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(1); - - // second run - underTest.execute(); - assertThat(db.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(1); - } - - @Test - public void copy_nullable_fields() throws SQLException { - String key = "U1"; - String type = "ACTIVATED"; - // no login nor data - insertActivity(key, "P1", null, "QPROFILE", type, null, A_DATE); - - underTest.execute(); - - Map<String, Object> change = selectChangeByKey(key); - assertThat(change.get("qprofileKey")).isEqualTo("P1"); - assertThat(change.get("createdAt")).isEqualTo(A_DATE); - assertThat(change.get("changeType")).isEqualTo(type); - assertThat(change.get("login")).isNull(); - assertThat(change.get("data")).isNull(); - } - - @Test - public void ignore_activities_that_do_not_relate_to_qprofiles() throws SQLException { - insertActivity("U1", "P1", "marcel", "OTHER_ACTIVITY_TYPE", "T1", "D1", A_DATE); - - underTest.execute(); - - assertThat(db.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(0); - } - - @Test - public void ignore_invalid_activities() throws SQLException { - // no change type - insertActivity("U1", "P1", "marcel", "QPROFILE", null, "D1", A_DATE); - // no date - insertActivity("U2", "P1", "marcel", "QPROFILE", "ACTIVATED", "D1", null); - - underTest.execute(); - - assertThat(db.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(0); - } - - private void insertActivity(String key, @Nullable String profileKey, @Nullable String login, @Nullable String activityType, @Nullable String type, @Nullable String data, @Nullable Long createdAt) { - db.executeInsert(TABLE_ACTIVITIES, "log_key", key, "profile_key", profileKey, "user_login", login, "log_type", activityType, "log_action", type, "data_field", data, "created_at", createdAt != null ? new Date(createdAt) : null); - } - - private Map<String, Object> selectChangeByKey(String key) { - return db.selectFirst("select qprofile_key as \"qprofileKey\", created_at as \"createdAt\", user_login as \"login\", change_type as \"changeType\", change_data as \"changeData\" from qprofile_changes where kee='" + key + "'"); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableCeTaskInputTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableCeTaskInputTest.java deleted file mode 100644 index eb6d1dfd1a5..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableCeTaskInputTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateTableCeTaskInputTest { - private static final String TABLE_CE_TASK_INPUT = "ce_task_input"; - - @Rule - public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableCeTaskInputTest.class, "empty.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private CreateTableCeTaskInput underTest = new CreateTableCeTaskInput(dbTester.database()); - - @Test - public void creates_table_on_empty_db() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable(TABLE_CE_TASK_INPUT)).isEqualTo(0); - - dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "task_uuid", Types.VARCHAR, 40, false); - dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "input_data", Types.BLOB, null, true); - dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "created_at", Types.BIGINT, null, false); - dbTester.assertColumnDefinition(TABLE_CE_TASK_INPUT, "updated_at", Types.BIGINT, null, false); - dbTester.assertPrimaryKey(TABLE_CE_TASK_INPUT, "pk_" + TABLE_CE_TASK_INPUT, "task_uuid"); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - - underTest.execute(); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableInternalPropertiesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableInternalPropertiesTest.java deleted file mode 100644 index 768144a2d70..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableInternalPropertiesTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateTableInternalPropertiesTest { - private static final String TABLE_INTERNAL_PROPERTIES = "internal_properties"; - - @Rule - public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableInternalPropertiesTest.class, "empty.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private CreateTableInternalProperties underTest = new CreateTableInternalProperties(dbTester.database()); - - @Test - public void creates_table_on_empty_db() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable(TABLE_INTERNAL_PROPERTIES)).isEqualTo(0); - - dbTester.assertColumnDefinition(TABLE_INTERNAL_PROPERTIES, "kee", Types.VARCHAR, 20, false); - dbTester.assertColumnDefinition(TABLE_INTERNAL_PROPERTIES, "is_empty", Types.BOOLEAN, null, false); - dbTester.assertColumnDefinition(TABLE_INTERNAL_PROPERTIES, "text_value", Types.VARCHAR, 4000, true); - dbTester.assertColumnDefinition(TABLE_INTERNAL_PROPERTIES, "clob_value", Types.CLOB, null, true); - dbTester.assertColumnDefinition(TABLE_INTERNAL_PROPERTIES, "created_at", Types.BIGINT, null, false); - dbTester.assertPrimaryKey(TABLE_INTERNAL_PROPERTIES, "pk_" + TABLE_INTERNAL_PROPERTIES, "kee"); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - - underTest.execute(); - } - -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableProperties2Test.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableProperties2Test.java deleted file mode 100644 index 223b84ff0e5..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableProperties2Test.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateTableProperties2Test { - private static final String TABLE_PROPERTIES_2 = "properties2"; - - @Rule - public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableProperties2Test.class, "empty.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private CreateTableProperties2 underTest = new CreateTableProperties2(dbTester.database()); - - @Test - public void creates_table_on_empty_db() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable(TABLE_PROPERTIES_2)).isEqualTo(0); - - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "id", Types.INTEGER, null, false); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "prop_key", Types.VARCHAR, 512, false); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "resource_id", Types.BIGINT, null, true); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "user_id", Types.BIGINT, null, true); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "is_empty", Types.BOOLEAN, null, false); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "text_value", Types.VARCHAR, 4000, true); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "clob_value", Types.CLOB, null, true); - dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "created_at", Types.BIGINT, null, false); - dbTester.assertPrimaryKey(TABLE_PROPERTIES_2, "pk_properties", "id"); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - - underTest.execute(); - } - -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableQprofileChangesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableQprofileChangesTest.java deleted file mode 100644 index 362e9cd96e4..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableQprofileChangesTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateTableQprofileChangesTest { - private static final String TABLE_QPROFILE_CHANGES = "qprofile_changes"; - - @Rule - public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableQprofileChangesTest.class, "empty.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private CreateTableQprofileChanges underTest = new CreateTableQprofileChanges(dbTester.database()); - - @Test - public void creates_table_on_empty_db() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(0); - - dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "kee", Types.VARCHAR, 40, false); - dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "qprofile_key", Types.VARCHAR, 255, false); - dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "change_type", Types.VARCHAR, 20, false); - dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "user_login", Types.VARCHAR, 255, true); - dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "change_data", Types.CLOB, null, true); - dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "created_at", Types.BIGINT, null, false); - dbTester.assertPrimaryKey(TABLE_QPROFILE_CHANGES, "pk_" + TABLE_QPROFILE_CHANGES, "kee"); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - - underTest.execute(); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableRuleRepositoriesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableRuleRepositoriesTest.java deleted file mode 100644 index f3cb6303bd1..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableRuleRepositoriesTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateTableRuleRepositoriesTest { - private static final String TABLE_RULE_REPOSITORIES = "rule_repositories"; - - @Rule - public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableRuleRepositoriesTest.class, "empty.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private CreateTableRuleRepositories underTest = new CreateTableRuleRepositories(dbTester.database()); - - @Test - public void creates_table_on_empty_db() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable(TABLE_RULE_REPOSITORIES)).isEqualTo(0); - - dbTester.assertColumnDefinition(TABLE_RULE_REPOSITORIES, "kee", Types.VARCHAR, 200, false); - dbTester.assertColumnDefinition(TABLE_RULE_REPOSITORIES, "language", Types.VARCHAR, 20, false); - dbTester.assertColumnDefinition(TABLE_RULE_REPOSITORIES, "name", Types.VARCHAR, 4000, false); - dbTester.assertColumnDefinition(TABLE_RULE_REPOSITORIES, "created_at", Types.BIGINT, null, false); - dbTester.assertPrimaryKey(TABLE_RULE_REPOSITORIES, "pk_" + TABLE_RULE_REPOSITORIES, "kee"); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - - underTest.execute(); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableScannerContextTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableScannerContextTest.java deleted file mode 100644 index 0847efdae5d..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/CreateTableScannerContextTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateTableScannerContextTest { - private static final String TABLE_CE_SCANNER_CONTEXT = "ce_scanner_context"; - - @Rule - public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableCeTaskInputTest.class, "empty.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private CreateTableScannerContext underTest = new CreateTableScannerContext(dbTester.database()); - - @Test - public void creates_table_on_empty_db() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable(TABLE_CE_SCANNER_CONTEXT)).isEqualTo(0); - - dbTester.assertColumnDefinition(TABLE_CE_SCANNER_CONTEXT, "task_uuid", Types.VARCHAR, 40, false); - dbTester.assertColumnDefinition(TABLE_CE_SCANNER_CONTEXT, "context_data", Types.BLOB, null, false); - dbTester.assertColumnDefinition(TABLE_CE_SCANNER_CONTEXT, "created_at", Types.BIGINT, null, false); - dbTester.assertColumnDefinition(TABLE_CE_SCANNER_CONTEXT, "updated_at", Types.BIGINT, null, false); - dbTester.assertPrimaryKey(TABLE_CE_SCANNER_CONTEXT, "pk_" + TABLE_CE_SCANNER_CONTEXT, "task_uuid"); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - - underTest.execute(); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteProjectDashboardsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteProjectDashboardsTest.java deleted file mode 100644 index 705fd7f2774..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteProjectDashboardsTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static java.lang.String.valueOf; -import static org.assertj.core.api.Assertions.assertThat; - -public class DeleteProjectDashboardsTest { - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, DeleteProjectDashboardsTest.class, "schema.sql"); - - private DeleteProjectDashboards underTest = new DeleteProjectDashboards(db.database()); - - @Test - public void no_effect_on_empty_tables() throws SQLException { - underTest.execute(); - - assertThat(db.countRowsOfTable("dashboards")).isEqualTo(0); - } - - @Test - public void delete_project_dashboard_data() throws SQLException { - insertGlobalDashboards(1L, 10L, 11L); - insertProjectDashboards(2L, 20L, 21L); - insertActiveDashboards(1L, 10L, 11L, 12L); - insertActiveDashboards(2L, 20L, 21L, 22L); - insertWidgets(1L, 100L, 101L, 102L); - insertWidgets(2L, 200L, 201L, 202L); - insertWidgetProperties(100L, 1001L, 1002L, 1003L); - insertWidgetProperties(202L, 2021L, 2022L, 2023L); - - underTest.execute(); - - assertIdsOfDashboardsAre(1L, 10L, 11L); - assertIdsOfActiveDashboardsAre(10L, 11L, 12L); - assertIdsOfWidgetsAre(100L, 101L, 102L); - assertIdsOfWidgetPropertiesAre(1001L, 1002L, 1003L); - } - - @Test - public void is_reentrant() throws SQLException { - insertGlobalDashboards(10L, 11L, 12L); - insertProjectDashboards(20L, 21L, 22L); - underTest.execute(); - assertIdsOfDashboardsAre(10L, 11L, 12L); - - underTest.execute(); - assertIdsOfDashboardsAre(10L, 11L, 12L); - } - - private void insertProjectDashboards(long... ids) { - Arrays.stream(ids).forEach(id -> insertDashboard(id, false)); - } - - private void insertGlobalDashboards(long... ids) { - Arrays.stream(ids).forEach(id -> insertDashboard(id, true)); - } - - private void insertDashboard(long id, boolean isGlobal) { - db.executeInsert( - "dashboards", - "ID", valueOf(id), - "IS_GLOBAL", valueOf(isGlobal)); - } - - private void insertActiveDashboards(long dashboardId, long... ids) { - Arrays.stream(ids).forEach( - id -> db.executeInsert( - "active_dashboards", - "ID", valueOf(id), - "DASHBOARD_ID", valueOf(dashboardId))); - } - - private void insertWidgets(long dashboardId, long... ids) { - Arrays.stream(ids).forEach( - id -> db.executeInsert( - "widgets", - "ID", valueOf(id), - "WIDGET_KEY", valueOf(id), - "DASHBOARD_ID", valueOf(dashboardId))); - } - - private void insertWidgetProperties(long widgetId, long... ids) { - Arrays.stream(ids).forEach( - id -> db.executeInsert( - "widget_properties", - "ID", valueOf(id), - "WIDGET_ID", valueOf(widgetId))); - } - - private void assertIdsOfDashboardsAre(Long... ids) { - List<Long> idsInDb = db.select("select ID from dashboards").stream().map(map -> (Long) map.get("ID")).collect(Collectors.toList()); - - assertThat(idsInDb).containsOnly(ids); - } - - private void assertIdsOfActiveDashboardsAre(Long... ids) { - List<Long> idsInDb = db.select("select ID from active_dashboards").stream().map(map -> (Long) map.get("ID")).collect(Collectors.toList()); - - assertThat(idsInDb).containsOnly(ids); - } - - private void assertIdsOfWidgetsAre(Long... ids) { - List<Long> idsInDb = db.select("select ID from widgets").stream().map(map -> (Long) map.get("ID")).collect(Collectors.toList()); - - assertThat(idsInDb).containsOnly(ids); - } - - private void assertIdsOfWidgetPropertiesAre(Long... ids) { - List<Long> idsInDb = db.select("select ID from widget_properties").stream().map(map -> (Long) map.get("ID")).collect(Collectors.toList()); - - assertThat(idsInDb).containsOnly(ids); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java deleted file mode 100644 index a357db11dd6..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; -import org.sonar.db.ce.CeTaskTypes; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DeleteReportsFromCeQueueTest { - - private static final long NOW = 1_500_000_000_000L; - private static final String TABLE_NAME = "ce_queue"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, DeleteReportsFromCeQueueTest.class, "schema.sql"); - - private DeleteReportsFromCeQueue underTest = new DeleteReportsFromCeQueue(db.database()); - - @Test - public void no_effect_on_empty_tables() throws SQLException { - underTest.execute(); - - assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(0); - } - - @Test - public void delete_tasks_with_type_REPORT_only() throws SQLException { - db.executeInsert("ce_queue", "uuid", "U1", "task_type", CeTaskTypes.REPORT, "status", "PENDING", "created_at", NOW, "updated_at", NOW); - db.executeInsert("ce_queue", "uuid", "U2", "task_type", "REFRESH_VIEWS", "status", "PENDING", "created_at", NOW, "updated_at", NOW); - - underTest.execute(); - - List<Map<String, Object>> uuids = db.select("select uuid as \"uuid\" from ce_queue"); - assertThat(uuids).hasSize(1); - assertThat(uuids.get(0).get("uuid")).isEqualTo("U2"); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/DropIsGlobalFromDashboardsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/DropIsGlobalFromDashboardsTest.java deleted file mode 100644 index 346d4c54355..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/DropIsGlobalFromDashboardsTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import org.junit.Test; -import org.sonar.db.Database; -import org.sonar.db.dialect.PostgreSql; -import org.sonar.db.version.DdlChange; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class DropIsGlobalFromDashboardsTest { - - Database database = mock(Database.class); - - DropIsGlobalFromDashboards underTest = new DropIsGlobalFromDashboards(database); - - @Test - public void verify_generated_sql_on_postgresql() throws SQLException { - when(database.getDialect()).thenReturn(new PostgreSql()); - - DdlChange.Context context = mock(DdlChange.Context.class); - underTest.execute(context); - - verify(context).execute("ALTER TABLE dashboards DROP COLUMN is_global"); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/PopulateTableProperties2Test.java b/sonar-db/src/test/java/org/sonar/db/version/v61/PopulateTableProperties2Test.java deleted file mode 100644 index 7bc68019971..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/PopulateTableProperties2Test.java +++ /dev/null @@ -1,406 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.util.Map; -import java.util.Objects; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.assertj.core.api.AbstractAssert; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; - -import static java.lang.Boolean.FALSE; -import static java.lang.Boolean.TRUE; -import static java.lang.String.valueOf; -import static java.util.Objects.requireNonNull; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class PopulateTableProperties2Test { - private static final String EMPTY_PROPERTY = ""; - private static final String VALUE_SMALL = "some small value"; - private static final String VALUE_SIZE_4000 = String.format("%1$4000.4000s", "*"); - private static final String VALUE_SIZE_4001 = VALUE_SIZE_4000 + "P"; - private static final long DATE_1 = 1_555_000L; - private static final long DATE_2 = 2_666_000L; - private static final long DATE_3 = 3_777_000L; - private static final long DATE_4 = 4_888_000L; - - private System2 system2 = mock(System2.class); - - @Rule - public DbTester dbTester = DbTester.createForSchema(system2, PopulateTableProperties2Test.class, - "properties_and_properties_2_tables.sql"); - - private PopulateTableProperties2 underTest = new PopulateTableProperties2(dbTester.database(), system2); - - @Test - public void migration_has_no_effect_on_empty_tables() throws SQLException { - underTest.execute(); - - assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(0); - assertThat(dbTester.countRowsOfTable("properties2")).isEqualTo(0); - } - - @Test - public void migration_does_copy_again_properties_which_are_already_copied() throws SQLException { - insertProperty(1, VALUE_SMALL, null, null); - insertProperty(10, VALUE_SMALL, null, null); - insertProperty(2, VALUE_SMALL, null, 21); - insertProperty(20, VALUE_SMALL, null, 21); - insertProperty(3, VALUE_SMALL, 31, null); - insertProperty(30, VALUE_SMALL, 31, null); - - insertProperty2(1, VALUE_SMALL, null, null); - insertProperty2(2, VALUE_SMALL, null, 21); - insertProperty2(3, VALUE_SMALL, 31, null); - - assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(6); - assertThat(dbTester.countRowsOfTable("properties2")).isEqualTo(3); - - underTest.execute(); - - assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(6); - assertThat(dbTester.countRowsOfTable("properties2")).isEqualTo(6); - } - - @Test - public void migration_moves_global_properties() throws SQLException { - when(system2.now()).thenReturn(DATE_1, DATE_2, DATE_3, DATE_4); - - insertProperty(1, VALUE_SMALL, null, null); - insertProperty(2, EMPTY_PROPERTY, null, null); - insertProperty(3, VALUE_SIZE_4000, null, null); - insertProperty(4, VALUE_SIZE_4001, null, null); - - underTest.execute(); - - assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(4); - assertThat(dbTester.countRowsOfTable("properties2")).isEqualTo(4); - - assertThatProperty2(1) - .hasNoResourceId() - .hasNoUserId() - .hasTextValue(VALUE_SMALL) - .hasCreatedAt(DATE_1); - assertThatProperty2(2) - .hasNoResourceId() - .hasNoUserId() - .isEmpty() - .hasCreatedAt(DATE_2); - assertThatProperty2(3) - .hasNoResourceId() - .hasNoUserId() - .hasTextValue(VALUE_SIZE_4000) - .hasCreatedAt(DATE_3); - assertThatProperty2(4) - .hasNoResourceId() - .hasNoUserId() - .hasClobValue(VALUE_SIZE_4001) - .hasCreatedAt(DATE_4); - } - - @Test - public void migration_moves_user_properties() throws SQLException { - when(system2.now()).thenReturn(DATE_1, DATE_2, DATE_3, DATE_4); - - insertProperty(1, VALUE_SMALL, null, 11); - insertProperty(2, EMPTY_PROPERTY, null, 12); - insertProperty(3, VALUE_SIZE_4000, null, 13); - insertProperty(4, VALUE_SIZE_4001, null, 14); - - underTest.execute(); - - assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(4); - assertThat(dbTester.countRowsOfTable("properties2")).isEqualTo(4); - - assertThatProperty2(1) - .hasNoResourceId() - .hasUserId(11) - .hasTextValue(VALUE_SMALL) - .hasCreatedAt(DATE_1); - assertThatProperty2(2) - .hasNoResourceId() - .hasUserId(12) - .isEmpty() - .hasCreatedAt(DATE_2); - assertThatProperty2(3) - .hasNoResourceId() - .hasUserId(13) - .hasTextValue(VALUE_SIZE_4000) - .hasCreatedAt(DATE_3); - assertThatProperty2(4) - .hasNoResourceId() - .hasUserId(14) - .hasClobValue(VALUE_SIZE_4001) - .hasCreatedAt(DATE_4); - } - - @Test - public void migration_moves_component_properties() throws SQLException { - when(system2.now()).thenReturn(DATE_1, DATE_2, DATE_3, DATE_4); - - insertProperty(1, VALUE_SMALL, 11, null); - insertProperty(2, EMPTY_PROPERTY, 12, null); - insertProperty(3, VALUE_SIZE_4000, 13, null); - insertProperty(4, VALUE_SIZE_4001, 14, null); - - underTest.execute(); - - assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(4); - assertThat(dbTester.countRowsOfTable("properties2")).isEqualTo(4); - - assertThatProperty2(1) - .hasResourceId(11) - .hasNoUserId() - .hasTextValue(VALUE_SMALL) - .hasCreatedAt(DATE_1); - assertThatProperty2(2) - .hasResourceId(12) - .hasNoUserId() - .isEmpty() - .hasCreatedAt(DATE_2); - assertThatProperty2(3) - .hasResourceId(13) - .hasNoUserId() - .hasTextValue(VALUE_SIZE_4000) - .hasCreatedAt(DATE_3); - assertThatProperty2(4) - .hasResourceId(14) - .hasNoUserId() - .hasClobValue(VALUE_SIZE_4001) - .hasCreatedAt(DATE_4); - } - - private void insertProperty(int idAndKey, String value, @Nullable Integer resourceId, @Nullable Integer userId) { - dbTester.executeInsert("PROPERTIES", - "id", valueOf(idAndKey), - "prop_key", valueOf(idAndKey), - "text_value", value, - "resource_id", resourceId == null ? null : valueOf(resourceId), - "user_id", userId == null ? null : valueOf(userId)); - dbTester.commit(); - } - - private void insertProperty2(int idAndKey, @Nullable String value, @Nullable Integer resourceId, @Nullable Integer userId) { - dbTester.executeInsert("PROPERTIES2", - "id", valueOf(idAndKey), - "prop_key", valueOf(idAndKey), - "resource_id", resourceId == null ? null : valueOf(resourceId), - "user_id", userId == null ? null : valueOf(userId), - "is_empty", valueOf(value == null || value.isEmpty()), - "text_value", value != null && value.length() <= 4000 ? value : null, - "clob_value", value != null && value.length() > 4000 ? value : null, - "created_at", valueOf(1_55555_555)); - dbTester.commit(); - } - - private Property2Assert assertThatProperty2(int key) { - return new Property2Assert(dbTester, dbTester.getSession(), valueOf(key)); - } - - private static class Property2Assert extends AbstractAssert<Property2Assert, Property2> { - - private Property2Assert(DbTester dbTester, DbSession dbSession, String internalPropertyKey) { - super(asInternalProperty(dbTester, dbSession, internalPropertyKey), Property2Assert.class); - } - - private static Property2 asInternalProperty(DbTester dbTester, DbSession dbSession, String key) { - Map<String, Object> row = dbTester.selectFirst( - dbSession, - "select" + - " user_id as \"userId\", resource_id as \"resourceId\", is_empty as \"isEmpty\", text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\"" + - " from properties2" + - " where prop_key='" + key + "'"); - return new Property2( - (Long) row.get("userId"), - (Long) row.get("resourceId"), - isEmpty(row), - (String) row.get("textValue"), - (String) row.get("clobValue"), - (Long) row.get("createdAt")); - } - - private static Boolean isEmpty(Map<String, Object> row) { - Object flag = row.get("isEmpty"); - if (flag instanceof Boolean) { - return (Boolean) flag; - } - if (flag instanceof Long) { - Long longBoolean = (Long) flag; - return longBoolean.equals(1L); - } - throw new IllegalArgumentException("Unsupported object type returned for column \"isEmpty\": " + flag.getClass()); - } - - public Property2Assert hasNoUserId() { - isNotNull(); - - if (actual.getUserId() != null) { - failWithMessage("Expected Property2 to have column USER_ID to be null but was <%s>", actual.getUserId()); - } - - return this; - } - - public Property2Assert hasUserId(long expected) { - isNotNull(); - - if (!Objects.equals(actual.getUserId(), expected)) { - failWithMessage("Expected Property2 to have column USER_ID to be <%s> but was <%s>", true, actual.getUserId()); - } - - return this; - } - - public Property2Assert hasNoResourceId() { - isNotNull(); - - if (actual.getResourceId() != null) { - failWithMessage("Expected Property2 to have column RESOURCE_ID to be null but was <%s>", actual.getResourceId()); - } - - return this; - } - - public Property2Assert hasResourceId(long expected) { - isNotNull(); - - if (!Objects.equals(actual.getResourceId(), expected)) { - failWithMessage("Expected Property2 to have column RESOURCE_ID to be <%s> but was <%s>", true, actual.getResourceId()); - } - - return this; - } - - public Property2Assert isEmpty() { - isNotNull(); - - if (!Objects.equals(actual.getEmpty(), TRUE)) { - failWithMessage("Expected Property2 to have column IS_EMPTY to be <%s> but was <%s>", true, actual.getEmpty()); - } - if (actual.getTextValue() != null) { - failWithMessage("Expected Property2 to have column TEXT_VALUE to be null but was <%s>", actual.getTextValue()); - } - if (actual.getClobValue() != null) { - failWithMessage("Expected Property2 to have column CLOB_VALUE to be null but was <%s>", actual.getClobValue()); - } - - return this; - } - - public Property2Assert hasTextValue(String expected) { - isNotNull(); - - if (!Objects.equals(actual.getTextValue(), requireNonNull(expected))) { - failWithMessage("Expected Property2 to have column TEXT_VALUE to be <%s> but was <%s>", expected, actual.getTextValue()); - } - if (actual.getClobValue() != null) { - failWithMessage("Expected Property2 to have column CLOB_VALUE to be null but was <%s>", actual.getClobValue()); - } - if (!Objects.equals(actual.getEmpty(), FALSE)) { - failWithMessage("Expected Property2 to have column IS_EMPTY to be <%s> but was <%s>", false, actual.getEmpty()); - } - - return this; - } - - public Property2Assert hasClobValue(String expected) { - isNotNull(); - - if (!Objects.equals(actual.getClobValue(), requireNonNull(expected))) { - failWithMessage("Expected Property2 to have column CLOB_VALUE to be <%s> but was <%s>", expected, actual.getClobValue()); - } - if (actual.getTextValue() != null) { - failWithMessage("Expected Property2 to have column TEXT_VALUE to be null but was <%s>", actual.getTextValue()); - } - if (!Objects.equals(actual.getEmpty(), FALSE)) { - failWithMessage("Expected Property2 to have column IS_EMPTY to be <%s> but was <%s>", false, actual.getEmpty()); - } - - return this; - } - - public Property2Assert hasCreatedAt(long expected) { - isNotNull(); - - if (!Objects.equals(actual.getCreatedAt(), expected)) { - failWithMessage("Expected Property2 to have column CREATED_AT to be <%s> but was <%s>", expected, actual.getCreatedAt()); - } - - return this; - } - - } - - private static final class Property2 { - private final Long userId; - private final Long resourceId; - private final Boolean empty; - private final String textValue; - private final String clobValue; - private final Long createdAt; - - private Property2(@Nullable Long userId, @Nullable Long resourceId, - @Nullable Boolean empty, @Nullable String textValue, @Nullable String clobValue, - @Nullable Long createdAt) { - this.userId = userId; - this.resourceId = resourceId; - this.empty = empty; - this.textValue = textValue; - this.clobValue = clobValue; - this.createdAt = createdAt; - } - - public Long getUserId() { - return userId; - } - - public Long getResourceId() { - return resourceId; - } - - @CheckForNull - public Boolean getEmpty() { - return empty; - } - - @CheckForNull - public String getTextValue() { - return textValue; - } - - @CheckForNull - public String getClobValue() { - return clobValue; - } - - @CheckForNull - public Long getCreatedAt() { - return createdAt; - } - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v61/RemoveViewsDefinitionFromPropertiesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v61/RemoveViewsDefinitionFromPropertiesTest.java deleted file mode 100644 index bcabb800230..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v61/RemoveViewsDefinitionFromPropertiesTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v61; - -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -public class RemoveViewsDefinitionFromPropertiesTest { - - private static final long NOW = 1_500_000_000_000L; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveViewsDefinitionFromPropertiesTest.class, "properties_and_internal_properties.sql"); - - private System2 system2 = spy(System2.INSTANCE); - private RemoveViewsDefinitionFromProperties underTest = new RemoveViewsDefinitionFromProperties(db.database(), system2); - - @Test - public void ignore_missing_views_definition() throws SQLException { - underTest.execute(); - - assertThat(db.countRowsOfTable("internal_properties")).isEqualTo(0); - } - - @Test - public void move_views_definition_from_properties_to_text_value_of_internal_properties_table_when_less_than_4000() throws SQLException { - executeAndVerify("views content", false); - } - - @Test - public void move_views_definition_from_properties_to_text_value_of_internal_properties_table_when_is_4000() throws SQLException { - executeAndVerify(String.format("%1$4000.4000s", "*"), false); - } - - @Test - public void move_views_definition_from_properties_to_clob_value_of_internal_properties_table_when_is_more_than_4000() throws SQLException { - executeAndVerify(String.format("%1$4000.4000s", "*") + "abc", true); - } - - private void executeAndVerify(String xml, boolean isClob) throws SQLException { - when(system2.now()).thenReturn(NOW); - db.executeInsert("properties", "prop_key", "views.def", "text_value", xml); - db.executeInsert("properties", "prop_key", "other.property", "text_value", "other content"); - - underTest.execute(); - - assertThat(db.countRowsOfTable("internal_properties")).isEqualTo(1); - Map<String, Object> internalProp = db.selectFirst("select" + - " kee as \"key\", is_empty as \"isEmpty\", text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\"" + - " from internal_properties"); - assertThat(internalProp.get("key")).isEqualTo("views.def"); - assertThat(internalProp.get("isEmpty")).isEqualTo(false); - if (isClob) { - assertThat(internalProp.get("clobValue")).isEqualTo(xml); - assertThat(internalProp.get("textValue")).isNull(); - } else { - assertThat(internalProp.get("textValue")).isEqualTo(xml); - assertThat(internalProp.get("clobValue")).isNull(); - } - assertThat(internalProp.get("createdAt")).isEqualTo(NOW); - - // property "views.def" has been deleted - List<Map<String, Object>> properties = db.select("select prop_key as \"prop_key\" from properties"); - assertThat(properties).hasSize(1); - assertThat(properties.get(0).get("prop_key")).isEqualTo("other.property"); - } - -} diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest/old_ce_activity.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest/old_ce_activity.sql deleted file mode 100644 index a519e005821..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/AddErrorColumnsToCeActivityTest/old_ce_activity.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE "CE_ACTIVITY" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "UUID" VARCHAR(40) NOT NULL, - "TASK_TYPE" VARCHAR(15) NOT NULL, - "COMPONENT_UUID" VARCHAR(40) NULL, - "ANALYSIS_UUID" VARCHAR(50) NULL, - "STATUS" VARCHAR(15) NOT NULL, - "IS_LAST" BOOLEAN NOT NULL, - "IS_LAST_KEY" VARCHAR(55) NOT NULL, - "SUBMITTER_LOGIN" VARCHAR(255) NULL, - "SUBMITTED_AT" BIGINT NOT NULL, - "STARTED_AT" BIGINT NULL, - "EXECUTED_AT" BIGINT NULL, - "CREATED_AT" BIGINT NOT NULL, - "UPDATED_AT" BIGINT NOT NULL, - "EXECUTION_TIME_MS" BIGINT NULL -); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CopyActivitiesToQprofileChangesTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CopyActivitiesToQprofileChangesTest/schema.sql deleted file mode 100644 index 8f8df334379..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/CopyActivitiesToQprofileChangesTest/schema.sql +++ /dev/null @@ -1,22 +0,0 @@ -CREATE TABLE "ACTIVITIES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "LOG_KEY" VARCHAR(250), - "PROFILE_KEY" VARCHAR(255) NOT NULL, - "CREATED_AT" TIMESTAMP, - "USER_LOGIN" VARCHAR(255), - "LOG_TYPE" VARCHAR(250), - "LOG_ACTION" VARCHAR(250), - "LOG_MESSAGE" VARCHAR(250), - "DATA_FIELD" CLOB(2147483647) -); -CREATE UNIQUE INDEX "ACTIVITIES_LOG_KEY" ON "ACTIVITIES" ("LOG_KEY"); - -CREATE TABLE "QPROFILE_CHANGES" ( - "KEE" VARCHAR(40) NOT NULL PRIMARY KEY, - "QPROFILE_KEY" VARCHAR(255) NOT NULL, - "CHANGE_TYPE" VARCHAR(20) NOT NULL, - "CREATED_AT" BIGINT NOT NULL, - "USER_LOGIN" VARCHAR(255), - "CHANGE_DATA" CLOB -); -CREATE INDEX "QPROFILE_CHANGES_QPROFILE_KEY" ON "QPROFILE_CHANGES" ("QPROFILE_KEY"); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableCeTaskInputTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableCeTaskInputTest/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableCeTaskInputTest/empty.sql +++ /dev/null diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableInternalPropertiesTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableInternalPropertiesTest/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableInternalPropertiesTest/empty.sql +++ /dev/null diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableProperties2Test/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableProperties2Test/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableProperties2Test/empty.sql +++ /dev/null diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableQprofileChangesTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableQprofileChangesTest/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableQprofileChangesTest/empty.sql +++ /dev/null diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableRuleRepositoriesTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableRuleRepositoriesTest/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/CreateTableRuleRepositoriesTest/empty.sql +++ /dev/null diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteProjectDashboardsTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteProjectDashboardsTest/schema.sql deleted file mode 100644 index 1030e93bff0..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteProjectDashboardsTest/schema.sql +++ /dev/null @@ -1,39 +0,0 @@ -CREATE TABLE "DASHBOARDS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "USER_ID" INTEGER, - "NAME" VARCHAR(256), - "DESCRIPTION" VARCHAR(1000), - "COLUMN_LAYOUT" VARCHAR(20), - "SHARED" BOOLEAN, - "IS_GLOBAL" BOOLEAN, - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP -); - -CREATE TABLE "ACTIVE_DASHBOARDS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "DASHBOARD_ID" INTEGER NOT NULL, - "USER_ID" INTEGER, - "ORDER_INDEX" INTEGER -); - -CREATE TABLE "WIDGETS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "DASHBOARD_ID" INTEGER NOT NULL, - "WIDGET_KEY" VARCHAR(256) NOT NULL, - "NAME" VARCHAR(256), - "DESCRIPTION" VARCHAR(1000), - "COLUMN_INDEX" INTEGER, - "ROW_INDEX" INTEGER, - "CONFIGURED" BOOLEAN, - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP, - "RESOURCE_ID" INTEGER -); - -CREATE TABLE "WIDGET_PROPERTIES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "WIDGET_ID" INTEGER NOT NULL, - "KEE" VARCHAR(100), - "TEXT_VALUE" VARCHAR(4000) -); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql deleted file mode 100644 index 2b74746090d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/DeleteReportsFromCeQueueTest/schema.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE "CE_QUEUE" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "UUID" VARCHAR(40) NOT NULL, - "TASK_TYPE" VARCHAR(15) NOT NULL, - "COMPONENT_UUID" VARCHAR(40) NULL, - "STATUS" VARCHAR(15) NOT NULL, - "SUBMITTER_LOGIN" VARCHAR(255) NULL, - "STARTED_AT" BIGINT NULL, - "CREATED_AT" BIGINT NOT NULL, - "UPDATED_AT" BIGINT NOT NULL -); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/PopulateTableProperties2Test/properties_and_properties_2_tables.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/PopulateTableProperties2Test/properties_and_properties_2_tables.sql deleted file mode 100644 index 9781eda6197..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/PopulateTableProperties2Test/properties_and_properties_2_tables.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE TABLE "PROPERTIES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROP_KEY" VARCHAR(512), - "RESOURCE_ID" INTEGER, - "TEXT_VALUE" CLOB(2147483647), - "USER_ID" INTEGER -); -CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY"); - -CREATE TABLE "PROPERTIES2" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROP_KEY" VARCHAR(512) NOT NULL, - "RESOURCE_ID" INTEGER, - "USER_ID" INTEGER, - "IS_EMPTY" BOOLEAN NOT NULL, - "TEXT_VALUE" VARCHAR(4000), - "CLOB_VALUE" CLOB(2147483647), - "CREATED_AT" BIGINT -); -CREATE INDEX "PROPERTIES2_KEY" ON "PROPERTIES2" ("PROP_KEY"); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v61/RemoveViewsDefinitionFromPropertiesTest/properties_and_internal_properties.sql b/sonar-db/src/test/resources/org/sonar/db/version/v61/RemoveViewsDefinitionFromPropertiesTest/properties_and_internal_properties.sql deleted file mode 100644 index e38510f469a..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v61/RemoveViewsDefinitionFromPropertiesTest/properties_and_internal_properties.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE "PROPERTIES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROP_KEY" VARCHAR(512), - "RESOURCE_ID" INTEGER, - "TEXT_VALUE" CLOB(2147483647), - "USER_ID" INTEGER -); - -CREATE TABLE "INTERNAL_PROPERTIES" ( - "KEE" VARCHAR(50) NOT NULL PRIMARY KEY, - "IS_EMPTY" BOOLEAN NOT NULL, - "TEXT_VALUE" VARCHAR(4000), - "CLOB_VALUE" CLOB, - "CREATED_AT" BIGINT -); - -CREATE UNIQUE INDEX "UNIQ_INTERNAL_PROPERTIES" ON "INTERNAL_PROPERTIES" ("KEE"); |