use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapperTest method testMapPropertiesToBean2.
@Test
public void testMapPropertiesToBean2() {
Properties properties = new Properties();
properties.setProperty("name", "hello");
properties.put("age", 24);
properties.put("clazz", ClassA.class.getName());
properties.put("date", new SimpleDateFormat(Dates.getPattern()).format(new Date()));
ClassA object = new PropertiesMapper().data(PropertiesUtil.toMap(properties)).bean(new ClassA()).map();
assertEquals(object.getName(), "hello");
assertEquals(object.getAge(), 24);
assertEquals(object.getMoney(), 10);
assertEquals(object.getClazz(), ClassA.class);
assertNotNull(object.getDate());
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapperTest method testMapPropertiesToBeanWithMapClazz.
@Test
public void testMapPropertiesToBeanWithMapClazz() {
Properties properties = new Properties();
properties.setProperty("name", "hello");
properties.put("age", 24);
properties.put("clazz", ClassA.class.getName());
properties.put("date", new SimpleDateFormat(Dates.getPattern()).format(new Date()));
ClassA object = new PropertiesMapper().data(PropertiesUtil.toMap(properties)).map(ClassA.class);
assertEquals(object.getName(), "hello");
assertEquals(object.getAge(), 24);
assertEquals(object.getMoney(), 10);
assertEquals(object.getClazz(), ClassA.class);
assertNotNull(object.getDate());
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapper2Test method testMapPropertiesToBean.
@Test
public void testMapPropertiesToBean() {
Properties properties = new Properties();
properties.setProperty("name", "hello");
properties.put("age", 24);
properties.put("clazz", ClassA.class.getName());
properties.put("date", new SimpleDateFormat(Dates.getPattern()).format(new Date()));
properties.put("x", "123");
properties.put("valid", "true");
ClassA object = new PropertiesMapper().data(properties).clazz(ClassA.class).map();
assertEquals(object.isValid(), true);
assertEquals(object.getName(), "hello");
assertEquals(object.getAge(), 24);
assertEquals(object.getMoney(), 10);
assertEquals(object.getClazz(), ClassA.class);
assertNotNull(object.getDate());
assertEquals(object.getString(), "123");
assertEquals(object.getString2(), "st2");
assertEquals(object.getNotExists(), null);
PropertiesMapper propertiesMapper = new PropertiesMapper().data(properties).clazz(ClassA.class);
propertiesMapper.map(ClassA.class);
ClassA objectx = propertiesMapper.map(ClassA.class);
assertEquals(objectx.getName(), "hello");
assertEquals(objectx.getAge(), 24);
assertEquals(objectx.getMoney(), 10);
assertEquals(objectx.getClazz(), ClassA.class);
assertNotNull(objectx.getDate());
assertEquals(objectx.getString(), "123");
assertEquals(objectx.getString2(), "st2");
assertEquals(objectx.getNotExists(), null);
PropertiesMapper propertiesMapperx = new PropertiesMapper().data(properties).bean(new ClassA());
propertiesMapper.map(ClassA.class);
ClassA objectxx = propertiesMapperx.map(ClassA.class);
assertEquals(objectxx.getName(), "hello");
assertEquals(objectxx.getAge(), 24);
assertEquals(objectxx.getMoney(), 10);
assertEquals(objectxx.getClazz(), ClassA.class);
assertNotNull(objectxx.getDate());
assertEquals(objectxx.getString(), "123");
assertEquals(objectxx.getString2(), "st2");
assertEquals(objectxx.getNotExists(), null);
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapper3Test method test1.
@Test
public void test1() {
Properties properties = new Properties();
properties.setProperty("valueA", "a");
properties.setProperty("valueB", "b");
properties.setProperty("hello", "galaxy");
properties.setProperty("welcome", "Dzung");
ClassB obj = new PropertiesMapper().clazz(ClassB.class).context(getClass()).data(properties).map();
assertEquals(obj.getValueA(), "a");
assertEquals(obj.getValueB(), "b");
}
use of com.tvd12.properties.file.mapping.PropertiesMapper 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