From 7b237f393114a8ead34955c96fc874987015604f Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Wed, 21 Apr 2021 13:23:27 +0200 Subject: [PATCH] SONAR-14686 - Fail silently on PK to be dropped not found --- .../sql/DbPrimaryKeyConstraintFinder.java | 5 ++--- .../sql/DropPrimaryKeySqlGenerator.java | 15 ++++++++++----- .../sql/DbPrimaryKeyConstraintFinderTest.java | 12 ++++++------ .../sql/DropPrimaryKeySqlGeneratorTest.java | 16 +++++++++------- ...nIdColumnOfActiveRuleParametersTableTest.java | 7 +++---- ...imaryKeyOnIdColumnOfActiveRulesTableTest.java | 7 +++---- ...rimaryKeyOnIdColumnOfCeActivityTableTest.java | 7 +++---- ...opPrimaryKeyOnIdColumnOfCeQueueTableTest.java | 7 +++---- ...eyOnIdColumnOfDuplicationsIndexTableTest.java | 7 +++---- ...ropPrimaryKeyOnIdColumnOfEventsTableTest.java | 7 +++---- ...imaryKeyOnIdColumnOfFileSourcesTableTest.java | 7 +++---- ...rimaryKeyOnIdColumnOfGroupRolesTableTest.java | 7 +++---- ...ropPrimaryKeyOnIdColumnOfGroupsTableTest.java | 7 +++---- ...ryKeyOnIdColumnOfManualMeasuresTableTest.java | 7 +++---- ...opPrimaryKeyOnIdColumnOfMetricsTableTest.java | 5 +++-- ...maryKeyOnIdColumnOfNotificationTableTest.java | 7 +++---- ...OnIdColumnOfPermissionTemplatesTableTest.java | 7 +++---- ...OnIdColumnOfPermTemplatesGroupsTableTest.java | 7 +++---- ...yOnIdColumnOfPermTemplatesUsersTableTest.java | 7 +++---- ...dColumnOfPermTplCharacteristicsTableTest.java | 7 +++---- ...yKeyOnIdColumnOfProjectMeasuresTableTest.java | 8 +++----- ...KeyOnIdColumnOfProjectQProfilesTableTest.java | 7 +++---- ...rimaryKeyOnIdColumnOfPropertiesTableTest.java | 7 +++---- ...IdColumnOfQualityGateConditionsTableTest.java | 7 +++---- ...ropPrimaryKeyOnIdColumnOfQGatesTableTest.java | 7 +++---- ...DropPrimaryKeyOnIdColumnOfRulesTableTest.java | 12 +++++++----- ...aryKeyOnIdColumnOfRulesMetadataTableTest.java | 14 +++++++------- ...yKeyOnIdColumnOfRulesParametersTableTest.java | 7 +++---- ...aryKeyOnIdColumnOfRulesProfilesTableTest.java | 7 +++---- ...PrimaryKeyOnIdColumnOfSnapshotsTableTest.java | 7 +++---- ...DropPrimaryKeyOnIdColumnOfUsersTableTest.java | 7 +++---- ...zationUuidOfOrganizationMembersTableTest.java | 7 +++---- ...rimaryKeyOnIdColumnOfUserTokensTableTest.java | 7 +++---- 33 files changed, 122 insertions(+), 140 deletions(-) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java index 833db36471f..01754aebd0c 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java @@ -42,10 +42,9 @@ public class DbPrimaryKeyConstraintFinder { this.db = db; } - public String findConstraintName(String tableName) throws SQLException { + public Optional findConstraintName(String tableName) throws SQLException { String constraintQuery = getDbVendorSpecificQuery(tableName); - return executeQuery(constraintQuery) - .orElseThrow(() -> constraintNotFoundException(tableName)); + return executeQuery(constraintQuery); } String getDbVendorSpecificQuery(String tableName) { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java index 1e4731386dd..6e42b47eb92 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java @@ -22,7 +22,9 @@ package org.sonar.server.platform.db.migration.sql; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.sonar.db.Database; import org.sonar.db.dialect.Dialect; import org.sonar.db.dialect.H2; @@ -51,16 +53,19 @@ public class DropPrimaryKeySqlGenerator { public List generate(String tableName, Collection columnNames, boolean isAutoGenerated) throws SQLException { Dialect dialect = db.getDialect(); - String constraintName = dbConstraintFinder.findConstraintName(tableName); + Optional constraintName = dbConstraintFinder.findConstraintName(tableName); + if (!constraintName.isPresent()) { + return Collections.emptyList(); + } switch (dialect.getId()) { case PostgreSql.ID: - return generateForPostgresSql(tableName, columnNames, constraintName); + return generateForPostgresSql(tableName, columnNames, constraintName.get()); case MsSql.ID: - return generateForMsSql(tableName, constraintName); + return generateForMsSql(tableName, constraintName.get()); case Oracle.ID: - return generateForOracle(tableName, constraintName, isAutoGenerated); + return generateForOracle(tableName, constraintName.get(), isAutoGenerated); case H2.ID: - return generateForH2(tableName, constraintName); + return generateForH2(tableName, constraintName.get()); default: throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId())); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java index faf94bea5c9..ce68bdd0f0d 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java @@ -21,6 +21,7 @@ package org.sonar.server.platform.db.migration.sql; import java.sql.Connection; import java.sql.SQLException; +import java.util.Optional; import javax.sql.DataSource; import org.junit.Rule; import org.junit.Test; @@ -52,16 +53,15 @@ public class DbPrimaryKeyConstraintFinderTest { @Test public void findConstraintName_constraint_exists() throws SQLException { DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database()); - String constraintName = underTest.findConstraintName("TEST_PRIMARY_KEY"); - assertThat(constraintName).isEqualTo("PK_TEST_PRIMARY_KEY"); + Optional constraintName = underTest.findConstraintName("TEST_PRIMARY_KEY"); + assertThat(constraintName).isPresent(); + assertThat(constraintName.get()).contains("PK_TEST_PRIMARY_KEY"); } @Test - public void findConstraintName_constraint_not_exist() { + public void findConstraintName_constraint_not_exist_fails_silently() throws SQLException { DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database()); - assertThatThrownBy(() -> underTest.findConstraintName("NOT_EXISTING_TABLE")) - .hasMessage("Cannot find constraint for table 'NOT_EXISTING_TABLE'") - .isInstanceOf(IllegalStateException.class); + assertThat(underTest.findConstraintName("NOT_EXISTING_TABLE")).isNotPresent(); } @Test diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java index f74a7602767..e44495148c8 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java @@ -21,6 +21,7 @@ package org.sonar.server.platform.db.migration.sql; import java.sql.SQLException; import java.util.List; +import java.util.Optional; import org.junit.Test; import org.sonar.db.Database; import org.sonar.db.dialect.Dialect; @@ -51,10 +52,11 @@ public class DropPrimaryKeySqlGeneratorTest { private final DropPrimaryKeySqlGenerator underTest = new DropPrimaryKeySqlGenerator(db, dbConstraintFinder); @Test - public void generate_unknown_dialect() { + public void generate_unknown_dialect() throws SQLException { Dialect mockDialect = mock(Dialect.class); when(mockDialect.getId()).thenReturn("unknown-db-vendor"); when(db.getDialect()).thenReturn(mockDialect); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); assertThatThrownBy(() -> underTest.generate(TABLE_NAME, PK_COLUMN, true)) .isInstanceOf(IllegalStateException.class); @@ -62,7 +64,7 @@ public class DropPrimaryKeySqlGeneratorTest { @Test public void generate_for_postgres_sql() throws SQLException { - when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); when(dbConstraintFinder.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(TABLE_NAME + "_id_seq"); when(db.getDialect()).thenReturn(POSTGRESQL); @@ -75,7 +77,7 @@ public class DropPrimaryKeySqlGeneratorTest { @Test public void generate_for_postgres_sql_no_seq() throws SQLException { - when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); when(dbConstraintFinder.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(null); when(db.getDialect()).thenReturn(POSTGRESQL); @@ -87,7 +89,7 @@ public class DropPrimaryKeySqlGeneratorTest { @Test public void generate_for_ms_sql() throws SQLException { - when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); when(db.getDialect()).thenReturn(MS_SQL); List sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true); @@ -97,7 +99,7 @@ public class DropPrimaryKeySqlGeneratorTest { @Test public void generate_for_oracle_autogenerated_true() throws SQLException { - when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); when(db.getDialect()).thenReturn(ORACLE); List sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true); @@ -109,7 +111,7 @@ public class DropPrimaryKeySqlGeneratorTest { @Test public void generate_for_oracle_autogenerated_false() throws SQLException { - when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); when(db.getDialect()).thenReturn(ORACLE); List sqls = underTest.generate(TABLE_NAME, PK_COLUMN, false); @@ -119,7 +121,7 @@ public class DropPrimaryKeySqlGeneratorTest { @Test public void generate_for_h2() throws SQLException { - when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT); + when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT)); when(db.getDialect()).thenReturn(H2); List sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java index 6694a3a73d9..c30ebc22584 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest { private static final String TABLE_NAME = "active_rule_parameters"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java index 624616b197d..f33d82dd7b5 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfActiveRulesTableTest { private static final String TABLE_NAME = "active_rules"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfActiveRulesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/DropPrimaryKeyOnIdColumnOfCeActivityTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/DropPrimaryKeyOnIdColumnOfCeActivityTableTest.java index 8d38f859bfd..09b11b665d6 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/DropPrimaryKeyOnIdColumnOfCeActivityTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/DropPrimaryKeyOnIdColumnOfCeActivityTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfCeActivityTableTest { private static final String TABLE_NAME = "ce_activity"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfCeActivityTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java index 02c6d4108e1..4f17918162b 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfCeQueueTableTest { private static final String TABLE_NAME = "ce_queue"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfCeQueueTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java index c5e6d3fc027..aeaf762def7 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest { private static final String TABLE_NAME = "duplications_index"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java index 3334c73ac7d..acd069c82c9 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java @@ -26,8 +26,6 @@ import org.sonar.db.CoreDbTester; import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfEventsTableTest { private static final String TABLE_NAME = "events"; @@ -46,9 +44,10 @@ public class DropPrimaryKeyOnIdColumnOfEventsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/filesources/DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/filesources/DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.java index d919b23671d..d859424ac43 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/filesources/DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/filesources/DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfFileSourcesTableTest { private static final String TABLE_NAME = "file_sources"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfFileSourcesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java index c29a70cfe17..65e279e04c3 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java @@ -26,8 +26,6 @@ import org.sonar.db.CoreDbTester; import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfGroupRolesTableTest { private static final String TABLE_NAME = "group_roles"; @@ -46,9 +44,10 @@ public class DropPrimaryKeyOnIdColumnOfGroupRolesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java index 3bb6a676462..99723e8f692 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfGroupsTableTest { private static final String TABLE_NAME = "groups"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfGroupsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.java index 447568e81a9..c670d997839 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest { private static final String TABLE_NAME = "manual_measures"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java index d4ff27457cb..ba2cc6188d2 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java @@ -47,9 +47,10 @@ public class DropPrimaryKeyOnIdColumnOfMetricsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/notifications/DropPrimaryKeyOnIdColumnOfNotificationTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/notifications/DropPrimaryKeyOnIdColumnOfNotificationTableTest.java index 4c4b65fd6c8..aa332a489a5 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/notifications/DropPrimaryKeyOnIdColumnOfNotificationTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/notifications/DropPrimaryKeyOnIdColumnOfNotificationTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfNotificationTableTest { private static final String TABLE_NAME = "notifications"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfNotificationTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.java index 3b285271f6a..66bb2ffb0cc 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest { private static final String TABLE_NAME = "permission_templates"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java index 8ad1b9e2ffa..b429bf529ee 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest { private static final String TABLE_NAME = "perm_templates_groups"; @@ -48,9 +46,10 @@ public class DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java index 5ce74c6d0a7..0754f744af5 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest { private static final String TABLE_NAME = "perm_templates_users"; @@ -48,9 +46,10 @@ public class DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java index 4ba5de120ff..55a39f46937 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest { private static final String TABLE_NAME = "perm_tpl_characteristics"; @@ -48,9 +46,10 @@ public class DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java index 69b19b097c3..6dd3642e47c 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest { private static final String TABLE_NAME = "project_measures"; @@ -47,10 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { underTest.execute(); - - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + underTest.execute(); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.java index 437d7718428..9f92f2447fc 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest { private static final String TABLE_NAME = "project_qprofiles"; @Rule @@ -46,9 +44,10 @@ public class DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/properties/DropPrimaryKeyOnIdColumnOfPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/properties/DropPrimaryKeyOnIdColumnOfPropertiesTableTest.java index b5c60304746..9c748ecdd43 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/properties/DropPrimaryKeyOnIdColumnOfPropertiesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/properties/DropPrimaryKeyOnIdColumnOfPropertiesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfPropertiesTableTest { private static final String TABLE_NAME = "properties"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfPropertiesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java index cea7cc9e615..ce1a4861f3e 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest { private static final String TABLE_NAME = "quality_gate_conditions"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java index 9bf5c072b5e..684e534d2c2 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfQGatesTableTest { private static final String TABLE_NAME = "quality_gates"; @@ -48,9 +46,10 @@ public class DropPrimaryKeyOnIdColumnOfQGatesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java index 34083c06d6b..e47a9781f51 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java @@ -30,6 +30,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStep; import static org.assertj.core.api.Assertions.assertThatThrownBy; public class DropPrimaryKeyOnIdColumnOfRulesTableTest { + private static final String TABLE_NAME = "rules"; @Rule public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesTableTest.class, "schema.sql"); @@ -39,18 +40,19 @@ public class DropPrimaryKeyOnIdColumnOfRulesTableTest { @Test public void execute() throws SQLException { - db.assertTableExists("rules"); - db.assertPrimaryKey("rules", "pk_rules", "id"); + db.assertTableExists(TABLE_NAME); + db.assertPrimaryKey(TABLE_NAME, "pk_rules", "id"); underTest.execute(); - db.assertNoPrimaryKey("rules"); + db.assertNoPrimaryKey(TABLE_NAME); } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java index 9599070a71e..351dcd1c21c 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java @@ -27,9 +27,8 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest { + private static final String TABLE_NAME = "rules_metadata"; @Rule public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.class, "schema.sql"); @@ -39,18 +38,19 @@ public class DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest { @Test public void execute() throws SQLException { - db.assertTableExists("rules_metadata"); - db.assertPrimaryKey("rules_metadata", "pk_rules_metadata", "rule_id", "organization_uuid"); + db.assertTableExists(TABLE_NAME); + db.assertPrimaryKey(TABLE_NAME, "pk_rules_metadata", "rule_id", "organization_uuid"); underTest.execute(); - db.assertNoPrimaryKey("rules_metadata"); + db.assertNoPrimaryKey(TABLE_NAME); } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java index 2a99521b12b..44715d55692 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfRulesParametersTableTest { private static final String TABLE_NAME = "rules_parameters"; @@ -47,10 +45,11 @@ public class DropPrimaryKeyOnIdColumnOfRulesParametersTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java index c4c7eeef714..1062c2c04eb 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest { private static final String TABLE_NAME = "rules_profiles"; @Rule @@ -46,9 +44,10 @@ public class DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/snapshots/DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/snapshots/DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.java index c6cb5abb90d..f55068b7a4f 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/snapshots/DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/snapshots/DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.version.v84.snapshots.issues.DropPrimaryKeyOnIdColumnOfSnapshotsTable; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfSnapshotsTableTest { private static final String TABLE_NAME = "snapshots"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfSnapshotsTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/DropPrimaryKeyOnIdColumnOfUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/DropPrimaryKeyOnIdColumnOfUsersTableTest.java index b5e43bd15a6..677b97c8f36 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/DropPrimaryKeyOnIdColumnOfUsersTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/DropPrimaryKeyOnIdColumnOfUsersTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfUsersTableTest { private static final String TABLE_NAME = "users"; @Rule @@ -46,9 +44,10 @@ public class DropPrimaryKeyOnIdColumnOfUsersTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.java index 02857768714..cbc0310e1f5 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.DdlChange; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest { private static final String TABLE_NAME = "organization_members"; @Rule @@ -46,9 +44,10 @@ public class DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/usertokens/DropPrimaryKeyOnIdColumnOfUserTokensTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/usertokens/DropPrimaryKeyOnIdColumnOfUserTokensTableTest.java index fdcc034b15d..48b4fd82831 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/usertokens/DropPrimaryKeyOnIdColumnOfUserTokensTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/usertokens/DropPrimaryKeyOnIdColumnOfUserTokensTableTest.java @@ -27,8 +27,6 @@ import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DropPrimaryKeyOnIdColumnOfUserTokensTableTest { private static final String TABLE_NAME = "user_tokens"; @@ -47,9 +45,10 @@ public class DropPrimaryKeyOnIdColumnOfUserTokensTableTest { } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant_but_fails_silently() throws SQLException { + underTest.execute(); underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + db.assertNoPrimaryKey(TABLE_NAME); } } -- 2.39.5