Skip to content

Commit

Permalink
HV-1692 Change when beans are marked as processed
Browse files Browse the repository at this point in the history
- in case of redefined group sequences only the last group was marked as
processed while all other groups were ignored. Marking bean as processed
in the loop allows to catch all the groups in the sequence
  • Loading branch information
marko-bekhta authored and gsmet committed Feb 17, 2019
1 parent d1f6377 commit 29c257f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Expand Up @@ -453,6 +453,9 @@ private <U> void validateConstraintsForDefaultGroup(ValidationContext<?> validat
validationSuccessful = validateConstraintsForSingleDefaultGroupElement( validationContext, valueContext, validatedInterfaces, clazz,
metaConstraints, defaultSequenceMember );
}

validationContext.markCurrentBeanAsProcessed( valueContext );

if ( !validationSuccessful ) {
break;
}
Expand All @@ -464,10 +467,9 @@ private <U> void validateConstraintsForDefaultGroup(ValidationContext<?> validat
Set<MetaConstraint<?>> metaConstraints = hostingBeanMetaData.getDirectMetaConstraints();
validateConstraintsForSingleDefaultGroupElement( validationContext, valueContext, validatedInterfaces, clazz, metaConstraints,
Group.DEFAULT_GROUP );
validationContext.markCurrentBeanAsProcessed( valueContext );
}

validationContext.markCurrentBeanAsProcessed( valueContext );

// all constraints in the hierarchy has been validated, stop validation.
if ( defaultGroupSequenceIsRedefined ) {
break;
Expand Down
@@ -0,0 +1,64 @@
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.test.internal.engine.groups.sequence;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.GroupSequence;
import javax.validation.Valid;
import javax.validation.Validator;

import org.hibernate.validator.testutil.TestForIssue;
import org.hibernate.validator.testutils.ValidatorUtil;

import org.testng.Assert;
import org.testng.annotations.Test;

@TestForIssue(jiraKey = "HV-1692")
public class SequenceOnObjectsWithCycles {

@Test
public void groupSequenceOfGroupSequences() {
Validator validator = ValidatorUtil.getValidator();

YourAnnotatedBean yourEntity1 = new YourAnnotatedBean();
AnotherBean anotherBean = new AnotherBean();
anotherBean.setYourAnnotatedBean( yourEntity1 );
yourEntity1.setBean( anotherBean );

Set<ConstraintViolation<YourAnnotatedBean>> constraintViolations = validator.validate( yourEntity1 );
Assert.assertEquals( 0, constraintViolations.size() );

}

@GroupSequence({ AnotherBean.class, Magic.class })
public class AnotherBean {

@Valid
private YourAnnotatedBean yourAnnotatedBean;


public void setYourAnnotatedBean(YourAnnotatedBean yourAnnotatedBean) {
this.yourAnnotatedBean = yourAnnotatedBean;
}
}

@GroupSequence({ YourAnnotatedBean.class, Magic.class })
public class YourAnnotatedBean {

@Valid
private AnotherBean bean;

public void setBean(AnotherBean bean) {
this.bean = bean;
}
}

public interface Magic {
}
}

0 comments on commit 29c257f

Please sign in to comment.