The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

cjchalmers (2) [Avatar] Offline

I'm experimenting with integrating OrmUnit into our project but am having difficulty with my first test. Perhaps someone can clarify one or two things for me.

If I change my mapping files without updating my code, Hibernate will detect this whilst starting up my unit tests, OK no probs. Now I want to add a property to my class without changing my mapping file. Then if I use assertAllFieldsMapped() I should get an error, right?

Unfortunately this is not what happens. Do I understand the workings correctly, are others looking at this problem?

cjchalmers (2) [Avatar] Offline
Re: Some problems writing own tests
Well I seem to have caught this problem myself, here's the run down in case walk into it.

In HibernateassertUtils there's a method called "getPersistableFields" that should return all the fields in the class. This method only returns the fields in that specific class and not including superclasses or baseclasses. We generated our code using tools which have properties in baseclasses and logic in the extended ones. This was the reason I wasn't seeing any properties. I wrote a small additional method to iterate up the superclasses and aggregate the fields for me, see below. Now I can continue smilie

There was talk earlier on this site about open sourcing this project, any thoughts on this?


private static Field[] getAllFields(Class type)
Field[] fields = type.getDeclaredFields();

List superClasses = ClassUtils.getAllSuperclasses(type);

for (int cnt=0; cnt < superClasses.size(); cnt++)
Class superType = (Class) superClasses.get(cnt);
Field[] superFields = superType.getDeclaredFields();
fields = (Field[]) ArrayUtils.addAll(fields, superFields);

return fields;
ceracm (113) [Avatar] Offline
Re: Some problems writing own tests

sorry for the delayed response - consulting and training has been keeping me busy.

Thanks for your interest in ORMUnit and identifying the problem.
I'll write a test case and incorporate the fix.

Creating a real open-source project is definitely on my todo list (as is getting ORMUnit to work on JDK 1.4). As a step in that direction I have ORMUnit as a completely separate code base rather than as part of the book code.

I hope to get to set up the project in the next month or two.

On a separate topic. You commented about code generating the base classes. How is that working for you? Which tools are you using?