Example usage for org.apache.commons.collections BeanMap getType

List of usage examples for org.apache.commons.collections BeanMap getType

Introduction

In this page you can find the example usage for org.apache.commons.collections BeanMap getType.

Prototype

public Class getType(String name) 

Source Link

Document

Returns the type of the property with the given name.

Usage

From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java

void doGetterSetterValuesMatch(Object o) throws IllegalAccessException, InstantiationException {
    BeanMap bm = new BeanMap(o);

    final String javaLangPackageName = String.class.getPackage().getName();

    for (Object key : bm.keySet()) {
        String name = (String) key;

        if ("ideaContentPrivate".equals(name) || "ideaPerson".equals(name)
                || "ideaContentPublic".equals(name)) {
            continue;
        }/*from w  w  w.ja  v a 2  s .co  m*/

        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                bm.put(name, name);
                Assert.assertTrue(name == bm.get(name));
            } else {
                Class clazz = bm.getType(name);

                if (!clazz.getName().startsWith(javaLangPackageName) && !clazz.isEnum()) {
                    Object value = defaultPrim.get(clazz);
                    if (value == null) {
                        value = clazz.newInstance();
                    }
                    bm.put(name, value);
                    Assert.assertTrue("1, " + o.getClass() + "." + key, value.equals(bm.get(name)));
                    Assert.assertTrue("2, " + o.getClass() + "." + key,
                            value.hashCode() == bm.get(name).hashCode());
                }
            }
        }

    }
}

From source file:se.vgregion.service.barium.BariumRestClientIT.java

License:asdf

/**
 * After this 'test' go to Barium and check the data. Did this seem to be thread safe?
 * @throws BariumException// w w w . j  a v a  2  s . co m
 */
@Ignore
@Test
public void toCreateConcurrent() throws BariumException {
    BariumRestClientImpl client = createBariumRestClient();
    client.connect();
    for (int i = 0; i < 3; i++) {
        IdeaObjectFields fields = new IdeaObjectFields();
        BeanMap bm = new BeanMap(fields);
        for (Object key : bm.keySet()) {
            String name = (String) key;
            if (bm.getWriteMethod(name) != null && String.class.equals(bm.getType(name))) {
                bm.put(name, name + " " + i);
            }
        }
        fields.setInstanceName("instanceName (async) " + i + " " + System.currentTimeMillis());
        createAsync(client, fields);
    }

    try {
        do {
            System.out.println("Delaying some to make the threads finish.");
            Thread.sleep(1000);
        } while (asyncCount != 0);
        System.exit(0);
    } catch (InterruptedException ie) {
        System.out.println("Child thread interrupted! " + ie);
    }

}

From source file:se.vgregion.service.innovationsslussen.idea.IdeaServiceImplTest.java

private void initDefaultStringValues(Object o) {
    BeanMap bm = new BeanMap(o);
    for (Object key : bm.keySet()) {
        String name = (String) key;
        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                bm.put(name, name);/*from  w w w .j  a  v  a 2s.  co  m*/
            }
        }
    }
}

From source file:se.vgregion.service.innovationsslussen.ldap.PersonTest.java

@Test
public void beanStringPropertiesGetterSetters() {
    KivPerson person = new KivPerson();
    BeanMap bm = new BeanMap(person);
    int i = 0;//ww  w . j  a  v  a 2s  .c o m
    for (Object key : bm.keySet()) {
        String name = (String) key;
        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                String setterValue = "" + i++;
                bm.put(key, setterValue);
                String getterValue = (String) bm.get(key);
                Assert.assertEquals(setterValue, getterValue);
            }
        }
    }
}