use of org.knime.core.table.schema.traits.StructDataTraits in project knime-core by knime.
the class ValueFactoryUtilsTest method testGetTraitsOnCollectionValueFactory.
@Test
void testGetTraitsOnCollectionValueFactory() {
var valueFactory = new ListValueFactory();
valueFactory.initialize(new IntValueFactory(), IntCell.TYPE);
//
assertThat(ValueFactoryUtils.getTraits(valueFactory)).isInstanceOf(//
ListDataTraits.class).matches(//
this::hasLogicalTypeTrait).matches(this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).matches(//
this::hasLogicalTypeTrait).extracting(//
ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
// collection of data cell value factories
var listOfDataCells = createListValueFactory(createDataCellValueFactory(), XMLCell.TYPE);
//
assertThat(ValueFactoryUtils.getTraits(listOfDataCells)).isInstanceOf(//
ListDataTraits.class).matches(//
this::hasLogicalTypeTrait).matches(//
this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).extracting(//
ValueFactoryUtilsTest::extractLogicalTypeJson).matches(j -> j.get("value_factory_class").asText().equals(DictEncodedDataCellValueFactory.class.getName())).extracting(//
j -> j.get("data_type")).extracting(//
j -> j.get("cell_class").asText()).isEqualTo(XMLCell.class.getName());
// nested collection
var nestedCollection = createListValueFactory(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), DataType.getType(ListCell.class, IntCell.TYPE));
//
assertThat(ValueFactoryUtils.getTraits(nestedCollection)).isInstanceOf(//
ListDataTraits.class).matches(//
this::hasLogicalTypeTrait).matches(//
this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).matches(//
this::hasLogicalTypeTrait).matches(//
this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).matches(//
this::hasLogicalTypeTrait).extracting(//
ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
// SparseListValueFactory (uses StructDataTraits)
var sparseList = new SparseListValueFactory();
sparseList.initialize(IntValueFactory.INSTANCE, IntCell.TYPE);
//
assertThat(ValueFactoryUtils.getTraits(sparseList)).isInstanceOf(//
StructDataTraits.class).extracting(//
StructDataTraits.class::cast).matches(//
this::hasLogicalTypeTrait).matches(//
t -> extractValueFactoryClassName(t).equals(SparseListValueFactory.class.getName())).extracting(//
t -> t.getDataTraits(0)).matches(//
this::hasLogicalTypeTrait).extracting(//
ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
}
Aggregations