Clover Coverage Report - Liquibase Integration Tests 2.0.2
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
40   100   6   8
2   85   0.15   5
5     1.2  
1    
 
  AddColumnExecutorTest       Line # 27 40 0% 6 47 0% 0.0
 
No Tests
 
1    package liquibase.statementexecute;
2   
3    import liquibase.database.Database;
4    import liquibase.database.core.MSSQLDatabase;
5    import liquibase.database.core.MaxDBDatabase;
6    import liquibase.database.core.MySQLDatabase;
7    import liquibase.database.core.PostgresDatabase;
8    import liquibase.database.core.SQLiteDatabase;
9    import liquibase.database.core.SybaseASADatabase;
10    import liquibase.database.core.SybaseDatabase;
11    import liquibase.database.core.CacheDatabase;
12    import liquibase.database.core.*;
13    import liquibase.database.typeconversion.TypeConverterFactory;
14    import liquibase.test.TestContext;
15    import liquibase.test.DatabaseTestContext;
16    import liquibase.statement.*;
17    import liquibase.statement.core.AddColumnStatement;
18    import liquibase.statement.core.CreateTableStatement;
19    import liquibase.sqlgenerator.SqlGeneratorFactory;
20    import liquibase.sql.Sql;
21   
22    import java.util.List;
23    import java.util.ArrayList;
24   
25    import org.junit.Test;
26   
 
27    public class AddColumnExecutorTest extends AbstractExecuteTest {
28   
29    protected static final String TABLE_NAME = "table_name";
30   
 
31  0 toggle @Override
32    protected List<? extends SqlStatement> setupStatements(Database database) {
33  0 ArrayList<CreateTableStatement> statements = new ArrayList<CreateTableStatement>();
34  0 CreateTableStatement table = new CreateTableStatement(null, TABLE_NAME);
35  0 table.addColumn("id", TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false), null, new NotNullConstraint());
36  0 statements.add(table);
37   
38  0 if (database.supportsSchemas()) {
39  0 table = new CreateTableStatement(DatabaseTestContext.ALT_SCHEMA, TABLE_NAME);
40  0 table.addColumn("id", TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false), null, new NotNullConstraint());
41  0 statements.add(table);
42    }
43  0 return statements;
44    }
45   
 
46  0 toggle @SuppressWarnings("unchecked")
47    @Test
48    public void generateSql_autoIncrement() throws Exception {
49  0 this.statementUnderTest = new AddColumnStatement(null, "table_name", "column_name", "int", null, new AutoIncrementConstraint("column_name"));
50   
51  0 assertCorrect("alter table table_name add column_name serial", InformixDatabase.class);
52  0 assertCorrect("alter table [table_name] add [column_name] int default autoincrement null", SybaseASADatabase.class);
53  0 assertCorrect("alter table [table_name] add [column_name] serial", PostgresDatabase.class);
54  0 assertCorrect("alter table [dbo].[table_name] add [column_name] int identity", MSSQLDatabase.class);
55  0 assertCorrect("alter table [table_name] add [column_name] int identity null", SybaseDatabase.class);
56  0 assertCorrect("not supported. fixme!!", SQLiteDatabase.class);
57  0 assertCorrect("alter table table_name add column_name int auto_increment_clause");
58    }
59   
 
60  0 toggle @SuppressWarnings("unchecked")
61    @Test
62    public void generateSql_notNull() throws Exception {
63  0 this.statementUnderTest = new AddColumnStatement(null, "table_name", "column_name", "int", 42, new NotNullConstraint());
64  0 assertCorrect("alter table [table_name] add [column_name] int not null default 42", CacheDatabase.class, MaxDBDatabase.class);
65  0 assertCorrect("alter table [table_name] add [column_name] int default 42 not null", SybaseASADatabase.class, SybaseDatabase.class);
66  0 assertCorrect("alter table table_name add column_name int not null default 42", PostgresDatabase.class);
67  0 assertCorrect("alter table [dbo].[table_name] add [column_name] int not null constraint df_table_name_column_name default 42", MSSQLDatabase.class);
68  0 assertCorrect("alter table `table_name` add `column_name` int not null default 42", MySQLDatabase.class);
69  0 assertCorrect("not supported. fixme!!", SQLiteDatabase.class);
70  0 assertCorrect("ALTER TABLE [table_name] ADD [column_name] int DEFAULT 42 NOT NULL");
71    }
72   
 
73  0 toggle @SuppressWarnings("unchecked")
74    @Test
75    public void generateSql_primaryKey() throws Exception {
76  0 this.statementUnderTest = new AddColumnStatement(null, "table_name", "column_name", "int", null, new PrimaryKeyConstraint());
77   
78  0 assertCorrect("alter table [table_name] add [column_name] int not null primary key", HsqlDatabase.class, MaxDBDatabase.class);
79  0 assertCorrect("alter table [table_name] add [column_name] int primary key not null", SybaseASADatabase.class, SybaseDatabase.class);
80  0 assertCorrect("alter table [dbo].[table_name] add [column_name] int not null primary key", MSSQLDatabase.class);
81  0 assertCorrect("alter table table_name add column_name int not null primary key", PostgresDatabase.class);
82  0 assertCorrect("alter table `table_name` add `column_name` int not null primary key", MySQLDatabase.class);
83  0 assertCorrect("ALTER TABLE [table_name] ADD [column_name] int PRIMARY KEY NOT NULL");
84    }
85   
 
86  0 toggle @SuppressWarnings("unchecked")
87    @Test
88    public void generateSql_foreignKey() throws Exception {
89  0 this.statementUnderTest = new AddColumnStatement(null, "table_name", "column_name", "int", null, new PrimaryKeyConstraint(), new ForeignKeyConstraint("fk_test_fk", "table_name(column_name)"));
90   
91  0 assertCorrect(new String[] {"alter table [table_name] add [column_name] int not null primary key", "alter table [table_name] add constraint [fk_test_fk] foreign key ([column_name]) references [table_name]([column_name])"}, HsqlDatabase.class, MaxDBDatabase.class);
92  0 assertCorrect(new String[] {"alter table [table_name] add [column_name] int primary key not null", "alter table [table_name] add constraint [fk_test_fk] foreign key ([column_name]) references [table_name]([column_name])"}, SybaseASADatabase.class, SybaseDatabase.class);
93  0 assertCorrect(new String[] {"alter table [dbo].[table_name] add [column_name] int not null primary key", "alter table [dbo].[table_name] add constraint [fk_test_fk] foreign key ([column_name]) references [dbo].[table_name]([column_name])"}, MSSQLDatabase.class);
94  0 assertCorrect(new String[] {"alter table table_name add column_name int not null primary key", "alter table [table_name] add constraint [fk_test_fk] foreign key ([column_name]) references [table_name]([column_name])"}, PostgresDatabase.class);
95  0 assertCorrect(new String[] {"alter table `table_name` add `column_name` int not null primary key", "alter table [table_name] add constraint [fk_test_fk] foreign key ([column_name]) references [table_name]([column_name])"}, MySQLDatabase.class);
96  0 assertCorrect(new String[] {"ALTER TABLE [table_name] ADD [column_name] int PRIMARY KEY NOT NULL", "alter table [table_name] add constraint foreign key ([column_name]) references [table_name]([column_name]) constraint [fk_test_fk]"}, InformixDatabase.class);
97  0 assertCorrect(new String[] {"ALTER TABLE [table_name] ADD [column_name] int PRIMARY KEY NOT NULL", "alter table [table_name] add constraint [fk_test_fk] foreign key ([column_name]) references [table_name]([column_name])"});
98    }
99   
100    }