Correction, the sentence "The keys of those two entries are "null" and "class" both having a PropertyDescriptor as value."
should have been "The keys of those two entries are "empty" and "class" both having a PropertyDescriptor as value." in my previous post. Chun-Yian Liew wrote: > > celeraman+, have you managed to get the properties based population > working? > > I am currently running into a similar kind of a problem with the appfuse > tutorial PersonDaoTest example. > I am also trying to populate the Person object with the populate method of > the BaseDaoTestCase class. > At first I received a NullPointerException when I put the > PersonDaoTest.properties file in the same directory as the > PersonDaoTest.java file as explained on > http://www.appfuse.org/display/APF/Using+Hibernate. After putting the > properties file in the test resources directory as mentioned above the > NullPointerException didn't occur anymore. > But the person object in the example method "testAddAndRemovePerson" is > now getting filled with null values. > > Because I just succeeded in getting my personDaoTest running as a junit > test within eclipse I was able to start debugging this issue: > > 1. In the BaseDaoTestCase populate method BeanUtils.copyProperties(map, > obj); is called, where map is a HashMap containing the key/values out of > the PersonDaoTest.properties file and obj is the person object to be > filled. > > 2. copyProperties(map, obj) ends up in another method of BeanUtils: > > private static void copyProperties(Object source, Object target, Class > editable, String[] ignoreProperties) > > were the following line is being executed > > 3. PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), > targetPd.getName()); > > Below you can see the code of the method called. > > public static PropertyDescriptor getPropertyDescriptor(Class clazz, > String propertyName) > throws BeansException { > > CachedIntrospectionResults cr = > CachedIntrospectionResults.forClass(clazz); > return cr.getPropertyDescriptor(propertyName); > } > > and here is were it goes wrong. > > The cr.getPropertyDescriptor is trying to retrieve a PropertyDescriptor > for a given propertyName, i.e. firstName. > It tries to look it up in the private Map propertyDescriptorCache of the > org.springframework.beans.CachedIntrospectionResults class. At that moment > that map only contains two entries. > The keys of those two entries are "null" and "class" both having a > PropertyDescriptor as value. > So the getPropertyDescriptor is returning a null value for the requested > propertyNames (id, firstName and lastName). > > Does anybody have an idea what the reason could be why that map doesn't > contain the values for the values defined in the PersonDaoTest.properties > file? > > Chun > > > > celeraman+ wrote: >> >> FIY, I got some progress... >> >> >> 1. The bean definition in src/main/webapp/WEB-INF/aplicationContext.xml >> file for DepartmentDao >> was wrong as following: >> <bean id="DepartmentDao" >> class="org.appfuse.tutorial.dao.hibernate.DepartamentDaoHibernate"> >> <property name="sessionFactory" ref="sessionFactory"/> >> </bean> >> >> Note *DepartmentDao* where must be *departmentDao*. >> >> 2. my test case properties files was including the id property. The >> Hibernate Tutorial don't include a id property, so I think this could be >> a future problem and I removed it. >> >> 3. I replaced the populate method call by calling the setters for myself >> and bingo... the test case was BUILD SUCCESSFUL. >> >> But the question continues: >> Why the populate method call do not load my Department bean from the >> .properties file? >> >> Any help are welcome! >> >> -- >> celeraman+ >> >> > > -- View this message in context: http://www.nabble.com/NullPointerException-when-trying-to-populate-in-test-case-tf3604674s2369.html#a10227835 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
