-->
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.  [ 8 posts ] 
Author Message
 Post subject: Validator problem
PostPosted: Thu Jan 26, 2006 4:38 am 
Newbie

Joined: Thu Jan 26, 2006 4:26 am
Posts: 16
Hello, i have got a problem with validator. I try to explain. I have created a class model annotated with the next validator annotation:
Quote:
@Pattern(regex="expression")


This works perfectly. But when i have created a junit file occurs the next situation. If i put the test method that has correct values for
Quote:
@Pattern
n, first, then the method is executed ok, and the next test method (what has an invalid value for
Quote:
@Pattern
), works perfectly too and detects the error. But if i put first the test that has invalid value, the invalid value test works perfectly, but the second test (which has a correct value) also tells me that the value is incorrect, and the exception of InvalidStateException is thrown.

Im using Annotations 3.1beta8 and Hibernate 3.1.1, and using an interceptor for controlling the session. That interceptor is a copy paste of Caveatemptor Servlet Filter but in an interceptor.

It curious because depends of the order of execution all works or only the tests that has valid parameters doesn't work.

Thank you very much for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 5:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't understand your problem.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Validator problem
PostPosted: Thu Jan 26, 2006 5:44 am 
Newbie

Joined: Thu Jan 26, 2006 4:26 am
Posts: 16
Ok sorry because i have posted an error text file, let me try to explain. Im using Validator Annotations. The problem is while testing the object.

Depending of the order of execution of test methods, my code works perfectly. For exemple i create a test method (we call correct method) that must not thrown the InvalidStateException because the entry are correct. Also i create a test method (we call incorrect method) that has an invalid entry so InvalidStateException must be thrown. Then if i execute the junit file, first executing correct method and second incorrect method, all works perfectly, at first case no exception is thrown and in second method yes. But if i execute first the incorrect method and secondly the correct method, the incorrect method rises an exception and, then when it executes the correct method the exception is thrown too.

I just don't know why.

Thank you very much


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 11:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I would be very surprised if it comes from Hibernate Validator. Double check your configuration and initialization process in your tests

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 11:11 am 
Newbie

Joined: Thu Jan 26, 2006 4:26 am
Posts: 16
Code:
<event type="pre-update">
           <listener
          class="org.hibernate.validator.event.ValidatePreUpdateEventListener"/>
       </event>
       <event type="pre-insert">
           <listener
          class="org.hibernate.validator.event.ValidatePreInsertEventListener"/>
</event>


My configuration is as simple as what i have posted, and the configuration file is an annoted that is like

Quote:
@Pattern(regex="\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b")


It is for validating an ipv4.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 9:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And waht is your unit test exactly

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 11:05 am 
Newbie

Joined: Thu Jan 26, 2006 4:26 am
Posts: 16
Code:
public void testCreateInvalidAnalyzer(){
      AnalyzerBO analyzerBO = BOFactory.DEFAULT.getAnalyzerBO();
      
      Analyzer analyzer = new Analyzer();
      HostComponent hc = new HostComponent();
      
      hc.setIp4Address("130.a.42.160");
      analyzer.setHostComponent(hc);
      
      try {
         analyzer = analyzerBO.createAnalyzer(analyzer);
         fail();
      } catch (DatabaseException e) {
         
         assertTrue(e.getMessage(),true);
      }
   }
   
   public void testUpdateAnalyzer(){
      
      AnalyzerBO analyzerBO = BOFactory.DEFAULT.getAnalyzerBO();
      
      Analyzer analyzer = new Analyzer();
      HostComponent hc = new HostComponent();
      
      hc.setIp4Address("130.206.42.160");
      analyzer.setHostComponent(hc);
      
      try {
         analyzer = analyzerBO.createAnalyzer(analyzer);
      } catch (DatabaseException e) {
         fail(e.getMessage());
      }
      
      Analyzer analyzer2 = null;
      try {
         analyzer2 = analyzerBO.findAnalyzerById(analyzer);
         analyzer2.setEnabled(true);
         analyzerBO.updateAnalyzer(analyzer2);
      } catch (DatabaseException e) {
         fail(e.getMessage());
      }
      
      Analyzer analyzer3 = null;
      try {
          analyzer3 = analyzerBO.findAnalyzerById(analyzer2);
      } catch (DatabaseException e) {
         fail(e.getMessage());
      }
      
      assertEquals(Boolean.TRUE,analyzer3.getEnabled());
   }


The first test, the result is GREEN so all goes perfectly, but the second test throws the exception:

Quote:
junit.framework.AssertionFailedError: org.hibernate.validator.InvalidStateException: validation failed for:


This exception is from the next line:

Code:
analyzer = analyzerBO.createAnalyzer(analyzer);


Thank you very much for your patience.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I do have unit tests for that, so if you manage to package the failure in a minimal test case wo dependency except junit and hibernate libs, post it to JIRA, I'll have a look.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.