Search in sources :

Example 1 with ExampleBean

use of org.apache.camel.util.jndi.ExampleBean in project camel by apache.

the class IntrospectionSupportTest method testIsSetter.

public void testIsSetter() throws Exception {
    ExampleBean bean = new ExampleBean();
    Method name = bean.getClass().getMethod("setName", String.class);
    assertEquals(false, IntrospectionSupport.isGetter(name));
    assertEquals(true, IntrospectionSupport.isSetter(name));
    Method price = bean.getClass().getMethod("setPrice", double.class);
    assertEquals(false, IntrospectionSupport.isGetter(price));
    assertEquals(true, IntrospectionSupport.isSetter(price));
}
Also used : ExampleBean(org.apache.camel.util.jndi.ExampleBean) Method(java.lang.reflect.Method)

Example 2 with ExampleBean

use of org.apache.camel.util.jndi.ExampleBean in project camel by apache.

the class IntrospectionSupportTest method testGetPropertiesSkipNull.

public void testGetPropertiesSkipNull() throws Exception {
    ExampleBean bean = new ExampleBean();
    bean.setName("Claus");
    bean.setPrice(10.0);
    bean.setId(null);
    Map<String, Object> map = new HashMap<String, Object>();
    IntrospectionSupport.getProperties(bean, map, null, false);
    assertEquals(2, map.size());
    assertEquals("Claus", map.get("name"));
    String price = map.get("price").toString();
    assertTrue(price.startsWith("10"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ExampleBean(org.apache.camel.util.jndi.ExampleBean)

Example 3 with ExampleBean

use of org.apache.camel.util.jndi.ExampleBean in project camel by apache.

the class IntrospectionSupportTest method testGetPropertyLocaleIndependent.

public void testGetPropertyLocaleIndependent() throws Exception {
    Locale oldLocale = Locale.getDefault();
    Locale.setDefault(new Locale("tr", "TR"));
    try {
        ExampleBean bean = new ExampleBean();
        bean.setName("Claus");
        bean.setPrice(10.0);
        bean.setId("1");
        Object name = IntrospectionSupport.getProperty(bean, "name");
        Object id = IntrospectionSupport.getProperty(bean, "id");
        Object price = IntrospectionSupport.getProperty(bean, "price");
        assertEquals("Claus", name);
        assertEquals(10.0, price);
        assertEquals("1", id);
    } finally {
        Locale.setDefault(oldLocale);
    }
}
Also used : Locale(java.util.Locale) ExampleBean(org.apache.camel.util.jndi.ExampleBean)

Example 4 with ExampleBean

use of org.apache.camel.util.jndi.ExampleBean in project camel by apache.

the class IntrospectionSupportTest method testGetProperty.

public void testGetProperty() throws Exception {
    ExampleBean bean = new ExampleBean();
    bean.setId("123");
    bean.setName("Claus");
    bean.setPrice(10.0);
    Object name = IntrospectionSupport.getProperty(bean, "name");
    assertEquals("Claus", name);
}
Also used : ExampleBean(org.apache.camel.util.jndi.ExampleBean)

Example 5 with ExampleBean

use of org.apache.camel.util.jndi.ExampleBean in project camel by apache.

the class IntrospectionSupportTest method testGetPropertiesOptionPrefix.

public void testGetPropertiesOptionPrefix() throws Exception {
    ExampleBean bean = new ExampleBean();
    bean.setName("Claus");
    bean.setPrice(10.0);
    bean.setId("123");
    Map<String, Object> map = new HashMap<String, Object>();
    IntrospectionSupport.getProperties(bean, map, "bean.");
    assertEquals(3, map.size());
    assertEquals("Claus", map.get("bean.name"));
    String price = map.get("bean.price").toString();
    assertTrue(price.startsWith("10"));
    assertEquals("123", map.get("bean.id"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ExampleBean(org.apache.camel.util.jndi.ExampleBean)

Aggregations

ExampleBean (org.apache.camel.util.jndi.ExampleBean)11 Method (java.lang.reflect.Method)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)1