-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Complex Criteria Testing
PostPosted: Thu Sep 28, 2006 7:14 am 
Newbie

Joined: Thu Sep 28, 2006 7:07 am
Posts: 2
I am going to test criteria (org.hibernate.Criteria or org.hibernate.criterion.DetachedCriteria) that I gather in a complicated way. How can I do this without involving database? I.e. could I check whether a sample of model bean matches hibernate criteria just in memory?

Any recommendation is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:44 am 
Beginner
Beginner

Joined: Fri Jun 02, 2006 1:23 am
Posts: 27
Since Criteria is an interface you could probably mock it out and test the values that are being set in it.

So basically if you had a seperate method for creating your criteria,

Code:
public void buildCrazyCriteria( Criteria c, Object arg1, Object arg2 )
{
    // start doing stuff to your criteria...
}


Then you could call that method with your mock criteria and test against that.


Alternatively you could also test your DAOs against an in memory database like HSQLDB. See,

http://www.theserverside.com/tt/articles/article.tss?l=UnitTesting

Personally I prefer testing against my target DB as I trust my test more.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 3:42 am 
Newbie

Joined: Thu Sep 28, 2006 7:07 am
Posts: 2
georgef wrote:
Since Criteria is an interface you could probably mock it out and test the values that are being set in it.


Sure I can. The problem is that the Criterion's (which Criteria is build on) knows only how to generate its part of sql statement, but knows nothing about model beans. In other words Criterion does not have such method as 'match(Object)'. Taking this into account it appears that it would be necessary to analyze the class of the specific criterion and perform matching depending on this class. This is not very hard but it's not trivial anyway. And I hoped someone already did it, so I would not reinvent the wheel.

georgef wrote:
Alternatively you could also test your DAOs against an in memory database like HSQLDB. See,

http://www.theserverside.com/tt/articles/article.tss?l=UnitTesting

Personally I prefer testing against my target DB as I trust my test more.


As for HSQLDB (or another in-memory database), I looked at this approach and saw several drawbacks in it. We have legacy database, we forced to create mapping that is bound to Oracle. HSQLDB and Oracle have rather different dialects and we cannot use the same mapping for Oracle and for HSQLDB as well. And maintenaning two separate mappings, one for Oracle and one for HSQLDB, looks like overhead.

Using Oracle database for testing requires extra setup and takes long time to run. That's why I looked up solution that does not require database at all.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.