public void testMapTypeProperty() throws Exception { Map<String, String> entry = new HashMap(1, 1.0f); entry.put("name", "23"); ManagedBeanInfo.MapEntry mapEntry = new ManagedBeanInfo.MapEntry("java.lang.String", "java.lang.Integer", entry); List<ManagedBeanInfo.ManagedProperty> properties = new ArrayList<ManagedBeanInfo.ManagedProperty>(1); ManagedBeanInfo.ManagedProperty property = new ManagedBeanInfo.ManagedProperty("mapProperty", null, null, mapEntry, null); properties.add(property); ManagedBeanInfo bean = new ManagedBeanInfo(beanName, beanName, "request", null, null, properties, null); BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager(); beanManager.register(bean); // testing with a property set assertNotNull(testBean = (TestBean) beanManager.create(beanName, getFacesContext())); // make sure bean instantiated properly. Get property back from bean. HashMap mapProperty = (HashMap) testBean.getMapProperty(); assertTrue(mapProperty.get("name") instanceof Integer); Integer integer = new Integer("23"); assertTrue(mapProperty.get("name").equals(integer)); }
public void testMapProperty() throws Exception { Map<String, String> entry = new HashMap(1, 1.0f); entry.put("name", "Justyna"); ManagedBeanInfo.MapEntry mapEntry = new ManagedBeanInfo.MapEntry(null, null, entry); List<ManagedBeanInfo.ManagedProperty> properties = new ArrayList<ManagedBeanInfo.ManagedProperty>(2); ManagedBeanInfo.ManagedProperty property = new ManagedBeanInfo.ManagedProperty("mapProperty", null, null, mapEntry, null); properties.add(property); property = new ManagedBeanInfo.ManagedProperty("mapPropertyNull", null, null, mapEntry, null); properties.add(property); ManagedBeanInfo bean = new ManagedBeanInfo(beanName, beanName, "request", null, null, properties, null); BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager(); beanManager.register(bean); // testing with a property set assertNotNull(testBean = (TestBean) beanManager.create(beanName, getFacesContext())); // make sure bean instantiated properly. Get property back from bean. HashMap mapProperty = (HashMap) testBean.getMapProperty(); assertTrue(((String) mapProperty.get("name")).equals("Justyna")); // setter shouldn't be called if bean getter returns Map assertTrue(!testBean.getMapPropertySetterCalled()); // setter should be called if bean getter returned null assertTrue(testBean.getMapPropertyNullSetterCalled()); // make sure scope is stored properly BeanBuilder builder = beanManager.getBuilder(beanName); assertTrue(builder.getScope() == ELUtils.Scope.REQUEST); }