package datability;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.sql.Connection;

public class PostgreSqlTest {

    @ClassRule
    public static PostgresqlRule postgreSql = new PostgresqlRule();

    @Test
    public void table_with_not_null() throws Exception {
        postgreSql.execute("drop table if exists mytable", "create table mytable (a int not null)");

        try (Connection connection = postgreSql.openConnection()) {
            Databases.postgresql(connection).disableNotNulls("mytable");
            connection.createStatement().execute("insert into mytable(a) values (null)");
        }
    }

    @Test
    public void table_with_many_not_nulls() throws Exception {
        postgreSql.execute("drop table if exists mytable", "create table mytable (a int not null, b text not null)");

        try (Connection connection = postgreSql.openConnection()) {
            Databases.postgresql(connection).disableNotNulls("mytable");
            connection.createStatement().execute("insert into mytable(a,b) values (null,null)");
        }
    }

    @Test
    public void table_with_not_null_and_primary_key() throws Exception {
        postgreSql.execute("drop table if exists mytable", "create table mytable (a int primary key, b int not null)");

        try (Connection connection = postgreSql.openConnection()) {
            Databases.postgresql(connection).disableNotNulls("mytable");
            connection.createStatement().execute("insert into mytable(a,b) values (1, null)");
        }
    }

    @Test
    public void two_tables_with_not_nulls() throws Exception {
        postgreSql.execute(
                "drop table if exists tablea", "create table tablea (a int not null, b text not null)",
                "drop table if exists tableb", "create table tableb (c int not null, d text not null)");

        try (Connection connection = postgreSql.openConnection()) {
            Databases.postgresql(connection).disableNotNulls("tablea", "tableb");
            connection.createStatement().execute("insert into tablea(a,b) values (null, null)");
            connection.createStatement().execute("insert into tableb(c,d) values (null, null)");
        }
    }
}
@@ -259,35 +259,46 @@
 ic void 
-table_with_not_null
+drop_not_nulls_on_single_table
 () throw
@@ -679,32 +679,57 @@
     public void 
+drop_not_nulls_on_single_
 table_with_many_
@@ -1163,31 +1163,43 @@
 oid 
-table_with_not_null_and
+drop_not_nulls_on_single_table_with
 _pri
@@ -1632,32 +1632,536 @@
 oid 
-two
+drop_not_nulls_on_single
 _table
-s
 _with_
-not_null
+composite_primary_key() throws Exception %7B%0A        postgreSql.execute(%22drop table if exists mytable%22, %22create table mytable (a int, b int, c int not null, primary key (a,b))%22);%0A%0A        try (Connection connection = postgreSql.openConnection()) %7B%0A            Databases.postgresql(connection).disableNotNulls(%22mytable%22);%0A            connection.createStatement().execute(%22insert into mytable(a,b,c) values (1,1,null)%22);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void drop_not_nulls_on_multiple_table
 s() 

Add test case for composite primary key