use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceDoubleReturningDoubleWhereShortValueIsPositive.
@Test
public void testEnforceDoubleReturningDoubleWhereShortValueIsPositive() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("double", SchemaBuilder.float64());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
assertEquals(366.0, genericRowValueTypeEnforcer.enforceFieldType(0, 366L));
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceStringReturningNull.
@Test
public void testEnforceStringReturningNull() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("string", SchemaBuilder.string());
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 testEnforceDouble.
@Test
public void testEnforceDouble() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("double", SchemaBuilder.float64());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
Object object = new Object();
try {
genericRowValueTypeEnforcer.enforceFieldType(0, object);
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 testEnforceLongOnValidCharSequence.
@Test
public void testEnforceLongOnValidCharSequence() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("long", SchemaBuilder.int64());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
assertEquals(123L, genericRowValueTypeEnforcer.enforceFieldType(0, new StringBuilder("123")));
}
use of org.apache.kafka.connect.data.SchemaBuilder in project ksql by confluentinc.
the class GenericRowValueTypeEnforcerTest method testEnforceDoubleThrowsNumberFormatExceptionOnInvalidString.
@Test(expected = NumberFormatException.class)
public void testEnforceDoubleThrowsNumberFormatExceptionOnInvalidString() {
SchemaBuilder schemaBuilder = SchemaBuilder.struct().field("double", SchemaBuilder.float64());
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
genericRowValueTypeEnforcer.enforceFieldType(0, "not a double");
}
Aggregations