1 package org.sonar.server.platform.db.migration.version.v63;
3 import java.sql.SQLException;
5 import javax.annotation.Nullable;
8 import org.junit.rules.ExpectedException;
9 import org.sonar.api.utils.System2;
10 import org.sonar.db.DbTester;
12 public class MakeColumnGuardedOfOrganizationsNotNullableTest {
13 private static final String TABLE_ORGANIZATIONS = "organizations";
16 public DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, MakeColumnGuardedOfOrganizationsNotNullableTest.class, "organizations_with_nullable_guarded.sql");
18 public ExpectedException expectedException = ExpectedException.none();
20 private MakeColumnGuardedOfOrganizationsNotNullable underTest = new MakeColumnGuardedOfOrganizationsNotNullable(dbTester.database());
23 public void migration_sets_guarded_column_not_nullable_on_empty_table() throws SQLException {
26 verifyColumnDefinition();
30 public void migration_sets_guarded_column_not_nullable_on_populated_table() throws SQLException {
31 insertOrganization("org_A", true);
32 insertOrganization("org_B", false);
36 verifyColumnDefinition();
40 public void migration_fails_if_some_row_has_a_null_guarded() throws SQLException {
41 insertOrganization("org_c", null);
43 expectedException.expect(IllegalStateException.class);
44 expectedException.expectMessage("Fail to execute");
49 private void verifyColumnDefinition() {
50 dbTester.assertColumnDefinition(TABLE_ORGANIZATIONS, "guarded", Types.BOOLEAN, null, false);
53 private void insertOrganization(String uuid, @Nullable Boolean guarded) {
54 dbTester.executeInsert(
59 "GUARDED", guarded == null ? null : String.valueOf(guarded),
61 "UPDATED_AT", "1000");