-->
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: Unit testing event triggered validation
PostPosted: Fri Mar 30, 2012 7:39 am 
Newbie

Joined: Fri Mar 30, 2012 5:52 am
Posts: 1
I've created a custom class level validator. The valid() method has it's own session to query the table because I'm trying to validate that the insert or update won't put the data in an invalid state. This all seems to work.

The part that I'm struggling with is unit testing it. Is it even possible? In the test I persist entities to the database, triggering the validation. I annotated the tests with @Test(expected = ConstraintViolationException.class), but then both the validation and the test fails. Can the validator be unit tested in this way?


Top
 Profile  
 
 Post subject: Re: Unit testing event triggered validation
PostPosted: Tue Apr 03, 2012 5:16 am 
Newbie

Joined: Mon Mar 26, 2012 4:57 am
Posts: 2
Without any information why the tests or validation failed, I think it will be hard to help you.

Is the Validator called on persist?
Has your validator implementation the session object?
How is the validator called inside your test?

_________________
Homepage: http://box68.net


Top
 Profile  
 
 Post subject: Re: Unit testing event triggered validation
PostPosted: Tue Apr 03, 2012 10:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
The part that I'm struggling with is unit testing it. Is it even possible?
{quote}


Quote:
In the test I persist entities to the database, triggering the validation. I annotated the tests with @Test(expected = ConstraintViolationException.class), but then both the validation and the test fails. Can the validator be unit tested in this way?

It all depends on your test harness and how you set up things. You will need to be more specific.


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.