-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-1831 Add a couple of examples illustrating various cases
- Loading branch information
Showing
9 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../hibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingCycles1Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* <p> | ||
* This is the most simple example. | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingCycles1Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
@Valid | ||
private Child child; | ||
} | ||
|
||
private static class Child { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
@Valid | ||
private Parent parent; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../hibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingCycles2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import java.util.List; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* <p> | ||
* Simple enough but this time the cascading annotation is in the container element. | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingCycles2Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
private List<@Valid Child> children; | ||
} | ||
|
||
private static class Child { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
@Valid | ||
private Parent parent; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../hibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingCycles3Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* <p> | ||
* Simple enough but this time the cascading annotation is deep in a container element. | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingCycles3Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
private Map<String, List<@Valid Child>> children; | ||
} | ||
|
||
private static class Child { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
@Valid | ||
private Parent parent; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../hibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingCycles4Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* <p> | ||
* Simple enough but this time the cascading annotation is deep in a container element with a bound. | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingCycles4Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
private Map<String, List<@Valid ? extends Child>> children; | ||
} | ||
|
||
private static class Child { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
@Valid | ||
private Parent parent; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../hibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingCycles5Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import java.util.List; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* <p> | ||
* This one is a bit more tricky: during the validation, when cascading, we take into account the runtime type to get | ||
* the metadata, not the declared type. | ||
* <p> | ||
* So even if you couldn't have a cycle with the declared type, when trying to find the cycles, we need to take into | ||
* consideration all the subclasses too. The good news is that we are in a closed world so we have them all passed | ||
* to our PredefinedScopedValidatorFactoryImpl! | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingCycles5Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
private List<@Valid ChildWithNoCycles> children; | ||
} | ||
|
||
private static class ChildWithNoCycles { | ||
|
||
@NotNull | ||
private String property; | ||
} | ||
|
||
private static class Child extends ChildWithNoCycles { | ||
|
||
@Valid | ||
private Parent parent; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingNoCycles1Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingNoCycles1Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
@Valid | ||
private Child child; | ||
} | ||
|
||
private static class Child { | ||
|
||
@NotNull | ||
private String property; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ibernate/validator/test/internal/engine/tracking/ProcessedBeansTrackingNoCycles2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.tracking; | ||
|
||
import java.util.List; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.Validator; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.hibernate.validator.testutils.ValidatorUtil; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This is not a real test, just an illustration. | ||
* | ||
* @author Guillaume Smet | ||
*/ | ||
public class ProcessedBeansTrackingNoCycles2Test { | ||
|
||
@Test | ||
public void testSerializeHibernateEmail() throws Exception { | ||
Validator validator = ValidatorUtil.getValidator(); | ||
|
||
validator.validate( new Parent() ); | ||
} | ||
|
||
private static class Parent { | ||
|
||
@NotNull | ||
private String property; | ||
|
||
private List<@Valid Child> children; | ||
} | ||
|
||
private static class Child { | ||
|
||
@NotNull | ||
private String property; | ||
} | ||
} |
Oops, something went wrong.