use of com.tvd12.properties.file.annotation.PropertyAnnotation in project properties-file by tvd12.
the class PropertiesMapperTest method testMapPropertiesToBeanWithAnntations.
@Test
public void testMapPropertiesToBeanWithAnntations() {
Properties properties = new Properties();
properties.setProperty("name", "hello");
properties.put("value", "world");
properties.put("age", 24);
properties.put("clazz", ClassC.class.getName());
properties.put("date", new SimpleDateFormat(Dates.getPattern()).format(new Date()));
properties.put("datasource.username", "hello");
properties.put("datasource.password", "world");
properties.put("datasource.driver", "dahlia");
ClassD object = new PropertiesMapper().data(PropertiesUtil.toMap(properties)).mappingLevel(MappingLevel.ANNOTATION).addPropertyAnnotation(new PropertyAnnotation(PropertyForTest.class, a -> ((PropertyForTest) a).value(), a -> ((PropertyForTest) a).prefix())).addPropertyAnnotation(new PropertyAnnotation(PropertyForTest.class, a -> ((PropertyForTest) a).value(), a -> ((PropertyForTest) a).prefix())).map(ClassD.class);
assertEquals(object.name, "hello");
assertEquals(object.value, "value");
assertEquals(object.age, 24);
assertEquals(object.money, 10);
assertEquals(object.clazz, ClassC.class);
assertEquals(object.datasourceDriver, "dahlia");
assertNotNull(object.date);
assertEquals(object.dataSourceConfig.username, "hello");
assertEquals(object.dataSourceConfig.password, "world");
assertEquals(object.dataSourceConfig.driverClass, "dahlia");
Properties dataSourceProperties = PropertiesUtil.getPropertiesByPrefix(properties, "datasource");
assertEquals(object.dataSourceProperties, dataSourceProperties);
System.out.println("dataSourceProperties: " + dataSourceProperties);
}
use of com.tvd12.properties.file.annotation.PropertyAnnotation in project properties-file by tvd12.
the class PropertiesMapperTest method testMapPropertiesToBeanWithAnntations.
@Test
public void testMapPropertiesToBeanWithAnntations() {
Properties properties = new Properties();
properties.setProperty("name", "hello");
properties.put("value", "world");
properties.put("age", 24);
properties.put("clazz", ClassC.class.getName());
properties.put("date", new SimpleDateFormat(Dates.getPattern()).format(new Date()));
properties.put("datasource.username", "hello");
properties.put("datasource.password", "world");
properties.put("datasource.driver", "dahlia");
ClassD object = new PropertiesMapper().data(PropertiesUtil.toMap(properties)).mappingLevel(MappingLevel.ANNOTATION).addPropertyAnnotation(new PropertyAnnotation(PropertyForTest.class, a -> ((PropertyForTest) a).value(), a -> ((PropertyForTest) a).prefix())).addPropertyAnnotation(new PropertyAnnotation(PropertyForTest.class, a -> ((PropertyForTest) a).value(), a -> ((PropertyForTest) a).prefix())).map(ClassD.class);
assertEquals(object.name, "hello");
assertEquals(object.value, "value");
assertEquals(object.age, 24);
assertEquals(object.money, 10);
assertEquals(object.clazz, ClassC.class);
assertEquals(object.datasourceDriver, "dahlia");
assertNotNull(object.date);
assertEquals(object.dataSourceConfig.username, "hello");
assertEquals(object.dataSourceConfig.password, "world");
assertEquals(object.dataSourceConfig.driverClass, "dahlia");
Properties dataSourceProperties = PropertiesUtil.getPropertiesByPrefix(properties, "datasource");
assertEquals(object.dataSourceProperties, dataSourceProperties);
System.out.println("dataSourceProperties: " + dataSourceProperties);
}
Aggregations