use of org.hibernate.validator.cfg.defs.NotEmptyDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testDefaultGroupSequenceProvider.
@Test
public void testDefaultGroupSequenceProvider() {
mapping.type(Marathon.class).defaultGroupSequenceProviderClass(MarathonDefaultGroupSequenceProvider.class).getter("name").constraint(new NotNullDef().groups(Foo.class)).getter("runners").constraint(new NotEmptyDef());
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Marathon marathon = new Marathon();
Set<ConstraintViolation<Marathon>> violations = validator.validate(marathon);
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
marathon.setName("Stockholm Marathon");
violations = validator.validate(marathon);
assertThat(violations).containsOnlyViolations(violationOf(NotEmpty.class).withMessage("must not be empty"));
}
use of org.hibernate.validator.cfg.defs.NotEmptyDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testDefaultGroupSequence.
@Test
public void testDefaultGroupSequence() {
mapping.type(Marathon.class).defaultGroupSequence(Foo.class, Marathon.class).getter("name").constraint(new NotNullDef().groups(Foo.class)).getter("runners").constraint(new NotEmptyDef());
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Marathon marathon = new Marathon();
Set<ConstraintViolation<Marathon>> violations = validator.validate(marathon);
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
marathon.setName("Stockholm Marathon");
violations = validator.validate(marathon);
assertThat(violations).containsOnlyViolations(violationOf(NotEmpty.class).withMessage("must not be empty"));
}
use of org.hibernate.validator.cfg.defs.NotEmptyDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testProgrammaticDefaultGroupSequenceAndDefaultGroupSequenceProviderDefinedOnSameClass.
@Test(expectedExceptions = GroupDefinitionException.class, expectedExceptionsMessageRegExp = "HV[0-9]*: Default group sequence and default group sequence provider cannot be defined at the same time.")
public void testProgrammaticDefaultGroupSequenceAndDefaultGroupSequenceProviderDefinedOnSameClass() {
mapping.type(Marathon.class).defaultGroupSequence(Foo.class, Marathon.class).defaultGroupSequenceProviderClass(MarathonDefaultGroupSequenceProvider.class).getter("name").constraint(new NotNullDef().groups(Foo.class)).getter("runners").constraint(new NotEmptyDef());
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
validator.validate(new Marathon());
}
use of org.hibernate.validator.cfg.defs.NotEmptyDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testDefaultGroupSequenceDefinedOnClassWithNoConstraints.
@Test(description = "HV-444")
public void testDefaultGroupSequenceDefinedOnClassWithNoConstraints() {
mapping.type(Marathon.class).getter("name").constraint(new NotNullDef().groups(Foo.class)).getter("runners").constraint(new NotEmptyDef()).type(ExtendedMarathon.class).defaultGroupSequence(Foo.class, ExtendedMarathon.class);
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
ExtendedMarathon extendedMarathon = new ExtendedMarathon();
Set<ConstraintViolation<ExtendedMarathon>> violations = validator.validate(extendedMarathon);
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
extendedMarathon.setName("Stockholm Marathon");
violations = validator.validate(extendedMarathon);
assertThat(violations).containsOnlyViolations(violationOf(NotEmpty.class).withMessage("must not be empty"));
}
Aggregations