Search in sources :

Example 1 with ClassA

use of com.tvd12.ezyfoxserver.testing.jaxberror.ClassA 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);
}
Also used : PropertiesMapper(com.tvd12.properties.file.mapping.PropertiesMapper) Properties(java.util.Properties) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 2 with ClassA

use of com.tvd12.ezyfoxserver.testing.jaxberror.ClassA 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());
}
Also used : PropertiesMapper(com.tvd12.properties.file.mapping.PropertiesMapper) Properties(java.util.Properties) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 3 with ClassA

use of com.tvd12.ezyfoxserver.testing.jaxberror.ClassA in project properties-file by tvd12.

the class PropertiesBeanTest method test.

@Test
public void test() {
    new PropertiesBean(ClassA.class);
    ClassA classA = new ClassA();
    PropertiesBean mapping2 = new PropertiesBean(classA, new PropertyAnnotations());
    mapping2.put("charValue", "c");
    mapping2.put("byteValue", "1");
    mapping2.put("doubleValue", "2.0");
    mapping2.put("floatValue", "3.0");
    mapping2.put("longValue", "4");
    mapping2.put("shortValue", "5");
    mapping2.put("not found", "not found");
    assertEquals(classA.getCharValue(), 'c');
    assertEquals(classA.getByteValue(), 1);
    assertEquals(classA.getDoubleValue(), 2.0D);
    assertEquals(classA.getFloatValue(), 3.0F);
    assertEquals(classA.getLongValue(), 4);
    assertEquals(classA.getShortValue(), 5);
    Properties dataSourceProperties = new Properties();
    dataSourceProperties.put("datasource.username", "hello");
    dataSourceProperties.put("datasource.password", "world");
    PropertiesBean mapping3 = new PropertiesBean(classA, new PropertyAnnotations());
    mapping3.put("dataSourceConfig", null, dataSourceProperties);
    assert classA.dataSourceConfig.username.equals("hello");
    assert classA.dataSourceConfig.password.equals("world");
}
Also used : PropertyAnnotations(com.tvd12.properties.file.annotation.PropertyAnnotations) PropertiesBean(com.tvd12.properties.file.struct.PropertiesBean) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 4 with ClassA

use of com.tvd12.ezyfoxserver.testing.jaxberror.ClassA 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());
}
Also used : PropertiesMapper(com.tvd12.properties.file.mapping.PropertiesMapper) Properties(java.util.Properties) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 5 with ClassA

use of com.tvd12.ezyfoxserver.testing.jaxberror.ClassA in project properties-file by tvd12.

the class PropertiesBeanTest method test.

@Test
public void test() {
    new PropertiesBean(ClassA.class);
    ClassA classA = new ClassA();
    PropertiesBean mapping2 = new PropertiesBean(classA, new PropertyAnnotations());
    mapping2.put("charValue", "c");
    mapping2.put("byteValue", "1");
    mapping2.put("doubleValue", "2.0");
    mapping2.put("floatValue", "3.0");
    mapping2.put("longValue", "4");
    mapping2.put("shortValue", "5");
    mapping2.put("not found", "not found");
    assertEquals(classA.getCharValue(), 'c');
    assertEquals(classA.getByteValue(), 1);
    assertEquals(classA.getDoubleValue(), 2.0D);
    assertEquals(classA.getFloatValue(), 3.0F);
    assertEquals(classA.getLongValue(), 4);
    assertEquals(classA.getShortValue(), 5);
    Properties dataSourceProperties = new Properties();
    dataSourceProperties.put("datasource.username", "hello");
    dataSourceProperties.put("datasource.password", "world");
    PropertiesBean mapping3 = new PropertiesBean(classA, new PropertyAnnotations());
    mapping3.put("dataSourceConfig", null, dataSourceProperties);
    assert classA.dataSourceConfig.username.equals("hello");
    assert classA.dataSourceConfig.password.equals("world");
}
Also used : PropertyAnnotations(com.tvd12.properties.file.annotation.PropertyAnnotations) PropertiesBean(com.tvd12.properties.file.struct.PropertiesBean) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)15 Properties (java.util.Properties)10 PropertiesMapper (com.tvd12.properties.file.mapping.PropertiesMapper)8 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 PropertyAnnotations (com.tvd12.properties.file.annotation.PropertyAnnotations)6 SetterMethod (com.tvd12.properties.file.struct.SetterMethod)4 Method (java.lang.reflect.Method)4 PropertiesBean (com.tvd12.properties.file.struct.PropertiesBean)2 Prototypes (com.tvd12.calabash.core.prototype.Prototypes)1 SimplePrototypes (com.tvd12.calabash.core.prototype.SimplePrototypes)1