use of org.hibernate.validator.cfg.defs.AssertTrueDef in project hibernate-validator by hibernate.
the class MyConstraintMappingContributor method createConstraintMappings.
@Override
public void createConstraintMappings(ConstraintMappingBuilder builder) {
builder.addConstraintMapping().type(Marathon.class).getter("name").constraint(new NotNullDef()).field("numberOfHelpers").constraint(new MinDef().value(1));
builder.addConstraintMapping().type(Runner.class).field("paidEntryFee").constraint(new AssertTrueDef());
}
use of org.hibernate.validator.cfg.defs.AssertTrueDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testValidWithSeveralGroupConversions.
@Test
public void testValidWithSeveralGroupConversions() {
mapping.type(Marathon.class).getter("runners").valid().convertGroup(Default.class).to(Foo.class).convertGroup(Bar.class).to(Default.class).type(Runner.class).field("paidEntryFee").constraint(new AssertTrueDef().groups(Foo.class)).constraint(new AssertTrueDef().message("really, it must be true"));
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Marathon marathon = new Marathon();
marathon.setName("New York Marathon");
marathon.addRunner(new Runner());
Set<ConstraintViolation<Marathon>> violations = validator.validate(marathon, Default.class, Bar.class);
assertThat(violations).containsOnlyViolations(violationOf(AssertTrue.class).withMessage("must be true"), violationOf(AssertTrue.class).withMessage("really, it must be true"));
}
use of org.hibernate.validator.cfg.defs.AssertTrueDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testValid.
@Test
public void testValid() {
mapping.type(Marathon.class).getter("runners").valid().type(Runner.class).field("paidEntryFee").constraint(new AssertTrueDef());
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Marathon marathon = new Marathon();
marathon.setName("New York Marathon");
Set<ConstraintViolation<Marathon>> violations = validator.validate(marathon);
assertNoViolations(violations);
marathon.addRunner(new Runner());
violations = validator.validate(marathon);
assertThat(violations).containsOnlyViolations(violationOf(AssertTrue.class).withMessage("must be true"));
}
use of org.hibernate.validator.cfg.defs.AssertTrueDef in project hibernate-validator by hibernate.
the class ConstraintMappingTest method testValidWithGroupConversion.
@Test
public void testValidWithGroupConversion() {
mapping.type(Marathon.class).getter("runners").valid().convertGroup(Default.class).to(Foo.class).type(Runner.class).field("paidEntryFee").constraint(new AssertTrueDef().groups(Foo.class));
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Marathon marathon = new Marathon();
marathon.setName("New York Marathon");
marathon.addRunner(new Runner());
Set<ConstraintViolation<Marathon>> violations = validator.validate(marathon);
assertThat(violations).containsOnlyViolations(violationOf(AssertTrue.class).withMessage("must be true"));
}
Aggregations