use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactoryTest method testDoubleWithFormatterAppender.
@Test
public void testDoubleWithFormatterAppender() throws Exception {
MappingContextFactoryBuilder<DbPrimitiveObjectWithSetter, CsvColumnKey> builder = getMappingContextBuilder();
FieldMapperColumnDefinition<CsvColumnKey> format = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new FormatProperty(new DecimalFormat("0.0")));
FieldMapper<DbPrimitiveObjectWithSetter, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("pDouble", dbPrimitiveObjectClassMeta, format), builder, null);
testFieldMapper("3.1", fieldMapper, dbPrimitiveObject, builder.newFactory());
}
use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactoryTest method testJodaDateTimeWithDateFormat.
@Test
public void testJodaDateTimeWithDateFormat() throws Exception {
MappingContextFactoryBuilder<JodaObject, CsvColumnKey> builder = getMappingContextBuilder();
FieldMapperColumnDefinition<CsvColumnKey> format = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new DateFormatProperty("yyyyMMdd"));
FieldMapper<JodaObject, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("dateTime", jodaObjectClassMeta, format), builder, null);
testFieldMapper("20140607", fieldMapper, jodaObject, builder.newFactory());
}
use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactoryJavaTimeTest method testLocalDateTimeWithFormaterAppender.
@Test
public void testLocalDateTimeWithFormaterAppender() throws Exception {
MappingContextFactoryBuilder<JavaTimeObject, CsvColumnKey> builder = getMappingContextBuilder();
FieldMapper<JavaTimeObject, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("localDateTime", javaTimeObjectClassMeta, FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new JavaDateTimeFormatterProperty(DateTimeFormatter.ofPattern("dd/MM/yyyy")))), builder, null);
testFieldMapper("03/12/2011", fieldMapper, javaTimeObject, builder.newFactory());
}
use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.
the class CsvColumnDefinitionTest method testComposition.
@Test
public void testComposition() {
TimeZone tz = TimeZone.getTimeZone("Europe/Brussels");
CellValueReaderFactory cellValueReaderFactory = new CellValueReaderFactory() {
@Override
public <P> CellValueReader<P> getReader(Type propertyType, int index, CsvColumnDefinition columnDefinition, ParsingContextFactoryBuilder contextFactoryBuilder) {
return null;
}
@Override
public String toString() {
return "CellValueReaderFactory";
}
};
final Predicate<PropertyMeta<?, ?>> appliesTo = ConstantPredicate.falsePredicate();
CsvColumnDefinition compose = CsvColumnDefinition.identity().addDateFormat("yyyyMM").addRename("blop").addCustomReader(new CellValueReader<Integer>() {
@Override
public Integer read(char[] chars, int offset, int length, ParsingContext parsingContext) {
return 3;
}
@Override
public String toString() {
return "CellValueReader";
}
}).addCustomCellValueReaderFactory(cellValueReaderFactory).addTimeZone(tz).addKey(appliesTo);
assertEquals("blop", compose.rename(new CsvColumnKey("bar", -1)).getName());
assertEquals("blop", CsvColumnDefinition.renameDefinition("blop").rename(new CsvColumnKey("bar", -1)).getName());
assertArrayEquals(new String[] { "yyyyMM" }, compose.dateFormats());
assertEquals(new Integer(3), compose.getCustomReader().read(null, 0, 0, null));
assertEquals(cellValueReaderFactory, compose.getCustomCellValueReaderFactory());
assertEquals(tz, compose.getTimeZone());
assertEquals(tz, CsvColumnDefinition.timeZoneDefinition(tz).getTimeZone());
assertTrue(compose.hasCustomSourceFrom(Object.class));
assertFalse(compose.ignore());
assertEquals(Integer.class, compose.getCustomSourceReturnTypeFrom(Object.class));
assertTrue(CsvColumnDefinition.identity().addIgnore().ignore());
assertTrue(compose.isKey());
assertTrue(CsvColumnDefinition.key(appliesTo).isKey());
assertSame(appliesTo, compose.keyAppliesTo());
final String toString = compose.addIgnore().toString();
System.out.println("toString = " + toString);
}
use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.
the class CsvColumnKeyTest method testIsAlias.
@Test
public void testIsAlias() throws Exception {
assertFalse(new CsvColumnKey("c", 0).isAlias());
assertTrue(new CsvColumnKey("c", 0).alias("b").isAlias());
}
Aggregations