|
| 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.tracking; |
| 8 | + |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +import javax.validation.Valid; |
| 12 | +import javax.validation.Validator; |
| 13 | +import javax.validation.constraints.NotNull; |
| 14 | + |
| 15 | +import org.hibernate.validator.testutils.ValidatorUtil; |
| 16 | +import org.testng.annotations.Test; |
| 17 | + |
| 18 | +/** |
| 19 | + * This is not a real test, just an illustration. |
| 20 | + * <p> |
| 21 | + * This one is a bit more tricky: during the validation, when cascading, we take into account the runtime type to get |
| 22 | + * the metadata, not the declared type. |
| 23 | + * <p> |
| 24 | + * So even if you couldn't have a cycle with the declared type, when trying to find the cycles, we need to take into |
| 25 | + * consideration all the subclasses too. The good news is that we are in a closed world so we have them all passed |
| 26 | + * to our PredefinedScopedValidatorFactoryImpl! |
| 27 | + * |
| 28 | + * @author Guillaume Smet |
| 29 | + */ |
| 30 | +public class ProcessedBeansTrackingCycles5Test { |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testSerializeHibernateEmail() throws Exception { |
| 34 | + Validator validator = ValidatorUtil.getValidator(); |
| 35 | + |
| 36 | + validator.validate( new Parent() ); |
| 37 | + } |
| 38 | + |
| 39 | + private static class Parent { |
| 40 | + |
| 41 | + @NotNull |
| 42 | + private String property; |
| 43 | + |
| 44 | + private List<@Valid ChildWithNoCycles> children; |
| 45 | + } |
| 46 | + |
| 47 | + private static class ChildWithNoCycles { |
| 48 | + |
| 49 | + @NotNull |
| 50 | + private String property; |
| 51 | + } |
| 52 | + |
| 53 | + private static class Child extends ChildWithNoCycles { |
| 54 | + |
| 55 | + @Valid |
| 56 | + private Parent parent; |
| 57 | + } |
| 58 | +} |
0 commit comments