use of org.knime.core.table.schema.traits.DataTraits in project knime-core by knime.
the class ValueFactoryUtilsTest method testLoadValueFactory.
@Test
void testLoadValueFactory() {
var dataRepo = NotInWorkflowDataRepository.newInstance();
// no logical type trait
assertThrows(IllegalArgumentException.class, () -> ValueFactoryUtils.loadValueFactory(DefaultDataTraits.EMPTY, dataRepo));
// void
var voidTrait = ValueFactoryUtils.getTraits(VoidValueFactory.INSTANCE);
assertThat(ValueFactoryUtils.loadValueFactory(voidTrait, dataRepo)).isEqualTo(VoidValueFactory.INSTANCE);
// ordinary
DataTraits traits = ValueFactoryUtils.getTraits(IntValueFactory.INSTANCE);
//
assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isInstanceOf(IntValueFactory.class);
// specific collection
traits = ValueFactoryUtils.getTraits(IntListValueFactory.INSTANCE);
//
assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isEqualTo(IntListValueFactory.INSTANCE);
// nested collection
var nestedListValueFactory = new ListValueFactory();
nestedListValueFactory.initialize(IntListValueFactory.INSTANCE, DataType.getType(ListCell.class, DataType.getType(ListCell.class, IntCell.TYPE)));
traits = ValueFactoryUtils.getTraits(nestedListValueFactory);
//
assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isInstanceOf(//
ListValueFactory.class).extracting(//
ListValueFactory.class::cast).extracting(//
ListValueFactory::getElementValueFactory).isEqualTo(IntListValueFactory.INSTANCE);
// data cell value factory
var dictEncodedDataCellValueFactory = createDataCellValueFactory();
traits = ValueFactoryUtils.getTraits(dictEncodedDataCellValueFactory);
//
assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isInstanceOf(//
DictEncodedDataCellValueFactory.class).extracting(//
DictEncodedDataCellValueFactory.class::cast).extracting(//
DictEncodedDataCellValueFactory::getType).isEqualTo(XMLCell.TYPE);
// try to load an unregistered value factory
final var finalTraits = createSimpleTypeTraits(DummyDataValueFactory.class.getName());
assertThrows(IllegalArgumentException.class, () -> ValueFactoryUtils.loadValueFactory(finalTraits, dataRepo));
}
Aggregations