@Test public void fresh_install_verifies_that_default_collation_is_CS_AS() throws SQLException { answerDefaultCollation("Latin1_General_CS_AS"); underTest.handle(connection, DatabaseCharsetChecker.State.FRESH_INSTALL); verify(metadata).getDefaultCollation(connection); }
@Test public void do_not_repair_system_tables_of_sql_azure() throws Exception { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs(new ColumnDef("sys.sysusers", COLUMN_NAME, "Latin1_General", "Latin1_General_CI_AI", "varchar", 10, false)); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor, never()).executeDdl(any(Connection.class), anyString()); }
@Test @UseDataProvider("combinationOfBinAndSuffix") public void do_not_repair_if_collation_contains_BIN(String collation) throws Exception { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs(new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", collation, "varchar", 10, false)); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor, never()).executeDdl(any(Connection.class), anyString()); }
@Test @UseDataProvider("combinationOfBin2AndSuffix") public void do_not_repair_if_collation_contains_BIN2(String collation) throws Exception { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs(new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", collation, "varchar", 10, false)); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor, never()).executeDdl(any(Connection.class), anyString()); }
/** * SONAR-7988 */ @Test public void fix_Latin1_CS_AS_columns_created_in_5_x() throws SQLException { answerDefaultCollation("SQL_Latin1_General_CP1_CS_AS"); answerColumnDefs(new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", "Latin1_General_CS_AS", "nvarchar", 10, false)); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor).executeDdl(connection, "ALTER TABLE projects ALTER COLUMN name nvarchar(10) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL"); }
@Test public void fresh_install_fails_if_default_collation_is_not_CS_AS() throws SQLException { answerDefaultCollation("Latin1_General_CI_AI"); expectedException.expect(MessageException.class); expectedException.expectMessage("Database collation must be case-sensitive and accent-sensitive. It is Latin1_General_CI_AI but should be Latin1_General_CS_AS."); underTest.handle(connection, DatabaseCharsetChecker.State.FRESH_INSTALL); }
@Test public void upgrade_repairs_CI_AI_columns() throws SQLException { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs( new ColumnDef(TABLE_ISSUES, COLUMN_KEE, "Latin1_General", "Latin1_General_CS_AS", "varchar", 10, false), new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", "Latin1_General_CI_AI", "varchar", 10, false)); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor).executeDdl(connection, "ALTER TABLE projects ALTER COLUMN name varchar(10) COLLATE Latin1_General_CS_AS NOT NULL"); }
@Test public void upgrade_fails_if_default_collation_is_not_CS_AS() throws SQLException { answerDefaultCollation("Latin1_General_CI_AI"); expectedException.expect(MessageException.class); expectedException.expectMessage("Database collation must be case-sensitive and accent-sensitive. It is Latin1_General_CI_AI but should be Latin1_General_CS_AS."); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); }
@Test @UseDataProvider("combinationsOfCsAsAndSuffix") public void repair_case_insensitive_accent_insensitive_combinations_with_or_without_suffix(String collation, String expectedCollation) throws Exception { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs(new ColumnDef(TABLE_ISSUES, COLUMN_KEE, "Latin1_General", collation, "varchar", 10, false)); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor).executeDdl(connection, "ALTER TABLE issues ALTER COLUMN kee varchar(10) COLLATE " + expectedCollation + " NOT NULL"); }
@Test public void support_the_max_size_of_varchar_column() throws Exception { answerDefaultCollation("Latin1_General_CS_AS"); // returned size is -1 answerColumnDefs(new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", "Latin1_General_CI_AI", "nvarchar", -1, false)); answerIndices(); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor).executeDdl(connection, "ALTER TABLE projects ALTER COLUMN name nvarchar(max) COLLATE Latin1_General_CS_AS NOT NULL"); }
@Test public void upgrade_checks_that_columns_are_CS_AS() throws SQLException { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs( new ColumnDef(TABLE_ISSUES, COLUMN_KEE, "Latin1_General", "Latin1_General_CS_AS", "varchar", 10, false), new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", "Latin1_General_CS_AS", "varchar", 10, false)); // do not fail underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); }
@Test public void upgrade_repairs_indexed_CI_AI_columns() throws SQLException { answerDefaultCollation("Latin1_General_CS_AS"); answerColumnDefs( new ColumnDef(TABLE_ISSUES, COLUMN_KEE, "Latin1_General", "Latin1_General_CS_AS", "varchar", 10, false), new ColumnDef(TABLE_PROJECTS, COLUMN_NAME, "Latin1_General", "Latin1_General_CI_AI", "varchar", 10, false)); answerIndices( new MssqlCharsetHandler.ColumnIndex("projects_name", false, "name"), // This index is on two columns. Note that it does not make sense for table "projects" ! new MssqlCharsetHandler.ColumnIndex("projects_login_and_name", true, "login,name")); underTest.handle(connection, DatabaseCharsetChecker.State.UPGRADE); verify(sqlExecutor).executeDdl(connection, "DROP INDEX projects.projects_name"); verify(sqlExecutor).executeDdl(connection, "DROP INDEX projects.projects_login_and_name"); verify(sqlExecutor).executeDdl(connection, "ALTER TABLE projects ALTER COLUMN name varchar(10) COLLATE Latin1_General_CS_AS NOT NULL"); verify(sqlExecutor).executeDdl(connection, "CREATE INDEX projects_name ON projects (name)"); verify(sqlExecutor).executeDdl(connection, "CREATE UNIQUE INDEX projects_login_and_name ON projects (login,name)"); }