-->
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: Hibernate Validator - @GroupSequence inheritance
PostPosted: Mon Mar 21, 2011 8:31 pm 
Newbie

Joined: Mon Mar 21, 2011 7:59 pm
Posts: 2
While reading the JSR 303 specification I came to the understanding (Item C of section 3.4.5) that if a class extends another, the subclass inherits the @GroupSequence annotation that the parent class defines on itself if the subclass does not explicitly create a group sequence.

I have tried to test this theory by extending the https://github.com/hibernate/hibernate-validator/blob/master/hibernate-validator-archetype/src/test/java/com/example/GroupTest.java tests.

Unfortunately these tests are not behaving how I had expected them to based upon my understanding. If someone could please steer me in the right direction of what the intended functionality of GroupSequence is in a hierarchy, and more specifically explain Item C of Section 3.4.5 to me, I would greatly appreciate it.

The following our the unit test cases that I've added to test my theory on this item which may lend more information about how I understand the spec.
Code:
@Test
   public void testOrderedChecksFailsFast() {
      RentalCar rentalCar = new RentalCar("Morris", "DD-AB-123", 0);

      // This should not create a violation exception due to the 0 seat count failing first due to the GroupSequence on RentalCar
      rentalCar.setPassedVehicleInspection(false);

      Driver john = new Driver("John Doe");
      john.setAge(18);
      john.passedDrivingTest(true);
      rentalCar.setDriver(john);

      assertEquals(1, validator.validate(rentalCar).size());
      assertEquals(validator.validate(rentalCar).iterator().next()
            .getPropertyPath().toString(), "seatCount");

      rentalCar.setSeatCount(4);
      assertEquals(1, validator.validate(rentalCar).size());
      assertEquals(validator.validate(rentalCar).iterator().next()
            .getPropertyPath().toString(), "passedVehicleInspection");
   }
   
   @Test
   public void testSubclassesInheritGroupSequence() {
      //Our assertion here is based around Item C from Section 3.4.5 of the JSR 303 Validation Spec
      //that class X (MiniRentalCar) without explicitly defining a Default group would then inherit
      //it's superclasse's "Default" constraints along with  it's own attribute level constraints
      //not explicitly tied to a group other than Default.
      class MiniRentalCar extends RentalCar{
         public MiniRentalCar(String manufacturer, String licencePlate, int seatCount) {
            super( manufacturer, licencePlate, seatCount );
         }
      }
      
      MiniRentalCar miniRentalCar = new MiniRentalCar("Morris", "DD-AB-123", 0);

      // This should not create a violation exception due to the 0 seat count.
      miniRentalCar.setPassedVehicleInspection(false);

      Driver john = new Driver("John Doe");
      john.setAge(18);
      john.passedDrivingTest(true);
      miniRentalCar.setDriver(john);

      assertEquals(1, validator.validate(miniRentalCar).size());
      assertEquals(validator.validate(miniRentalCar).iterator().next()
            .getPropertyPath().toString(), "seatCount");

      miniRentalCar.setSeatCount(4);
      assertEquals(1, validator.validate(miniRentalCar).size());
      assertEquals(validator.validate(miniRentalCar).iterator().next()
            .getPropertyPath().toString(), "passedVehicleInspection");
   }
   
   @Test
   public void testExplicitGroupSequenceOnSubclass(){
      //With the testSubclassesInheritGroupSequence test failing, we then try
      //a similar test case whereby we explicitly set the Default group for this class.
      @GroupSequence({ AnotherMiniRentalCar.class, CarChecks.class })
      class AnotherMiniRentalCar extends RentalCar{
         public AnotherMiniRentalCar(String manufacturer, String licencePlate, int seatCount) {
            super( manufacturer, licencePlate, seatCount );
         }
      }
      
      AnotherMiniRentalCar anotherMiniRentalCar = new AnotherMiniRentalCar("Morris", "DD-AB-123", 0);

      // This should not create a violation exception due to the 0 seat count.
      anotherMiniRentalCar.setPassedVehicleInspection(false);

      Driver john = new Driver("John Doe");
      john.setAge(18);
      john.passedDrivingTest(true);
      anotherMiniRentalCar.setDriver(john);

      assertEquals(1, validator.validate(anotherMiniRentalCar).size());
      assertEquals(validator.validate(anotherMiniRentalCar).iterator().next()
            .getPropertyPath().toString(), "seatCount");

      anotherMiniRentalCar.setSeatCount(4);
      assertEquals(1, validator.validate(anotherMiniRentalCar).size());
      assertEquals(validator.validate(anotherMiniRentalCar).iterator().next()
            .getPropertyPath().toString(), "passedVehicleInspection");
   }


Top
 Profile  
 
 Post subject: Re: Hibernate Validator - @GroupSequence inheritance
PostPosted: Tue Mar 22, 2011 1:39 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I think you discovered a bug :-)
I created http://opensource.atlassian.com/project ... wse/HV-458. I found the root of the problem and have a local fix, but I need to clean it up first.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator - @GroupSequence inheritance
PostPosted: Wed Mar 23, 2011 9:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

could you try against the latest 4.2 SNAPSHOT? https://repository.jboss.org/nexus/cont ... -SNAPSHOT/


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.