author.setFirstName( "Gavin" );
author.setLastName( "King" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
assertCorrectPropertyPaths( constraintViolations, "title" );
book.setTitle( "Hibernate Persistence with JPA" );
book.setSubtitle( "Revised Edition of Hibernate in Action" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
assertCorrectNumberOfViolations( constraintViolations, 1 );
assertCorrectConstraintViolationMessages( constraintViolations, "size must be between 0 and 30" );
constraintViolation = constraintViolations.iterator().next();
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
assertCorrectPropertyPaths( constraintViolations, "subtitle" );
book.setSubtitle( "Revised Edition" );
author.setCompany( "JBoss a divison of RedHat" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
constraintViolation = constraintViolations.iterator().next();
assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
assertEquals( constraintViolation.getMessage(), "size must be between 0 and 20" );
assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
assertCorrectPropertyPaths( constraintViolations, "author.company" );
author.setCompany( "JBoss" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );