List of usage examples for org.apache.commons.collections BeanMap getWriteMethod
protected Method getWriteMethod(Object name)
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 . j av a2s . 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/*from w ww . j a va2 s .c o 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);/* w w w. j a v a2 s .c om*/ } } } }
From source file:se.vgregion.service.innovationsslussen.ldap.LdapService.java
AttributesMapper newAttributesMapper(final Class type) { return new AttributesMapper() { @Override/*ww w .jav a 2 s . c o m*/ public Object mapFromAttributes(Attributes attributes) throws NamingException { try { return mapFromAttributesImpl(attributes); } catch (Exception e) { throw new RuntimeException(e); } } public Object mapFromAttributesImpl(Attributes attributes) throws NamingException, IllegalAccessException, InstantiationException { Object result = type.newInstance(); BeanMap bm = new BeanMap(result); NamingEnumeration<? extends Attribute> all = attributes.getAll(); while (all.hasMore()) { Attribute attribute = all.next(); String name = toBeanPropertyName(attribute.getID()); if (bm.containsKey(name) && bm.getWriteMethod(name) != null) { bm.put(name, attribute.get()); } } return result; } }; }
From source file:se.vgregion.service.innovationsslussen.ldap.LdapService.java
AndFilter toAndCondition(Object obj) { AndFilter filter = new AndFilter(); BeanMap bm = new BeanMap(obj); Class type = obj.getClass();/* ww w. j ava 2s. co m*/ for (Object entryObj : bm.entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryObj; String property = entry.getKey(); if (bm.getWriteMethod(property) != null) { Object value = entry.getValue(); if (value != null && !"".equals(value.toString().trim())) { String ldapPropertyName = getPlainNameOrExplicit(type, property); filter.and(newAttributeFilter(ldapPropertyName, value.toString())); } } } return filter; }
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;/* w ww . j av a 2 s . 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); } } } }