Skip to content

Commit

Permalink
#24133 fixing tests errors and implementing code review sugestions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyDotcms committed Apr 24, 2023
1 parent 879ca88 commit 19c11b6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Expand Up @@ -16,7 +16,7 @@ public class Task230420AlterVarcharLengthOfLockedByColTest {
// Change the length to recreate the scenario
private void setMinLengthBeforeTask (String tblName) throws SQLException {
String query = "";
if (DbType.POSTGRESQL == DbType.getDbType(DbConnectionFactory.getDBType())){
if (DbConnectionFactory.isPostgres()){
query = "alter table "+tblName+" alter column locked_by type varchar (36);";
}

Expand All @@ -26,7 +26,7 @@ private void setMinLengthBeforeTask (String tblName) throws SQLException {

// get the modified columns properties
private Map<String, String> getColProperties(String tblName) throws DotDataException {
String query = "select character_maximum_length as field_length, is_nullable as nullable_value " +
final String query = "select character_maximum_length as field_length, is_nullable as nullable_value " +
"from information_schema.columns " +
"where table_name = '"+tblName+"' and column_name='locked_by'";

Expand All @@ -44,26 +44,29 @@ private Map<String, String> getColProperties(String tblName) throws DotDataExcep
*/
@Test
public void test_executeUpgrade_GivenIncreaseLockedByLength_LengthShouldBeMoreThan36() throws SQLException, DotDataException {
String[] tableNames = { "contentlet_version_info", "container_version_info", "template_version_info", "link_version_info" };
Task230420AlterVarcharLengthOfLockedByCol taskToBeTested;
final String[] tableNames = { "contentlet_version_info", "container_version_info", "template_version_info", "link_version_info" };
Map<String, String> result;

//iterate and test all the tables
for (String tableName : tableNames) {
setMinLengthBeforeTask(tableName);
//set the length 36 to recreate the given scenario
result = getColProperties(tableName);
assertEquals("36", result.get("field_length"));
}
//The method is created and tested only for postgres
if (DbConnectionFactory.isPostgres()){

//iterate and test all the tables
for (String tableName : tableNames) {
setMinLengthBeforeTask(tableName);
//set the length 36 to recreate the given scenario
result = getColProperties(tableName);
assertEquals("36", result.get("field_length"));
}

//Execute the task
taskToBeTested = new Task230420AlterVarcharLengthOfLockedByCol();
taskToBeTested.executeUpgrade();
//Execute the task
final Task230420AlterVarcharLengthOfLockedByCol taskToBeTested = new Task230420AlterVarcharLengthOfLockedByCol();
taskToBeTested.executeUpgrade();

//Check if the length was increased to 100
for (String tableName : tableNames) {
result = getColProperties(tableName);
assertEquals("100", result.get("field_length"));
//Check if the length was increased to 100
for (String tableName : tableNames) {
result = getColProperties(tableName);
assertEquals("100", result.get("field_length"));
}
}

}
Expand Down
Expand Up @@ -14,11 +14,11 @@
*/
public class Task230420AlterVarcharLengthOfLockedByCol implements StartupTask {
private void alterTables() throws SQLException {
DotConnect dc = new DotConnect();
dc.executeStatement("alter table contentlet_version_info alter column locked_by type varchar (100);");
dc.executeStatement("alter table container_version_info alter column locked_by type varchar (100);");
dc.executeStatement("alter table template_version_info alter column locked_by type varchar (100);");
dc.executeStatement("alter table link_version_info alter column locked_by type varchar (100);");
final DotConnect dc = new DotConnect();
dc.executeStatement("alter table contentlet_version_info alter column locked_by type varchar (100)");
dc.executeStatement("alter table container_version_info alter column locked_by type varchar (100)");
dc.executeStatement("alter table template_version_info alter column locked_by type varchar (100)");
dc.executeStatement("alter table link_version_info alter column locked_by type varchar (100)");
}
@Override
public boolean forceRun() {
Expand Down

0 comments on commit 19c11b6

Please sign in to comment.