1 package net.jaekl.cfb.db.driver;
3 import static net.jaekl.cfb.db.Column.Null.*;
4 import static net.jaekl.cfb.db.Column.Type.*;
5 import static org.junit.Assert.*;
6 import net.jaekl.cfb.db.Column;
7 import net.jaekl.cfb.db.Table;
8 import net.jaekl.cfb.db.driver.PostgresqlDriver;
10 import org.junit.Test;
12 public class PostgresqlDriverTest {
15 public void testCreateColumnSql() {
16 final Object[][] input = {
17 {"FIRSTNAME", VARCHAR, 20, NOT_NULL},
18 {"LASTNAME", VARCHAR, 32, NOT_NULL},
19 {"COMPANYNAME", VARCHAR, 25, NULL},
20 {"AGE", INTEGER, -1, NULL},
21 {"GENDER", CHAR, 1, NOT_NULL}
23 final String[] expected = {
24 "FIRSTNAME VARCHAR(20) NOT NULL",
25 "LASTNAME VARCHAR(32) NOT NULL",
26 "COMPANYNAME VARCHAR(25) NULL",
28 "GENDER CHAR(1) NOT NULL"
31 PostgresqlDriver driver = new PostgresqlDriver();
33 for (int idx = 0; idx < input.length; ++idx) {
34 Object[] spec = input[idx];
35 Column column = Column.construct(spec);
36 String actual = driver.createColumnSql(column);
38 assertEquals(expected[idx], actual);
44 public void testCreateTableSql() {
45 Object[][][] input = {
48 {"ID", INTEGER, -1, NOT_NULL},
49 {"NAME", VARCHAR, 64, NOT_NULL}
54 "CREATE TABLE STUDENT(ID INTEGER NOT NULL, NAME VARCHAR(64) NOT NULL)"
57 PostgresqlDriver driver = new PostgresqlDriver();
59 for (int idx = 0; idx < input.length; ++idx) {
60 Table table = Table.construct(input[idx]);
61 String actual = driver.createTableSql(table);
62 assertEquals(expected[idx], actual);