|
| 1 | +/* |
| 2 | + * Hibernate Validator, declare and validate application constraints |
| 3 | + * |
| 4 | + * License: Apache License, Version 2.0 |
| 5 | + * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. |
| 6 | + */ |
| 7 | +package org.hibernate.validator.test.internal.engine.groups.sequence; |
| 8 | + |
| 9 | +import java.util.Set; |
| 10 | + |
| 11 | +import javax.validation.ConstraintViolation; |
| 12 | +import javax.validation.GroupSequence; |
| 13 | +import javax.validation.Valid; |
| 14 | +import javax.validation.Validator; |
| 15 | + |
| 16 | +import org.hibernate.validator.testutil.TestForIssue; |
| 17 | +import org.hibernate.validator.testutils.ValidatorUtil; |
| 18 | + |
| 19 | +import org.testng.Assert; |
| 20 | +import org.testng.annotations.Test; |
| 21 | + |
| 22 | +@TestForIssue(jiraKey = "HV-1692") |
| 23 | +public class SequenceOnObjectsWithCycles { |
| 24 | + |
| 25 | + @Test |
| 26 | + public void groupSequenceOfGroupSequences() { |
| 27 | + Validator validator = ValidatorUtil.getValidator(); |
| 28 | + |
| 29 | + YourAnnotatedBean yourEntity1 = new YourAnnotatedBean(); |
| 30 | + AnotherBean anotherBean = new AnotherBean(); |
| 31 | + anotherBean.setYourAnnotatedBean( yourEntity1 ); |
| 32 | + yourEntity1.setBean( anotherBean ); |
| 33 | + |
| 34 | + Set<ConstraintViolation<YourAnnotatedBean>> constraintViolations = validator.validate( yourEntity1 ); |
| 35 | + Assert.assertEquals( 0, constraintViolations.size() ); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + @GroupSequence({ AnotherBean.class, Magic.class }) |
| 40 | + public class AnotherBean { |
| 41 | + |
| 42 | + @Valid |
| 43 | + private YourAnnotatedBean yourAnnotatedBean; |
| 44 | + |
| 45 | + |
| 46 | + public void setYourAnnotatedBean(YourAnnotatedBean yourAnnotatedBean) { |
| 47 | + this.yourAnnotatedBean = yourAnnotatedBean; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + @GroupSequence({ YourAnnotatedBean.class, Magic.class }) |
| 52 | + public class YourAnnotatedBean { |
| 53 | + |
| 54 | + @Valid |
| 55 | + private AnotherBean bean; |
| 56 | + |
| 57 | + public void setBean(AnotherBean bean) { |
| 58 | + this.bean = bean; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public interface Magic { |
| 63 | + } |
| 64 | +} |
0 commit comments