DBZ-870 Adding test

This commit is contained in:
Gunnar Morling 2018-08-23 10:12:59 +02:00
parent 99ab131910
commit 414ebe5f13
2 changed files with 40 additions and 3 deletions

View File

@ -32,11 +32,11 @@
*/
public abstract class AbstractMysqlDefaultValueTest {
private AbstractDdlParser parser;
private Tables tables;
protected AbstractDdlParser parser;
protected Tables tables;
private MySqlValueConverters converters;
protected Function<MySqlValueConverters, AbstractDdlParser> parserProducer;
@Before
public void beforeEach() {
converters = new MySqlValueConverters(JdbcValueConverters.DecimalMode.DOUBLE,
@ -355,4 +355,6 @@ public void parseTimeDefaultValue() {
assertThat(table.columnWithName("K").defaultValue()).isEqualTo(Date.from(ZonedDateTime.of(2018, 6, 26, 12, 34, 56, 0, ZoneOffset.UTC).toInstant()));
assertThat(table.columnWithName("L").defaultValue()).isEqualTo(Date.from(ZonedDateTime.of(2018, 6, 26, 12, 34, 56, 780_000_000, ZoneOffset.UTC).toInstant()));
}
}

View File

@ -5,7 +5,18 @@
*/
package io.debezium.connector.mysql;
import static org.fest.assertions.Assertions.assertThat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import org.junit.Test;
import io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser;
import io.debezium.doc.FixFor;
import io.debezium.relational.Table;
import io.debezium.relational.TableId;
/**
* @author Jiri Pechanec <jpechane@redhat.com>
@ -15,4 +26,28 @@ public class MysqlAntlrDefaultValueTest extends AbstractMysqlDefaultValueTest {
{
parserProducer = MySqlAntlrDdlParser::new;
}
@Test
@FixFor("DBZ-870")
public void shouldAcceptZeroAsDefaultValueForDateColumn() {
String ddl = "CREATE TABLE data(id INT, nullable_date date default 0, not_nullable_date date not null default 0, PRIMARY KEY (id))";
parser.parse(ddl, tables);
Table table = tables.forTable(new TableId(null, null, "data"));
assertThat(table.columnWithName("nullable_date").hasDefaultValue()).isTrue();
// zero date should be mapped to null for nullable column
assertThat(table.columnWithName("nullable_date").defaultValue()).isNull();
assertThat(table.columnWithName("not_nullable_date").hasDefaultValue()).isTrue();
// zero date should be mapped to epoch for non-nullable column (expecting Date, as this test is using "connect"
// mode)
assertThat(table.columnWithName("not_nullable_date").defaultValue()).isEqualTo(getEpochDate());
}
private Date getEpochDate() {
return Date.from(LocalDate.of(1970, 1, 1).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
}