* test case for column name mangled object.
*/
@Test
public void mangled() {
DataModelDescriptor descriptor = FieldPropertyDescriptor.extract(MockSimple.class);
MockSimple obj = (MockSimple) descriptor.createDataModelObject();
obj.number.modify(12345);
obj.string.modify("Hello, world!");
List<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>();
for (final PropertyDescriptor property : descriptor.getPropertyDescriptors()) {
properties.add(new PropertyDescriptor(String.format("_col%d", properties.size()), property) {
@Override
public ValueOption<?> extract(Object dataModel) {
return property.extract(dataModel);
}
});
}
DataModelDescriptor mangled = new DataModelDescriptor(descriptor.getDataModelClass(), properties);
DataModelMapping config = new DataModelMapping();
config.setFieldMappingStrategy(FieldMappingStrategy.NAME);
config.setOnMissingSource(ExceptionHandlingStrategy.FAIL);
config.setOnMissingTarget(ExceptionHandlingStrategy.IGNORE);
config.setOnIncompatibleType(ExceptionHandlingStrategy.IGNORE);
try {
DataModelDriver driver = new DataModelDriver(descriptor, new DataModelInspector(mangled), config);
MockSimple copy = new MockSimple();
driver.set(copy, obj);
throw new AssertionError();
} catch (IllegalArgumentException e) {
// ok.
}
config.setFieldMappingStrategy(FieldMappingStrategy.POSITION);
DataModelDriver driver = new DataModelDriver(descriptor, new DataModelInspector(mangled), config);
MockSimple copy = new MockSimple();
driver.set(copy, obj);
assertThat(copy.number, equalTo(obj.number));
assertThat(copy.string, equalTo(obj.string));
}