use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ConstraintApiTest method constraintMapping.
@Test
public void constraintMapping() {
// tag::constraintMapping[]
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
ConstraintMapping constraintMapping = configuration.createConstraintMapping();
constraintMapping.type(Car.class).field("manufacturer").constraint(new NotNullDef()).field("licensePlate").ignoreAnnotations(true).constraint(new NotNullDef()).constraint(new SizeDef().min(2).max(14)).type(RentalCar.class).getter("rentalStation").constraint(new NotNullDef());
Validator validator = configuration.addMapping(constraintMapping).buildValidatorFactory().getValidator();
// end::constraintMapping[]
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ConstraintApiTest method executableConfiguration.
@Test
public void executableConfiguration() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
// tag::executableConfiguration[]
ConstraintMapping constraintMapping = configuration.createConstraintMapping();
constraintMapping.type(Car.class).constructor(String.class).parameter(0).constraint(new SizeDef().min(3).max(50)).returnValue().valid().method("drive", int.class).parameter(0).constraint(new MaxDef().value(75)).method("load", List.class, List.class).crossParameter().constraint(new GenericConstraintDef<>(LuggageCountMatchesPassengerCount.class).param("piecesOfLuggagePerPassenger", 2)).method("getDriver").returnValue().constraint(new NotNullDef()).valid();
// end::executableConfiguration[]
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ConstraintApiTest method cascaded.
@Test
public void cascaded() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
// tag::cascaded[]
ConstraintMapping constraintMapping = configuration.createConstraintMapping();
constraintMapping.type(Car.class).field("driver").constraint(new NotNullDef()).valid().convertGroup(Default.class).to(PersonDefault.class).field("partManufacturers").containerElementType(0).valid().containerElementType(1, 0).valid().type(Person.class).field("name").constraint(new NotNullDef().groups(PersonDefault.class));
// end::cascaded[]
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ConstraintApiTest method nestedContainerElementConstraint.
@Test
public void nestedContainerElementConstraint() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
// tag::nestedContainerElementConstraint[]
ConstraintMapping constraintMapping = configuration.createConstraintMapping();
constraintMapping.type(Car.class).field("manufacturer").constraint(new NotNullDef()).field("licensePlate").ignoreAnnotations(true).constraint(new NotNullDef()).constraint(new SizeDef().min(2).max(14)).field("partManufacturers").containerElementType(0).constraint(new NotNullDef()).containerElementType(1, 0).constraint(new NotNullDef()).type(RentalCar.class).getter("rentalStation").constraint(new NotNullDef());
// end::nestedContainerElementConstraint[]
}
use of org.hibernate.validator.cfg.defs.NotNullDef 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());
}
Aggregations