use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceLongReturningNull.
@Test
public void testEnforceLongReturningNull() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("long", SchemaBuilder.int64());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
assertNull(genericRowValueTypeEnforcer.enforceFieldType(0, null));
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceDoubleOnValidCharSequence.
@Test
public void testEnforceDoubleOnValidCharSequence() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("double", SchemaBuilder.float64());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
assertEquals(1.0, genericRowValueTypeEnforcer.enforceFieldType(0, new StringBuilder("1.0")));
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceIntegerAndEnforceIntegerOne.
@Test
public void testEnforceIntegerAndEnforceIntegerOne() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("int", SchemaBuilder.int32());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
assertEquals(55, genericRowValueTypeEnforcer.enforceFieldType(0, 55));
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceInteger.
@Test
public void testEnforceInteger() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("int", SchemaBuilder.int32());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
try {
genericRowValueTypeEnforcer.enforceFieldType(0, schemaBuilder);
fail("Expecting exception: KsqlException");
} catch (KsqlException e) {
assertEquals(GenericRowValueTypeEnforcer.class.getName(), e.getStackTrace()[0].getClassName());
}
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceIntegerThrowsNumberFormatExceptionOnInvalidCharSequence.
@Test
public void testEnforceIntegerThrowsNumberFormatExceptionOnInvalidCharSequence() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("int", SchemaBuilder.int32());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
try {
genericRowValueTypeEnforcer.enforceFieldType(0, new StringBuilder("Not A number"));
fail("Expecting exception: NumberFormatException");
} catch (NumberFormatException e) {
assertEquals(NumberFormatException.class.getName(), e.getStackTrace()[0].getClassName());
}
}
Aggregations